From 0384e8012e45aa177fda50716666954680a85a48 Mon Sep 17 00:00:00 2001 From: PhatPhuckDave Date: Sat, 22 Mar 2025 00:09:10 +0100 Subject: [PATCH] Make skip counting file size for existing mods --- lib/main.dart | 86 ++++++++++++++++++++++++++++++++++++++++++++--- lib/mod_list.dart | 6 ++-- 2 files changed, 85 insertions(+), 7 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index a4122c9..6f4361d 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -394,9 +394,19 @@ class _ModManagerPageState extends State { ], ), const SizedBox(height: 24), - ElevatedButton( - onPressed: _startLoadingMods, - child: const Text('Scan for Mods'), + Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + ElevatedButton( + onPressed: _startLoadingMods, + 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 { // Reload button IconButton( icon: const Icon(Icons.refresh), - tooltip: 'Reload mods', + tooltip: 'Reload all mods (full scan)', 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), // Load Dependencies button @@ -1270,6 +1295,59 @@ class _ModManagerPageState extends State { loadMods(); } + void _startQuickScan() { + setState(() { + _isLoading = true; + _statusMessage = 'Quick scanning for mods...'; + _hasCycles = false; + _cycleInfo = null; + _incompatibleMods = []; + }); + + // Create an async function to load mods + Future 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) { // Cannot deactivate base game or expansions if ((mod.isBaseGame || mod.isExpansion) && mod.enabled) { diff --git a/lib/mod_list.dart b/lib/mod_list.dart index 34e058f..9cbe852 100644 --- a/lib/mod_list.dart +++ b/lib/mod_list.dart @@ -130,7 +130,7 @@ class ModList { return newModlist; } - Stream loadAvailable() async* { + Stream loadAvailable({bool skipExistingSizes = false}) async* { final logger = Logger.instance; final stopwatch = Stopwatch()..start(); @@ -160,12 +160,12 @@ class ModList { continue; } - final mod = Mod.fromDirectory(modDir); + final mod = Mod.fromDirectory(modDir, skipFileCount: skipExistingSizes); logger.info('Loaded mod from directory: ${mod.name} (ID: ${mod.id})'); if (mods.containsKey(mod.id)) { 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]!; mods[mod.id] = Mod(