-
Notifications
You must be signed in to change notification settings - Fork 23
/
CommandLine.cs
155 lines (145 loc) · 5.06 KB
/
CommandLine.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
using System;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Threading;
using System.Windows.Forms;
namespace MelonLoader
{
internal static class CommandLine
{
internal static bool IsCMD = false;
internal static bool IsSilent = false;
internal static int CmdMode = 0;
internal static string ExePath = null;
internal static string ZipPath = null;
internal static string RequestedVersion = null;
internal static bool AutoDetectArch = true;
internal static bool Requested32Bit = false;
internal static bool Run(string[] args, ref int returnval)
{
if (args.Length <= 0)
return false;
if (string.IsNullOrEmpty(args[0]))
return false;
ExePath = string.Copy(args[0]);
if (args.Length == 1)
return false;
bool breakforhelp = false;
foreach (string arg in args)
{
if (string.IsNullOrEmpty(arg))
continue;
switch (arg)
{
case "/silent":
IsSilent = true;
break;
case "/i":
if (CmdMode == 0)
CmdMode = 1;
break;
case "/u":
if (CmdMode == 0)
CmdMode = 2;
break;
case "/x86":
Requested32Bit = true;
break;
case "/zip":
// Grab Zip Path
break;
case "/version":
// Grab Requested Version
break;
default:
breakforhelp = true;
break;
}
if (breakforhelp)
break;
}
if (breakforhelp)
PrintHelp();
else
switch(CmdMode)
{
case 1:
Install(ref returnval);
break;
case 2:
Uninstall(ref returnval);
break;
default:
PrintHelp();
break;
}
return true;
}
private static void PrintHelp()
{
}
private static void Install(ref int returnval)
{
if (!Program.ValidateUnityGamePath(ref ExePath))
{
// Output Error
return;
}
Program.GetCurrentInstallVersion(Path.GetDirectoryName(ExePath));
if (!string.IsNullOrEmpty(ZipPath))
{
InstallFromZip(ref returnval);
return;
}
Releases.RequestLists();
if (Releases.All.Count <= 0)
{
// Output Error
return;
}
// Pull Latest Version
string selected_version = "v0.0.0.0";
if (Program.CurrentInstalledVersion == null)
OperationHandler.CurrentOperation = OperationHandler.Operations.INSTALL;
else
{
Version selected_ver = new Version(selected_version);
int compare_ver = selected_ver.CompareTo(Program.CurrentInstalledVersion);
if (compare_ver < 0)
OperationHandler.CurrentOperation = OperationHandler.Operations.DOWNGRADE;
else if (compare_ver > 0)
OperationHandler.CurrentOperation = OperationHandler.Operations.UPDATE;
else
OperationHandler.CurrentOperation = OperationHandler.Operations.REINSTALL;
}
OperationHandler.Automated_Install(Path.GetDirectoryName(ExePath), selected_version, Requested32Bit, (selected_version.StartsWith("v0.2") || selected_version.StartsWith("v0.1")));
}
private static void InstallFromZip(ref int returnval)
{
if (!Program.ValidateZipPath(ZipPath))
{
// Output Error
return;
}
OperationHandler.ManualZip_Install(ZipPath, Path.GetDirectoryName(ExePath));
}
private static void Uninstall(ref int returnval)
{
if (!Program.ValidateUnityGamePath(ref ExePath))
{
// Output Error
return;
}
string folderpath = Path.GetDirectoryName(ExePath);
Program.GetCurrentInstallVersion(folderpath);
if (Program.CurrentInstalledVersion == null)
{
// Output Error
return;
}
OperationHandler.CurrentOperation = OperationHandler.Operations.UNINSTALL;
OperationHandler.Uninstall(folderpath);
}
}
}