Пример #1
0
        private async void listView_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (listView.SelectedItem == null)
            {
                return;
            }

            if (listView.SelectionMode == ListViewSelectionMode.Single)
            {
                AppDetails.DataContext = null;

                AdvancedDetails.Visibility     = Visibility.Collapsed;
                ShowAdvancedDetails.Visibility = App.hiddenMode ? Visibility.Visible : Visibility.Collapsed;

                AppData          data   = (AppData)listView.SelectedItem;
                AppDataExtension dataEx = App.GetAppDataEx(data);

                AppDetails.DataContext = dataEx;
                AppDetails.Visibility  = Visibility.Visible;

                commandBar.Visibility = Visibility.Collapsed;

                currentApp = dataEx;

                List <Backup> backupsContainingThisApp = (from Backup b in BackupManager.currentBackups
                                                          where b.Apps.Any(x => x.FamilyName == currentApp.familyName)
                                                          select b).ToList();

                noBackupsAvailable.Visibility = backupsContainingThisApp.Count == 0 ? Visibility.Visible : Visibility.Collapsed;
                backupsList.ItemsSource       = backupsContainingThisApp;

                await dataEx.CalculateSize();
            }
        }
        private void LoadBackupAppsList(Backup backup, out bool isThereAtLeastOneNotInstalled, out bool isThereAtLeastOneInstalled)
        {
            isThereAtLeastOneNotInstalled = false;
            isThereAtLeastOneInstalled    = false;
            List <BackupListOfApps> listOfApps = new List <BackupListOfApps>();

            foreach (var item in backup.Apps)
            {
                BackupListOfApps b = new BackupListOfApps();
                b.AppName  = item.DisplayName;
                b.cAppData = item;

                AppData appd = AppDataExtension.GetAppDataFromCompactAppData(item);

                if (appd == null)
                {
                    b.IsInstalled = false;
                    isThereAtLeastOneNotInstalled = true;
                }
                else
                {
                    b.Publisher   = appd.Publisher;
                    b.IsInstalled = true;
                    isThereAtLeastOneInstalled = true;
                }

                listOfApps.Add(b);
            }

            appsList.ItemsSource = listOfApps;
        }
Пример #3
0
 internal static void ResetAppSizes()
 {
     foreach (AppData item in LoadAppData.appsData)
     {
         AppDataExtension itemEx = App.GetAppDataEx(item);
         itemEx.ResetSizeData();
     }
 }
Пример #4
0
        private List <AppData> getAppDatas()
        {
            List <AppData> list = new List <AppData>();

            foreach (CompactAppData c in backup.Apps)
            {
                AppData data = AppDataExtension.FindAppData(c.FamilyName);
                if (data != null)
                {
                    list.Add(data);
                }
            }
            return(list);
        }
Пример #5
0
        public static AppDataExtension GetAppDataEx(AppData app)
        {
            AppDataExtension ade = appsSizeData.FirstOrDefault(x => x.familyName == app.FamilyName);

            if (ade == null)
            {
                ade = new AppDataExtension()
                {
                    familyName = app.FamilyName,
                    TheApp     = app
                };
                appsSizeData.Add(ade);
            }
            return(ade);
        }
Пример #6
0
        private void OnResuming(object sender, object e)
        {
            Frame rootFrame = (Frame)Window.Current.Content;

            /**
             * if (rootFrame.CurrentSourcePageType == typeof(Backups))
             * {
             *  Backups thePage = (Backups)rootFrame.Content;
             *  thePage.RefreshCurrentBackupDataIfNecessary();
             * }
             * /**/
            AppListCacheUpdater.LoadAppsInBackground();

            FileOperations.ClearGetContentsCache();
            AppDataExtension.ResetAppSizes();
        }
