1414
1515namespace EventLogExpert . Shared . Components ;
1616
17- public sealed partial class SettingsModal
17+ public sealed partial class SettingsModal : IDisposable
1818{
1919 private readonly List < ( string name , bool isEnabled , bool hasChanged ) > _databases = [ ] ;
2020
@@ -40,6 +40,8 @@ public sealed partial class SettingsModal
4040
4141 [ Inject ] private IFileLogger TraceLogger { get ; init ; } = null ! ;
4242
43+ public void Dispose ( ) => Settings . Loaded -= OnSettingsLoaded ;
44+
4345 protected internal override async Task Close ( )
4446 {
4547 if ( _databaseRemoved )
@@ -84,22 +86,32 @@ private async Task ImportDatabase()
8486
8587 Directory . CreateDirectory ( FileLocationOptions . DatabasePath ) ;
8688
89+ List < string > importedFiles = [ ] ;
90+
8791 foreach ( var item in result )
8892 {
89- if ( item ? . FileName is null ) { continue ; }
93+ if ( string . IsNullOrEmpty ( item ? . FileName ) || string . IsNullOrEmpty ( item . FullPath ) ) { continue ; }
9094
9195 var destination = Path . Join ( FileLocationOptions . DatabasePath , item . FileName ) ;
9296 File . Copy ( item . FullPath , destination , true ) ;
9397
94- if ( Path . GetExtension ( destination ) != ".zip" ) { continue ; }
98+ importedFiles . Add ( item . FileName ) ;
99+
100+ if ( ! Path . GetExtension ( destination ) . Equals ( ".zip" , StringComparison . OrdinalIgnoreCase ) ) { continue ; }
95101
96102 await ZipFile . ExtractToDirectoryAsync ( destination , FileLocationOptions . DatabasePath , overwriteFiles : true ) ;
97103 File . Delete ( destination ) ;
98104 }
99105
100- var message = result . Length > 1 ?
101- $ "{ result . Length } databases have successfully been imported" :
102- $ "{ result [ 0 ] ? . FileName ?? "Database" } has successfully been imported";
106+ if ( importedFiles . Count == 0 )
107+ {
108+ await AlertDialogService . ShowAlert ( "Import Failed" , "No valid database files were selected." , "OK" ) ;
109+ return ;
110+ }
111+
112+ var message = importedFiles . Count > 1 ?
113+ $ "{ importedFiles . Count } databases have successfully been imported" :
114+ $ "{ importedFiles [ 0 ] } has successfully been imported";
103115
104116 await AlertDialogService . ShowAlert ( "Import Successful" , message , "OK" ) ;
105117
0 commit comments