Skip to content

Commit 2ae6044

Browse files
committed
refactor: all consumers of JSON changed to TOML
1 parent f70f3ea commit 2ae6044

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

src/SharpWebserver/ListenServer/InputHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public static async Task HandleInputAsync()
7474
break;
7575
case "config-reload":
7676
Utilities.SecurityPolicy.LoadBlockList();
77-
if (ConfigManager.LoadConfig<SharpConfig>("SharpConfig.json") is not SharpConfig gc)
77+
if (ConfigManager.LoadConfig<SharpConfig>("SharpConfig.toml") is not SharpConfig gc)
7878
Logger.LogWarning("Failed to reload global config");
7979
else
8080
{

src/SharpWebserver/Program.cs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ it under the terms of the GNU General Public License as published by
1717
using System.Threading.Tasks;
1818
using SharpWebserver.Config;
1919
using System.Runtime.InteropServices;
20+
using Tomlyn;
2021

2122
namespace SharpWebserver;
2223
partial class ListenServer
@@ -45,6 +46,16 @@ You should have received a copy of the GNU General Public License
4546
static void Main(string[] args)
4647
{
4748

49+
/*
50+
var GlobalToml = @"SafeMode = true
51+
PortNumber = 8080
52+
";
53+
54+
var BlockToml = @"BlockList = [
55+
'item', 'item2', 'item3'
56+
]
57+
";
58+
*/
4859
ProcessArguments(in args);
4960

5061
if (ExitNow)
@@ -80,7 +91,7 @@ static void Main(string[] args)
8091
Utilities.EnsureDirectory(IncludesDir);
8192

8293
//Load global config
83-
if (ConfigManager.LoadConfig<SharpConfig>("SharpConfig.json") is not SharpConfig gc)
94+
if (ConfigManager.LoadConfig<SharpConfig>("SharpConfig.toml") is not SharpConfig gc)
8495
Logger.LogInfo("Using default global config");
8596
else
8697
GlobalConfig = gc;
@@ -189,7 +200,7 @@ static void Main(string[] args)
189200
Console.ResetColor();
190201
Console.Write(" or your distro's equivalent superuser or edit ");
191202
Console.ForegroundColor = ConsoleColor.Magenta;
192-
Console.Write("SharpConfig.json");
203+
Console.Write("SharpConfig.toml");
193204
Console.ResetColor();
194205
Console.WriteLine(" to change the port number.\n");
195206
}
@@ -214,7 +225,7 @@ static void Main(string[] args)
214225
#region Cleanup
215226

216227
//Perform cleanup and eventually save configurations here, etc
217-
ConfigManager.SaveConfig("SharpConfig.json", GlobalConfig);
228+
ConfigManager.SaveConfig("SharpConfig.toml", GlobalConfig);
218229
Utilities.SecurityPolicy.SaveBlockList();
219230

220231
#endregion

src/SharpWebserver/Utilities/SecurityPolicy.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ public static class SecurityPolicy
2020

2121
public static void SaveBlockList()
2222
{
23-
ConfigManager.SaveConfig("bannedClients.json", blockedClients);
23+
ConfigManager.SaveConfig("BannedClients.toml", blockedClients);
2424
}
2525
public static void LoadBlockList()
2626
{
27-
if (ConfigManager.LoadConfig<ClientBlockList>("bannedClients.json") is ClientBlockList list)
27+
if (ConfigManager.LoadConfig<ClientBlockList>("BannedClients.toml") is ClientBlockList list)
2828
blockedClients = list;
2929
}
3030
public static void BanRemote(string item)

0 commit comments

Comments
 (0)