示例#1
0
        private async Task <bool> RestoreBackupDatabase(string chosenBackupPath)
        {
            if (!Services.NoteDatabase.ValidateDatabaseAtPath(chosenBackupPath))
            {
                await Services.Popups.AlertPopup
                (
                    AppResources.Alert_BackupRestoreFailed_Title,
                    AppResources.Alert_BackupRestoreFailed_Message + $" ({chosenBackupPath})",
                    AppResources.AlertOption_OK
                );

                return(false);
            }

            string databasePath = Services.DatabasePath;
            await Services.NoteDatabase.CloseAsync();                      // first close database connections (maybe unnecessary idk)

            Services.FileSystem.File.Delete(databasePath);                 // delete existing database
            Services.FileSystem.File.Copy(chosenBackupPath, databasePath); // replace with chosen database
            Services.ResetDatabase();                                      // then reload the database path
            return(true);
        }