2121using Windows . UI . StartScreen ;
2222using ZLinq ;
2323using static Community . CsharpSqlite . Sqlite3 ;
24+ using static System . Windows . Forms . VisualStyles . VisualStyleElement ;
2425#endregion
2526
2627namespace Crystallography . Controls ;
@@ -436,11 +437,9 @@ private static bool checkMD5(string path, byte[] md5)
436437 /// <summary>
437438 /// CODデータベースのダウンロードや読み込み.
438439 /// </summary>
439- /// <param name="sender"></param>
440- /// <param name="e"></param>
441- public void ReadCOD ( )
440+ /// <returns>正常に読み込めた場合はtrue, 途中キャンセルされたりした場合はfalse</returns>
441+ public bool ReadCOD ( )
442442 {
443- this . Enabled = false ;
444443 var ( Valid , DataNum , FileNum , FileSizes , CheckSums ) = CheckDatabaseFiles ( UserAppDataPath + "COD.cdb3" , true ) ;
445444 string urlHeader = "https://github.com/seto77/CSManager/raw/master/COD/" ;
446445 if ( Valid )
@@ -450,7 +449,7 @@ public void ReadCOD()
450449 if ( new WebClient ( ) . DownloadData ( new Uri ( urlHeader + "COD.cdb3" ) ) . SequenceEqual ( File . ReadAllBytes ( UserAppDataPath + "COD.cdb3" ) ) )
451450 { //ローカルのCODが最新版の場合
452451 ReadDatabase ( UserAppDataPath + "COD.cdb3" ) ;
453- return ;
452+ return true ;
454453 }
455454 else
456455 { //更新版が存在する場合
@@ -461,27 +460,26 @@ public void ReadCOD()
461460 ReadDatabase ( UserAppDataPath + "COD.cdb3" ) ;
462461
463462 if ( result == DialogResult . No || result == DialogResult . Cancel ) //NoかCancelの場合
464- return ;
463+ return false ;
465464 }
466465
467466 }
468467 catch //WEBが落ちている場合は、現状のCODを読み込む
469468 {
470469 ReadDatabase ( UserAppDataPath + "COD.cdb3" ) ;
471- return ;
470+ return true ;
472471 }
473472 }
474473 else //CODデータが存在しないか、適切でない場合
475474 {
476475 if ( MessageBox . Show ( "Local COD database is missing.\r \n Do you download the new database now ?" , "Local COD database is missing." ,
477476 MessageBoxButtons . YesNo ) == DialogResult . No )
478- return ;
477+ return false ;
479478 }
480479
481480 //ここまでくる場合は、CODデータが存在しない場合
482481 //CODをダウンロードする
483- if ( DownloadCodWorker . IsBusy ) return ;
484- this . Enabled = false ;
482+ if ( DownloadCodWorker . IsBusy ) return false ;
485483 DownloadCodWorker . RunWorkerAsync ( UserAppDataPath ) ;
486484
487485 while ( DownloadCodWorker . IsBusy ) //ダウンロードが完了するまで待つ
@@ -491,6 +489,7 @@ public void ReadCOD()
491489 }
492490 //this.Enabled = true;
493491 ReadDatabase ( UserAppDataPath + "COD.cdb3" ) ;
492+ return true ;
494493 }
495494
496495 private void DownloadCodWorker_DoWork ( object sender , DoWorkEventArgs e )
@@ -685,24 +684,40 @@ private void CrystalDatabaseControl_Resize(object sender, EventArgs e)
685684
686685 private void checkBoxAMCSD_CheckedChanged ( object sender , EventArgs e )
687686 {
688- if ( checkBoxAMCSD . Checked && ! AMCSD_Has_Read )
687+ Enabled = false ;
688+ if ( checkBoxAMCSD . Checked && ! AMCSD_Has_Read )
689689 {
690690 ReadDatabase ( UserAppDataPath + "AMCSD.cdb3" ) ;
691691 AMCSD_Has_Read = true ;
692692 }
693693
694694 DataBaseChanged ? . Invoke ( sender , e ) ;
695+ Enabled = true ;
695696 }
696697
697698 private void checkBoxCOD_CheckedChanged ( object sender , EventArgs e )
698699 {
699- if ( checkBoxCOD . Checked && ! COD_Has_Read )
700+ Enabled = false ;
701+ var text = textBox1 . Text ;
702+ if ( checkBoxCOD . Checked )
700703 {
701- ReadCOD ( ) ;
702- COD_Has_Read = true ;
703- do { Thread . Sleep ( 100 ) ; Application . DoEvents ( ) ; } while ( ! Enabled ) ;
704+ textBox1 . Text = "Now, loading COD database..." ;
705+ Application . DoEvents ( ) ;
706+ if ( ! COD_Has_Read )
707+ {
708+ if ( ReadCOD ( ) )
709+ {
710+ COD_Has_Read = true ;
711+ do { Thread . Sleep ( 100 ) ; Application . DoEvents ( ) ; } while ( ! Enabled ) ;
712+ }
713+ else
714+ { checkBoxCOD . Checked = false ; Enabled = true ; }
715+ }
704716 }
705717 DataBaseChanged ? . Invoke ( sender , e ) ;
718+ textBox1 . Text = text ;
719+ Enabled = true ;
720+
706721 }
707722}
708723
0 commit comments