-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFrmMain.cs
100 lines (81 loc) · 2.75 KB
/
FrmMain.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
using System.Text.Json;
namespace VampireSurvivorsSaveSync
{
public partial class FrmMain : Form
{
private Settings? UserSettings { get; set; } = default!;
private static string _settingsFile = Path.Combine(Directory.GetCurrentDirectory(), "usersettings.json");
public FrmMain()
{
UserSettings = new Settings();
if (_settingsFile != null && File.Exists(_settingsFile))
{
try
{
var settingsJson = File.ReadAllText(_settingsFile);
UserSettings = JsonSerializer.Deserialize<Settings>(settingsJson);
}
catch
{
// just keep empty settings file
}
}
InitializeComponent();
}
private void BtnChooseSteamSave_Click(object sender, EventArgs e)
{
var ofd = new OpenFileDialog();
if (ofd.ShowDialog() == DialogResult.OK)
{
string filePath = ofd.FileName;
txtSteam.Text = filePath;
}
}
private void BtnChooseAndroidSave_Click(object sender, EventArgs e)
{
var ofd = new OpenFileDialog();
if (ofd.ShowDialog() == DialogResult.OK)
{
string filePath = ofd.FileName;
txtAndroid.Text = filePath;
}
}
private void BtnSyncSteamAndroid_Click(object sender, EventArgs e)
{
if (File.Exists(txtSteam.Text))
{
File.Copy(txtSteam.Text, txtAndroid.Text, true);
}
}
private void BtnSyncAndroidSteam_Click(object sender, EventArgs e)
{
if (File.Exists(txtAndroid.Text))
{
File.Copy(txtAndroid.Text, txtSteam.Text, true);
}
}
private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
{
}
private void exitToolStripMenuItem_Click(object sender, EventArgs e)
{
Close();
}
private void saveToolStripMenuItem_Click(object sender, EventArgs e)
{
UserSettings ??= new Settings();
UserSettings.AndroidSave = txtAndroid.Text;
UserSettings.SteamSave = txtSteam.Text;
var jsonUserSettings = JsonSerializer.Serialize(UserSettings);
File.WriteAllText(_settingsFile, jsonUserSettings);
}
private void FrmMain_Load(object sender, EventArgs e)
{
if (UserSettings is not null)
{
txtAndroid.Text = UserSettings.AndroidSave;
txtSteam.Text = UserSettings.SteamSave;
}
}
}
}