Skip to content

Commit

Permalink
added dat repack overwrite option
Browse files Browse the repository at this point in the history
  • Loading branch information
ArthurHeitmann committed Sep 1, 2024
1 parent b21dda7 commit 77e5cf0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
9 changes: 9 additions & 0 deletions lib/stateManagement/hierarchy/types/DatHierarchyEntry.dart
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ class DatHierarchyEntry extends ExtractableHierarchyEntry {
await exportDat(extractedPath, checkForNesting: true);
}

Future<void> repackOverwriteDatAction() async {
await exportDat(extractedPath, overwriteOriginal: true);
}

@override
List<HierarchyEntryAction> getActions() {
var scriptRelatedClasses = [RubyScriptGroupHierarchyEntry, RubyScriptHierarchyEntry, XmlScriptHierarchyEntry, PakHierarchyEntry];
Expand All @@ -118,6 +122,11 @@ class DatHierarchyEntry extends ExtractableHierarchyEntry {
icon: Icons.file_upload,
action: repackDatAction,
),
HierarchyEntryAction(
name: "Repack DAT (overwrite)",
icon: Icons.file_upload,
action: repackOverwriteDatAction,
),
HierarchyEntryAction(
name: "Change packed files",
icon: Icons.folder_open,
Expand Down
7 changes: 5 additions & 2 deletions lib/utils/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ Future<List<String>> _getDatFileListFromMetadata(String metadataPath) async {
return files;
}

Future<void> exportDat(String datFolder, { bool checkForNesting = false }) async {
Future<void> exportDat(String datFolder, { bool checkForNesting = false, bool overwriteOriginal = false }) async {
var exportDir = PreferencesData().dataExportPath?.value ?? "";
if (exportDir.isNotEmpty && !await Directory(exportDir).exists()) {
messageLog.add("Export path does not exist: $exportDir");
Expand All @@ -556,7 +556,10 @@ Future<void> exportDat(String datFolder, { bool checkForNesting = false }) async
String datExportDir = "";
bool recursive = false;
// check if this DAT is inside another DAT
if (checkForNesting) {
if (overwriteOriginal) {
datExportDir = dirname(dirname(datFolder));
}
if (checkForNesting && datExportDir.isEmpty) {
var parentDirs = [dirname(datFolder), dirname(dirname(datFolder))];
for (var parentDir in parentDirs) {
if (!await Directory(parentDir).exists())
Expand Down

0 comments on commit 77e5cf0

Please sign in to comment.