@@ -232,15 +232,34 @@ private void ProcessCleanButton_Click(object sender, EventArgs e)
232232 return ;
233233 }
234234
235+ DialogResult cleanModePrompt = MessageBox . Show ( "Do you want to clean all empty files?" , "" , MessageBoxButtons . YesNo ) ;
236+ bool cleanEmpty = cleanModePrompt == DialogResult . Yes ;
237+
235238 string [ ] storageFiles = Directory . GetFiles ( "Scribe\\ storage" , "*.scstore" ) ;
236239 int storageClean = 0 ;
237240
238241 for ( int i = 0 ; i < storageFiles . Length ; i ++ )
239242 {
240- string storeFile = File . ReadAllText ( storageFiles [ i ] ) ;
241- string [ ] mediaPath = storeFile . Split ( '\n ' , 2 , StringSplitOptions . None ) ;
243+ string storeFileRaw = File . ReadAllText ( storageFiles [ i ] ) ;
244+ string [ ] storeFile = storeFileRaw . Split ( '\n ' , 2 , StringSplitOptions . None ) ;
245+
246+ bool deleteCurrent = ! File . Exists ( storeFile [ 0 ] ) || storeFile . Length != 2 ;
242247
243- if ( ! File . Exists ( mediaPath [ 0 ] ) || mediaPath . Length != 2 )
248+ if ( storeFile . Length > 1 )
249+ {
250+ // delete file if it is empty
251+ if ( cleanEmpty && String . IsNullOrEmpty ( storeFile [ 1 ] ) )
252+ {
253+ deleteCurrent = true ;
254+ }
255+ }
256+ else
257+ {
258+ // delete file if it is null, no matter what
259+ deleteCurrent = true ;
260+ }
261+
262+ if ( deleteCurrent )
244263 {
245264 File . Delete ( storageFiles [ i ] ) ;
246265 storageClean ++ ;
@@ -648,7 +667,7 @@ private void UpdateSearch()
648667 }
649668
650669 stopwatch . Stop ( ) ;
651-
670+
652671 SearchSecondsLabel . Text = $ "in { ( stopwatch . Elapsed . TotalMilliseconds / 1000 ) . ToString ( "F3" ) } seconds";
653672 SearchSecondsLabel . Location = new Point ( 238 - ( SearchSecondsLabel . Width - 88 ) , SearchSecondsLabel . Location . Y ) ;
654673 }
@@ -690,7 +709,10 @@ private void SearchResultsListBox_KeyDown(object sender, KeyEventArgs e)
690709 SearchResultsListBox . Items . Remove ( SearchResultsListBox . SelectedItem ) ;
691710 }
692711
693- SearchResultsListBox . SelectedIndex = 0 ;
712+ if ( SearchResultsListBox . Items . Count > 0 )
713+ {
714+ SearchResultsListBox . SelectedIndex = 0 ;
715+ }
694716 }
695717 }
696718
0 commit comments