-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathProgram.cs
More file actions
246 lines (212 loc) · 6.74 KB
/
Program.cs
File metadata and controls
246 lines (212 loc) · 6.74 KB
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Globalization;
using System.Threading;
using EnterpriseDT.Net.Ftp;
namespace modsync
{
class Program
{
#region Variables
static FtpLib ftp;
static FTPConnection ftpcon;
#endregion
#region Main
static void Main(string[] args)
{
// check for clickonce updates
if (Update.ClickOnceUpdate())
{
return;
}
// add embedded dll
Resources.RegisterEmbeddedResources();
// start program
MainLoad(args);
}
static void MainLoad(string[] args)
{
// create directory if missing
if (!Directory.Exists(Locations.LocalFolderName_Minecraft))
{
Directory.CreateDirectory(Locations.LocalFolderName_Minecraft);
}
// read ftp link from file
Config.FtpLinkRead();
// parse simple command line options
bool push = false;
foreach (string arg in args)
{
if (arg == "updateserver")
{
push = true;
}
else if (arg.StartsWith("ftp://"))
{
Config.FtpLinkParse(arg);
}
}
// require ftp server from here
// have user input the details if required
if (Config.ftpsettings.FtpServerAddress == "")
{
Config.FtpLinkInput();
}
// open ftp
if (!FtpOpen())
{
return;
}
// ask for repair
Repair();
// update config from server
Config.FtpUpdate(ref ftpcon);
// check for executable updates
Update.ExecutableUpdate(ref ftpcon, args);
// handle push
if (push)
{
Mods.Push(ref ftp);
Exit(false);
}
// check for java
Java.Check(ref ftpcon);
// check minecraft
Minecraft.Check(ref ftpcon);
switch (Config.settings.MinecraftMode)
{
case "Fabric":
// check fabric
Fabric.Check(ref ftpcon);
break;
case "Forge":
// check forge
Forge.Check(ref ftpcon);
break;
default:
Vanilla.Check(ref ftpcon);
break;
}
// sync folders
Mods.Pull(ref ftp);
// update servers file
Servers.Check();
// exit launching game
Exit(true);
}
static void Repair()
{
Console.WriteLine(Strings.Get("RepairAsk"));
Thread.Sleep(2000);
if (Console.KeyAvailable)
{
ConsoleKeyInfo repair = Console.ReadKey();
if (repair.Key == ConsoleKey.R)
{
// backup saves
RepairMoveSaves(Locations.LocalFolderName_Saves, Locations.LocalFolderName_SavesBackup);
// delete minecraft
try
{
Directory.Delete(Locations.LocalFolderName_Minecraft, true);
Console.WriteLine(Strings.Get("RepairSuccess"));
}
catch (Exception)
{
Console.WriteLine(Strings.Get("RepairFail"));
}
if (!Directory.Exists(Locations.LocalFolderName_Minecraft))
{
Directory.CreateDirectory(Locations.LocalFolderName_Minecraft);
}
// restore saves
RepairMoveSaves(Locations.LocalFolderName_SavesBackup, Locations.LocalFolderName_Saves);
}
}
}
static void RepairMoveSaves(string src, string dst)
{
try
{
if (!Directory.Exists(dst))
{
Directory.CreateDirectory(dst);
}
foreach (string save in Directory.GetDirectories(src))
{
DirectoryInfo dir = new DirectoryInfo(save);
if (!Directory.Exists(dst + "\\" + dir.Name))
{
Directory.Move(save, dst + "\\" + dir.Name);
}
}
}
catch (Exception) { }
}
public static void Exit(bool launchgame)
{
// disconnect
if (ftp != null)
{
if (ftp.IsConnected())
{
ftp.DisConnect();
}
}
if (launchgame)
{
Minecraft.Start();
}
Environment.Exit(0);
}
#endregion
#region FTP
static bool FtpOpen()
{
// create connection
try
{
ftpcon = new FTPConnection();
ftpcon.UserName = Config.ftpsettings.FtpUserName;
ftpcon.Password = Config.ftpsettings.FtpPassword;
ftpcon.ServerAddress = Config.ftpsettings.FtpServerAddress;
ftpcon.ServerPort = int.Parse(Config.ftpsettings.FtpServerPort);
ftpcon.TransferNotifyInterval = (long)4096;
ftp = new FtpLib(ref ftpcon);
}
catch (Exception)
{
Console.WriteLine(Strings.Get("FtpBadConfig"));
Console.ReadKey();
return false;
}
// try to connect
try
{
ftp.LogIn();
}
catch (Exception)
{
Console.WriteLine(Strings.Get("FtpNoConnection"));
Console.ReadKey();
return false;
}
// check if folder exists
if (!Config.ftpsettings.FtpServerFolder.StartsWith("/"))
{
Config.ftpsettings.FtpServerFolder = "/" + Config.ftpsettings.FtpServerFolder;
}
if (!ftpcon.DirectoryExists(Config.ftpsettings.FtpServerFolder))
{
Console.WriteLine(Strings.Get("FtpBadFolder") + Config.ftpsettings.FtpServerFolder);
Console.ReadKey();
return false;
}
return true;
}
#endregion
}
}