-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathProgram.cs
More file actions
76 lines (66 loc) · 2.73 KB
/
Copy pathProgram.cs
File metadata and controls
76 lines (66 loc) · 2.73 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
using System;
using System.IO;
using System.Reflection;
using System.Threading.Tasks;
static class Program {
public static bool tempUpdater = false;
public static bool gameUpdate = false;
public static string gamePath = AppContext.BaseDirectory;
// funny
static async Task<bool> CheckForUpdaterUpdate() {
if (Utils.IsRunningFromAppBundle() || tempUpdater || gameUpdate) { return true; }
string remoteVersion = await Utils.GetSloppyAsync("https://api.github.com/repos/coop-deluxe/coopdx-updater/releases/latest", "tag_name");
string version = Assembly.GetExecutingAssembly().GetName().Version.ToString();
return remoteVersion == version;
}
static async Task Main(string[] args) {
for (int i = 0; i < args.Length; i++) {
if (args[i] == "--temporary") {
tempUpdater = true;
continue;
}
if (args[i] == "--game-update") {
gameUpdate = true;
continue;
}
if (args[i] == "--game-path") {
// get string from next argument if we can
if (i < args.Length - 1) {
try {
// bit weird, but c# doesn't provide a simple function to validate the path, so this will have to do
string fullPath = Path.GetFullPath(args[i + 1]);
gamePath = fullPath;
} catch {
Console.WriteLine($"Invalid path: {args[i + 1]}");
Environment.Exit(0);
}
} else {
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("Please enter a path after using --game-path");
Environment.Exit(0);
}
continue;
}
}
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine("coopdx-updater (CLI)");
Console.ForegroundColor = ConsoleColor.Gray;
bool upToDate = await CheckForUpdaterUpdate();
if (!upToDate) {
Console.ForegroundColor = ConsoleColor.Blue;
Console.WriteLine("[ ! ] There is an update available for coopdx-updater!\nDownload at https://github.com/coop-deluxe/coopdx-updater/releases/latest");
Console.ForegroundColor = ConsoleColor.Gray;
Console.WriteLine("Press any key to exit...");
Console.ReadKey();
return;
}
if (!Updater.CheckForUpdate()) {
Utils.StartGame();
return;
}
await Updater.DownloadLatestVersion();
if (File.Exists("update.zip")) {
File.Delete("update.zip");
}
}
}