-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMain.cs
291 lines (246 loc) · 9.85 KB
/
Main.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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
using Abdal_Security_Group_App.Core;
using System.Diagnostics;
using System.Reflection;
using Telerik.WinControls.Enumerations;
namespace Abdal_Security_Group_App
{
public partial class Main : Telerik.WinControls.UI.RadForm
{
private bool stop_op_status = false;
private string abdal_app_name = Assembly.GetExecutingAssembly().GetName().ToString().Split(',')[0];
private AbdalSoundPlayer ab_player = new AbdalSoundPlayer();
private string abdal_app_name_for_url = Assembly.GetExecutingAssembly().GetName().ToString().Split(',')[0]
.ToLower().Replace(' ', '-');
public Main()
{
InitializeComponent();
//change form title
Version version = Assembly.GetExecutingAssembly().GetName().Version!;
Text = abdal_app_name + " " + version.Major + "." + version.Minor;
// Call Global Chilkat Unlock
ChilkatMng.UnlockChilkat();
}
#region Dragable Form Start
protected override void WndProc(ref Message m)
{
base.WndProc(ref m);
if (m.Msg == WM_NCHITTEST)
m.Result = (IntPtr)(HT_CAPTION);
}
private const int WM_NCHITTEST = 0x84;
private const int HT_CLIENT = 0x1;
private const int HT_CAPTION = 0x2;
#endregion
private void Main_Load(object sender, EventArgs e)
{
for (char drive = 'A'; drive <= 'Z'; drive++)
{
drive_list.Items.Add(drive.ToString());
}
}
private void menuItem_github_Click(object sender, EventArgs e)
{
ab_player.sPlayer("checkbox");
Process.Start(new ProcessStartInfo("https://github.com/ebrasha/" + abdal_app_name_for_url)
{ UseShellExecute = true });
}
private void menuItem_gitlab_Click(object sender, EventArgs e)
{
ab_player.sPlayer("checkbox");
Process.Start(new ProcessStartInfo("https://gitlab.com/Prof.Shafiei/" + abdal_app_name_for_url)
{ UseShellExecute = true });
}
private void menuItem_donate_Click(object sender, EventArgs e)
{
}
private void menuItem_about_us_Click(object sender, EventArgs e)
{
ab_player.sPlayer("checkbox");
about_us about_form = new Abdal_Security_Group_App.about_us();
about_form.ShowDialog();
about_form.TopMost = true;
}
private void Main_FormClosing(object sender, FormClosingEventArgs e)
{
ab_player.sPlayer("checkbox");
Process.GetCurrentProcess().Kill();
Environment.Exit(0);
}
private void bg_worker_RunWorkerCompleted(object sender, System.ComponentModel.RunWorkerCompletedEventArgs e)
{
waitingBar.StopWaiting();
waitingBar.Visible = false;
if (e.Cancelled == true)
{
this.desk_alert.CaptionText = abdal_app_name;
this.desk_alert.ContentText = "Canceled Process By User!";
this.desk_alert.Show();
ab_player.sPlayer("cancel");
}
else if (e.Error != null)
{
this.desk_alert.CaptionText = abdal_app_name;
this.desk_alert.ContentText = e.Error.Message;
this.desk_alert.Show();
ab_player.sPlayer("error");
}
else
{
this.desk_alert.CaptionText = abdal_app_name;
this.desk_alert.ContentText = "Done!";
this.desk_alert.Show();
if (stop_op_status)
{
ab_player.sPlayerSync("cancel");
}
else
{
ab_player.sPlayerSync("op-com");
}
ab_player.sPlayer("done");
}
}
static bool DriveExists(string driveName)
{
DriveInfo[] allDrives = DriveInfo.GetDrives();
foreach (DriveInfo drive in allDrives)
{
if (drive.Name.Equals(driveName, StringComparison.OrdinalIgnoreCase))
{
return true;
}
}
return false;
}
private void btn_start_Click(object sender, EventArgs e)
{
string driveName = drive_list.Text + ":\\";
bool driveExists = DriveExists(driveName);
if (tbFileName.Text == "")
{
ab_player.sPlayer("error");
ShowMessage(
"The file name is not specified. Please enter the file name along with the extension first");
}
else if (!driveExists)
{
ab_player.sPlayer("error");
ShowMessage($"The drive {driveName} does not exist");
}
else
{
if (bg_worker.IsBusy != true)
{
waitingBar.StartWaiting();
waitingBar.Visible = true;
bg_worker.RunWorkerAsync();
}
}
}
private void btn_exit_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void btn_minimize_Click(object sender, EventArgs e)
{
this.WindowState = FormWindowState.Minimized;
}
private void irDonationBtn_Click(object sender, EventArgs e)
{
ab_player.sPlayer("coin");
Process.Start(new ProcessStartInfo("https://alphajet.ir/abdal-donation") { UseShellExecute = true });
}
private void EnDonationBtn_Click(object sender, EventArgs e)
{
ab_player.sPlayer("coin");
Process.Start(new ProcessStartInfo("https://ebrasha.com/abdal-donation") { UseShellExecute = true });
}
public void ShowMessage(string message)
{
this.desk_alert.CaptionText = abdal_app_name;
this.desk_alert.ContentText = message;
this.desk_alert.Show();
}
private void bg_worker_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
{
long fileSize = 0;
if (!string.IsNullOrEmpty(drive_list.Text) && drive_list.Text.Length == 1)
{
string driveName = drive_list.Text + ":\\";
// Check if the drive exists
if (DriveInfo.GetDrives().Any(d => d.Name.Equals(driveName, StringComparison.OrdinalIgnoreCase)))
{
DriveInfo driveInfo = new DriveInfo(driveName);
// Get the available free space in bytes
long availableFreeSpace = driveInfo.AvailableFreeSpace;
fileSize = availableFreeSpace;
// If fileSize is 0 or more than available space, use availableFreeSpace
if (fillDriveToggleSwitch.Value)
{
tbFileSize.Text = availableFreeSpace.ToString();
radioBtByteUnit.ToggleState = ToggleState.On;
}
else
{
if (radioBtByteUnit.ToggleState == ToggleState.On)
{
fileSize = Convert.ToInt64(tbFileSize.Text);
}
if (radioBtMBUnit.ToggleState == ToggleState.On)
{
fileSize = Convert.ToInt64(tbFileSize.Text) * 1048576;
}
if (radioBtGBUnit.ToggleState == ToggleState.On)
{
fileSize = Convert.ToInt64(tbFileSize.Text) * 1073741824;
}
}
// Create a file to fill the free space
string filePath = Path.Combine(driveName, tbFileName.Text);
ShowMessage($"Creating a file '{tbFileName.Text}' with {fileSize} bytes.");
try
{
// Run the fsutil command to create the file
ProcessStartInfo processStartInfo = new ProcessStartInfo("fsutil")
{
Arguments = $"file createnew {filePath} {fileSize}",
RedirectStandardOutput = true,
UseShellExecute = false,
CreateNoWindow = true
};
using (Process process = Process.Start(processStartInfo))
{
process.WaitForExit();
// Display the output of the command
string output = process.StandardOutput.ReadToEnd();
ShowMessage(output);
}
ShowMessage("File created successfully.");
}
catch (Exception ex)
{
ab_player.sPlayer("error");
ShowMessage($"An error occurred: {ex.Message}");
}
}
else
{
ab_player.sPlayer("error");
ShowMessage("Invalid drive letter or drive does not exist.");
}
}
else
{
ab_player.sPlayer("error");
ShowMessage("Invalid input. Please enter a single drive letter.");
}
}
private void tbFileSize_KeyPress(object sender, KeyPressEventArgs e)
{
if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar))
{
e.Handled = true;
}
}
}
}