コード例 #1
0
        private async void ButtonRestore_Click(object sender, RoutedEventArgs e)
        {
            var selected = ListBoxBackups.SelectedItem as BackupFile;

            if (selected == null)
            {
                return;
            }
            var result =
                await
                Core.MainWindow.ShowMessageAsync("Restore backup " + selected.DisplayName,
                                                 "This can not be undone! Make sure you have a current backup (if necessary). To create one, CANCEL and click \"CREATE NEW\".",
                                                 MessageDialogStyle.AffirmativeAndNegative);

            if (result != MessageDialogResult.Affirmative)
            {
                return;
            }
            var archive = new ZipArchive(selected.FileInfo.OpenRead(), ZipArchiveMode.Read);

            archive.ExtractToDirectory(Config.Instance.DataDir, true);
            Config.Load();
            Config.Save();
            DeckList.Reload();
            DeckList.Save();
            DeckStatsList.Reload();
            DeckStatsList.Save();
            DefaultDeckStats.Reload();
            DefaultDeckStats.Save();
            Core.MainWindow.ShowMessage("Success", "Please restart HDT for this to take effect.").Forget();
        }
コード例 #2
0
 internal static bool Restore(FileInfo backup, bool reload, params string[] files)
 {
     try
     {
         var archive = new ZipArchive(backup.OpenRead(), ZipArchiveMode.Read);
         if (files.Length == 0)
         {
             archive.ExtractToDirectory(Config.Instance.DataDir, true);
         }
         else
         {
             foreach (var file in files.Where(x => Files.Contains(x)))
             {
                 archive.GetEntry(file).ExtractToFile(Path.Combine(Config.Instance.DataDir, file), true);
             }
         }
         if (!reload)
         {
             return(true);
         }
         if (files.Length == 0 || files.Contains("config.xml"))
         {
             Config.Load();
             Config.Save();
         }
         if (files.Length == 0 || files.Contains("PlayerDecks.xml"))
         {
             DeckList.Reload();
             DeckList.Save();
         }
         if (files.Length == 0 || files.Contains("DeckStats.xml"))
         {
             DeckStatsList.Reload();
             DeckStatsList.Save();
         }
         if (files.Length == 0 || files.Contains("DefaultDeckStats.xml"))
         {
             DefaultDeckStats.Reload();
             DefaultDeckStats.Save();
         }
         return(true);
     }
     catch (Exception ex)
     {
         Log.Error(ex);
         return(false);
     }
 }