-
Notifications
You must be signed in to change notification settings - Fork 0
/
AppConfig.cs
66 lines (52 loc) · 2.64 KB
/
AppConfig.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
using System.Net;
namespace HexoArticleEditor
{
public static class AppConfig
{
public static string HexoBasePath { get; set; } = "";
public static string HexoArticlePath { get; set; } = "";
public static string HexoImagePath { get; set; } = "";
public static string Password { get; set; } = "";
public static int MaxFileSize { get; set; } = 10 * 1024 * 1024;
public static bool UseUploadFileName { get; set; } = true;
public static int AutoSaveIntervalMinutes { get; set; } = 3;
public static int AutoSaveMaxCount { get; set; } = 10;
public static bool DeleteAutoSaveAfterSave { get; set; }
public static string ListenIP { get; set; } = "127.0.0.1";
public static int ListenPort { get; set; } = 5000;
public static List<string> HexoTerminalCommands { get; set; } = ["hexo generate", "hexo clean"];
public static bool Load()
{
try
{
HexoBasePath = ConfigHelper.GetConfig("HexoBasePath", "");
HexoArticlePath = ConfigHelper.GetConfig("HexoArticlePath", "");
HexoImagePath = ConfigHelper.GetConfig("HexoImagePath", "");
Password = ConfigHelper.GetConfig("Password", Guid.NewGuid().ToString().Replace("-", ""));
MaxFileSize = ConfigHelper.GetConfig("MaxFileSize", 10 * 1024 * 1024);
UseUploadFileName = ConfigHelper.GetConfig("UseUploadFileName", true);
DeleteAutoSaveAfterSave = ConfigHelper.GetConfig("DeleteAutoSaveAfterSave", false);
AutoSaveIntervalMinutes = ConfigHelper.GetConfig("AutoSaveIntervalMinutes", 3);
AutoSaveMaxCount = ConfigHelper.GetConfig("AutoSaveMaxCount", 10);
HexoTerminalCommands = ConfigHelper.GetConfig("HexoTerminalCommands", new List<string>() { "hexo generate", "hexo clean" });
ListenIP = ConfigHelper.GetConfig("ListenIP", "127.0.0.1");
ListenPort = ConfigHelper.GetConfig("ListenPort", 5000);
if (IPAddress.TryParse(ListenIP, out _) is false)
{
Console.Error.WriteLine($"ListenIP {ListenIP} is invalid ip, now changed to 127.0.0.1");
ListenIP = "127.0.0.1";
}
if (ListenPort < 0 || ListenPort > 65535)
{
Console.Error.WriteLine($"ListenPort {ListenPort} is invalid port, now changed to 5000");
ListenPort = 5000;
}
}
catch
{
return false;
}
return true;
}
}
}