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,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." ) ;
0 commit comments