|
19 | 19 | using System.Threading.Tasks; |
20 | 20 | using System.Windows.Forms; |
21 | 21 | using Brightbits.BSH.Engine; |
| 22 | +using Brightbits.BSH.Engine.Database; |
22 | 23 | using Brightbits.BSH.Engine.Security; |
23 | 24 | using Brightbits.BSH.Engine.Storage; |
24 | 25 | using BSH.Main.Properties; |
@@ -480,17 +481,16 @@ private async Task ShowWizardStepAsync(int iStep) |
480 | 481 | } |
481 | 482 |
|
482 | 483 | // copy database from backup device |
| 484 | + DeleteCurrentDatabaseFile(); |
483 | 485 | File.Copy(lvBackups.SelectedItems[0].Tag.ToString() + @"\backup.bshdb", BackupLogic.DatabaseFile, true); |
484 | 486 | } |
485 | 487 | else if (tcStep5.SelectedIndex == 1) |
486 | 488 | { |
487 | 489 | // ftp server |
488 | 490 | try |
489 | 491 | { |
490 | | - // delete old database file |
491 | | - File.Delete(BackupLogic.DatabaseFile); |
492 | | - |
493 | 492 | // download backup database |
| 493 | + DeleteCurrentDatabaseFile(); |
494 | 494 | using IStorage storage = new FtpStorage( |
495 | 495 | txtFTPServer2.Text, |
496 | 496 | int.Parse(txtFTPPort2.Text), |
@@ -524,6 +524,7 @@ private async Task ShowWizardStepAsync(int iStep) |
524 | 524 | } |
525 | 525 |
|
526 | 526 | // copy database from backup device |
| 527 | + DeleteCurrentDatabaseFile(); |
527 | 528 | File.Copy(txtPath.Text + @"\backup.bshdb", BackupLogic.DatabaseFile, true); |
528 | 529 | } |
529 | 530 |
|
@@ -633,6 +634,30 @@ private async Task ShowWizardStepAsync(int iStep) |
633 | 634 | } |
634 | 635 | } |
635 | 636 |
|
| 637 | + private static void DeleteCurrentDatabaseFile() |
| 638 | + { |
| 639 | + DbClientFactory.ClosePool(); |
| 640 | + |
| 641 | + // delete old database file |
| 642 | + File.Delete(BackupLogic.DatabaseFile); |
| 643 | + try |
| 644 | + { |
| 645 | + File.Delete(BackupLogic.DatabaseFile + "-wal"); |
| 646 | + } |
| 647 | + catch |
| 648 | + { |
| 649 | + // ignore error |
| 650 | + } |
| 651 | + try |
| 652 | + { |
| 653 | + File.Delete(BackupLogic.DatabaseFile + "-shm"); |
| 654 | + } |
| 655 | + catch (Exception) |
| 656 | + { |
| 657 | + // ignore error |
| 658 | + } |
| 659 | + } |
| 660 | + |
636 | 661 | private sealed class VersionEntry |
637 | 662 | { |
638 | 663 | public VersionEntry(string path, bool changed) |
|
0 commit comments