forked from AM2R-Community-Developers/Atomic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ModPacker.cs
681 lines (572 loc) · 27.7 KB
/
ModPacker.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.IO.Compression;
using System.Security.Cryptography;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Diagnostics;
using Microsoft.WindowsAPICodePack.Dialogs;
using System.Text.RegularExpressions;
namespace AM2R_ModPacker
{
public partial class ModPacker : Form
{
private static readonly string VERSION = "2.0.3";
private static readonly string ORIGINAL_MD5 = "f2b84fe5ba64cb64e284be1066ca08ee";
private bool isOriginalLoaded, isModLoaded, isApkLoaded, isLinuxLoaded, isMacLoaded;
private string localPath, originalPath, modPath, apkPath, linuxPath, macPath;
private static readonly string[] DATAFILES_BLACKLIST = { "data.win", "AM2R.exe", "D3DX9_43.dll", "game.unx", "game.ios" };
private static string saveFilePath = null;
private ModProfileXML profile;
public ModPacker()
{
InitializeComponent();
profile = new ModProfileXML("", 1, "", "", "", false, "", false, false, ""); // (1, "", "", false, "default", false, false);
isOriginalLoaded = false;
isModLoaded = false;
isApkLoaded = false;
isLinuxLoaded = false;
isMacLoaded = false;
localPath = Directory.GetCurrentDirectory();
originalPath = "";
modPath = "";
linuxPath = "";
apkPath = "";
macPath = "";
Text = "AM2R ModPacker " + VERSION;
}
#region WinForms events
private void OriginalButton_Click(object sender, EventArgs e)
{
// Open window to select AM2R 1.1
(isOriginalLoaded, originalPath) = SelectFile("Please select AM2R_11.zip", "zip", "zip files (*.zip)|*.zip");
OriginalLabel.Visible = isOriginalLoaded;
UpdateCreateButton();
}
private void ModButton_Click(object sender, EventArgs e)
{
// Open window to select modded AM2R
(isModLoaded, modPath) = SelectFile("Please select your custom AM2R .zip", "zip", "zip files (*.zip)|*.zip");
ModLabel.Visible = isModLoaded;
UpdateCreateButton();
}
private void CreateButton_Click(object sender, EventArgs e)
{
if (NameTextBox.Text == "" || AuthorTextBox.Text == "" || versionTextBox.Text == "")
{
MessageBox.Show("Text field missing! Mod packaging aborted.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (Path.GetInvalidFileNameChars().Any(NameTextBox.Text.Contains))
{
MessageBox.Show("Name contains invalid characters! These characters are not allowed:\n" + string.Join("\n", Path.GetInvalidFileNameChars()));
return;
}
CreateLabel.Visible = true;
CreateLabel.Text = "Packaging mod(s)... This could take a while!";
string output;
using (SaveFileDialog saveFile = new SaveFileDialog { RestoreDirectory = true, Title = "Save Windows mod profile", Filter = "zip files (*.zip)|*.zip", AddExtension = true })
{
if (saveFile.ShowDialog() == DialogResult.OK)
{
output = saveFile.FileName;
}
else
{
CreateLabel.Text = "Mod packaging aborted!";
return;
}
}
CreateModPack("Windows", modPath, output);
if (linuxCheckBox.Checked)
{
using (SaveFileDialog saveFile = new SaveFileDialog { RestoreDirectory = true, Title = "Save Linux mod profile", Filter = "zip files (*.zip)|*.zip", AddExtension = true })
{
if (saveFile.ShowDialog() == DialogResult.OK)
{
output = saveFile.FileName;
}
else
{
CreateLabel.Text = "Mod packaging aborted!";
return;
}
}
CreateModPack("Linux", linuxPath, output);
}
if (macCheckBox.Checked)
{
using (SaveFileDialog saveFile = new SaveFileDialog { RestoreDirectory = true, Title = "Save Mac mod profile", Filter = "zip files (*.zip)|*.zip", AddExtension = true })
{
if (saveFile.ShowDialog() == DialogResult.OK)
{
output = saveFile.FileName;
}
else
{
CreateLabel.Text = "Mod packaging aborted!";
return;
}
}
CreateModPack("Mac", macPath, output);
}
CreateLabel.Text = "Mod package(s) created!";
}
private void CreateModPack(string operatingSystem, string input, string output)
{
LoadProfileParameters(operatingSystem);
// Cleanup in case of previous errors
if (Directory.Exists(Path.GetTempPath() + "\\AM2RModPacker"))
{
Directory.Delete(Path.GetTempPath() + "\\AM2RModPacker", true);
}
// Create temp work folders
string tempPath = "",
tempOriginalPath = "",
tempModPath = "",
tempProfilePath = "";
// We might not have permission to access to the temp directory, so we need to catch the exception.
try
{
tempPath = Directory.CreateDirectory(Path.GetTempPath() + "\\AM2RModPacker").FullName;
tempOriginalPath = Directory.CreateDirectory(tempPath + "\\original").FullName;
tempModPath = Directory.CreateDirectory(tempPath + "\\mod").FullName;
tempProfilePath = Directory.CreateDirectory(tempPath + "\\profile").FullName;
}
catch (System.Security.SecurityException)
{
MessageBox.Show("Could not create temp directory! Please run the application with administrator rights.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
AbortPatch();
return;
}
// Extract 1.1 and modded AM2R to their own directories in temp work
ZipFile.ExtractToDirectory(originalPath, tempOriginalPath);
ZipFile.ExtractToDirectory(input, tempModPath);
if (Directory.Exists(tempModPath + "\\AM2R"))
tempModPath += "\\AM2R";
// Verify 1.1 with an MD5. If it does not match, exit cleanly and provide a warning window.
try
{
string newMD5 = CalculateMD5(tempOriginalPath + "\\data.win");
if (newMD5 != ORIGINAL_MD5)
{
// Show error box
MessageBox.Show("1.1 data.win does not meet MD5 checksum! Mod packaging aborted.\n1.1 MD5: " + ORIGINAL_MD5 + "\nYour MD5: " + newMD5, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
AbortPatch();
return;
}
}
catch (FileNotFoundException)
{
// Show error message
MessageBox.Show("data.win not found! Are you sure you selected AM2R 1.1? Mod packaging aborted.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
AbortPatch();
return;
}
// Create AM2R.exe and data.win patches
if (profile.OperatingSystem == "Windows")
{
if (!File.Exists(tempModPath + "/AM2R.exe"))
{
var result = MessageBox.Show("Modded game not found, make sure it's not placed in any subfolders.\nCreated profile will likely not be installable, are you sure you want to continue?", "WARNING", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
if (result != DialogResult.Yes)
AbortPatch();
}
if (File.Exists(tempModPath + "profile.xml"))
{
var result = MessageBox.Show("profile.xml found. This file is used by the AM2RLauncher to determine profile stats and its inclusion may make the profile uninstallable. Are you sure you want to continue?", "WARNING", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
if (result != DialogResult.Yes)
AbortPatch();
}
if (profile.UsesYYC)
{
CreatePatch(tempOriginalPath + "\\data.win", tempModPath + "\\AM2R.exe", tempProfilePath + "\\AM2R.xdelta");
}
else
{
CreatePatch(tempOriginalPath + "\\data.win", tempModPath + "\\data.win", tempProfilePath + "\\data.xdelta");
CreatePatch(tempOriginalPath + "\\AM2R.exe", tempModPath + "\\AM2R.exe", tempProfilePath + "\\AM2R.xdelta");
}
}
else if (profile.OperatingSystem == "Linux")
{
string runnerName = File.Exists(tempModPath + "\\" + "AM2R") ? "AM2R" : "runner";
if (!File.Exists(tempModPath + "/" + runnerName))
{
var result = MessageBox.Show("Modded Linux game not found, make sure it's not placed in any subfolders.\nCreated profile will likely not be installable, are you sure you want to continue?", "WARNING", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
if (result != DialogResult.Yes)
AbortPatch();
}
if (File.Exists(tempModPath + "profile.xml"))
{
var result = MessageBox.Show("profile.xml found. This file is used by the AM2RLauncher to determine profile stats and its inclusion may make the profile uninstallable. Are you sure you want to continue?", "WARNING", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
if (result != DialogResult.Yes)
AbortPatch();
}
CreatePatch(tempOriginalPath + "\\data.win", tempModPath + "\\assets\\game.unx", tempProfilePath + "\\game.xdelta");
CreatePatch(tempOriginalPath + "\\AM2R.exe", tempModPath + "\\" + runnerName, tempProfilePath + "\\AM2R.xdelta");
}
else if (profile.OperatingSystem == "Mac")
{
if (!File.Exists(tempModPath + "/AM2R.app/Contents/MacOS/Mac_Runner"))
{
var result = MessageBox.Show("Modded Mac game not found, make sure it's not placed in any subfolders.\nCreated profile will likely not be installable, are you sure you want to continue?", "WARNING", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
if (result != DialogResult.Yes)
AbortPatch();
}
if (File.Exists(tempModPath + "profile.xml"))
{
var result = MessageBox.Show("profile.xml found. This file is used by the AM2RLauncher to determine profile stats and its inclusion may make the profile uninstallable. Are you sure you want to continue?", "WARNING", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
if (result != DialogResult.Yes)
AbortPatch();
}
CreatePatch(tempOriginalPath + "\\data.win", tempModPath + "\\AM2R.app\\Contents\\Resources\\game.ios", tempProfilePath + "\\game.xdelta");
CreatePatch(tempOriginalPath + "\\AM2R.exe", tempModPath + "\\AM2R.app\\Contents\\MacOS\\Mac_Runner", tempProfilePath + "\\AM2R.xdelta");
// Copy plist over for custom title name
File.Copy(tempModPath + "\\AM2R.app\\Contents\\Info.plist", tempProfilePath + "\\Info.plist");
}
// Create game.droid patch and wrapper if Android is supported
if (profile.Android)
{
string tempAndroid = Directory.CreateDirectory(tempPath + "\\android").FullName;
// Extract APK
// - java -jar apktool.jar d "%~dp0AM2RWrapper_old.apk"
// Process startInfo
ProcessStartInfo procStartInfo = new ProcessStartInfo
{
FileName = "cmd.exe",
WorkingDirectory = tempAndroid,
Arguments = "/C java -jar \"" + localPath + "\\utilities\\android\\apktool.jar\" d -f -o \"" + tempAndroid + "\" \"" + apkPath + "\"",
UseShellExecute = false,
CreateNoWindow = true
};
// Run process
using (Process proc = new Process { StartInfo = procStartInfo })
{
proc.Start();
proc.WaitForExit();
}
// Create game.droid patch
CreatePatch(tempOriginalPath + "\\data.win", tempAndroid + "\\assets\\game.droid", tempProfilePath + "\\droid.xdelta");
// Delete excess files in APK
// Create whitelist
string[] whitelist = { "splash.png", "portrait_splash.png" };
// Get directory
DirectoryInfo androidAssets = new DirectoryInfo(tempAndroid + "\\assets");
// Delete files
foreach (FileInfo file in androidAssets.GetFiles())
{
if (file.Name.EndsWith(".ini") && file.Name != "modifiers.ini")
{
if (File.Exists(tempProfilePath + "\\AM2R.ini"))
{
// This shouldn't be a problem... normally...
File.Delete(tempProfilePath + "\\AM2R.ini");
}
File.Copy(file.FullName, tempProfilePath + "\\AM2R.ini");
}
if (!whitelist.Contains(file.Name))
{
File.Delete(file.FullName);
}
}
foreach (DirectoryInfo dir in androidAssets.GetDirectories())
{
Directory.Delete(dir.FullName, true);
}
// Create wrapper
// Process startInfo
// - java -jar apktool.jar b "%~dp0AM2RWrapper_old" -o "%~dp0AM2RWrapper.apk"
ProcessStartInfo procStartInfo2 = new ProcessStartInfo
{
FileName = "cmd.exe",
WorkingDirectory = tempAndroid,
Arguments = "/C java -jar \"" + localPath + "\\utilities\\android\\apktool.jar\" b -f \"" + tempAndroid + "\" -o \"" + tempProfilePath + "\\AM2RWrapper.apk\"",
UseShellExecute = false,
CreateNoWindow = true
};
// Run process
using (Process proc = new Process { StartInfo = procStartInfo2 })
{
proc.Start();
proc.WaitForExit();
}
string tempAndroidProfilePath = tempProfilePath + "\\android";
Directory.CreateDirectory(tempAndroidProfilePath);
File.Move(tempProfilePath + "\\AM2RWrapper.apk", tempAndroidProfilePath + "\\AM2RWrapper.apk");
if (File.Exists(tempProfilePath + "\\AM2R.ini"))
File.Move(tempProfilePath + "\\AM2R.ini", tempAndroidProfilePath + "\\AM2R.ini");
}
// Copy datafiles (exclude .ogg if custom music is not selected)
DirectoryInfo dinfo = new DirectoryInfo(tempModPath);
if (profile.OperatingSystem == "Linux")
dinfo = new DirectoryInfo(tempModPath + "\\assets");
else if (profile.OperatingSystem == "Mac")
dinfo = new DirectoryInfo(tempModPath + "\\AM2R.app\\Contents\\Resources");
Directory.CreateDirectory(tempProfilePath + "\\files_to_copy");
if (profile.UsesCustomMusic)
{
// Copy files, excluding the blacklist
CopyFilesRecursive(dinfo, DATAFILES_BLACKLIST, tempProfilePath + "\\files_to_copy");
}
else
{
// Get list of 1.1's music files
string[] musFiles = Directory.GetFiles(tempOriginalPath, "*.ogg").Select(file => Path.GetFileName(file)).ToArray();
if (profile.OperatingSystem == "Linux" || profile.OperatingSystem == "Mac")
musFiles = Directory.GetFiles(tempOriginalPath, "*.ogg").Select(file => Path.GetFileName(file).ToLower()).ToArray();
// Combine musFiles with the known datafiles for a blacklist
string[] blacklist = musFiles.Concat(DATAFILES_BLACKLIST).ToArray();
// Copy files, excluding the blacklist
CopyFilesRecursive(dinfo, blacklist, tempProfilePath + "\\files_to_copy");
}
// Export profile as XML
string xmlOutput = Serializer.Serialize<ModProfileXML>(profile);
File.WriteAllText(tempProfilePath + "\\profile.xml", xmlOutput);
// Compress temp folder to .zip
if (File.Exists(output))
{
File.Delete(output);
}
ZipFile.CreateFromDirectory(tempProfilePath, output);
// Delete temp folder
Directory.Delete(tempPath, true);
}
private void ApkButton_Click(object sender, EventArgs e)
{
// Open window to select modded AM2R APK
(isApkLoaded, apkPath) = SelectFile("Please select your custom AM2R .apk", "apk", "android application packages (*.apk)|*.apk");
ApkLabel.Visible = isApkLoaded;
UpdateCreateButton();
}
private void AndroidCheckBox_CheckedChanged(object sender, EventArgs e)
{
ApkButton.Enabled = AndroidCheckBox.Checked;
UpdateCreateButton();
}
private void SaveCheckBox_CheckedChanged(object sender, EventArgs e)
{
winSaveButton.Enabled = SaveCheckBox.Checked;
saveTextBox.Enabled = SaveCheckBox.Checked;
UpdateCreateButton();
}
#endregion
private void LoadProfileParameters(string operatingSystem)
{
profile.Name = NameTextBox.Text;
profile.Author = AuthorTextBox.Text;
profile.Version = versionTextBox.Text;
profile.UsesCustomMusic = MusicCheckBox.Checked;
profile.UsesYYC = YYCCheckBox.Checked;
profile.Android = AndroidCheckBox.Checked;
profile.ProfileNotes = modNotesTextBox.Text;
profile.OperatingSystem = operatingSystem;
if (SaveCheckBox.Checked && saveTextBox.Text != "")
{
profile.SaveLocation = saveTextBox.Text;
}
else
{
profile.SaveLocation = "%localappdata%/AM2R";
}
if (operatingSystem == "Linux")
{
profile.SaveLocation = profile.SaveLocation.Replace("%localappdata%", "~/.config");
}
else if (operatingSystem == "Mac")
{
if (profile.SaveLocation.Contains("%localappdata%/AM2R"))
profile.SaveLocation = profile.SaveLocation.Replace("%localappdata%/AM2R", "~/Library/Application Support/com.yoyogames.am2r");
else
profile.SaveLocation = "~/Library/Application Support/com.yoyogames." + new DirectoryInfo(profile.SaveLocation).Name.ToLower();
}
}
private void AbortPatch()
{
// Unload files
isOriginalLoaded = false;
isModLoaded = false;
isApkLoaded = false;
isLinuxLoaded = false;
originalPath = "";
modPath = "";
apkPath = "";
linuxPath = "";
saveFilePath = null;
// Set labels
CreateLabel.Text = "Mod packaging aborted!";
OriginalLabel.Visible = false;
ModLabel.Visible = false;
ApkLabel.Visible = false;
linuxLabel.Visible = false;
// Remove temp directory
if (Directory.Exists(Path.GetTempPath() + "\\AM2RModPacker"))
{
Directory.Delete(Path.GetTempPath() + "\\AM2RModPacker", true);
}
}
private void linuxCheckBox_CheckedChanged(object sender, EventArgs e)
{
linuxButton.Enabled = linuxCheckBox.Checked;
UpdateCreateButton();
}
private void YYCCheckBox_CheckedChanged(object sender, EventArgs e)
{
if (YYCCheckBox.Checked)
{
macCheckBox.Checked = false;
macLabel.Visible = false;
macPath = "";
}
}
private void macCheckBox_CheckedChanged(object sender, EventArgs e)
{
if (!YYCCheckBox.Checked)
{
macButton.Enabled = macCheckBox.Checked;
UpdateCreateButton();
}
else if (macCheckBox.Checked)
{
MessageBox.Show("YoYoCompiler isn't supported with Mac!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
macCheckBox.Checked = false;
}
}
private void macButton_Click(object sender, EventArgs e)
{
// Open window to select modded Mac .zip
(isMacLoaded, macPath) = SelectFile("Please select your custom Mac AM2R .zip", "zip", "zip archives (*.zip)|*.zip");
macLabel.Visible = isMacLoaded;
UpdateCreateButton();
}
private void linuxButton_Click(object sender, EventArgs e)
{
// Open window to select modded Linux .zip
(isLinuxLoaded, linuxPath) = SelectFile("Please select your custom Linux AM2R .zip", "zip", "zip archives (*.zip)|*.zip");
linuxLabel.Visible = isLinuxLoaded;
UpdateCreateButton();
}
private void CustomSaveDataButton_Click(object sender, EventArgs e)
{
bool wasSuccessfull = false;
Regex saveRegex = new Regex(@"C:\\Users\\.*\\AppData\\Local\\"); //this is to ensure, that the save directory is valid. so far, this is only important for windows
// we either use this nuget package. Or we choose a very bad native solution. Went for nuget instead.
CommonOpenFileDialog dialog = new CommonOpenFileDialog();
dialog.InitialDirectory = Environment.GetEnvironmentVariable("LocalAppData");
dialog.IsFolderPicker = true;
while (!wasSuccessfull)
{
if (dialog.ShowDialog() == CommonFileDialogResult.Ok)
{
Match match = saveRegex.Match(dialog.FileName);
if (match.Success == false)
MessageBox.Show("Invalid Save Directory! Please choose one in %LocalAppData%");
else
{
wasSuccessfull = true;
saveFilePath = dialog.FileName.Replace(match.Value, "%localappdata%/");
saveFilePath = saveFilePath.Replace("\\", "/"); // if we don't do this, custom save locations are going to fail on Linux
// if someone has a custom save path inside of am2r and creates these whithin game maker, they will always be lower case
// we need to adjust them here to lowercase as well, as otherwise launcher gets problems on nix systems
string vanillaPrefix = "%localappdata%/AM2R/";
if (saveFilePath.Contains(vanillaPrefix))
saveFilePath = vanillaPrefix + saveFilePath.Substring(vanillaPrefix.Length).ToLower();
}
}
else
{
wasSuccessfull = true;
saveFilePath = null;
}
}
saveTextBox.Text = saveFilePath;
}
private void CopyFilesRecursive(DirectoryInfo source, string[] blacklist, string destination)
{
foreach (FileInfo file in source.GetFiles())
{
if (!blacklist.Contains(file.Name))
{
file.CopyTo(destination + "\\" + file.Name);
}
}
foreach (DirectoryInfo dir in source.GetDirectories())
{
// Folders need to be lowercase, because GM only reads from lowercase names on *nix systems. Windows is case-insensitive so doesnt matter for them
string newDir = Directory.CreateDirectory(destination + "\\" + dir.Name.ToLower()).FullName;
CopyFilesRecursive(dir, blacklist, newDir);
}
}
private void UpdateCreateButton()
{
if (isOriginalLoaded &&
isModLoaded &&
(!AndroidCheckBox.Checked || isApkLoaded) &&
(!linuxCheckBox.Checked || isLinuxLoaded) &&
(!macCheckBox.Checked || isMacLoaded) &&
(!SaveCheckBox.Checked || saveTextBox.Text != ""))
{
CreateButton.Enabled = true;
}
else
{
CreateButton.Enabled = false;
}
}
// Thanks, stackoverflow: https://stackoverflow.com/questions/10520048/calculate-md5-checksum-for-a-file
private string CalculateMD5(string filename)
{
using (var stream = File.OpenRead(filename))
{
using (var md5 = MD5.Create())
{
var hash = md5.ComputeHash(stream);
return BitConverter.ToString(hash).Replace("-", "").ToLowerInvariant();
}
}
}
private void CreatePatch(string original, string modified, string output)
{
// Specify process start info
ProcessStartInfo parameters = new ProcessStartInfo
{
FileName = localPath + "\\utilities\\xdelta\\xdelta3.exe",
WorkingDirectory = localPath,
UseShellExecute = false,
CreateNoWindow = true,
Arguments = "-f -e -s \"" + original + "\" \"" + modified + "\" \"" + output + "\""
};
// Launch process and wait for exit. using statement automatically disposes the object for us!
using (Process proc = new Process { StartInfo = parameters })
{
proc.Start();
proc.WaitForExit();
}
}
private (bool, string) SelectFile(string title, string extension, string filter)
{
using (OpenFileDialog fileFinder = new OpenFileDialog())
{
fileFinder.RestoreDirectory = true;
fileFinder.Title = title;
fileFinder.DefaultExt = extension;
fileFinder.Filter = filter;
fileFinder.CheckFileExists = true;
fileFinder.CheckPathExists = true;
fileFinder.Multiselect = false;
if (fileFinder.ShowDialog() == DialogResult.OK)
{
string location = fileFinder.FileName;
return (true, location);
}
else return (false, "");
}
}
}
}