-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMainForm.cs
More file actions
115 lines (103 loc) · 3.84 KB
/
MainForm.cs
File metadata and controls
115 lines (103 loc) · 3.84 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
namespace MTGAM;
public partial class MainForm : Form {
private readonly (Guid create, Guid save, Guid load) dialogGUID =
(Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid());
private AddonConfigFile? acf;
/// <summary>
/// Shows a <see cref="FolderBrowserDialog"/>, so that the user can select a plugin directory. If one is selected, <see cref="TryToLoadPlugin"/> will be called.
/// </summary>
private void ShowLoadPluginDialog() {
FolderBrowserDialog fbd = new() {
ClientGuid = dialogGUID.load,
Description = "Select a folder that contains a 'plugin.cfg' file.",
RootFolder = Environment.SpecialFolder.MyComputer,
InitialDirectory = "",
AutoUpgradeEnabled = true,
ShowNewFolderButton = false,
ShowPinnedPlaces = true,
UseDescriptionForTitle = true,
};
DialogResult res = fbd.ShowDialog();
if (res == DialogResult.Cancel)
return;
this.TryToLoadPlugin(fbd.SelectedPath);
}
private void submitChange(object? sender, EventArgs? e) { }
private void refreshInfo() {
if (this.acf is null) {
B_Reload.Enabled = false;
B_SaveChanges.Enabled = false;
return;
}
B_Reload.Enabled = true;
B_SaveChanges.Enabled = true;
TB_Name.Text = this.acf.FindValue("name");
TB_Description.Text = this.acf.FindValue("description");
TB_Author.Text = this.acf.FindValue("author");
TB_Version.Text = this.acf.FindValue("version");
TB_Script.Text = this.acf.FindValue("script");
}
private void CreatePlugin(String root) {
//this.acf = new(root) {
// Name = TB_Name.Text,
// Description = TB_Description.Text,
// Author = TB_Author.Text,
// Version = TB_Version.Text,
// Script = TB_Script.Text
//};
if (this.acf is not null)
return;
//String cfgData = this.acf.Compile();
File.WriteAllText(this.acf.FilePath, null);
}
private void TryToLoadPlugin(String root) {
TB_PluginRoot.Text = root;
if (!AddonConfigFile.DirectoryIsValidPlugin(root)) {
CB_ValidPath.Checked = false;
return;
}
CB_ValidPath.Checked = true;
this.acf = new(root);
this.refreshInfo();
}
public MainForm() {
this.InitializeComponent();
}
private void MainForm_Load(object sender, EventArgs e) {
TB_Author.Text = Environment.UserName;
}
private void TSMI_Exit_Click(object sender, EventArgs e) {
this.Close();
}
private void TSMI_StartSync_Click(object sender, EventArgs e) { }
private void TSMI_NewAddon_Click(object sender, EventArgs e) {
FolderBrowserDialog fbd = new() {
ClientGuid = dialogGUID.load,
Description = "Select a folder that will contain a 'plugin.cfg' file.",
RootFolder = Environment.SpecialFolder.MyComputer,
InitialDirectory = "",
AutoUpgradeEnabled = true,
ShowNewFolderButton = false,
ShowPinnedPlaces = true,
UseDescriptionForTitle = true,
};
DialogResult res = fbd.ShowDialog();
if (res == DialogResult.Cancel)
return;
this.acf = new(fbd.SelectedPath);
this.acf.Create();
}
private void TSMI_Load_Click(object sender, EventArgs e) {
this.ShowLoadPluginDialog();
}
private void TB_PluginRoot_Click(object sender, EventArgs e) {
this.ShowLoadPluginDialog();
}
private void B_Reload_Click(object sender, EventArgs e) {
this.refreshInfo();
}
private void TB_Script_Click(object sender, EventArgs e) {
}
private void CB_ScriptType_SelectedIndexChanged(object sender, EventArgs e) {
}
}