Skip to content

Commit c1be413

Browse files
authored
Added toggleable compression (#59)
* Added toggleable compression * Set default compression to false
1 parent 5f296ac commit c1be413

File tree

9 files changed

+44
-17
lines changed

9 files changed

+44
-17
lines changed

lib/arc/arc.dart

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -111,17 +111,21 @@ class Arc {
111111
return files;
112112
}
113113

114-
void _addMPQFile(String path, Uint8List data) {
114+
void _addMPQFile(String path, Uint8List data, bool compress) {
115115
final mpqArchive = handle as MPQArchive;
116116
final timestamp = DateTime.now().millisecondsSinceEpoch ~/ 1000;
117-
mpqArchive.createFile(path, timestamp, data.length, 0, 0)
118-
..write(data, data.length, MPQ_COMPRESSION_ZLIB)
117+
mpqArchive.createFile(path, timestamp, data.length, 0, compress ? MPQ_FILE_COMPRESS : 0)
118+
..write(data, data.length, compress ? MPQ_COMPRESSION_ZLIB : 0)
119119
..finish();
120120
}
121121

122-
void _addZipFile(String path, Uint8List data) {
122+
void _addZipFile(String path, Uint8List data, bool compress) {
123123
final archive = handle as Archive;
124-
archive.addFile(ArchiveFile(path, data.length, data));
124+
if(compress) {
125+
archive.addFile(ArchiveFile(path, data.length, data));
126+
} else {
127+
archive.addFile(ArchiveFile.noCompress(path, data.length, data));
128+
}
125129
}
126130

127131
void _closeMPQ() {
@@ -147,11 +151,11 @@ class Arc {
147151
}
148152
}
149153

150-
void addFile(String path, Uint8List data) {
154+
void addFile(String path, Uint8List data, { bool compress = false }) {
151155
if(handle is MPQArchive) {
152-
return _addMPQFile(path, data);
156+
return _addMPQFile(path, data, compress);
153157
} else {
154-
return _addZipFile(path, data);
158+
return _addZipFile(path, data, compress);
155159
}
156160
}
157161

lib/features/create/create_finish/create_finish_viewmodel.dart

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class CreateFinishViewModel with ChangeNotifier {
2828
bool isEphemeralBarExpanded = false;
2929
bool isGenerating = false;
3030
bool prependAlt = false;
31+
bool compressFiles = false;
3132
int totalFiles = 0;
3233
int filesProcessed = 0;
3334

@@ -46,6 +47,11 @@ class CreateFinishViewModel with ChangeNotifier {
4647
notifyListeners();
4748
}
4849

50+
Future<void> onToggleCompressFiles(bool newCompressFilesValue) async {
51+
compressFiles = newCompressFilesValue;
52+
notifyListeners();
53+
}
54+
4955
void reset() {
5056
currentState = AppState.none;
5157
totalFiles = 0;
@@ -166,7 +172,7 @@ class CreateFinishViewModel with ChangeNotifier {
166172

167173
isGenerating = true;
168174
notifyListeners();
169-
await createGenerationIsolate(entries, outputFile, prependAlt);
175+
await createGenerationIsolate(entries, outputFile, prependAlt, compressFiles);
170176
// await compute(generateOTR, Tuple2(entries, outputFile));
171177
isGenerating = false;
172178
notifyListeners();
@@ -176,11 +182,11 @@ class CreateFinishViewModel with ChangeNotifier {
176182
}
177183

178184
Future createGenerationIsolate(HashMap<String, StageEntry> entries,
179-
String outputFile, bool shouldPrependAlt) async {
185+
String outputFile, bool shouldPrependAlt, bool shouldCompress) async {
180186
final receivePort = ReceivePort();
181187
await Isolate.spawn(
182188
generateOTR,
183-
Tuple4(entries, outputFile, receivePort.sendPort, shouldPrependAlt),
189+
Tuple5(entries, outputFile, receivePort.sendPort, shouldPrependAlt, shouldCompress),
184190
onExit: receivePort.sendPort,
185191
onError: receivePort.sendPort,
186192
);
@@ -212,8 +218,9 @@ class CreateFinishViewModel with ChangeNotifier {
212218
}
213219
}
214220

215-
Future<void> generateOTR(Tuple4<HashMap<String, StageEntry>, String, SendPort, bool> params) async {
221+
Future<void> generateOTR(Tuple5<HashMap<String, StageEntry>, String, SendPort, bool, bool> params) async {
216222
try {
223+
final compress = params.item5;
217224
final arcFile = Arc(params.item2);
218225

219226
for (final entry in params.item1.entries) {
@@ -222,15 +229,15 @@ Future<void> generateOTR(Tuple4<HashMap<String, StageEntry>, String, SendPort, b
222229
final fileData = await file.readAsBytes();
223230
final fileName =
224231
"${entry.key}/${p.normalize(file.path).split("/").last}";
225-
arcFile.addFile(fileName, fileData);
232+
arcFile.addFile(fileName, fileData, compress: compress);
226233
params.item3.send(1);
227234
}
228235
} else if (entry.value is CustomSequencesEntry) {
229236
for (final pair in (entry.value as CustomSequencesEntry).pairs) {
230237
final sequence = await compute(Sequence.fromSeqFile, pair);
231238
final fileName = '${entry.key}/${sequence.path}';
232239
final data = sequence.build();
233-
arcFile.addFile(fileName, data);
240+
arcFile.addFile(fileName, data, compress: compress);
234241
params.item3.send(1);
235242
}
236243
} else if (entry.value is CustomTexturesEntry) {
@@ -248,7 +255,7 @@ Future<void> generateOTR(Tuple4<HashMap<String, StageEntry>, String, SendPort, b
248255
continue;
249256
}
250257

251-
arcFile.addFile(texture.item1, texture.item2!);
258+
arcFile.addFile(texture.item1, texture.item2!, compress: compress);
252259
}
253260
}
254261
}

lib/features/create/create_replace_textures/components/folder_content_view.dart

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ Widget FolderContent(
3333
style: ElevatedButton.styleFrom(minimumSize: const Size(100, 50)),
3434
child: Text(i18n.folderContentView_selectButton),)
3535
],),
36+
const SizedBox(height: 10),
3637
Row(children: [
3738
Switch(
3839
activeColor: Colors.blue,
@@ -43,6 +44,16 @@ Widget FolderContent(
4344
),
4445
Text(i18n.folderContentView_prependAltToggle),
4546
],),
47+
Row(children: [
48+
Switch(
49+
activeColor: Colors.blue,
50+
value: finishViewModel.compressFiles,
51+
onChanged: (value) {
52+
finishViewModel.onToggleCompressFiles(value);
53+
},
54+
),
55+
Text(i18n.folderContentView_compressToggle),
56+
],),
4657
if (viewModel.processedFiles.isEmpty && viewModel.isProcessing == false)
4758
const Spacer(),
4859
if (viewModel.processedFiles.isNotEmpty || viewModel.isProcessing)

lib/l10n/app_de.arb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"otrContentView_processing": "Verarbeite...",
2727
"folderContentView_customTexturePath": "Benutzeridentifizierter Austausch-Texturen Ordner",
2828
"folderContentView_prependAltToggle": "Füge einen `alt/` Dies ermöglicht es den Spielern, Assets im Spiel zu aktivieren oder zu deaktivieren.",
29+
"folderContentView_compressToggle": "Dateien komprimieren. Dadurch wird die Größe der OTR / O2R reduziert.",
2930
"folderContentView_selectButton": "Wähle",
3031
"folderContentView_stageTextures": "Texturen indexieren",
3132
"createCustomSequences_addCustomSequences": "Füge benutzeridentifizierte Sequenzen hinzu",

lib/l10n/app_en.arb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"otrContentView_processing": "Processing...",
2727
"folderContentView_customTexturePath": "Custom Texture Replacements Folder",
2828
"folderContentView_prependAltToggle": "Prepend `alt/`. This will allow players to toggle these assets on-the-fly in game.",
29+
"folderContentView_compressToggle": "Compress Files. This will reduce the size of the OTR / O2R.",
2930
"folderContentView_selectButton": "Select",
3031
"folderContentView_stageTextures": "Stage Textures",
3132
"createCustomSequences_addCustomSequences": "Add Custom Sequences",

lib/l10n/app_es.arb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"otrContentView_processing": "Procesando...",
2727
"folderContentView_customTexturePath": "Carpeta de reemplazos de texturas personalizadas",
2828
"folderContentView_prependAltToggle": "Agregar en `alt/`. Esto permitirá a los jugadores cambiar los recursos durante el juego.",
29+
"folderContentView_compressToggle": "Comprimir archivos, esto puede reducir el tamaño del OTR / O2R",
2930
"folderContentView_selectButton": "Seleccionar",
3031
"folderContentView_stageTextures": "Agregar texturas",
3132
"createCustomSequences_addCustomSequences": "Agregar secuencias personalizadas",

lib/l10n/app_fr.arb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"otrContentView_processing": "Traitement en cours...",
2727
"folderContentView_customTexturePath": "Dossier de remplacements de textures personnalisées",
2828
"folderContentView_prependAltToggle": "Ajouter un dossier `alt/` à votre OTR / O2R. Permet aux joueurs d'activer ou désactiver les assets en jeu.",
29+
"folderContentView_compressToggle": "Compresser les fichiers. Cela réduira la taille de l'OTR / O2R.",
2930
"folderContentView_selectButton": "Sélectionner",
3031
"folderContentView_stageTextures": "Indexer les textures",
3132
"createCustomSequences_addCustomSequences": "Ajouter des séquences personnalisées",

lib/l10n/app_nl.arb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
"otrContentView_step5": "5. We genereren een OTR / O2R met de gewijzigde textures! 🚀",
2626
"otrContentView_processing": "Verwerken...",
2727
"folderContentView_customTexturePath": "Vervangende Texture Map",
28-
"folderContentView_prependAltToggle": "Prepend `alt/`. This will allow players to toggle these assets on-the-fly in game.",
28+
"folderContentView_prependAltToggle": "Voeg 'alt/' toe aan het begin. Dit stelt spelers in staat om deze assets tijdens het spel direct aan en uit te zetten.",
29+
"folderContentView_compressToggle": "Bestanden comprimeren. Dit zal de grootte van de OTR / O2R verkleinen.",
2930
"folderContentView_selectButton": "Selecteer",
3031
"folderContentView_stageTextures": "Stage-Textures",
3132
"createCustomSequences_addCustomSequences": "Voeg aangepaste composities toe",

lib/ui/components/ephemeral_bar.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ class _EphemeralBarState extends State<EphemeralBar>
9595
child: Row(
9696
mainAxisAlignment: MainAxisAlignment.end,
9797
children: [
98-
Text('Retro: 0.1.0', style: textTheme.bodyMedium!.copyWith(
98+
Text('Retro: 0.1.1', style: textTheme.bodyMedium!.copyWith(
9999
color: colorScheme.onSurface,),
100100
),
101101
if (!isExpanded)

0 commit comments

Comments
 (0)