Make skip counting file size for existing mods

This commit is contained in:
2025-03-22 00:09:10 +01:00
parent 1bb8ed9084
commit 0384e8012e
2 changed files with 85 additions and 7 deletions

View File

@@ -394,9 +394,19 @@ class _ModManagerPageState extends State<ModManagerPage> {
], ],
), ),
const SizedBox(height: 24), const SizedBox(height: 24),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
ElevatedButton( ElevatedButton(
onPressed: _startLoadingMods, onPressed: _startLoadingMods,
child: const Text('Scan for Mods'), child: const Text('Full Scan'),
),
const SizedBox(width: 16),
ElevatedButton(
onPressed: _startQuickScan,
child: const Text('Quick Scan'),
),
],
), ),
], ],
), ),
@@ -526,8 +536,23 @@ class _ModManagerPageState extends State<ModManagerPage> {
// Reload button // Reload button
IconButton( IconButton(
icon: const Icon(Icons.refresh), icon: const Icon(Icons.refresh),
tooltip: 'Reload mods', tooltip: 'Reload all mods (full scan)',
onPressed: _startLoadingMods, onPressed: _startLoadingMods,
style: IconButton.styleFrom(
backgroundColor: Colors.blueGrey.shade800,
foregroundColor: Colors.white,
),
),
const SizedBox(width: 8),
// Scan New button
IconButton(
icon: const Icon(Icons.update),
tooltip: 'Quick scan (skip existing mods)',
onPressed: _startQuickScan,
style: IconButton.styleFrom(
backgroundColor: Colors.green.shade800,
foregroundColor: Colors.white,
),
), ),
const SizedBox(width: 8), const SizedBox(width: 8),
// Load Dependencies button // Load Dependencies button
@@ -1270,6 +1295,59 @@ class _ModManagerPageState extends State<ModManagerPage> {
loadMods(); loadMods();
} }
void _startQuickScan() {
setState(() {
_isLoading = true;
_statusMessage = 'Quick scanning for mods...';
_hasCycles = false;
_cycleInfo = null;
_incompatibleMods = [];
});
// Create an async function to load mods
Future<void> loadMods() async {
try {
// First load available mods with the quick option
await for (final mod in modManager.loadAvailable(skipExistingSizes: true)) {
// Update UI for each mod loaded
if (mounted) {
setState(() {
_statusMessage = 'Loaded mod: ${mod.name}';
});
}
}
// Then load active mods from config
await for (final mod in modManager.loadActive()) {
// Update UI as active mods are loaded
if (mounted) {
setState(() {
_statusMessage = 'Loading active mod: ${mod.name}';
});
}
}
// Update the UI with all loaded mods
if (mounted) {
_loadModsFromGlobalState();
setState(() {
_statusMessage = 'Quick scan complete: ${_availableMods.length} mods, ${_activeMods.length} active';
});
}
} catch (error) {
if (mounted) {
setState(() {
_isLoading = false;
_statusMessage = 'Error during quick scan: $error';
});
}
}
}
// Start the loading process
loadMods();
}
void _toggleModActive(Mod mod) { void _toggleModActive(Mod mod) {
// Cannot deactivate base game or expansions // Cannot deactivate base game or expansions
if ((mod.isBaseGame || mod.isExpansion) && mod.enabled) { if ((mod.isBaseGame || mod.isExpansion) && mod.enabled) {

View File

@@ -130,7 +130,7 @@ class ModList {
return newModlist; return newModlist;
} }
Stream<Mod> loadAvailable() async* { Stream<Mod> loadAvailable({bool skipExistingSizes = false}) async* {
final logger = Logger.instance; final logger = Logger.instance;
final stopwatch = Stopwatch()..start(); final stopwatch = Stopwatch()..start();
@@ -160,12 +160,12 @@ class ModList {
continue; continue;
} }
final mod = Mod.fromDirectory(modDir); final mod = Mod.fromDirectory(modDir, skipFileCount: skipExistingSizes);
logger.info('Loaded mod from directory: ${mod.name} (ID: ${mod.id})'); logger.info('Loaded mod from directory: ${mod.name} (ID: ${mod.id})');
if (mods.containsKey(mod.id)) { if (mods.containsKey(mod.id)) {
logger.warning( logger.warning(
'Mod $mod.id already exists in mods list, overwriting', 'Mod ${mod.id} already exists in mods list, overwriting',
); );
final existingMod = mods[mod.id]!; final existingMod = mods[mod.id]!;
mods[mod.id] = Mod( mods[mod.id] = Mod(