-
Notifications
You must be signed in to change notification settings - Fork 0
/
formMain.cs
149 lines (124 loc) · 4.29 KB
/
formMain.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
using System;
using System.Diagnostics;
using System.IO;
using System.Runtime.InteropServices;
using System.Threading;
using System.Windows.Forms;
namespace ShortcutCleaner
{
public partial class formMain : Form
{
[DllImport("Shell32.dll", CharSet = CharSet.Auto, SetLastError = true)]
private static extern void SHChangeNotify(uint wEventId, uint uFlags, IntPtr dwItem1, IntPtr dwItem2);
public const int SHCNE_ASSOCCHANGED = 0x8000000;
public const int SHCNF_IDLIST = 0;
public string commonPath;
public string specialPath;
public formMain()
{
InitializeComponent();
this.WindowState = FormWindowState.Minimized;
}
private void formMain_Load(object sender, EventArgs e)
{
commonPath = Environment.GetFolderPath(Environment.SpecialFolder.CommonDesktopDirectory);
specialPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
fileSystemWatcher1.Path = commonPath;
fileSystemWatcher2.Path = specialPath;
this.ShowInTaskbar = false;
loadClean(commonPath);
loadClean(specialPath);
}
private void timer1_Tick(object sender, EventArgs e)
{
}
private void clean(string cleanPath)
{
string checkEx = @".lnk";
string extension = Path.GetExtension(cleanPath);
if (extension == checkEx)
{
Thread.Sleep(2000);
File.Delete(cleanPath);
}
SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, IntPtr.Zero, IntPtr.Zero);
}
private void loadClean(string cleanPath)
{
string checkEx = @".lnk";
foreach (string fileName in Directory.GetFiles(cleanPath))
{
string extension = Path.GetExtension(fileName);
if (extension == checkEx)
{
File.Delete(fileName);
}
}
}
private void bClean_Click(object sender, EventArgs e)
{
clean(commonPath);
clean(specialPath);
}
private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e)
{
}
private void menuStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
{
}
private void cleanNowToolStripMenuItem_Click(object sender, EventArgs e)
{
this.clean(specialPath);
this.clean(commonPath);
}
private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
{
this.WindowState = FormWindowState.Normal;
this.Visible = true;
this.ShowInTaskbar = true;
}
private void TextBox1_TextChanged(object sender, EventArgs e)
{
}
private void lnkGitHub_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
Process.Start("https://github.com/MattGHarvey/ShortcutCleaner");
}
private void OnApplicationExit(object sender, EventArgs e)
{
//Cleanup so that the icon will be removed when the application is closed
notifyIcon1.Visible = false;
}
private void lnkGitHub_Resize(object sender, EventArgs e)
{
}
private void formMain_Resize(object sender, EventArgs e)
{
if (this.WindowState == FormWindowState.Minimized)
{
notifyIcon1.Visible = true;
this.Hide();
}
}
private void formMain_FormClosing(object sender, FormClosingEventArgs e)
{
this.WindowState = FormWindowState.Minimized;
e.Cancel = true;
}
private void exitToolStripMenuItem_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void fileSystemWatcher1_Changed(object sender, FileSystemEventArgs e)
{
}
private void fileSystemWatcher1_Created(object sender, FileSystemEventArgs e)
{
clean(e.FullPath);
}
private void fileSystemWatcher2_Created(object sender, FileSystemEventArgs e)
{
clean(e.FullPath);
}
}
}