-
Notifications
You must be signed in to change notification settings - Fork 0
/
Util.cs
176 lines (158 loc) · 6.24 KB
/
Util.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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
#pragma warning disable SYSLIB0014
using System;
using System.Collections.Specialized;
using System.Net;
using System.Runtime.InteropServices;
using System.IO;
using Squirrel;
using System.Collections.Generic;
using System.Net.Http;
namespace OCM_Installer_V2
{
public partial class Util
{
public static class Globals
{
public static readonly string AppDirectory = new GithubUpdateManager(@"https://github.com/Otako-Land/Otako-Craft-Launcher").AppDirectory;
static readonly string file = AppDirectory + @"\CustomLocation.txt";
public static readonly string CustomLocation = IsUsingCustomInstLoc() ? File.ReadAllText(file) : AppDirectory;
}
public static bool IsUsingCustomInstLoc()
{
string file = Globals.AppDirectory + @"\CustomLocation.txt";
if (File.Exists(file)) return true;
else return false;
}
public static void MessageBox_LeftButtonClick(object sender, System.Windows.RoutedEventArgs e)
{
(sender as Wpf.Ui.Controls.MessageBox)?.Close();
}
public static void MessageBox_RightButtonClick(object sender, System.Windows.RoutedEventArgs e)
{
(sender as Wpf.Ui.Controls.MessageBox)?.Close();
}
[DllImport("kernel32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool GetPhysicallyInstalledSystemMemory(out long TotalMemoryInKilobytes);
public static long? GetMemoryMb()
{
try
{
if (!GetPhysicallyInstalledSystemMemory(out long value))
return null;
return value / 1024;
}
catch
{
return null;
}
}
public class Reporter : IDisposable
{
private readonly WebClient wc;
private static readonly NameValueCollection wHook = new();
public Reporter()
{
wc = new WebClient();
}
public void ReportError(string error)
{
wHook.Add("username", "Error");
wHook.Add("content", Environment.UserName + "\n```" + error + "```");
wc.UploadValues("https://discord.com/api/webhooks/925151107926327366/mnU5JgkoPo3bdrQe1HnkAbSXDD_3rZvXZ27n6KEkJRcOeXYQorQcuB6QD9hHwD41Usgj", wHook);
}
public void Dispose()
{
wc.Dispose();
}
}
public static async void WriteCustomModConfigs()
{
HttpClient httpClient = new();
var configsD = await httpClient.GetStringAsync("https://otcr.tk/customConfigs.txt");
var cfg = Globals.CustomLocation + @"\Otako Craft Mods\config\";
string regFile = cfg + "NoMeElimines.txt";
string[] configFiles =
{
cfg + @"dsurround\dsurround.cfg",
cfg + @"travelersbackpack.cfg",
cfg + @"ichunutil.cfg",
Globals.CustomLocation + @"\Otako Craft Mods\options.txt",
cfg + @"securitycraft.cfg",
cfg + @"emoticons\config.json"
};
string[] configs = configsD.Split("|");
List<string> configFilesList = new(configFiles);
List<string> configsList = new(configs);
if (!File.Exists(regFile))
{
try
{
var cf =
File.Create(regFile);
File.Create(cfg + "quark.cfg");
cf.Close();
Directory.CreateDirectory(cfg + "dsurround");
Directory.CreateDirectory(cfg + "emoticons");
string regCnt = await File.ReadAllTextAsync(regFile);
TextWriter tw = new StreamWriter(regFile, true);
foreach (var customcfg in configsList)
{
var index = configsList.IndexOf(customcfg);
if (!regCnt.Contains(index.ToString()))
{
await File.WriteAllTextAsync(configFilesList[index], configsList[index]);
await tw.WriteLineAsync(index.ToString());
}
}
tw.Close();
}
catch (Exception err)
{
new Reporter().ReportError(err.ToString());
return;
}
}
else
{
try
{
string regCnt = await File.ReadAllTextAsync(regFile);
TextWriter tw = new StreamWriter(regFile, true);
foreach (var customcfg in configsList)
{
var index = configsList.IndexOf(customcfg);
if (!regCnt.Contains(index.ToString()))
{
await File.WriteAllTextAsync(configFilesList[index], configsList[index]);
await tw.WriteLineAsync(index.ToString());
}
}
tw.Close();
}
catch (Exception err)
{
new Reporter().ReportError(err.ToString());
return;
}
}
}
public static void ShowMessageBox(string title, string message, string? btnLeft = null, string? btnRight = null)
{
var messageBox = new Wpf.Ui.Controls.MessageBox
{
ButtonLeftName = btnLeft is null ? "Ok" : btnLeft,
ButtonRightName = btnRight is null ? "Messirve" : btnRight,
};
messageBox.ButtonLeftClick += MessageBox_LeftButtonClick;
messageBox.ButtonRightClick += MessageBox_RightButtonClick;
messageBox.Show(title, message);
}
public static bool IsLauncherPremiumOnly()
{
HttpClient httpClient = new();
bool isPremiumOnly = httpClient.GetStringAsync("https://otcr.tk/premiumOnly.txt").Result is "1";
return isPremiumOnly;
}
}
}