Skip to content

Commit

Permalink
Merge pull request #9 from KizKizz/backend-rework
Browse files Browse the repository at this point in the history
Added reapply all
  • Loading branch information
KizKizz committed Jun 27, 2022
2 parents bd95482 + 6ad8701 commit 269e425
Show file tree
Hide file tree
Showing 3 changed files with 148 additions and 3 deletions.
83 changes: 82 additions & 1 deletion lib/file_functions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,87 @@ import 'package:path/path.dart' as p;
Directory dataDir = Directory('$binDirPath\\data');
List<File> iceFiles = [];

Future<void> reapplyMods(List<ModFile> modList) async {
//Checksum
if (checkSumFilePath != null) {
File(checkSumFilePath!).copySync('$binDirPath\\data\\win32\\${checkSumFilePath!.split('\\').last}');
}

if (modList.length > 1) {
for (var modFile in modList) {
await Future(
() {
//Backup file check and apply
final matchedFile = iceFiles.firstWhere(
(e) => e.path.split('\\').last == modFile.iceName,
orElse: () {
return File('');
},
);

if (matchedFile.path != '') {
modFile.originalIcePath = matchedFile.path;
final matchedBackup = Directory(backupDirPath).listSync(recursive: true).whereType<File>().firstWhere(
(e) => p.extension(e.path) == '' && e.path.split('\\').last == modFile.iceName,
orElse: () {
return File('');
},
);

if (matchedBackup.path == '') {
modFile.backupIcePath = '$backupDirPath\\${modFile.iceName}';
//Backup file if not already
File(modFile.originalIcePath).copySync(modFile.backupIcePath);
}

//File actions
File(modFile.icePath).copySync(modFile.originalIcePath);
} else {
originalFilesMissingList.add(modFile);
}
},
);
}
} else {
for (var modFile in modList) {
//Backup file check and apply
final matchedFile = iceFiles.firstWhere(
(e) => e.path.split('\\').last == modFile.iceName,
orElse: () {
return File('');
},
);

if (matchedFile.path != '') {
modFile.originalIcePath = matchedFile.path;
final matchedBackup = Directory(backupDirPath).listSync(recursive: true).whereType<File>().firstWhere(
(e) => p.extension(e.path) == '' && e.path.split('\\').last == modFile.iceName,
orElse: () {
return File('');
},
);

if (matchedBackup.path == '') {
modFile.backupIcePath = '$backupDirPath\\${modFile.iceName}';
//Backup file if not already
File(modFile.originalIcePath).copySync(modFile.backupIcePath);
}

//File actions
File(modFile.icePath).copySync(modFile.originalIcePath);
DateTime now = DateTime.now();
String formattedDate = DateFormat('MM-dd-yyyy HH:mm:ss').format(now);
modFile.appliedDate = formattedDate;
} else {
originalFilesMissingList.add(modFile);
}
}
}

allModFiles.map((mod) => mod.toJson()).toList();
File(modSettingsPath).writeAsStringSync(json.encode(allModFiles));
}

Future<void> modsToDataAdder(List<ModFile> modList) async {
List<List<ModFile>> duplicateModsApplied = [];
List<ModFile> actualAppliedMods = [];
Expand Down Expand Up @@ -157,7 +238,7 @@ Future<void> modsToDataAdder(List<ModFile> modList) async {
//Applied mods to app list
for (var mod in actualAppliedMods) {
DateTime now = DateTime.now();
String formattedDate = DateFormat('MM-dd-yyyy').format(now);
String formattedDate = DateFormat('MM-dd-yyyy HH:mm:ss').format(now);
if (appliedModsList.isEmpty) {
mod.appliedDate = formattedDate;
appliedModsList.insert(0, [mod]);
Expand Down
64 changes: 64 additions & 0 deletions lib/home_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ class _HomePageState extends State<HomePage> with TickerProviderStateMixin {
bool modViewExpandAll = false;
bool isErrorInSingleItemName = false;
double searchBoxLeftPadding = 80;
int reappliedCount = 0;

late AnimationController cateAdderAniController;
late Animation<Offset> cateAdderAniOffset;
Expand Down Expand Up @@ -2492,6 +2493,7 @@ class _HomePageState extends State<HomePage> with TickerProviderStateMixin {
totalAppliedFiles += item.length;
}
}


return Column(
children: [
Expand Down Expand Up @@ -2520,6 +2522,68 @@ class _HomePageState extends State<HomePage> with TickerProviderStateMixin {
fontSize: 13,
))),
),
SizedBox(
width: 40,
height: 40,
child: Tooltip(
message: 'Hold to reapply all mods to the game',
height: 25,
textStyle: TextStyle(fontSize: 15, color: Theme.of(context).canvasColor),
waitDuration: const Duration(seconds: 1),
child: MaterialButton(
onLongPress: appliedModsList.isEmpty || totalAppliedItems < 1
? null
: (() {
setState(() {
reappliedCount = appliedModsList.length;
for (var modList in appliedModsList) {
reapplyMods(modList).then((_) {
setState(() {
reappliedCount--;
if (reappliedCount == 0) {
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'),
],
),
)));
}
originalFilesMissingList.clear();
const Text('Done');
}
});
});
}
});
}),
onPressed: appliedModsList.isEmpty || totalAppliedItems < 1 ? null : () {},
child: Row(
children: [
if (reappliedCount > 0)
const SizedBox(width: 20, height: 20, child: CircularProgressIndicator()),
if (reappliedCount < 1)
Icon(
Icons.add_to_queue,
color: totalAppliedItems < 1
? Theme.of(context).disabledColor
: MyApp.themeNotifier.value == ThemeMode.light
? Theme.of(context).primaryColorDark
: Theme.of(context).iconTheme.color,
),
],
),
),
),
),
SizedBox(
width: 40,
height: 40,
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,1,2
#define VERSION_AS_NUMBER 1,1,3
#endif

#ifdef FLUTTER_BUILD_NAME
#define VERSION_AS_STRING #FLUTTER_BUILD_NAME
#else
#define VERSION_AS_STRING "1.1.2"
#define VERSION_AS_STRING "1.1.3"
#endif

VS_VERSION_INFO VERSIONINFO
Expand Down

0 comments on commit 269e425

Please sign in to comment.