Skip to content

Commit 6e5e775

Browse files
committed
kms
windows being retarded as fuck
1 parent 7027f6f commit 6e5e775

File tree

11 files changed

+138
-149
lines changed

11 files changed

+138
-149
lines changed

ModLoader/App.config

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,5 @@
11
<?xml version="1.0" encoding="utf-8" ?>
22
<configuration>
33
<configSections>
4-
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
5-
<section name="DCTS.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
6-
</sectionGroup>
74
</configSections>
8-
<userSettings>
9-
<DCTS.Properties.Settings>
10-
<setting name="uriScheme" serializeAs="String">
11-
<value>dcts</value>
12-
</setting>
13-
<setting name="storedServers" serializeAs="String">
14-
<value>0</value>
15-
</setting>
16-
<setting name="branch" serializeAs="String">
17-
<value>main</value>
18-
</setting>
19-
<setting name="skippedVersion" serializeAs="String">
20-
<value />
21-
</setting>
22-
<setting name="FirstRunAfterUpgrade" serializeAs="String">
23-
<value>True</value>
24-
</setting>
25-
</DCTS.Properties.Settings>
26-
</userSettings>
275
</configuration>

ModLoader/Form1.cs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public partial class Form1 : Form
3333
private System.Windows.Forms.Timer fadeTimer;
3434
private bool isFadingOut = false;
3535
public static bool isDebug = false;
36-
public static string branch = DCTS.Properties.Settings.Default.branch;
36+
public static string branch = "main";
3737
private bool didInit = false;
3838

3939
public static string appPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "dcts");
@@ -121,6 +121,8 @@ public Form1(string uri = null)
121121
this.Controls.Add(webView);
122122

123123
InitializeAsync();
124+
125+
this.Text = $"DCTS | {GetVersion()}";
124126
}
125127

126128
private int GetWidth(int percent)
@@ -208,8 +210,17 @@ private void ListenForUris()
208210

209211
async void InitializeAsync()
210212
{
211-
CoreWebView2Environment env = await CoreWebView2Environment.CreateAsync();
213+
string userDataDir = Path.Combine(Form1.appPath, "webview-data");
214+
Directory.CreateDirectory(userDataDir);
215+
216+
CoreWebView2Environment env = await CoreWebView2Environment.CreateAsync(
217+
null, // can pick browser with this apparently
218+
userDataDir
219+
);
220+
212221
await webView.EnsureCoreWebView2Async(env);
222+
223+
213224
webView.CoreWebView2.Settings.AreHostObjectsAllowed = true;
214225
webView.CoreWebView2.AddHostObjectToScript("dcts", bridge);
215226

ModLoader/JSBridge.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ public void NavigateToUrl(string url)
176176
{
177177
if (!Form1.HandleArgs(url)) return;
178178
Form1.webView.CoreWebView2.Navigate($"http://{url}");
179-
Form1.formhelper.Text = $"DCTS » {url}";
179+
Form1.formhelper.Text = $"DCTS » {url} | {Form1.GetVersion()}";
180180
//Form1.webView.CoreWebView2.AddHostObjectToScript("dcts", Form1.bridge);
181181
}
182182

ModLoader/Program.cs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,13 @@ static class Program
77
[STAThread]
88
static void Main(string[] args)
99
{
10-
string appPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "dcts");
11-
string settingsDir = Path.Combine(appPath, "data");
12-
if(!Directory.Exists(settingsDir)) Directory.CreateDirectory(settingsDir);
13-
AppDomain.CurrentDomain.SetData("APPDATA", settingsDir);
14-
15-
16-
if (DCTS.Properties.Settings.Default.FirstRunAfterUpgrade)
10+
if (args.Contains("--register-uri"))
1711
{
18-
DCTS.Properties.Settings.Default.Upgrade();
19-
DCTS.Properties.Settings.Default.FirstRunAfterUpgrade = false;
20-
DCTS.Properties.Settings.Default.Save();
12+
URIHelper.RegisterUriScheme(true, args);
13+
return;
2114
}
2215

23-
bool isNewInstance;
16+
bool isNewInstance;
2417
using (Mutex mutex = new Mutex(true, "MySuperSickAppMutexForDCTS", out isNewInstance))
2518
{
2619
if (isNewInstance)

ModLoader/Properties/Settings.Designer.cs

Lines changed: 0 additions & 60 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,5 @@
11
<?xml version='1.0' encoding='utf-8'?>
2-
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)" GeneratedClassNamespace="DCTS.Properties" GeneratedClassName="Settings">
2+
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)">
33
<Profiles />
4-
<Settings>
5-
<Setting Name="uriScheme" Type="System.String" Scope="User">
6-
<Value Profile="(Default)">dcts</Value>
7-
</Setting>
8-
<Setting Name="storedServers" Type="System.String" Scope="User">
9-
<Value Profile="(Default)">0</Value>
10-
</Setting>
11-
<Setting Name="branch" Type="System.String" Scope="User">
12-
<Value Profile="(Default)">main</Value>
13-
</Setting>
14-
<Setting Name="skippedVersion" Type="System.String" Scope="User">
15-
<Value Profile="(Default)" />
16-
</Setting>
17-
<Setting Name="FirstRunAfterUpgrade" Type="System.Boolean" Scope="User">
18-
<Value Profile="(Default)">True</Value>
19-
</Setting>
20-
</Settings>
4+
<Settings />
215
</SettingsFile>

