Skip to content

Commit

Permalink
Merge pull request #31 from KizKizz/backend-rework
Browse files Browse the repository at this point in the history
applied list improv
  • Loading branch information
KizKizz committed Jul 19, 2022
2 parents 85a9f0f + 4d68d9d commit a129619
Show file tree
Hide file tree
Showing 5 changed files with 120 additions and 63 deletions.
7 changes: 4 additions & 3 deletions app_version_check/app_version.json
Original file line number Diff line number Diff line change
@@ -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": ""
Expand Down
71 changes: 21 additions & 50 deletions lib/file_functions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -135,37 +135,19 @@ Future<void> modsToDataAdder(List<ModFile> modList) async {
//check for dub applied mod
//set backup path to file
modFile.backupIcePath = '$backupDirPath$s${modFile.iceName}';
// for (var lists in modFilesList) {
// List<ModFile> 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));
// }
}
}
}
Expand Down Expand Up @@ -226,33 +208,19 @@ Future<void> modsToDataAdder(List<ModFile> modList) async {
//check for dub applied mod
//set backup path to file
modFile.backupIcePath = '$backupDirPath$s${modFile.iceName}';
// for (var lists in modFilesList) {
// List<ModFile> 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);
// }
}
}
}
Expand Down Expand Up @@ -298,12 +266,15 @@ Future<void> modsToDataAdder(List<ModFile> 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)));
}

Expand Down Expand Up @@ -348,10 +319,10 @@ void modsRemover(List<ModFile> 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);
}
}
Expand Down
88 changes: 81 additions & 7 deletions lib/home_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ List<ModFile> modAppliedDup = [];
List<ModFile> originalFilesMissingList = [];
List<ModFile> backupFilesMissingList = [];
List<bool> isLoading = [];
List<bool> isLoadingAppliedList = [];
bool isModAddFolderOnly = true;
bool isViewingFav = false;
bool isSearching = false;
Expand Down Expand Up @@ -348,7 +349,7 @@ class _HomePageState extends State<HomePage> with TickerProviderStateMixin {
default:
}
}

isModSelected = false;
modsViewAppBarName = 'Available Mods';
isRefreshing = true;
Expand Down Expand Up @@ -2174,7 +2175,7 @@ class _HomePageState extends State<HomePage> with TickerProviderStateMixin {
child: MaterialButton(
onPressed: (() {
setState(() {
modsRemover(modFilesList[index].toList());
modsRemover(modFilesList[index].where((element) => element.isApplied).toList());
});
}),
child: Icon(
Expand All @@ -2198,7 +2199,7 @@ class _HomePageState extends State<HomePage> 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
Expand Down Expand Up @@ -2833,7 +2834,7 @@ class _HomePageState extends State<HomePage> 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) {
Expand Down Expand Up @@ -2898,7 +2899,7 @@ class _HomePageState extends State<HomePage> with TickerProviderStateMixin {
tempDelete.add(mod);
}
}
modsRemover(tempDelete);
modsRemover(tempDelete.where((element) => element.isApplied).toList());
isPreviewImgsOn = false;
isPreviewVidOn = false;
totalAppliedFiles = 0;
Expand Down Expand Up @@ -2933,6 +2934,9 @@ class _HomePageState extends State<HomePage> 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),
Expand Down Expand Up @@ -3012,9 +3016,79 @@ class _HomePageState extends State<HomePage> 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,
Expand All @@ -3029,7 +3103,7 @@ class _HomePageState extends State<HomePage> with TickerProviderStateMixin {
setState(() {
isPreviewImgsOn = false;
isPreviewVidOn = false;
modsRemover(appliedModsList[index].toList());
modsRemover(appliedModsList[index].where((element) => element.isApplied).toList());
});
}),
child: Icon(
Expand All @@ -3040,7 +3114,7 @@ class _HomePageState extends State<HomePage> with TickerProviderStateMixin {
),
),
],
)
),
],
),
children: [
Expand Down
13 changes: 12 additions & 1 deletion lib/mods_loader.dart
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,18 @@ Future<List<List<ModFile>>> getModFilesByCategory(List<ModFile> allModFiles, Str
Future<List<List<ModFile>>> getAppliedModsList() async {
List<List<ModFile>> appliedList = [];
//Applied mods list add
final actualAppliedMods = allModFiles.where((element) => element.isApplied == true).toList();
List<ModFile> actualAppliedMods = allModFiles.where((element) => element.isApplied == true).toList();
List<String> 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) {
Expand Down
4 changes: 2 additions & 2 deletions windows/runner/Runner.rc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a129619

Please sign in to comment.