@@ -274,7 +274,7 @@ void addFilesAsync(string[] files)
274274 foreach ( string file in files )
275275 {
276276 Invoke ( new Action ( ( ) => addFileToList ( file ) ) ) ; // Оновлення UI
277- Thread . Sleep ( 10 ) ; //to let UI be responsive
277+ Thread . Sleep ( 20 ) ; //to let UI be responsive
278278 }
279279 status ( "Готово." ) ;
280280
@@ -294,48 +294,63 @@ void addFilesAsync(string[] files)
294294 }
295295 }
296296
297+ DateTime lastDoEventsTime = DateTime . MinValue ;
297298 private void addFileToList ( string filePath )
298299 {
299- //check folder
300- if ( Directory . Exists ( filePath ) )
300+ try
301301 {
302- log ( "OPEN, Add all files from folder: " + Path . GetFileName ( filePath ) ) ;
303- foreach ( string file in Directory . GetDirectories ( filePath ) )
304- addFileToList ( file ) ;
305- foreach ( string file in Directory . GetFiles ( filePath ) )
306- addFileToList ( file ) ;
307- return ;
308- }
302+ //check folder
303+ if ( Directory . Exists ( filePath ) )
304+ {
305+ log ( "ВІДКРИТИ ПАПКУ: " + Path . GetFileName ( filePath ) ) ;
306+ foreach ( string file in Directory . GetDirectories ( filePath ) )
307+ addFileToList ( file ) ;
308+ foreach ( string file in Directory . GetFiles ( filePath ) )
309+ addFileToList ( file ) ;
310+ return ;
311+ }
309312
310- //check format
311- if ( ! filePath . ToLower ( ) . EndsWith ( ".mp4" ) && ! filePath . ToLower ( ) . EndsWith ( ".avi" ) && ! filePath . ToLower ( ) . EndsWith ( ".mov" )
312- && ! filePath . ToLower ( ) . EndsWith ( ".mpg" ) && ! filePath . ToLower ( ) . EndsWith ( ".3gp" ) && ! filePath . ToLower ( ) . EndsWith ( ".wmv" )
313- && ! filePath . ToLower ( ) . EndsWith ( ".m4a" ) && ! filePath . ToLower ( ) . EndsWith ( ".mkv" ) )
314- {
315- log ( "SKIP, File have unsupported format: " + Path . GetFileName ( filePath ) ) ;
316- return ;
317- }
318- // check duplicate
319- for ( int i = 0 ; i < dataGridView1 . Rows . Count ; i ++ )
320- {
321- if ( ! dataGridView1 . Rows [ i ] . IsNewRow && dataGridView1 . Rows [ i ] . Cells [ "ColumnFilePath" ] . Value . ToString ( ) . Equals ( filePath ) )
313+ //check format
314+ if ( ! filePath . ToLower ( ) . EndsWith ( ".mp4" ) && ! filePath . ToLower ( ) . EndsWith ( ".avi" ) && ! filePath . ToLower ( ) . EndsWith ( ".mov" )
315+ && ! filePath . ToLower ( ) . EndsWith ( ".mpg" ) && ! filePath . ToLower ( ) . EndsWith ( ".3gp" ) && ! filePath . ToLower ( ) . EndsWith ( ".wmv" )
316+ && ! filePath . ToLower ( ) . EndsWith ( ".m4a" ) && ! filePath . ToLower ( ) . EndsWith ( ".mkv" ) )
322317 {
323- log ( "SKIP, Duplicate found : " + Path . GetFileName ( filePath ) ) ;
318+ // log("ПРОПУСТИТИ, File have unsupported format : " + Path.GetFileName(filePath));
324319 return ;
325320 }
326- }
321+ // check duplicate
322+ for ( int i = 0 ; i < dataGridView1 . Rows . Count ; i ++ )
323+ {
324+ if ( ! dataGridView1 . Rows [ i ] . IsNewRow && dataGridView1 . Rows [ i ] . Cells [ "ColumnFilePath" ] . Value . ToString ( ) . Equals ( filePath ) )
325+ {
326+ log ( "ПРОПУСТИТИ, Знайдено дублікат: " + Path . GetFileName ( filePath ) ) ;
327+ return ;
328+ }
329+ }
330+
327331
332+ int rowIndex = dataGridView1 . Rows . Add ( ) ;
333+ dataGridView1 . Rows [ rowIndex ] . Cells [ "ColumnFilePath" ] . Value = filePath ;
334+ dataGridView1 . Rows [ rowIndex ] . Cells [ "ColumnFileName" ] . Value = Path . GetFileName ( filePath ) ;
335+ dataGridView1 . Rows [ rowIndex ] . Cells [ "ColumnFileFolder" ] . Value = Path . GetFileName ( Path . GetDirectoryName ( filePath ) ) ?? "-" ;
336+ dataGridView1 . Rows [ rowIndex ] . Cells [ "ColumnFileSize" ] . Value = FormatBytes ( new FileInfo ( filePath ) . Length ) ;
337+ dataGridView1 . Rows [ rowIndex ] . Cells [ "ColumnFileFormat" ] . Value = FORMAT_PENDING ;
338+ dataGridView1 . Rows [ rowIndex ] . Cells [ "ColumnFileStatus" ] . Value = STATUS_WAITING ;
339+ dataGridView1 . Rows [ rowIndex ] . Cells [ "ColumnFileStatus" ] . Style . BackColor = STATUS_WAITING_COLOR ;
340+ dataGridView1 . Rows [ rowIndex ] . Cells [ "ColumnFileNewSize" ] . Value = " " ;
341+ log ( "Файл додано: " + filePath ) ;
328342
329- int rowIndex = dataGridView1 . Rows . Add ( ) ;
330- dataGridView1 . Rows [ rowIndex ] . Cells [ "ColumnFilePath" ] . Value = filePath ;
331- dataGridView1 . Rows [ rowIndex ] . Cells [ "ColumnFileName" ] . Value = Path . GetFileName ( filePath ) ;
332- dataGridView1 . Rows [ rowIndex ] . Cells [ "ColumnFileFolder" ] . Value = Path . GetFileName ( Path . GetDirectoryName ( filePath ) ) ?? "-" ;
333- dataGridView1 . Rows [ rowIndex ] . Cells [ "ColumnFileSize" ] . Value = FormatBytes ( new FileInfo ( filePath ) . Length ) ;
334- dataGridView1 . Rows [ rowIndex ] . Cells [ "ColumnFileFormat" ] . Value = FORMAT_PENDING ;
335- dataGridView1 . Rows [ rowIndex ] . Cells [ "ColumnFileStatus" ] . Value = STATUS_WAITING ;
336- dataGridView1 . Rows [ rowIndex ] . Cells [ "ColumnFileStatus" ] . Style . BackColor = STATUS_WAITING_COLOR ;
337- dataGridView1 . Rows [ rowIndex ] . Cells [ "ColumnFileNewSize" ] . Value = " " ;
338- log ( "File added: " + filePath ) ;
343+ TimeSpan timeSinceLast = DateTime . Now - lastDoEventsTime ;
344+ if ( timeSinceLast . TotalMilliseconds > 1500 )
345+ {
346+ Application . DoEvents ( ) ;
347+ lastDoEventsTime = DateTime . Now ;
348+ }
349+ }
350+ catch ( Exception e )
351+ {
352+ log ( e . ToString ( ) ) ;
353+ }
339354 }
340355
341356
@@ -1478,4 +1493,5 @@ private void dataGridView1_SortCompare(object sender, DataGridViewSortCompareEve
14781493- Перенесення метаданих зі старого файла на новий
14791494- Доповнено опис програми
14801495- Запобігання вимкненню або сну компа поки відкрита програма
1496+ - Додано костиль щоб програма не висла якщо скормити їй 10тис файлів
14811497 */
0 commit comments