From 34aef033bd38eb5f3d4b4e4afdf14eecab7a7f59 Mon Sep 17 00:00:00 2001 From: Denis Solonenko Date: Mon, 1 Jan 2024 21:14:44 +1100 Subject: [PATCH] Option to only show gamelist.xml roms --- lib/data/games.dart | 34 ++++++++++++++++++---------------- lib/data/repo.dart | 6 +++++- lib/pages/settings/ui.dart | 9 ++++++--- 3 files changed, 29 insertions(+), 20 deletions(-) diff --git a/lib/data/games.dart b/lib/data/games.dart index 2b7fbc3..737c2b7 100644 --- a/lib/data/games.dart +++ b/lib/data/games.dart @@ -43,6 +43,9 @@ Future> allGames(AllGamesRef ref) async { final detectedSystems = await ref.watch(detectedSystemsProvider.future); final romFolders = await ref.watch(romFoldersProvider.future); + final settings = await ref.read(settingsProvider.future); + final onlyGamelistRoms = settings.showOnlyGamelistRoms; + final allGames = []; if (detectedSystems.isEmpty) { @@ -56,7 +59,8 @@ Future> allGames(AllGamesRef ref) async { for (var system in detectedSystems) { for (var romsFolder in romFolders) { for (var folder in system.folders) { - final task = IsolatedWorker().run(_processFolder, GamelistTaskParams(romsFolder, folder, system)); + final task = + IsolatedWorker().run(_processFolder, GamelistTaskParams(romsFolder, folder, system, onlyGamelistRoms)); tasks.add(task); } } @@ -68,7 +72,7 @@ Future> allGames(AllGamesRef ref) async { } } finally { stopwatch.stop(); - debugPrint("Games fetching took ${stopwatch.elapsedMilliseconds}ms"); + debugPrint("Games fetching took ${stopwatch.elapsedMilliseconds}ms. onlyGamelistRoms=$onlyGamelistRoms"); } return allGames; @@ -78,8 +82,9 @@ class GamelistTaskParams { final String romsFolder; final String folder; final System system; + final bool onlyGamelistRoms; - GamelistTaskParams(this.romsFolder, this.folder, this.system); + GamelistTaskParams(this.romsFolder, this.folder, this.system, this.onlyGamelistRoms); } Future> _processFolder(GamelistTaskParams params) async { @@ -89,11 +94,13 @@ Future> _processFolder(GamelistTaskParams params) async { if (!pathExists) { return []; } - final gamesFromFiles = await listGamesFromFiles( - romsFolder: params.romsFolder, - folder: params.folder, - system: params.system, - ); + final List gamesFromFiles = params.onlyGamelistRoms + ? [] + : await listGamesFromFiles( + romsFolder: params.romsFolder, + folder: params.folder, + system: params.system, + ); final file = File("$romsPath/gamelist.xml"); final exists = await file.exists(); if (exists) { @@ -107,6 +114,9 @@ Future> _processFolder(GamelistTaskParams params) async { .expand((nodes) => nodes) .map((node) => Game.fromXmlNode(node, params.system, params.romsFolder, params.folder)) .toList(); + if (params.onlyGamelistRoms) { + return gamesFromGamelistXml; + } final romsMap = {for (var rom in gamesFromGamelistXml) rom.absoluteRomPath: rom}; final List games = []; for (var g in gamesFromFiles) { @@ -141,14 +151,6 @@ Future games(GamesRef ref, String systemId) async { allGames.removeWhere((game) => game.hidden); } - if (settings.checkMissingGames) { - Stopwatch stopwatch = Stopwatch()..start(); - allGames.retainWhere((game) => - game.isFolder ? Directory(game.absoluteRomPath).existsSync() : File(game.absoluteRomPath).existsSync()); - stopwatch.stop(); - debugPrint("checkMissingGames took ${stopwatch.elapsedMilliseconds}ms"); - } - switch (system.id) { case "favourites": compare(Game a, Game b) => a.name.compareTo(b.name); diff --git a/lib/data/repo.dart b/lib/data/repo.dart index 8dc736c..3adb7f6 100644 --- a/lib/data/repo.dart +++ b/lib/data/repo.dart @@ -18,7 +18,7 @@ class Settings { bool get favouritesOnTop => _getBoolean('favouritesOnTop', false); bool get showHiddenGames => _getBoolean('showHiddenGames', false); - bool get checkMissingGames => _getBoolean('checkMissingGames', false); + bool get showOnlyGamelistRoms => _getBoolean('showOnlyGamelistRoms', false); bool get uniqueGamesInCollections => _getBoolean('uniqueGamesInCollections', false); bool get compactGameList => _getBoolean('compactGameList', false); bool get showGameVideos => _getBoolean('showGameVideos', false); @@ -138,6 +138,10 @@ class SettingsRepo { return _setBoolean('checkMissingGames', value); } + Future setShowOnlyGamelistRoms(bool value) async { + return _setBoolean('showOnlyGamelistRoms', value); + } + Future setUniqueGamesInCollections(bool value) async { return _setBoolean('uniqueGamesInCollections', value); } diff --git a/lib/pages/settings/ui.dart b/lib/pages/settings/ui.dart index 28592af..ceac354 100644 --- a/lib/pages/settings/ui.dart +++ b/lib/pages/settings/ui.dart @@ -38,8 +38,9 @@ class UISettingsPage extends HookConsumerWidget { true, (p0, p1) => p0.setUniqueGamesInCollections(p1)), _setting(ref, selectedSetting, 'Show Hidden Games', settings.showHiddenGames, true, (p0, p1) => p0.setShowHiddenGames(p1)), - _setting(ref, selectedSetting, 'Check Missing games', settings.checkMissingGames, true, - (p0, p1) => p0.setCheckMissingGames(p1)), + _setting(ref, selectedSetting, 'Only Show Roms From gamelist.xml Files', settings.showOnlyGamelistRoms, + true, (p0, p1) => p0.setShowOnlyGamelistRoms(p1), + subtitle: 'Please refresh gamelists'), _setting(ref, selectedSetting, 'Show Game Videos', settings.showGameVideos, true, (p0, p1) => p0.setShowGameVideos(p1)), _setting(ref, selectedSetting, 'Fade Screenshot To Video', settings.fadeToVideo, settings.showGameVideos, @@ -60,7 +61,8 @@ class UISettingsPage extends HookConsumerWidget { } Widget _setting(WidgetRef ref, ValueNotifier selectedSetting, String title, bool value, bool enabled, - Future Function(SettingsRepo, bool) onChanged) { + Future Function(SettingsRepo, bool) onChanged, + {String? subtitle}) { return ListTile( enabled: enabled, autofocus: title == selectedSetting.value, @@ -74,6 +76,7 @@ class UISettingsPage extends HookConsumerWidget { onChanged(repo, !value).then((value) => ref.refresh(settingsProvider)); }, title: Text(title), + subtitle: subtitle != null ? Text(subtitle) : null, trailing: value ? toggleOnIcon : toggleOffIcon, ); }