Пример #7
0
        protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            displayRequest = new DisplayRequest();
            displayRequest.RequestActive();

            var message = Newtonsoft.Json.JsonConvert.DeserializeObject <BackupProgressMessage>(e.Parameter.ToString());

            if (message.IsRestore)
            {
                HeaderText.Visibility      = Visibility.Collapsed;
                HeaderText2.Visibility     = Visibility.Visible;
                WarningMessage.Visibility  = Visibility.Collapsed;
                WarningMessage2.Visibility = Visibility.Visible;

                List <CompactAppData> skipApps = new List <CompactAppData>();

                try
                {
                    backup = message.backup;

                    ((App)App.Current).BackRequested += BackupProgress_BackRequested;
                    backupManager.BackupProgress     += BackupManager_BackupProgress;

                    LogsView.ItemsSource = log;

                    string notAvailableNames = "";
                    foreach (var item in backup.Apps)
                    {
                        if (LoadAppData.appsData.Count(x => x.FamilyName == item.FamilyName) == 0)
                        {
                            skipApps.Add(item);
                            if (notAvailableNames.Length > 0)
                            {
                                notAvailableNames += "\r\n";
                            }
                            notAvailableNames += item.DisplayName;
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageDialog md = new MessageDialog("1" + ex.Message);
                    await md.ShowAsync();
                }

                try
                {
                    foreach (var item in backup.Apps)
                    {
                        if (!skipApps.Contains(item))
                        {
                            AppData appd = AppDataExtension.FindAppData(item.FamilyName);
                            if (appd.PackageId != item.PackageId)
                            {
                                MessageDialog md = new MessageDialog("Current installed version doesn't match the version backup was created from.\r\n\r\n" +
                                                                     "Current installed version: " + appd.PackageId + "\r\n\r\n" +
                                                                     "Backup: " + item.PackageId + "\r\n\r\n\r\n" +
                                                                     "Do you want to restore this app?",
                                                                     appd.DisplayName + ": Version mismatch");
                                md.Commands.Add(new UICommand("Restore")
                                {
                                    Id = 1
                                });
                                md.Commands.Add(new UICommand("Don't restore")
                                {
                                    Id = 0
                                });
                                md.DefaultCommandIndex = 1;
                                md.CancelCommandIndex  = 0;

                                var result = await md.ShowAsync();

                                if (((int)result.Id) == 0)
                                {
                                    skipApps.Add(item);
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageDialog md = new MessageDialog("2" + ex.Message);
                    await md.ShowAsync();
                }

                try
                {
                    cleanedCount   = -1;
                    totalAppsCount = backup.Apps.Count;
                }
                catch (Exception ex)
                {
                    MessageDialog md = new MessageDialog("3" + ex.Message);
                    await md.ShowAsync();
                }

                await backupManager.Restore(backup, skipApps);

                progressBar1.Value         = 100.0;
                messageTextBlock.Text      = "Restore completed.";
                HeaderText2.Text           = "DONE";
                WarningMessage2.Visibility = Visibility.Collapsed;
                FinalMessage.Visibility    = Visibility.Visible;
                progressRing.IsActive      = false;
                progressRing.Visibility    = Visibility.Collapsed;
            }
            else
            {
                backup = message.backup;

                ((App)App.Current).BackRequested += BackupProgress_BackRequested;
                backupManager.BackupProgress     += BackupManager_BackupProgress;

                LogsView.ItemsSource = log;

                List <AppData> appDatas = (from CompactAppData c in backup.Apps
                                           select AppDataExtension.FindAppData(c.FamilyName)).ToList();

                await backupManager.CreateBackup(appDatas, backup.Name);

                progressBar1.Value        = 100.0;
                messageTextBlock.Text     = "Backup completed.";
                HeaderText.Text           = "DONE";
                WarningMessage.Visibility = Visibility.Collapsed;
                FinalMessage.Visibility   = Visibility.Visible;
                progressRing.IsActive     = false;
                progressRing.Visibility   = Visibility.Collapsed;
            }

            ((App)App.Current).BackRequested -= BackupProgress_BackRequested;
            displayRequest.RequestRelease();
        }
        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));
        }