ModLoader/StorageHelper.cs

Lines changed: 83 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,89 @@ namespace ModLoader
1111
public class StorageHelper
1212
{
1313
public static StorageHelper instance { get; private set; }
14+
15+
public static string settingsDataPath = Path.Combine(Form1.appPath, "settings.json");
16+
private static bool settingsDidInit = false;
17+
1418
public StorageHelper()
1519
{
1620
instance = this;
1721
}
1822

23+
public class AppSettings
24+
{
25+
public string SavedServers { get; set; } = "{}";
26+
public string UriScheme { get; set; } = "dcts";
27+
public string SkippedVersion { get; set; } = "";
28+
}
29+
30+
public static AppSettings Current { get; private set; } = new AppSettings();
31+
32+
public static void InitSettings()
33+
{
34+
Directory.CreateDirectory(Path.GetDirectoryName(settingsDataPath)!);
35+
36+
if (!File.Exists(settingsDataPath))
37+
{
38+
SaveSettings(); // create file with defaults
39+
}
40+
else
41+
{
42+
LoadSettings();
43+
}
44+
45+
settingsDidInit = true;
46+
}
47+
48+
public static void SaveSettings()
49+
{
50+
if(!settingsDidInit) InitSettings();
51+
string json = JsonSerializer.Serialize(Current, new JsonSerializerOptions { WriteIndented = true });
52+
File.WriteAllText(settingsDataPath, json);
53+
}
54+
55+
public static void LoadSettings()
56+
{
57+
if (!File.Exists(settingsDataPath))
58+
{
59+
Current = new AppSettings();
60+
SaveSettings();
61+
return;
62+
}
63+
64+
try
65+
{
66+
string json = File.ReadAllText(settingsDataPath);
67+
Current = JsonSerializer.Deserialize<AppSettings>(json) ?? new AppSettings();
68+
}
69+
catch
70+
{
71+
Current = new AppSettings();
72+
SaveSettings();
73+
}
74+
}
75+
76+
public static T GetSetting<T>(string settingName)
77+
{
78+
if (!settingsDidInit) InitSettings();
79+
var prop = typeof(AppSettings).GetProperty(settingName);
80+
if (prop == null) return default!;
81+
object value = prop.GetValue(Current)!;
82+
return (T)Convert.ChangeType(value, typeof(T));
83+
}
84+
85+
86+
public static void SetSetting(string settingName, string value)
87+
{
88+
if (!settingsDidInit) InitSettings();
89+
var prop = typeof(AppSettings).GetProperty(settingName);
90+
if (prop != null && prop.CanWrite)
91+
{
92+
prop.SetValue(Current, value);
93+
SaveSettings();
94+
}
95+
}
96+
1997
public class ServerInfo
2098
{
2199
public string Address { get; set; }
@@ -26,7 +104,7 @@ public class ServerInfo
26104

27105
public Dictionary<string, ServerInfo> GetServers()
28106
{
29-
var json = DCTS.Properties.Settings.Default.storedServers;
107+
var json = StorageHelper.GetSetting<string>("SavedServers");
30108

31109
if (!string.IsNullOrWhiteSpace(json))
32110
{
@@ -39,9 +117,8 @@ public Dictionary<string, ServerInfo> GetServers()
39117

40118
public void SaveServers(Dictionary<string, ServerInfo> serverInfo)
41119
{
42-
DCTS.Properties.Settings.Default.storedServers = JsonSerializer.Serialize<Dictionary<string, ServerInfo>>(serverInfo);
43-
DCTS.Properties.Settings.Default.Save();
44-
DCTS.Properties.Settings.Default.Reload();
120+
StorageHelper.SetSetting("SavedServers", JsonSerializer.Serialize<Dictionary<string, ServerInfo>>(serverInfo));
121+
StorageHelper.SaveSettings();
45122
}
46123
public void ResetServers()
47124
{
@@ -50,9 +127,8 @@ public void ResetServers()
50127

51128
if (dr == DialogResult.Yes)
52129
{
53-
DCTS.Properties.Settings.Default.storedServers = "{}";
54-
DCTS.Properties.Settings.Default.Save();
55-
DCTS.Properties.Settings.Default.Reload();
130+
StorageHelper.SetSetting("SavedServers", "{}");
131+
StorageHelper.SaveSettings();
56132
}
57133
}
58134

0 commit comments

Comments
 (0)