diff --git a/app_version_check/app_version.json b/app_version_check/app_version.json index 1b9350f3..4303e294 100644 --- a/app_version_check/app_version.json +++ b/app_version_check/app_version.json @@ -1,9 +1,10 @@ { "name": "PSO2NGS Mod Manager", - "version": "1.4.3", + "version": "1.4.4", "description": [ - "Fixed a bug when applying duplicated mods - part 3", - "Minor bug fixes" + "Applied List improvement", + " - Keep track of duplicated files instead of removing them from list", + " - Reapply mods directly from applied list (For duplicate mods that have different number of ices)" ], "windows_file": "", "linux_file": "" diff --git a/lib/file_functions.dart b/lib/file_functions.dart index 255b306c..96edf650 100644 --- a/lib/file_functions.dart +++ b/lib/file_functions.dart @@ -135,37 +135,19 @@ Future modsToDataAdder(List modList) async { //check for dub applied mod //set backup path to file modFile.backupIcePath = '$backupDirPath$s${modFile.iceName}'; - // for (var lists in modFilesList) { - // List matchingList = lists.where((element) => element.iceName == modFile.iceName && element.isApplied == true).toList(); - // if (matchingList.isNotEmpty) { - // duplicateModsApplied.add(matchingList); - - // if (appliedModsList.isNotEmpty) { - // for (var mod in matchingList) { - // for (var appliedList in appliedModsList) { - // appliedList.firstWhere((element) => element.iceName == mod.iceName).isApplied = false; - // appliedList.remove(mod); - // } - // mod.isApplied = false; - // mod.appliedDate = ''; - // } - // appliedModsList.removeWhere((element) => element.isEmpty); - // } - // } - // } - // } for (var file in allModFiles) { if (file.iceName == modFile.iceName && file.isApplied) { duplicateModsApplied.add([file]); - if (appliedModsList.isNotEmpty) { - for (var appliedList in appliedModsList) { - appliedList.remove(file); - } + // if (appliedModsList.isNotEmpty) { + // // for (var appliedList in appliedModsList) { + // // //appliedList.remove(file); + // // } - appliedModsList.removeWhere((element) => element.isEmpty); - } + // appliedModsList.removeWhere((element) => element.isEmpty); + // appliedModsList.removeWhere((element) => element.every((file) => file.isApplied == false)); + // } } } } @@ -226,33 +208,19 @@ Future modsToDataAdder(List modList) async { //check for dub applied mod //set backup path to file modFile.backupIcePath = '$backupDirPath$s${modFile.iceName}'; - // for (var lists in modFilesList) { - // List matchingList = lists.where((element) => (element.iceName == modFile.iceName) && element.isApplied == true).toList(); - // if (matchingList.isNotEmpty) { - // duplicateModsApplied.add(matchingList); - - // if (appliedModsList.isNotEmpty) { - // for (var mod in matchingList) { - // for (var appliedList in appliedModsList) { - // appliedList.remove(mod); - // } - // } - // appliedModsList.removeWhere((element) => element.isEmpty); - // } - // } - // } for (var file in allModFiles) { if (file.iceName == modFile.iceName && file.isApplied) { duplicateModsApplied.add([file]); - if (appliedModsList.isNotEmpty) { - for (var appliedList in appliedModsList) { - appliedList.remove(file); - } - - appliedModsList.removeWhere((element) => element.isEmpty); - } + // if (appliedModsList.isNotEmpty) { + // for (var appliedList in appliedModsList) { + // //appliedList.remove(file); + // appliedList.firstWhere((element) => element.iceName == file.iceName).isApplied = false; + // } + // appliedModsList.removeWhere((element) => element.every((file) => file.isApplied == false)); + // appliedModsList.removeWhere((element) => element.isEmpty); + // } } } } @@ -298,12 +266,15 @@ Future modsToDataAdder(List modList) async { }, ); if (tempMods.isNotEmpty) { - tempMods.add(mod); + if (tempMods.indexWhere((element) => element.iceName == mod.iceName) == -1) { + tempMods.add(mod); + } } else { mod.appliedDate = formattedDate; appliedModsList.insert(0, [mod]); } } + appliedModsList.removeWhere((element) => element.every((file) => file.isApplied == false)); //appliedModsList.sort(((a, b) => a.first.appliedDate.compareTo(b.first.appliedDate))); } @@ -348,10 +319,10 @@ void modsRemover(List modsList) { tempMod = appliedMod; } } - if (tempList.isNotEmpty && tempMod != null) { + if (tempList.isNotEmpty && tempMod != null && tempMod.isApplied) { tempList.remove(tempMod); } - if (appliedList.isEmpty) { + if (appliedList.isEmpty || appliedList.indexWhere((element) => element.isApplied) == -1) { emptyList.add(appliedList); } } diff --git a/lib/home_page.dart b/lib/home_page.dart index 489afe4d..2c193bbd 100644 --- a/lib/home_page.dart +++ b/lib/home_page.dart @@ -34,6 +34,7 @@ List modAppliedDup = []; List originalFilesMissingList = []; List backupFilesMissingList = []; List isLoading = []; +List isLoadingAppliedList = []; bool isModAddFolderOnly = true; bool isViewingFav = false; bool isSearching = false; @@ -348,7 +349,7 @@ class _HomePageState extends State with TickerProviderStateMixin { default: } } - + isModSelected = false; modsViewAppBarName = 'Available Mods'; isRefreshing = true; @@ -2174,7 +2175,7 @@ class _HomePageState extends State with TickerProviderStateMixin { child: MaterialButton( onPressed: (() { setState(() { - modsRemover(modFilesList[index].toList()); + modsRemover(modFilesList[index].where((element) => element.isApplied).toList()); }); }), child: Icon( @@ -2198,7 +2199,7 @@ class _HomePageState extends State with TickerProviderStateMixin { onPressed: (() { setState(() { isLoading[index] = true; - modsToDataAdder(modFilesList[index]).then((_) { + modsToDataAdder(modFilesList[index].where((element) => element.isApplied == false).toList()).then((_) { setState(() { isLoading[index] = false; //Messages @@ -2833,7 +2834,7 @@ class _HomePageState extends State with TickerProviderStateMixin { setState(() { reappliedCount = appliedModsList.length; for (var modList in appliedModsList) { - reapplyMods(modList).then((_) { + reapplyMods(modList.where((element) => element.isApplied).toList()).then((_) { setState(() { reappliedCount--; if (reappliedCount == 0) { @@ -2898,7 +2899,7 @@ class _HomePageState extends State with TickerProviderStateMixin { tempDelete.add(mod); } } - modsRemover(tempDelete); + modsRemover(tempDelete.where((element) => element.isApplied).toList()); isPreviewImgsOn = false; isPreviewVidOn = false; totalAppliedFiles = 0; @@ -2933,6 +2934,9 @@ class _HomePageState extends State with TickerProviderStateMixin { return const Text('Error'); } else { appliedModsList = snapshot.data; + //if (isLoadingAppliedList.isEmpty) { + isLoadingAppliedList = List.generate(appliedModsList.length, (index) => false); + //} //print(snapshot.data); return SingleChildScrollView( controller: AdjustableScrollController(80), @@ -3012,9 +3016,79 @@ class _HomePageState extends State with TickerProviderStateMixin { Text(appliedModsList[index].first.iceParent.trimLeft()), ], )), + + //loading && add + if (isLoadingAppliedList[index]) + const SizedBox( + width: 40, + height: 40, + child: CircularProgressIndicator(), + ), //if (appliedModsList[index].length > 1) Row( children: [ + if (appliedModsList[index].indexWhere((element) => element.isApplied == false) != -1 && !isLoadingAppliedList[index]) + SizedBox( + width: 40, + height: 40, + child: Tooltip( + message: 'Apply unapplied mods under ${appliedModsList[index].first.iceParent} to the game', + height: 25, + textStyle: TextStyle(fontSize: 15, color: Theme.of(context).canvasColor), + waitDuration: const Duration(seconds: 1), + child: MaterialButton( + onPressed: (() { + setState(() { + isLoadingAppliedList[index] = true; + modsToDataAdder(appliedModsList[index].where((element) => element.isApplied == false).toList()).then((_) { + setState(() { + isLoadingAppliedList[index] = false; + //Messages + if (originalFilesMissingList.isNotEmpty) { + ScaffoldMessenger.of(context).showSnackBar(SnackBar( + duration: const Duration(seconds: 2), + //backgroundColor: Theme.of(context).focusColor, + content: SizedBox( + height: originalFilesMissingList.length * 20, + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + for (int i = 0; i < originalFilesMissingList.length; i++) + Text( + 'Original file of "${originalFilesMissingList[i].modName} ${originalFilesMissingList[i].iceParent} > ${originalFilesMissingList[i].iceName}" is not found'), + ], + ), + ))); + } + + if (modAppliedDup.isNotEmpty) { + ScaffoldMessenger.of(context).showSnackBar(SnackBar( + duration: Duration(seconds: modAppliedDup.length), + //backgroundColor: Theme.of(context).focusColor, + content: SizedBox( + height: modAppliedDup.length * 20, + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + for (int i = 0; i < modAppliedDup.length; i++) + Text( + 'Replaced: ${modAppliedDup[i].categoryName} > ${modAppliedDup[i].modName} ${modAppliedDup[i].iceParent} > ${modAppliedDup[i].iceName}'), + ], + ), + ))); + modAppliedDup.clear(); + } + }); + }); + }); + }), + child: Icon( + Icons.playlist_add, + color: MyApp.themeNotifier.value == ThemeMode.light ? Theme.of(context).primaryColor : Theme.of(context).iconTheme.color, + ), + ), + ), + ), if (appliedModsList.indexWhere((element) => element.indexWhere((e) => e.isApplied == true) != -1) != -1) SizedBox( width: 40, @@ -3029,7 +3103,7 @@ class _HomePageState extends State with TickerProviderStateMixin { setState(() { isPreviewImgsOn = false; isPreviewVidOn = false; - modsRemover(appliedModsList[index].toList()); + modsRemover(appliedModsList[index].where((element) => element.isApplied).toList()); }); }), child: Icon( @@ -3040,7 +3114,7 @@ class _HomePageState extends State with TickerProviderStateMixin { ), ), ], - ) + ), ], ), children: [ diff --git a/lib/mods_loader.dart b/lib/mods_loader.dart index 10304a1e..e72e91c8 100644 --- a/lib/mods_loader.dart +++ b/lib/mods_loader.dart @@ -412,7 +412,18 @@ Future>> getModFilesByCategory(List allModFiles, Str Future>> getAppliedModsList() async { List> appliedList = []; //Applied mods list add - final actualAppliedMods = allModFiles.where((element) => element.isApplied == true).toList(); + List actualAppliedMods = allModFiles.where((element) => element.isApplied == true).toList(); + List parentPathsList = []; + + for (var file in actualAppliedMods) { + if (parentPathsList.indexWhere((element) => element == file.icePath.replaceFirst(file.iceName, '')) == -1) { + parentPathsList.add(file.icePath.replaceFirst(file.iceName, '')); + } + } + + for (var path in parentPathsList) { + actualAppliedMods.addAll(allModFiles.where((element) => element.icePath.replaceFirst(element.iceName, '') == path && element.isApplied == false).toList()); + } //Applied mods list add for (var mod in actualAppliedMods) { diff --git a/windows/runner/Runner.rc b/windows/runner/Runner.rc index 56a9b27b..70da4a11 100644 --- a/windows/runner/Runner.rc +++ b/windows/runner/Runner.rc @@ -63,13 +63,13 @@ IDI_APP_ICON ICON "resources\\app_icon.ico" #ifdef FLUTTER_BUILD_NUMBER #define VERSION_AS_NUMBER FLUTTER_BUILD_NUMBER #else -#define VERSION_AS_NUMBER 1,4,3 +#define VERSION_AS_NUMBER 1,4,4 #endif #ifdef FLUTTER_BUILD_NAME #define VERSION_AS_STRING #FLUTTER_BUILD_NAME #else -#define VERSION_AS_STRING "1.4.3" +#define VERSION_AS_STRING "1.4.4" #endif VS_VERSION_INFO VERSIONINFO