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

Commit 92de9e5

Browse files
committed
Merge pull request #30 from Microsoft/users/tobyhu/improv
delete vs folders and reg
2 parents 855ae1d + 59f5377 commit 92de9e5

3 files changed

Lines changed: 84 additions & 10 deletions

File tree

src/Uninstall_Wrapper/DataFile.bin

153 KB
Binary file not shown.

src/Uninstall_Wrapper/Program.cs

Lines changed: 50 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,51 @@ 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+
180+
var vsVers = new string[] { "12.0", "14.0", "15.0" };
181+
182+
// %AppData%\Microsoft\VisualStudio\14.0 & 12.0 & 15.0
183+
// %LocalAppData%\Microsoft\VisualStudio\14.0 & 12.0 & 15.0
184+
// %LocalAppData%\Microsoft\VSCommon\14.0 & 12.0 & 15.0
185+
var appDataRoot = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
186+
var localAppDataRoot = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
187+
188+
foreach (var vsVer in vsVers)
189+
{
190+
if (Environment.Is64BitOperatingSystem)
191+
{
192+
var installDir = (string)Registry.GetValue(
193+
string.Format("HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\Microsoft\\VisualStudio\\{0}\\", vsVer),
194+
"ShellFolder",
195+
null);
196+
if (!string.IsNullOrEmpty(installDir))
197+
{
198+
vsDirs.Add(installDir);
199+
}
200+
}
201+
else
202+
{
203+
var installDir = (string)Registry.GetValue(
204+
string.Format("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\{0}\\", vsVer),
205+
"ShellFolder",
206+
null);
207+
if (!string.IsNullOrEmpty(installDir))
208+
{
209+
vsDirs.Add(installDir);
210+
}
211+
}
212+
213+
vsDirs.Add(Path.Combine(appDataRoot, "Microsoft", "VisualStudio", vsVer));
214+
vsDirs.Add(Path.Combine(localAppDataRoot, "Microsoft", "VisualStudio", vsVer));
215+
vsDirs.Add(Path.Combine(localAppDataRoot, "Microsoft", "VSCommon", vsVer));
216+
}
217+
218+
return vsDirs;
219+
}
220+
172221
private static void PrintUsage()
173222
{
174223
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 (!string.IsNullOrEmpty(path) && 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)