Ejemplo n.º 1
0
        private async void ResetAppButton_Tapped(object sender, TappedRoutedEventArgs e)
        {
            MessageDialog md = new MessageDialog("The data will be permanently lost. Consider creating a backup before this.\r\n\r\nNote: Doing this on 'system apps' is not safe, and might cause your phone to stop working.", "Are you sure you want to reset the state of this app?");

            md.Commands.Add(new UICommand("Yes")
            {
                Id = 1
            });
            md.Commands.Add(new UICommand("No")
            {
                Id = 0
            });
            md.DefaultCommandIndex = 1;
            md.CancelCommandIndex  = 0;

            var result = await md.ShowAsync();

            if (((int)result.Id) == 1)
            {
                progress.Visibility = Visibility.Visible;
                BackupManager bm = new BackupManager();
                bm.BackupProgress += Bm_BackupProgress;
                await bm.ResetAppData(currentApp.TheApp);

                bm.BackupProgress -= Bm_BackupProgress;
                FileOperations.RemoveFromGetContentsCache(currentApp.familyName);

                await currentApp.CalculateSize();

                progress.Visibility = Visibility.Collapsed;
                progressText.Text   = "";
            }
        }
        public async Task Restore(Backup backup, List <CompactAppData> skipApps)
        {
            int counter = 1;

            try
            {
                foreach (var item in backup.Apps)
                {
                    if (!skipApps.Contains(item))
                    {
                        OnBackupProgress(new BackupEventArgs(-1, BackupState.ResettingAppData, "Clearing current state of " + item.DisplayName, counter.ToString() + " / " + (backup.Apps.Count - skipApps.Count).ToString(), restoreLog));
                        await ResetAppData(AppDataExtension.GetAppDataFromCompactAppData(item));

                        counter++;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageDialog md = new MessageDialog("4" + ex.Message);
                await md.ShowAsync();
            }
            ArchiverPlus archiver = new ArchiverPlus();

            OnBackupProgress(new BackupEventArgs(-1, BackupState.Initializing, "Loading backup file...", "", restoreLog));
            StorageFolder folder = await StorageFolder.GetFolderFromPathAsync(System.IO.Path.Combine(App.BackupDestination, backup.Name));

            StorageFile file = await folder.GetFileAsync("data.zip");



            Dictionary <string, StorageFolder> dests = new Dictionary <string, StorageFolder>();

            familyToDisplayNames = new Dictionary <string, string>();
            try
            {
                foreach (var item in backup.Apps)
                {
                    if (!skipApps.Contains(item))
                    {
                        FileOperations.RemoveFromGetContentsCache(item.FamilyName);

                        dests[item.FamilyName] = await StorageFolder.GetFolderFromPathAsync(System.IO.Path.GetDirectoryName(await LoadAppData.GetDataFolder(AppDataExtension.GetAppDataFromCompactAppData(item))));

                        familyToDisplayNames.Add(item.FamilyName, item.DisplayName);
                    }
                    else
                    {
                        dests[item.FamilyName] = null; //Skip
                    }
                }
            }
            catch (Exception ex)
            {
                MessageDialog md = new MessageDialog("5" + ex.Message);
                await md.ShowAsync();
            }

            archiver.DecompressingProgress += Archiver_DecompressingProgress;

            try
            {
                await archiver.DecompressSpecial(file, dests);
            }
            catch (Exception ex)
            {
                MessageDialog md = new MessageDialog("6" + ex.Message);
                await md.ShowAsync();
            }
            archiver.DecompressingProgress -= Archiver_DecompressingProgress;

            OnBackupProgress(new BackupEventArgs(100.0, BackupState.Finished, "Restore completed.", "", restoreLog));
        }