@@ -360,8 +360,8 @@ private List<string> InstallModule(CkanModule module,
360360
361361 try
362362 {
363- var dll = registry . DllPath ( module . identifier ) ;
364- if ( dll is not null && ! string . IsNullOrEmpty ( dll ) )
363+ if ( registry . DllPath ( module . identifier )
364+ is string { Length : > 0 } dll )
365365 {
366366 // Find where we're installing identifier.optionalversion.dll
367367 // (file name might not be an exact match with manually installed)
@@ -393,22 +393,21 @@ private List<string> InstallModule(CkanModule module,
393393 // Look for overwritable files if session is interactive
394394 if ( ! User . Headless )
395395 {
396- var conflicting = FindConflictingFiles ( zipfile , files , registry ) . Memoize ( ) ;
397- if ( conflicting . Any ( ) )
396+ if ( FindConflictingFiles ( zipfile , files , registry ) . ToArray ( )
397+ is ( InstallableFile file , bool same ) [ ] { Length : > 0 } conflicting )
398398 {
399- var fileMsg = conflicting
400- . OrderBy ( c => c . Value )
401- . Aggregate ( "" , ( a , b ) =>
402- $ "{ a } \r \n - { instance . ToRelativeGameDir ( b . Key . destination ) } ({ ( b . Value ? Properties . Resources . ModuleInstallerFileSame : Properties . Resources . ModuleInstallerFileDifferent ) } )") ;
403- if ( User . RaiseYesNoDialog ( string . Format (
404- Properties . Resources . ModuleInstallerOverwrite , module . name , fileMsg ) ) )
399+ var fileMsg = string . Join ( Environment . NewLine ,
400+ conflicting . OrderBy ( tuple => tuple . same )
401+ . Select ( tuple => $ "- { instance . ToRelativeGameDir ( tuple . file . destination ) } ({ ( tuple . same ? Properties . Resources . ModuleInstallerFileSame : Properties . Resources . ModuleInstallerFileDifferent ) } )") ) ;
402+ if ( User . RaiseYesNoDialog ( string . Format ( Properties . Resources . ModuleInstallerOverwrite ,
403+ module . name , fileMsg ) ) )
405404 {
406- DeleteConflictingFiles ( conflicting . Select ( f => f . Key ) ) ;
405+ DeleteConflictingFiles( conflicting . Select ( tuple => tuple . file ) ) ;
407406 }
408407 else
409408 {
410- throw new CancelledActionKraken ( string . Format (
411- Properties . Resources . ModuleInstallerOverwriteCancelled , module . name ) ) ;
409+ throw new CancelledActionKraken( string . Format ( Properties . Resources . ModuleInstallerOverwriteCancelled ,
410+ module . name ) ) ;
412411 }
413412 }
414413 }
@@ -467,27 +466,25 @@ public static bool IsInternalCkan(ZipEntry ze)
467466 /// <returns>
468467 /// List of pairs: Key = file, Value = true if identical, false if different
469468 /// </returns>
470- private IEnumerable < KeyValuePair < InstallableFile , bool > > FindConflictingFiles ( ZipFile zip , IEnumerable < InstallableFile > files , Registry registry )
471- {
472- foreach ( InstallableFile file in files )
473- {
474- if ( ! file . source . IsDirectory
475- && File . Exists ( file . destination )
476- && registry . FileOwner ( instance . ToRelativeGameDir ( file . destination ) ) == null )
477- {
478- log . DebugFormat ( "Comparing {0}" , file . destination ) ;
479- using ( Stream zipStream = zip . GetInputStream ( file . source ) )
480- using ( FileStream curFile = new FileStream ( file . destination , FileMode . Open , FileAccess . Read ) )
469+ private IEnumerable< ( InstallableFile file , bool same ) > FindConflictingFiles ( ZipFile zip ,
470+ IEnumerable < InstallableFile > files ,
471+ Registry registry )
472+ => files . Where ( file => ! file . source . IsDirectory
473+ && File . Exists ( file . destination )
474+ && registry . FileOwner ( instance . ToRelativeGameDir ( file . destination ) ) == null )
475+ . Select ( file =>
481476 {
482- yield return new KeyValuePair < InstallableFile , bool > (
483- file ,
484- file . source . Size == curFile . Length
485- && StreamsEqual ( zipStream , curFile )
486- ) ;
487- }
488- }
489- }
490- }
477+ log . DebugFormat ( "Comparing {0}" , file . destination ) ;
478+ using ( Stream zipStream = zip . GetInputStream ( file . source ) )
479+ using ( FileStream curFile = new FileStream ( file . destination ,
480+ FileMode . Open ,
481+ FileAccess . Read ) )
482+ {
483+ return ( file ,
484+ same : file . source . Size == curFile . Length
485+ && StreamsEqual ( zipStream , curFile ) ) ;
486+ }
487+ } ) ;
491488
492489 /// <summary>
493490 /// Compare the contents of two streams
@@ -745,10 +742,7 @@ public static List<InstallableFile> FindInstallableFiles(CkanModule module, stri
745742 progress? . Report ( 0 ) ;
746743 StreamUtils. Copy ( zipStream , writer , buffer ,
747744 // This doesn't fire at all if the interval never elapses
748- ( sender , e ) =>
749- {
750- progress ? . Report ( e . Processed ) ;
751- } ,
745+ ( sender , e ) => progress ? . Report ( e . Processed ) ,
752746 UnzipProgressInterval ,
753747 entry , "InstallFile" ) ;
754748 }
@@ -1073,15 +1067,15 @@ private void Uninstall(string identifier,
10731067 }
10741068 }
10751069
1076- internal static void GroupFilesByRemovable ( string relRoot ,
1077- Registry registry ,
1078- string [ ] alreadyRemoving ,
1079- IGame game ,
1080- string [ ] relPaths ,
1081- out string [ ] removable ,
1082- out string [ ] notRemovable )
1070+ internal static void GroupFilesByRemovable( string relRoot ,
1071+ Registry registry ,
1072+ IReadOnlyCollection < string > alreadyRemoving ,
1073+ IGame game ,
1074+ IReadOnlyCollection < string > relPaths ,
1075+ out string [ ] removable ,
1076+ out string [ ] notRemovable )
10831077 {
1084- if ( relPaths . Length < 1 )
1078+ if ( relPaths . Count < 1 )
10851079 {
10861080 removable = Array. Empty < string > ( ) ;
10871081 notRemovable = Array. Empty < string > ( ) ;
@@ -1102,8 +1096,8 @@ internal static void GroupFilesByRemovable(string relRoot,
11021096 . ToDictionary ( grp => grp . Key ,
11031097 grp => grp . OrderByDescending ( f => f . Length )
11041098 . ToArray ( ) ) ;
1105- removable = contents . TryGetValue ( true , out string [ ] ? val1 ) ? val1 : Array . Empty < string > ( ) ;
1106- notRemovable = contents . TryGetValue ( false , out string [ ] ? val2 ) ? val2 : Array . Empty < string > ( ) ;
1099+ removable = contents. GetValueOrDefault ( true ) ?? Array . Empty < string > ( ) ;
1100+ notRemovable = contents . GetValueOrDefault ( false ) ?? Array . Empty < string > ( ) ;
11071101 log . DebugFormat ( "Got removable: {0}" , string . Join ( ", " , removable ) ) ;
11081102 log . DebugFormat ( "Got notRemovable: {0}" , string . Join ( ", " , notRemovable ) ) ;
11091103 }
0 commit comments