-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
124 lines (116 loc) · 4.66 KB
/
Program.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
using System.Diagnostics;
using System.Reflection;
namespace L2EliminateUpdater
{
internal class Program
{
static bool isFullCheck = false;
static bool isEngClient = false;
static void Main()
{
Console.Title = $"{Assembly.GetEntryAssembly().GetCustomAttribute<AssemblyProductAttribute>().Product} v.{Assembly.GetEntryAssembly().GetName().Version.ToString(2)} by {Assembly.GetEntryAssembly().GetCustomAttribute<AssemblyCopyrightAttribute>().Copyright}";
Console.Write("Full Check? [yes/no]\n(default: no, only check system): ");
string fullCheck = Console.ReadLine();
if(!string.IsNullOrEmpty(fullCheck))
{
isFullCheck = fullCheck.ToLower().StartsWith("y");
}
Console.WriteLine();
Console.Write("ENG Client? [yes/no]\n(default: no, start RU client): ");
string lang = Console.ReadLine();
if (!string.IsNullOrEmpty(lang))
{
isEngClient = lang.ToLower().StartsWith("y");
}
Console.WriteLine();
Update().ContinueWith(t =>
{
if(t.Result)
{
RunLineageClient(isEngClient);
}
else
{
Console.ForegroundColor = ConsoleColor.Red;
Console.Error.WriteLine("\nUpdate Failed. Not all files updated. Please run again.");
Console.ForegroundColor = ConsoleColor.White;
Thread.Sleep(Timeout.Infinite);
}
}).Wait();
}
static async Task<bool> Update()
{
Updater updater = new(isEngClient);
bool isFullCheckSuccess = false;
bool isSystemCheckSuccess = false;
if (isFullCheck)
{
Console.ForegroundColor = ConsoleColor.Yellow;
await Console.Out.WriteLineAsync("=== FULL CHECK ===");
Console.ForegroundColor = ConsoleColor.White;
await Check(Updater.ListType.Client, updater, isSuccess => isFullCheckSuccess = isSuccess);
await Check(Updater.ListType.Patch, updater, isSuccess => isSystemCheckSuccess = isSuccess);
}
else
{
isFullCheckSuccess = true;
Console.ForegroundColor = ConsoleColor.Yellow;
await Console.Out.WriteLineAsync("=== SYSTEM CHECK ===");
Console.ForegroundColor = ConsoleColor.White;
await Check(Updater.ListType.Patch, updater, isSuccess => isSystemCheckSuccess = isSuccess);
}
Directory.Delete(updater.GetUpdaterDir().FullName, true);
return isFullCheckSuccess && isSystemCheckSuccess;
}
static void RunLineageClient(bool isEngClient)
{
string dir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, isEngClient ? "system-en" : "system-ru");
Process.Start(new ProcessStartInfo
{
WorkingDirectory = dir,
Verb = "runas",
FileName = Path.Combine(dir, "l2.exe"),
UseShellExecute = true
});
}
static async Task Check(Updater.ListType checkType, Updater updater, Action<bool> onEndCallback)
{
bool isSuccess = true;
foreach (var fo in await updater.GetFileList(checkType))
{
if (checkType == Updater.ListType.Patch && IsFileFiltered(fo.File.TrimStart('\\'))) continue;
await Console.Out.WriteLineAsync();
await Console.Out.WriteAsync($"Cheking file: {fo.File.TrimStart('\\')} ... ");
try
{
if (await updater.DownloadFileAsync(fo, checkType))
{
updater.UnZip(fo);
}
}
catch (Exception ex)
{
await Console.Out.WriteLineAsync(ex.Message);
isSuccess = false;
}
}
onEndCallback.Invoke(isSuccess);
await Task.CompletedTask;
}
static bool IsFileFiltered(string file)
{
if(File.Exists(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, file)))
{
if(Enum.GetNames<FilteredFile>().Any(x => file.Contains(x))) return true;
else return false;
}
else return false;
}
enum FilteredFile
{
WindowsInfo,
Option,
chatfilter,
}
}
}