-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathForm1.cs
191 lines (172 loc) · 6.67 KB
/
Form1.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Management;
using System.IO;
namespace Ukiatality
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Initialize_Click(object sender, EventArgs e)
{
// find config dir
string myDocumentsPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments);
string targetFolderPath = Path.Combine(myDocumentsPath, "FALITATA");
CFGDir.Text = targetFolderPath;
if (!Directory.Exists(targetFolderPath))
{
Directory.CreateDirectory(targetFolderPath);
}
// list all config
string[] cfgFiles = Directory.GetFiles(targetFolderPath, "*", SearchOption.AllDirectories);
ConfigList.Items.Clear();
foreach (string cfgFile in cfgFiles)
{
string fileName = Path.GetFileName(cfgFile);
ConfigList.Items.Add(fileName);
}
Refresh.Enabled = true;
OpenDir.Enabled = true;
Create.Enabled = true;
// find cs dir
string processName = "CS2.EXE";
ManagementObjectSearcher searcher = new ManagementObjectSearcher($"SELECT * FROM Win32_Process WHERE Name = '{processName}'");
bool foundProcess = false;
foreach (ManagementObject process in searcher.Get())
{
string processPath = process["ExecutablePath"]?.ToString();
if (!string.IsNullOrEmpty(processPath))
{
string directoryPath = System.IO.Path.GetDirectoryName(processPath);
Dir.Text = directoryPath;
foundProcess = true;
Load.Enabled = true;
Save.Enabled = true;
}
}
if (!foundProcess)
{
Dir.Text = "Plz start CS2 first!!";
}
}
private void Save_Click(object sender, EventArgs e)
{
DialogResult result = MessageBox.Show("Are you sure to save?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
if (result == DialogResult.Yes)
{
string configFile = Path.Combine(Dir.Text, "fatal_settings.cfg");
string content = File.ReadAllText(configFile);
string ConfigName = CFGName.Text;
string configPath = Path.Combine(CFGDir.Text, ConfigName);
File.WriteAllText(configPath, content);
}
else
{
return;
}
}
private void Refresh_Click(object sender, EventArgs e)
{
if (!Directory.Exists(CFGDir.Text))
{
Directory.CreateDirectory(CFGDir.Text);
}
// list all config
string[] cfgFiles = Directory.GetFiles(CFGDir.Text, "*", SearchOption.AllDirectories);
ConfigList.Items.Clear();
foreach (string cfgFile in cfgFiles)
{
string fileName = Path.GetFileName(cfgFile);
ConfigList.Items.Add(fileName);
}
}
private void Load_Click(object sender, EventArgs e)
{
DialogResult result = MessageBox.Show("Are you sure to load?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
if (result == DialogResult.Yes)
{
string configFile = Path.Combine(Dir.Text, "fatal_settings.cfg");
string ConfigName = CFGName.Text;
string configPath = Path.Combine(CFGDir.Text, ConfigName);
string fileContent = File.ReadAllText(configPath);
File.WriteAllText(configFile, fileContent);
}
else
{
return;
}
}
private void Create_Click(object sender, EventArgs e)
{
string configFile = Path.Combine(CFGDir.Text, CFGName.Text);
if (!File.Exists(configFile) && CFGName.Text != "Config already exist!!")
{
// create file
FileStream fs = File.Create(configFile);
fs.Close(); // close file stream
string contentFile = Path.Combine(Dir.Text, "fatal_settings.cfg");
string content = File.ReadAllText(contentFile);
File.WriteAllText(configFile, content);
}
else
{
CFGName.Text = "Config already exist!!";
}
if (!Directory.Exists(CFGDir.Text))
{
Directory.CreateDirectory(CFGDir.Text);
}
// list all config
string[] cfgFiles = Directory.GetFiles(CFGDir.Text, "*", SearchOption.AllDirectories);
ConfigList.Items.Clear();
foreach (string cfgFile in cfgFiles)
{
string fileName = Path.GetFileName(cfgFile);
ConfigList.Items.Add(fileName);
}
}
private void ConfigList_SelectedIndexChanged(object sender, EventArgs e)
{
if (ConfigList.SelectedItem != null)
{
CFGName.Text = ConfigList.SelectedItem.ToString();
}
}
private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
System.Diagnostics.Process.Start("https://www.pcrf.net/");
}
private void linkLabel2_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
System.Diagnostics.Process.Start("https://help.unicef.org/donate-to-children");
}
private void linkLabel3_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
System.Diagnostics.Process.Start("https://donate.unrwa.org/gaza/~my-donation");
}
private void OpenDir_Click(object sender, EventArgs e)
{
System.Diagnostics.Process.Start("explorer.exe", CFGDir.Text);
// list all config
string[] cfgFiles = Directory.GetFiles(CFGDir.Text, "*", SearchOption.AllDirectories);
ConfigList.Items.Clear();
foreach (string cfgFile in cfgFiles)
{
string fileName = Path.GetFileName(cfgFile);
ConfigList.Items.Add(fileName);
}
}
}
}