Skip to content

Commit

Permalink
Option to only show gamelist.xml roms
Browse files Browse the repository at this point in the history
  • Loading branch information
dsolonenko committed Jan 1, 2024
1 parent 2e6623b commit 34aef03
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 20 deletions.
34 changes: 18 additions & 16 deletions lib/data/games.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ Future<List<Game>> 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 = <Game>[];

if (detectedSystems.isEmpty) {
Expand All @@ -56,7 +59,8 @@ Future<List<Game>> 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);
}
}
Expand All @@ -68,7 +72,7 @@ Future<List<Game>> 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;
Expand All @@ -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<List<Game>> _processFolder(GamelistTaskParams params) async {
Expand All @@ -89,11 +94,13 @@ Future<List<Game>> _processFolder(GamelistTaskParams params) async {
if (!pathExists) {
return [];
}
final gamesFromFiles = await listGamesFromFiles(
romsFolder: params.romsFolder,
folder: params.folder,
system: params.system,
);
final List<Game> 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) {
Expand All @@ -107,6 +114,9 @@ Future<List<Game>> _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<Game> games = [];
for (var g in gamesFromFiles) {
Expand Down Expand Up @@ -141,14 +151,6 @@ Future<GameList> 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);
Expand Down
6 changes: 5 additions & 1 deletion lib/data/repo.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -138,6 +138,10 @@ class SettingsRepo {
return _setBoolean('checkMissingGames', value);
}

Future<void> setShowOnlyGamelistRoms(bool value) async {
return _setBoolean('showOnlyGamelistRoms', value);
}

Future<void> setUniqueGamesInCollections(bool value) async {
return _setBoolean('uniqueGamesInCollections', value);
}
Expand Down
9 changes: 6 additions & 3 deletions lib/pages/settings/ui.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -60,7 +61,8 @@ class UISettingsPage extends HookConsumerWidget {
}

Widget _setting(WidgetRef ref, ValueNotifier<String> selectedSetting, String title, bool value, bool enabled,
Future<void> Function(SettingsRepo, bool) onChanged) {
Future<void> Function(SettingsRepo, bool) onChanged,
{String? subtitle}) {
return ListTile(
enabled: enabled,
autofocus: title == selectedSetting.value,
Expand All @@ -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,
);
}
Expand Down

0 comments on commit 34aef03

Please sign in to comment.