-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathProgram.cs
197 lines (190 loc) · 7.52 KB
/
Program.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
using System;
using System.Diagnostics;
using System.IO;
using System.Net;
using System.Security.Permissions;
namespace DiscordCleaner
{
class Program
{
static void DrawStartScreen()
{
Console.Clear();
Console.WriteLine("********************************************************************************");
Console.WriteLine("* Discord Cleaner v0.1 by DatMayo Rel. 01.05.18 *");
Console.WriteLine("* WARNING! All login credentials will be lost and must be re entered! *");
Console.WriteLine("* *");
Console.WriteLine("* GitHub: https://github.com/DatMayolein/Discord-Cleaner *");
Console.WriteLine("********************************************************************************");
Console.WriteLine("");
Console.Write("Would you like to cleanup your Discord installation? (y/N) ");
ConsoleKeyInfo key = Console.ReadKey();
if (key.Key.ToString().ToLower() == "n")
{
Console.WriteLine("");
Console.WriteLine("");
Console.WriteLine("Operation aborted!");
Console.ReadKey();
}
else if (key.Key.ToString().ToLower() == "y")
GetProcesses();
else
DrawStartScreen();
}
static void GetProcesses()
{
Console.WriteLine("");
bool killFailed = false;
Console.WriteLine("");
Console.WriteLine("Searching for Discord processes... ");
Process[] discordHandle = Process.GetProcessesByName("discord");
Console.WriteLine(string.Format("- {0} Discord process(es)", discordHandle.Length));
foreach(Process p in discordHandle)
{
try
{
Console.Write("-> Killing Discord process...");
p.Kill();
Console.WriteLine("OK");
}
catch
{
Console.WriteLine("Failed");
killFailed = true;
}
}
if (killFailed)
{
Console.WriteLine("Can not proceed, some discord processes are still running!");
Console.ReadKey();
}
else
{
Console.WriteLine("Killing Discord process finished...");
Console.WriteLine("");
Console.WriteLine("Searching for Discord-Update processes... ");
Process[] updateHandle = Process.GetProcessesByName("update");
Console.WriteLine(string.Format("- {0} Discord-Update process(es)", updateHandle.Length));
foreach (Process p in updateHandle)
{
try
{
Console.Write("-> Killing Discord process...");
p.Kill();
Console.WriteLine("OK");
}
catch
{
Console.WriteLine("Failed");
killFailed = true;
}
}
if (killFailed)
{
Console.WriteLine("Can not proceed, some discord processes are still running!");
Console.ReadKey();
}
else
{
Console.WriteLine("Killing Discord-Update process finished...");
Console.WriteLine("");
Console.Write("Now waiting for 5 seconds...");
System.Threading.Thread.Sleep(5000); //Necessary, for whatever reason
Console.WriteLine("OK");
Console.WriteLine("");
RemoveDiscord();
}
}
}
static void RemoveDiscord()
{
bool deleteFailed = false;
string discordAppData = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\discord";
string discordLocalAppData = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\discord";
Console.WriteLine(string.Format("Checking folder \"{0}\"", discordAppData));
if(Directory.Exists(discordAppData))
{
Console.Write("Found existing discord in appdata-folder, deleting it...");
try
{
Directory.Delete(discordAppData, true);
Console.WriteLine("OK");
}
catch (Exception ex)
{
deleteFailed = true;
Console.WriteLine("Failed");
Console.Write(ex.Message);
}
}
if (deleteFailed)
{
Console.WriteLine("Can not proceed, some discord files may remain!");
Console.ReadKey();
}
else
{
Console.WriteLine("");
Console.WriteLine(string.Format("Checking folder \"{0}\"", discordLocalAppData));
if (Directory.Exists(discordLocalAppData))
{
Console.Write("Found existing discord in localappdata-folder, deleting it...");
try
{
Directory.Delete(discordLocalAppData, true);
Console.WriteLine("OK");
}
catch (Exception ex)
{
deleteFailed = true;
Console.WriteLine("Failed");
Console.Write(ex.Message);
}
}
if (deleteFailed)
{
Console.WriteLine("Can not proceed, some discord files may remain!");
Console.ReadKey();
}
else
{
Console.WriteLine("");
DownloadDiscordSetup();
}
}
}
static void DownloadDiscordSetup()
{
Console.Write("Downloading new Discord-Version (this can take some time)...");
WebClient client = new WebClient();
byte[] DiscordSetup = client.DownloadData("https://discordapp.com/api/download?platform=win");
File.WriteAllBytes("DiscordSetup.exe", DiscordSetup);
Console.WriteLine("Finished");
Console.WriteLine("");
InstallDiscord();
}
static void InstallDiscord()
{
Console.Write("Starting DiscordSetup.exe...");
Process process = new Process();
process.StartInfo.FileName = "DiscordSetup.exe";
process.Start();
process.WaitForExit();// Waits here for the process to exit.
Console.WriteLine("Finished");
Console.WriteLine("");
Console.WriteLine("All Done! Discord will start automatically.");
Console.ReadKey();
}
static void DownloadFinished()
{
//Console
Console.ReadKey();
}
static void Main(string[] args)
{
Console.Title = "Discord Cleaner";
Console.SetWindowSize(80, 40);
DrawStartScreen();
}
}
}