@@ -241,35 +241,20 @@ private static void PatchLaunchFile(string launchFile)
241241 var content = File . ReadAllText ( launchFile ) ;
242242 var launch = JSONNode . Parse ( content ) ;
243243
244- var configurations = ( JSONArray ) launch [ configurationsKey ] ;
244+ var configurations = launch [ configurationsKey ] as JSONArray ;
245245 if ( configurations == null )
246246 {
247247 configurations = new JSONArray ( ) ;
248248 launch . Add ( configurationsKey , configurations ) ;
249249 }
250250
251- var containsVstucEntry = false ;
252- var patched = false ;
251+ if ( configurations . Linq . Any ( entry => entry . Value [ typeKey ] . Value == "vstuc" ) )
252+ return ;
253253
254- foreach ( var entry in configurations )
255- {
256- var type = entry . Value [ typeKey ] . Value ;
257- if ( type == "vstuc" )
258- {
259- containsVstucEntry = true ;
260- break ;
261- }
262- }
254+ var defaultContent = JSONNode . Parse ( DefaultLaunchFileContent ) ;
255+ configurations . Add ( defaultContent [ configurationsKey ] [ 0 ] ) ;
263256
264- if ( ! containsVstucEntry )
265- {
266- var defaultContent = JSONNode . Parse ( DefaultLaunchFileContent ) ;
267- configurations . Add ( defaultContent [ configurationsKey ] [ 0 ] ) ;
268- patched = true ;
269- }
270-
271- if ( patched )
272- WriteAllTextFromJObject ( launchFile , launch ) ;
257+ WriteAllTextFromJObject ( launchFile , launch ) ;
273258 }
274259 catch ( Exception )
275260 {
@@ -364,7 +349,7 @@ private void PatchSettingsFile(string settingsFile)
364349 var content = File . ReadAllText ( settingsFile ) ;
365350 var settings = JSONNode . Parse ( content ) ;
366351
367- var excludes = ( JSONObject ) settings [ excludesKey ] ;
352+ var excludes = settings [ excludesKey ] as JSONObject ;
368353 if ( excludes == null )
369354 return ;
370355
@@ -377,14 +362,16 @@ private void PatchSettingsFile(string settingsFile)
377362 if ( ! bool . TryParse ( exclude . Value , out var exc ) || ! exc )
378363 continue ;
379364
380- if ( exclude . Key . EndsWith ( ".sln" ) || exclude . Key . EndsWith ( ".csproj" ) )
381- {
382- if ( Regex . IsMatch ( exclude . Key , "^(\\ *\\ *[\\ \\ \\ /])?\\ *\\ .(sln|csproj)$" ) )
383- {
384- patchList . Add ( exclude . Key ) ;
385- patched = true ;
386- }
387- }
365+ var key = exclude . Key ;
366+
367+ if ( ! key . EndsWith ( ".sln" ) && ! key . EndsWith ( ".csproj" ) )
368+ continue ;
369+
370+ if ( ! Regex . IsMatch ( key , "^(\\ *\\ *[\\ \\ \\ /])?\\ *\\ .(sln|csproj)$" ) )
371+ continue ;
372+
373+ patchList . Add ( key ) ;
374+ patched = true ;
388375 }
389376
390377 // Check default solution
@@ -396,13 +383,13 @@ private void PatchSettingsFile(string settingsFile)
396383 patched = true ;
397384 }
398385
399- if ( patched )
400- {
401- foreach ( var patch in patchList )
402- excludes . Remove ( patch ) ;
386+ if ( ! patched )
387+ return ;
403388
404- WriteAllTextFromJObject ( settingsFile , settings ) ;
405- }
389+ foreach ( var patch in patchList )
390+ excludes . Remove ( patch ) ;
391+
392+ WriteAllTextFromJObject ( settingsFile , settings ) ;
406393 }
407394 catch ( Exception )
408395 {
@@ -442,18 +429,15 @@ private static void PatchRecommendedExtensionsFile(string extensionFile)
442429 var content = File . ReadAllText ( extensionFile ) ;
443430 var extensions = JSONNode . Parse ( content ) ;
444431
445- var recommendations = ( JSONArray ) extensions [ recommendationsKey ] ;
432+ var recommendations = extensions [ recommendationsKey ] as JSONArray ;
446433 if ( recommendations == null )
447434 {
448435 recommendations = new JSONArray ( ) ;
449436 extensions . Add ( recommendationsKey , recommendations ) ;
450437 }
451438
452- foreach ( var entry in recommendations )
453- {
454- if ( entry . Value . Value == MicrosoftUnityExtensionId )
455- return ;
456- }
439+ if ( recommendations . Linq . Any ( entry => entry . Value . Value == MicrosoftUnityExtensionId ) )
440+ return ;
457441
458442 recommendations . Add ( MicrosoftUnityExtensionId ) ;
459443 WriteAllTextFromJObject ( extensionFile , extensions ) ;
0 commit comments