-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
77 lines (70 loc) · 2.44 KB
/
Program.cs
File metadata and controls
77 lines (70 loc) · 2.44 KB
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
using System;
using System.IO;
using System.Text.Json;
using System.Windows.Forms;
namespace BitcoinFinder
{
// Классы конфигурации
public class ServerConfig
{
public int Port { get; set; } = 5000;
public string LastBitcoinAddress { get; set; } = "";
public int LastWordCount { get; set; } = 12;
public long BlockSize { get; set; } = 100000;
}
public class AppConfig
{
public ServerConfig Server { get; set; } = new ServerConfig();
public string DefaultBitcoinAddress { get; set; } = "1MCirzugBCrn5H6jHix6PJSLX7EqUEniBQ";
public int DefaultThreadCount { get; set; } = 4;
}
static class Program
{
private static AppConfig _config = new AppConfig();
private const string ConfigFile = "bitcoin_finder_config.json";
public static AppConfig Config => _config;
[STAThread]
static void Main()
{
LoadConfig();
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new MainForm());
}
public static void LoadConfig()
{
try
{
if (File.Exists(ConfigFile))
{
var json = File.ReadAllText(ConfigFile);
_config = JsonSerializer.Deserialize<AppConfig>(json) ?? new AppConfig();
}
else
{
// Создаем конфиг по умолчанию
_config = new AppConfig();
SaveConfig();
}
}
catch (Exception ex)
{
// В случае ошибки используем конфиг по умолчанию
_config = new AppConfig();
System.Diagnostics.Debug.WriteLine($"Ошибка загрузки конфигурации: {ex.Message}");
}
}
public static void SaveConfig()
{
try
{
var json = JsonSerializer.Serialize(_config, new JsonSerializerOptions { WriteIndented = true });
File.WriteAllText(ConfigFile, json);
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine($"Ошибка сохранения конфигурации: {ex.Message}");
}
}
}
}