Skip to content

Commit 7f48795

Browse files
committed
Code Removal, related to old "saveSettings"
1 parent 60df956 commit 7f48795

File tree

7 files changed

+1
-178
lines changed

7 files changed

+1
-178
lines changed

BHD-ServerManager/Classes/InstanceManagers/theInstanceManager.cs

Lines changed: 0 additions & 166 deletions
Original file line numberDiff line numberDiff line change
@@ -22,132 +22,6 @@ public static class theInstanceManager
2222
// The Instances (Data)
2323
private static theInstance theInstance => CommonCore.theInstance!;
2424

25-
public static void CheckSettings()
26-
{
27-
// Ensure AppData directory exists, with verbose logging and error handling.
28-
try
29-
{
30-
if (!Directory.Exists(CommonCore.AppDataPath))
31-
{
32-
AppDebug.Log("InstanceManager", $"AppData ({CommonCore.AppDataPath}) directory does not exist, creating it now.");
33-
Directory.CreateDirectory(CommonCore.AppDataPath);
34-
}
35-
36-
if (!File.Exists(lastKnownSettingsPath))
37-
{
38-
AppDebug.Log("InstanceManager", $"Settings file not found at {lastKnownSettingsPath}. Creating a new one with default values.");
39-
theInstanceManager.SaveSettings();
40-
}
41-
else
42-
{
43-
AppDebug.Log("InstanceManager", $"Settings file found at {lastKnownSettingsPath}. Loading settings.");
44-
theInstanceManager.LoadSettings();
45-
}
46-
}
47-
catch (Exception ex)
48-
{
49-
AppDebug.Log("InstanceManager", $"Error during settings check: {ex.Message}");
50-
throw;
51-
}
52-
}
53-
public static void LoadSettings(bool external = false, string? path = null)
54-
{
55-
string settingsPath = external && !string.IsNullOrWhiteSpace(path) ? path : lastKnownSettingsPath;
56-
AppDebug.Log("InstanceManager", $"Loading settings from {(external ? "external path" : "default path")}: {settingsPath}");
57-
58-
if (!File.Exists(settingsPath))
59-
{
60-
AppDebug.Log("InstanceManager", $"Settings file not found at {settingsPath}. Using default settings.");
61-
return;
62-
}
63-
64-
try
65-
{
66-
var tempInstance = JsonSerializer.Deserialize<theInstance>(File.ReadAllText(settingsPath));
67-
if (tempInstance == null) return;
68-
69-
if (!external)
70-
{
71-
// Copy all properties from tempInstance to theInstance
72-
foreach (var prop in typeof(theInstance).GetProperties())
73-
{
74-
if (prop.CanRead && prop.CanWrite && prop.GetCustomAttributes(typeof(JsonIgnoreAttribute), true).Length == 0)
75-
{
76-
var value = prop.GetValue(tempInstance);
77-
prop.SetValue(theInstance, value);
78-
}
79-
}
80-
theInstance.profileServerPath = tempInstance.profileServerPath != null ? Encoding.UTF8.GetString(Convert.FromBase64String(tempInstance.profileServerPath)) : string.Empty;
81-
82-
theInstanceManager.GetServerVariables();
83-
}
84-
else
85-
{
86-
theInstanceManager.GetServerVariables(true, tempInstance); // Get the variables from the tempInstance
87-
}
88-
}
89-
catch (Exception ex)
90-
{
91-
MessageBox.Show($"Failed to load settings: {ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
92-
AppDebug.Log("InstanceManager", $"Failed to load settings: {ex.Message}");
93-
}
94-
}
95-
public static void SaveSettings(bool external = false, string? path = null)
96-
{
97-
string settingsPath = external && !string.IsNullOrWhiteSpace(path) ? path : lastKnownSettingsPath;
98-
try
99-
{
100-
var options = new JsonSerializerOptions
101-
{
102-
WriteIndented = true,
103-
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull
104-
};
105-
theInstance tempInstance = new theInstance();
106-
foreach (var prop in typeof(theInstance).GetProperties())
107-
{
108-
if (prop.CanRead && prop.CanWrite && prop.GetCustomAttributes(typeof(JsonIgnoreAttribute), true).Length == 0)
109-
{
110-
var value = prop.GetValue(theInstance);
111-
if (value != null)
112-
{
113-
prop.SetValue(tempInstance, value);
114-
}
115-
}
116-
}
117-
// Only encode if not null or empty
118-
if (!string.IsNullOrEmpty(tempInstance.profileServerPath))
119-
{
120-
tempInstance.profileServerPath = Convert.ToBase64String(Encoding.UTF8.GetBytes(tempInstance.profileServerPath));
121-
}
122-
string json = JsonSerializer.Serialize(tempInstance, options);
123-
File.WriteAllText(settingsPath, json);
124-
}
125-
catch (Exception ex)
126-
{
127-
MessageBox.Show($"Failed to save settings: {ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
128-
AppDebug.Log("InstanceManager", $"Failed to save settings: {ex.Message}");
129-
}
130-
}
131-
public static void ExportSettings()
132-
{
133-
// Export the settings to a JSON file using a ShowFileDialog from CoreManager
134-
string savePath = CommonCore.AppDataPath;
135-
string exportPath = Functions.ShowFileDialog(true, "Server Settings (*.svset)|*.svset|All files (*.*)|*.*", "Export Server Settings", savePath, "exportedServerSettings.svset")!;
136-
if (!string.IsNullOrEmpty(exportPath))
137-
{
138-
theInstanceManager.SaveSettings(true, exportPath); // Save the settings to the specified path
139-
}
140-
141-
}
142-
public static void ImportSettings()
143-
{
144-
string savePath = CommonCore.AppDataPath;
145-
string importPath = Functions.ShowFileDialog(true, "Server Settings (*.svset)|*.svset|All files (*.*)|*.*", "Import Server Settings", savePath, "importServerSettings.svset")!;
146-
if (!string.IsNullOrEmpty(importPath))
147-
{
148-
theInstanceManager.LoadSettings(true, importPath);
149-
}
150-
}
15125
public static bool ValidateGameServerPath()
15226
{
15327
// Validate the profile server path
@@ -170,16 +44,6 @@ public static void GetServerVariables(bool import = false, theInstance updatedIn
17044
thisServer.StatsTab.functionEvent_GetStatSettings((updatedInstance != null ? updatedInstance : null!));
17145

17246
}
173-
public static void ValidateGameServerType(string serverPath)
174-
{
175-
// Additional checks can be added here if necessary
176-
if (File.Exists(Path.Combine(serverPath, "EXP1.pff")))
177-
{
178-
thisInstance.profileServerType = 1; // BHDTS
179-
return;
180-
}
181-
thisInstance.profileServerType = 0; // BHD
182-
}
18347
public static void UpdateGameServer()
18448
{
18549
// the following code will replace line by line until all variables have a "update" function in ServerMemory
@@ -392,35 +256,5 @@ public static void changeTeamGameMode(int currentMapType, int nextMapType)
392256

393257
}
394258

395-
public static void HighlightDifferences()
396-
{
397-
// TO DO: Remove the need for HighlightDifferences in theInstanceManager.
398-
}
399-
400-
// Helper methods for highlighting
401-
public static void HighlightTextBox(TextBox tb, string value)
402-
{
403-
tb.BackColor = tb.Text == value ? SystemColors.Window : Color.LightYellow;
404-
}
405-
406-
public static void HighlightComboBox(ComboBox cb, string value)
407-
{
408-
cb.BackColor = cb.Text == value ? SystemColors.Window : Color.LightYellow;
409-
}
410-
411-
public static void HighlightComboBoxIndex(ComboBox cb, int value)
412-
{
413-
cb.BackColor = cb.SelectedIndex == value ? SystemColors.Window : Color.LightYellow;
414-
}
415-
416-
public static void HighlightNumericUpDown(NumericUpDown num, int value)
417-
{
418-
num.BackColor = (int)num.Value == value ? SystemColors.Window : Color.LightYellow;
419-
}
420-
421-
public static void HighlightCheckBox(CheckBox cb, bool value)
422-
{
423-
cb.BackColor = cb.Checked == value ? SystemColors.Control : Color.LightYellow;
424-
}
425259
}
426260
}

BHD-ServerManager/Classes/Tickers/tickerServerManager.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ public static void runTicker()
6363
thisServer.functionEvent_tickerServerGUI(); // Ticker for the Main Server GUI
6464

6565
// --- UI Update Hooks ---
66-
thisServer.ProfileTab.tickerProfileTabHook(); // Toggle Profile Lock based on server status
6766
thisServer.ServerTab.tickerServerHook(); // Toggle Server Lock based on server status
6867
thisServer.PlayersTab.tickerPlayerHook(); // Update Players Tab
6968
thisServer.ChatTab.ChatTickerHook(); // Update Chat Tab

BHD-ServerManager/Forms/Panels/tabGamePlay.Designer.cs

Lines changed: 0 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

BHD-ServerManager/Forms/Panels/tabGamePlay.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -270,9 +270,6 @@ private void actionClick_ResetSettings(object sender, EventArgs e)
270270
{
271271
methodFunction_loadSettings();
272272
}
273-
// --- Import/Export Server Settings ---
274-
private void actionClick_ImportServerSettings(object sender, EventArgs e) => theInstanceManager.ImportSettings();
275-
private void actionClick_ExportServerSettings(object sender, EventArgs e) => theInstanceManager.ExportSettings();
276273
// --- Server Control Button Clicked ---
277274
private void actionClick_serverControl(object sender, EventArgs e)
278275
{

BHD-ServerManager/Forms/Panels/tabStats.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,6 @@ public void functionEvent_SaveSettings()
5656
theInstance.WebStatsAnnouncements = cb_enableAnnouncements.Checked;
5757
theInstance.WebStatsReportInterval = (int)num_WebStatsReport.Value;
5858
theInstance.WebStatsUpdateInterval = (int)num_WebStatsUpdates.Value;
59-
60-
// Save the settings to file
61-
theInstanceManager.SaveSettings();
6259
}
6360

6461

BHD-ServerManager/Forms/ServerManager.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ private void PostServerManagerInitalization(object? sender, EventArgs e)
3636
functionEvent_loadPanels(); // Load the User Control Tabs
3737

3838
// Old Server Settings Initialization
39-
theInstanceManager.CheckSettings();
4039
banInstanceManager.LoadSettings();
4140
chatInstanceManager.LoadSettings();
4241
theInstanceManager.InitializeTickers();
@@ -183,7 +182,6 @@ protected override void OnFormClosing(FormClosingEventArgs e)
183182
CommonCore.Ticker?.Stop("ChatManager");
184183
CommonCore.Ticker?.Stop("PlayerManager");
185184
CommonCore.Ticker?.Stop("BanManager");
186-
theInstanceManager.SaveSettings();
187185
base.OnFormClosing(e);
188186
}
189187

BHD-ServerManager/Properties/launchSettings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"profiles": {
33
"ServerManager": {
44
"commandName": "Project",
5-
"workingDirectory": "\\\\VM-DEV\\ServerData\\Development\\HawkSyncOld",
5+
"workingDirectory": "\\\\VM-DEV\\ServerData\\Development\\HawkSync",
66
"remoteDebugEnabled": true,
77
"remoteDebugMachine": "VM-DEV",
88
"authenticationMode": "None"

0 commit comments

Comments
 (0)