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

Commit

Permalink
Merge pull request #30 from Microsoft/users/tobyhu/improv
Browse files Browse the repository at this point in the history
delete vs folders and reg
  • Loading branch information
tobyhu87 committed May 4, 2016
2 parents 855ae1d + 59f5377 commit 92de9e5
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 10 deletions.
Binary file modified src/Uninstall_Wrapper/DataFile.bin
Binary file not shown.
51 changes: 50 additions & 1 deletion src/Uninstall_Wrapper/Program.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Microsoft.VS.ConfigurationManager;
using Microsoft.VS.ConfigurationManager.Support;
using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.Diagnostics;
Expand Down Expand Up @@ -140,14 +141,17 @@ private static int Main(string[] args)
var action = Console.ReadLine();
if (!string.IsNullOrEmpty(action) && action.StartsWith("y", StringComparison.OrdinalIgnoreCase))
{
// cache the vs dirs in memory before uninstalling.
var vsDirs = GetVisualStudioInstallationDirs();

int exitCode = ip.Uninstall();

if (exitCode == 3010)
{
Logger.LogWithOutput("Bundle requested to reboot the system. Please reboot your computer and run this application again.");
return 3010;
}
ip.CleanupVisualStudioPackageCache();
ip.CleanupVisualStudioFolders(vsDirs);
ip.CleanupSecondaryInstallerCache();
ip.CleanupVisualStudioRegistryHives();
}
Expand All @@ -169,6 +173,51 @@ private static int Main(string[] args)
return 0;
}

private static IEnumerable<string> GetVisualStudioInstallationDirs()
{
List<string> vsDirs = new List<string>();

var vsVers = new string[] { "12.0", "14.0", "15.0" };

// %AppData%\Microsoft\VisualStudio\14.0 & 12.0 & 15.0
// %LocalAppData%\Microsoft\VisualStudio\14.0 & 12.0 & 15.0
// %LocalAppData%\Microsoft\VSCommon\14.0 & 12.0 & 15.0
var appDataRoot = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
var localAppDataRoot = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);

foreach (var vsVer in vsVers)
{
if (Environment.Is64BitOperatingSystem)
{
var installDir = (string)Registry.GetValue(
string.Format("HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\Microsoft\\VisualStudio\\{0}\\", vsVer),
"ShellFolder",
null);
if (!string.IsNullOrEmpty(installDir))
{
vsDirs.Add(installDir);
}
}
else
{
var installDir = (string)Registry.GetValue(
string.Format("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\{0}\\", vsVer),
"ShellFolder",
null);
if (!string.IsNullOrEmpty(installDir))
{
vsDirs.Add(installDir);
}
}

vsDirs.Add(Path.Combine(appDataRoot, "Microsoft", "VisualStudio", vsVer));
vsDirs.Add(Path.Combine(localAppDataRoot, "Microsoft", "VisualStudio", vsVer));
vsDirs.Add(Path.Combine(localAppDataRoot, "Microsoft", "VSCommon", vsVer));
}

return vsDirs;
}

private static void PrintUsage()
{
Console.WriteLine("Welcome to Total Uninstaller.");
Expand Down
43 changes: 34 additions & 9 deletions src/VS.ConfigurationManager/Primitives.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,29 @@ public ICollection<Package> GetAllInstalledItems()
return installations;
}

/// <summary>
/// Clean up Visual Studio folders.
/// </summary>
/// <param name="vsInstallPaths"></param>
public void CleanupVisualStudioFolders(IEnumerable<string> vsInstallPaths)
{
foreach (var path in vsInstallPaths)
{
try
{
if (!string.IsNullOrEmpty(path) && Directory.Exists(path) && !this.DoNotExecuteProcess)
{
Logger.LogWithOutput(string.Format("Deleting: {0}", path));
this.RecursivelyDeleteFolder(path);
}
}
catch (Exception ex)
{
Logger.LogWithOutput(string.Format("Cannot delete Secondary Installer cache with error: {0}", ex.Message));
}
}
}

/// <summary>
/// Clean up HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio
/// Clean up HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\VisualStudio
Expand All @@ -173,7 +196,11 @@ public void CleanupVisualStudioRegistryHives()
var keyPaths = new string[] {
@"SOFTWARE\Microsoft\VisualStudio\12.0",
@"SOFTWARE\Microsoft\VisualStudio\14.0",
@"SOFTWARE\Microsoft\VisualStudio\15.0" };
@"SOFTWARE\Microsoft\VisualStudio\15.0",
@"SOFTWARE\Microsoft\VisualStudio\12.0_Config",
@"SOFTWARE\Microsoft\VisualStudio\14.0_Config",
@"SOFTWARE\Microsoft\VisualStudio\15.0_Config",
};

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

var x64View = Win32.RegistryKey.OpenBaseKey(Win32.RegistryHive.LocalMachine, Win32.RegistryView.Registry64);
x64View.DeleteSubKeyTree(keyPath, false);

x86View = Win32.RegistryKey.OpenBaseKey(Win32.RegistryHive.CurrentUser, Win32.RegistryView.Registry32);
x86View.DeleteSubKeyTree(keyPath, false);

x64View = Win32.RegistryKey.OpenBaseKey(Win32.RegistryHive.CurrentUser, Win32.RegistryView.Registry64);
x64View.DeleteSubKeyTree(keyPath, false);
}
catch (Exception ex)
{
Expand All @@ -221,14 +254,6 @@ public void CleanupSecondaryInstallerCache()
}
}

/// <summary>
/// Clean up sub-folders in %ProgramData%\Package Cache created by Visual Studio.
/// </summary>
public void CleanupVisualStudioPackageCache()
{
// TBD
}

private static string CommonApplicationDataDirectory
{
get
Expand Down

0 comments on commit 92de9e5

Please sign in to comment.