11using Microsoft . VS . ConfigurationManager ;
22using Microsoft . VS . ConfigurationManager . Support ;
3+ using Microsoft . Win32 ;
34using System ;
45using System . Collections . Generic ;
56using 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." ) ;
0 commit comments