-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathGoodMerge.cs
114 lines (103 loc) · 6.13 KB
/
GoodMerge.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
using System;
using System.IO;
using System.Xml;
using System.Drawing;
using System.Diagnostics;
using System.Windows.Forms;
using System.Collections.Specialized;
namespace GoodMerge {
public class GoodMerge {
private static void SecurityTest() { new Process(); }
private static Options options;
[STAThread]
public static void Main(string[] args) {
try { SecurityTest(); }
catch {
MessageBox.Show(options.Strings[1], options.Strings[0]+" - "+options.Strings[0], MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
options = new Options();
if (!options.Initialize()) return;
Start(args);
}
private static void Start(string[] args) {
#region <GUI>
if (args.Length==0) {
SettingsDialog settings = new SettingsDialog(options);
while (true) {
if (settings.ShowDialog()!=DialogResult.OK) { options.Save(); return; }
LogWindow log = new LogWindow(options);
log.ShowDialog();
foreach (FileInfo file in new DirectoryInfo(options.WorkingFolder).GetFiles("7z*.tmp")) {
try { file.Delete(); }
catch { }
}
settings = new SettingsDialog(options);
}
}
#endregion
#region <CLI>
else if (args.Length==1) {
(new CLIHelpWindow(options)).ShowDialog();
}
else {
options.SetName=args[0];
options.Version=args[1];
options.TestMode=false;
if (options.HaveFile.Equals("")) options.HaveFile=options.CurrentFolder+options.SetName+"Have.txt";
if (options.SourceFolder.Equals("")) options.SourceFolder=options.CurrentFolder+options.SetName+"ren\\";
if (options.OutputFolder.Equals("")) options.OutputFolder=options.CurrentFolder+options.SetName+"Merge\\";
int loop;
for (loop=2; loop<args.Length; loop++) {
if (args[loop].Equals("pm")) options.TestMode=true;
else if (args[loop].Equals("ubp")) options.Background=true;
else if (args[loop].Equals("sca")) options.Arguments=true;
else if (args[loop].Equals("dsf")) options.DeleteFiles=true;
else if (args[loop].Equals("min")) options.Minimal=true;
else if (args[loop].StartsWith("oc=") || args[loop].StartsWith("sc=")) {
string type=args[loop].Substring(3).ToLower();
if (!type.Equals("7z") && !type.Equals("zip") && !type.Equals("rar") && !type.Equals("ace")) { doError(options.Strings[3]+type); return; }
if (args[loop][0]=='o') options.OutputCompression=type;
else options.SourceCompression=type;
}
else if (args[loop].StartsWith("mr=")) {
try { options.SetDesiredRAM(Int32.Parse(args[loop].Substring(3))); }
catch { doError(options.Strings[4]+args[loop]); return; }
}
else if (args[loop].StartsWith("sf=") || args[loop].StartsWith("of=") || args[loop].StartsWith("wf=")) {
string dir;
if (args[loop].Substring(2).Equals("=.")) dir = options.CurrentFolder;
else if (args[loop].Length>4 && args[loop][4]==':') dir = args[loop].Substring(3)+"\\";
else if (args[loop].Substring(1).StartsWith("=\\")) dir = options.CurrentFolder.Substring(0,2)+args[loop].Substring(3)+"\\";
else dir = options.CurrentFolder+args[loop].Substring(3)+"\\";
if (args[loop][0]=='s') options.SourceFolder=dir;
else if (args[loop][0]=='o') options.OutputFolder=dir;
else if (args[loop][0]=='w') options.WorkingFolder=dir;
}
else if (args[loop].StartsWith("hf=")) {
options.HaveFile=args[loop].Substring(3);
}
else { doError(options.Strings[5]+args[loop]); return; }
}
if (!Directory.Exists(options.SourceFolder) && !options.TestMode) { doError(options.Strings[6]+"\n("+options.SourceFolder+")"); return; }
if (!Directory.Exists(options.WorkingFolder) && !options.TestMode) { doError(options.Strings[7]+"\n("+options.WorkingFolder+")"); return; }
if (!File.Exists(options.HaveFile)) { doError(options.Strings[8]+"\n("+options.HaveFile+")"); return; }
if ((options.SourceCompression.Equals("rar") || options.OutputCompression.Equals("rar")) && options.Rar.Equals("none")) { doError(options.Strings[9]+" \"Rar.exe\""); return; }
if ((options.SourceCompression.Equals("ace") || options.OutputCompression.Equals("ace")) && options.Ace.Equals("none")) { doError(options.Strings[9]+" \"ace32.exe\""); return; }
if ((options.SourceCompression.Equals("7z") || options.SourceCompression.Equals("zip") || options.OutputCompression.Equals("7z") || options.OutputCompression.Equals("zip")) && options.SevenZip.Equals("none")) { doError(options.Strings[9]+" \"7za.exe\""); return; }
if (options.OutputCompression.Equals("7z") && options.MaxDict==0) { doError(options.Strings[10]); return; }
LogWindow log = new LogWindow(options);
log.ShowDialog();
options.Save();
foreach (FileInfo file in new DirectoryInfo(options.WorkingFolder).GetFiles("7z*.tmp")) {
try { file.Delete(); }
catch { }
}
}
#endregion
}
private static void doError(string text) {
MessageBox.Show(text, options.Strings[0]+" - "+options.Strings[1], MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}