Skip to content
This repository was archived by the owner on Feb 21, 2019. It is now read-only.

Commit 03e617a

Browse files
committed
delete extra folders
1 parent 855ae1d commit 03e617a

2 files changed

Lines changed: 90 additions & 10 deletions

File tree

src/Uninstall_Wrapper/Program.cs

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Microsoft.VS.ConfigurationManager;
22
using Microsoft.VS.ConfigurationManager.Support;
3+
using Microsoft.Win32;
34
using System;
45
using System.Collections.Generic;
56
using System.Diagnostics;
@@ -140,14 +141,17 @@ private static int Main(string[] args)
140141
var action = Console.ReadLine();
141142
if (!string.IsNullOrEmpty(action) && action.StartsWith("y", StringComparison.OrdinalIgnoreCase))
142143
{
144+
// cache the vs dirs in memory before uninstalling.
145+
var vsDirs = GetVisualStudioInstallationDirs();
146+
143147
int exitCode = ip.Uninstall();
144148

145149
if (exitCode == 3010)
146150
{
147151
Logger.LogWithOutput("Bundle requested to reboot the system. Please reboot your computer and run this application again.");
148152
return 3010;
149153
}
150-
ip.CleanupVisualStudioPackageCache();
154+
ip.CleanupVisualStudioFolders(vsDirs);
151155
ip.CleanupSecondaryInstallerCache();
152156
ip.CleanupVisualStudioRegistryHives();
153157
}
@@ -169,6 +173,57 @@ private static int Main(string[] args)
169173
return 0;
170174
}
171175

176+
private static IEnumerable<string> GetVisualStudioInstallationDirs()
177+
{
178+
List<string> vsDirs = new List<string>();
179+
if (Environment.Is64BitOperatingSystem)
180+
{
181+
vsDirs.Add((string)Registry.GetValue(
182+
"HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\Microsoft\\VisualStudio\\12.0\\",
183+
"InstallDir",
184+
null));
185+
vsDirs.Add((string)Registry.GetValue(
186+
"HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\Microsoft\\VisualStudio\\14.0\\",
187+
"InstallDir",
188+
null));
189+
vsDirs.Add((string)Registry.GetValue(
190+
"HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\Microsoft\\VisualStudio\\15.0\\",
191+
"InstallDir",
192+
null));
193+
}
194+
else
195+
{
196+
vsDirs.Add((string)Registry.GetValue(
197+
"HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\12.0\\",
198+
"InstallDir",
199+
null));
200+
vsDirs.Add((string)Registry.GetValue(
201+
"HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\14.0\\",
202+
"InstallDir",
203+
null));
204+
vsDirs.Add((string)Registry.GetValue(
205+
"HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\15.0\\",
206+
"InstallDir",
207+
null));
208+
}
209+
210+
// %AppData%\Microsoft\VisualStudio\14.0 & 12.0 & 15.0
211+
// %LocalAppData%\Microsoft\VisualStudio\14.0 & 12.0 & 15.0
212+
// %LocalAppData%\Microsoft\VSCommon\14.0 & 12.0 & 15.0
213+
var appDataRoot = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
214+
var localAppDataRoot = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
215+
var vsVers = new string[] { "12.0", "14.0", "15.0" };
216+
217+
foreach (var vsVer in vsVers)
218+
{
219+
vsDirs.Add(Path.Combine(appDataRoot, "Microsoft", "VisualStudio", vsVer));
220+
vsDirs.Add(Path.Combine(localAppDataRoot, "Microsoft", "VisualStudio", vsVer));
221+
vsDirs.Add(Path.Combine(localAppDataRoot, "Microsoft", "VSCommon", vsVer));
222+
}
223+
224+
return vsDirs;
225+
}
226+
172227
private static void PrintUsage()
173228
{
174229
Console.WriteLine("Welcome to Total Uninstaller.");

src/VS.ConfigurationManager/Primitives.cs

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,29 @@ public ICollection<Package> GetAllInstalledItems()
164164
return installations;
165165
}
166166

167+
/// <summary>
168+
/// Clean up Visual Studio folders.
169+
/// </summary>
170+
/// <param name="vsInstallPaths"></param>
171+
public void CleanupVisualStudioFolders(IEnumerable<string> vsInstallPaths)
172+
{
173+
foreach (var path in vsInstallPaths)
174+
{
175+
try
176+
{
177+
if (Directory.Exists(path) && !this.DoNotExecuteProcess)
178+
{
179+
Logger.LogWithOutput(string.Format("Deleting: {0}", path));
180+
this.RecursivelyDeleteFolder(path);
181+
}
182+
}
183+
catch (Exception ex)
184+
{
185+
Logger.LogWithOutput(string.Format("Cannot delete Secondary Installer cache with error: {0}", ex.Message));
186+
}
187+
}
188+
}
189+
167190
/// <summary>
168191
/// Clean up HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio
169192
/// Clean up HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\VisualStudio
@@ -173,7 +196,11 @@ public void CleanupVisualStudioRegistryHives()
173196
var keyPaths = new string[] {
174197
@"SOFTWARE\Microsoft\VisualStudio\12.0",
175198
@"SOFTWARE\Microsoft\VisualStudio\14.0",
176-
@"SOFTWARE\Microsoft\VisualStudio\15.0" };
199+
@"SOFTWARE\Microsoft\VisualStudio\15.0",
200+
@"SOFTWARE\Microsoft\VisualStudio\12.0_Config",
201+
@"SOFTWARE\Microsoft\VisualStudio\14.0_Config",
202+
@"SOFTWARE\Microsoft\VisualStudio\15.0_Config",
203+
};
177204

178205
foreach(var keyPath in keyPaths)
179206
{
@@ -195,6 +222,12 @@ private void DeleteRegistryKey(string keyPath)
195222

196223
var x64View = Win32.RegistryKey.OpenBaseKey(Win32.RegistryHive.LocalMachine, Win32.RegistryView.Registry64);
197224
x64View.DeleteSubKeyTree(keyPath, false);
225+
226+
x86View = Win32.RegistryKey.OpenBaseKey(Win32.RegistryHive.CurrentUser, Win32.RegistryView.Registry32);
227+
x86View.DeleteSubKeyTree(keyPath, false);
228+
229+
x64View = Win32.RegistryKey.OpenBaseKey(Win32.RegistryHive.CurrentUser, Win32.RegistryView.Registry64);
230+
x64View.DeleteSubKeyTree(keyPath, false);
198231
}
199232
catch (Exception ex)
200233
{
@@ -221,14 +254,6 @@ public void CleanupSecondaryInstallerCache()
221254
}
222255
}
223256

224-
/// <summary>
225-
/// Clean up sub-folders in %ProgramData%\Package Cache created by Visual Studio.
226-
/// </summary>
227-
public void CleanupVisualStudioPackageCache()
228-
{
229-
// TBD
230-
}
231-
232257
private static string CommonApplicationDataDirectory
233258
{
234259
get

0 commit comments

Comments
 (0)