-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMainForm.cs
346 lines (327 loc) · 10.5 KB
/
MainForm.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
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
using Microsoft.Win32;
using NotifyBin.Properties;
using System;
using System.Diagnostics;
using System.Linq;
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace NotifyBin
{
public partial class MainForm : Form
{
//Автозапуск приложения
readonly RegistryKey myKey = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run", true);
//Папка в реестре где хранятся параметры программы
readonly RegistryKey key = Registry.CurrentUser.CreateSubKey(@"Software\NotifyBin");
enum RecycleFlags : uint
{
SHRB_NOCONFIRMATION = 0x00000001, // Don't ask confirmation
SHRB_NOPROGRESSUI = 0x00000002, // Don't show any windows dialog
SHRB_NOSOUND = 0x00000004 // Don't make sound, ninja mode enabled :v
}
[DllImport("Shell32.dll", CharSet = CharSet.Unicode)]
static extern uint SHEmptyRecycleBin(IntPtr hwnd, string pszRootPath, RecycleFlags dwFlags);
public MainForm()
{
InitializeComponent();
}
//Начало - Не показывать программу в Alt-tab
[DllImport("user32.dll")]
private static extern int SetWindowLong(IntPtr window, int index, int value);
[DllImport("user32.dll")]
private static extern int GetWindowLong(IntPtr window, int index);
private const int GWL_EXSTYLE = -20;
private const int WS_EX_TOOLWINDOW = 0x00000080;
public static void HideFromAltTab(IntPtr Handle)
{
SetWindowLong(Handle, GWL_EXSTYLE, GetWindowLong(Handle,
GWL_EXSTYLE) | WS_EX_TOOLWINDOW);
}
//Конец - Не показывать программу в Alt-tab
//Очистка корзины
private void clearToolStripMenuItem_Click(object sender, EventArgs e)
{
try
{
uint IsSuccess = SHEmptyRecycleBin(IntPtr.Zero, null, RecycleFlags.SHRB_NOCONFIRMATION);//Очистка корзины
GetNotifyData();
notify.BalloonTipTitle = "Notify Bin";
notify.BalloonTipText = Language.Translate("BinClear"); //"Recycle Bin is successfully cleared!";
notify.BalloonTipIcon = ToolTipIcon.Info;
notify.ShowBalloonTip(1000);
}
catch (Exception ex)
{
notify.BalloonTipTitle = "Notify Bin";
notify.BalloonTipText = Language.Translate("BinNotClear"); //"Recycle Bin has not been cleared!";
notify.BalloonTipIcon = ToolTipIcon.Error;
notify.ShowBalloonTip(1000);
}
}
//Открываем папку корзины
private void openToolStripMenuItem_Click(object sender, EventArgs e)
{
Process.Start("explorer", "shell:RecycleBinFolder"); // Открыть корзину
}
private void MainForm_Load(object sender, EventArgs e)
{
GetRegistryData();
GetLanguage(); //Надо пробовать
GetNotifyData();
timer.Start();
HideFromAltTab(this.Handle);//Запуск метода скрывает программу из alt-tab
}
//Локализация
private void GetLanguage()
{
Language.lang = key.GetValue("Language").ToString();
ControlsLang();
}
//Раз в минуту обновляем, информацию о корзине
private void timer_Tick(object sender, EventArgs e)
{
GetNotifyData();
}
//Размер и количество файлов при наведении на значек в строке уведомлений
private void GetNotifyData()
{
GetBinData databin = new GetBinData();
//Сколько сейчас данных в корзине
databin.GetSize();
if (databin._file_sizeMB == 0 && databin._num_itemsMB == 0)
{
clearToolStripMenuItem.Enabled = false;
}
else { clearToolStripMenuItem.Enabled = true; }
notify.Text = "Notify Bin v1.11\n\n" + databin._num_items + "\n" + databin._file_size;
//Сколько всего данных в корзине
double sum = databin.GetMaxSize();
int iconpersent = 0;
if (databin._file_sizeMB >= ((sum / 100) * 75) || databin._file_sizeMB <= ((sum / 100) * 75))
{
iconpersent = 75;
if (databin._file_sizeMB <= ((sum / 100) * 50))
{
iconpersent = 50;
if (databin._file_sizeMB <= ((sum / 100) * 25))
{
iconpersent = 25;
if (databin._file_sizeMB == 0)
{
iconpersent = 0;
if(databin._num_itemsMB >= 1)
{
iconpersent = 25;
}
}
}
}
}
if (databin._file_sizeMB >= ((sum / 100) * 99))
{
iconpersent = 100;
}
switch (iconpersent)
{
case 0:
notify.Icon = Resources.OkIcon;//Иконка OK
break;
case 25:
notify.Icon = Resources.NotIcon25;//Иконка 25%
break;
case 50:
notify.Icon = Resources.NotIcon50;//Иконка 50%
break;
case 75:
notify.Icon = Resources.NotIcon75;//Иконка 75%
break;
case 100:
notify.Icon = Resources.NotIcon100;//Иконка 100%
break;
default:
notify.Icon = Resources.DefaultIcon;
break;
}
}
//Все настройки записываються в реестр
private void GetRegistryData()
{
try
{
var value = key.GetValue("Autostart");
switch(value)
{
case 1:
onToolStripMenuItem.Checked = true;
offToolStripMenuItem.Checked = false;
break;
default :
key.SetValue("Autostart", 0);
onToolStripMenuItem.Checked = false;
offToolStripMenuItem.Checked = true;
break;
}
}
catch
{
key.SetValue("Autostart", 0);
}
//Узнаем действие на дабл клик по иконке из реестра, если в реестре пусто создаем.
//По умолчанию действие Открыть корзину
try
{
var value = key.GetValue("DoubleClickAction");
switch (value)
{
case "Open":
openDoubleClickAction.Checked = true;
clearDoubleClickAction.Checked = false;
break;
case "Clear":
openDoubleClickAction.Checked = false;
clearDoubleClickAction.Checked = true;
break;
default:
key.SetValue("DoubleClickAction", "Open");
openDoubleClickAction.Checked = true;
clearDoubleClickAction.Checked = false;
break;
}
}
catch
{
key.SetValue("DoubleClickAction", "Open");
}
//Определяем локализацию
try
{
var value = key.GetValue("Language");
switch (value)
{
case "ENG":
englishToolStripMenuItem.Checked = true;
russianToolStripMenuItem.Checked = false;
break;
case "RU":
englishToolStripMenuItem.Checked = false;
russianToolStripMenuItem.Checked = true;
break;
default:
key.SetValue("Language", "ENG");
englishToolStripMenuItem.Checked = true;
russianToolStripMenuItem.Checked = false;
break;
}
}
catch
{
key.SetValue("Language", "ENG");
}
}
//Включить автозапуск при старте Windows
private void onToolStripMenuItem_Click(object sender, EventArgs e)
{
try
{
if (myKey.GetValue("NotifyBin").ToString() != Application.ExecutablePath)
myKey.SetValue("NotifyBin", Application.ExecutablePath);
}
catch (NullReferenceException ex)
{
myKey.SetValue("NotifyBin", Application.ExecutablePath);
}
key.SetValue("Autostart", 1);
onToolStripMenuItem.Checked = true;
offToolStripMenuItem.Checked = false;
}
//Выключить автозапуск при старте Windows
public void offToolStripMenuItem_Click(object sender, EventArgs e)
{
try
{
if (myKey.GetValue("NotifyBin").ToString() == Application.ExecutablePath)
myKey.DeleteValue("NotifyBin");
}
catch (NullReferenceException ex)
{
myKey.DeleteValue("NotifyBin");
}
key.SetValue("Autostart", 0);
onToolStripMenuItem.Checked = false;
offToolStripMenuItem.Checked = true;
}
//Действие при двойном клике по иконке
private void notify_MouseDoubleClick(object sender, MouseEventArgs e)
{
if (key.GetValue("DoubleClickAction").ToString() == "Open")
{
Process.Start("explorer", "shell:RecycleBinFolder");
}
else
{
clearToolStripMenuItem_Click(null, null);
}
}
//Очистить - Действие при двойном клике по иконке
private void clearDoubleClickAction_Click(object sender, EventArgs e)
{
key.SetValue("DoubleClickAction", "Clear");
clearDoubleClickAction.Checked = true;
openDoubleClickAction.Checked = false;
}
//Открыть - Действие при двойном клике по иконке
private void openDoubleClickAction_Click(object sender, EventArgs e)
{
key.SetValue("DoubleClickAction", "Open");
clearDoubleClickAction.Checked = false;
openDoubleClickAction.Checked = true;
}
//О программе
private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
{
if (!Application.OpenForms.OfType<About>().Any())
new About().Show();
}
//Закрыть программму
private void exitToolStripMenuItem_Click(object sender, EventArgs e)
{
Dispose();
Application.Exit();
}
private void englishToolStripMenuItem_Click(object sender, EventArgs e)
{
Language.lang = "ENG";
key.SetValue("Language","ENG");
ControlsLang();
englishToolStripMenuItem.Checked = true;
russianToolStripMenuItem.Checked = false;
}
private void russianToolStripMenuItem_Click(object sender, EventArgs e)
{
Language.lang = "RU";
key.SetValue("Language", "RU");
ControlsLang();
englishToolStripMenuItem.Checked = false;
russianToolStripMenuItem.Checked = true;
}
//Интерфейс <-- Языковой словарь
//ENG
void ControlsLang()
{
openToolStripMenuItem.Text = Language.Translate("Open");
clearToolStripMenuItem.Text = Language.Translate("Clear");
settingsToolStripMenuItem.Text = Language.Translate("Settings");
autostartToolStripMenuItem.Text = Language.Translate("Autostart");
onToolStripMenuItem.Text = Language.Translate("onAutostart");
offToolStripMenuItem.Text = Language.Translate("offAutostart");
DoubleClickAction.Text = Language.Translate("IconDblClikAction");
openDoubleClickAction.Text = Language.Translate("openIconDblClikAction");
clearDoubleClickAction.Text = Language.Translate("clearIconDblClikAction");
languageToolStripMenuItem.Text = Language.Translate("Language");
englishToolStripMenuItem.Text = Language.Translate("engLanguage");
russianToolStripMenuItem.Text = Language.Translate("ruLanguage");
aboutToolStripMenuItem.Text = Language.Translate("About");
exitToolStripMenuItem.Text = Language.Translate("Exit");
}
}
}