private async Task ImportSettings() { FileOpenPicker filePicker = new FileOpenPicker(); filePicker.FileTypeFilter.Add(Path.GetExtension(Constants.LocalSettings.UserSettingsFileName)); StorageFile file = await filePicker.PickSingleFileAsync(); if (file != null) { try { string import = await FileIO.ReadTextAsync(file); UserSettingsService.ImportSettings(import); } catch { UIHelpers.CloseAllDialogs(); await DialogDisplayHelper.ShowDialogAsync("SettingsImportErrorTitle".GetLocalized(), "SettingsImportErrorDescription".GetLocalized()); } } }
private async Task ImportSettings() { FileOpenPicker filePicker = new FileOpenPicker(); filePicker.FileTypeFilter.Add(".zip"); StorageFile file = await filePicker.PickSingleFileAsync(); if (file != null) { try { var zipFolder = await ZipStorageFolder.FromStorageFileAsync(file); if (zipFolder == null) { return; } var localFolderPath = ApplicationData.Current.LocalFolder.Path; var settingsFolder = await StorageFolder.GetFolderFromPathAsync(Path.Combine(localFolderPath, Constants.LocalSettings.SettingsFolderName)); // Import user settings var userSettingsFile = await zipFolder.GetFileAsync(Constants.LocalSettings.UserSettingsFileName); string importSettings = await userSettingsFile.ReadTextAsync(); UserSettingsService.ImportSettings(importSettings); // Import bundles var bundles = await zipFolder.GetFileAsync(Constants.LocalSettings.BundlesSettingsFileName); string importBundles = await bundles.ReadTextAsync(); BundlesSettingsService.ImportSettings(importBundles); // Import pinned items var pinnedItems = await zipFolder.GetFileAsync(App.SidebarPinnedController.JsonFileName); await pinnedItems.CopyAsync(settingsFolder, pinnedItems.Name, NameCollisionOption.ReplaceExisting); await App.SidebarPinnedController.ReloadAsync(); // Import terminals config var terminals = await zipFolder.GetFileAsync(App.TerminalController.JsonFileName); await terminals.CopyAsync(settingsFolder, terminals.Name, NameCollisionOption.ReplaceExisting); // Import file tags list and DB var fileTagsList = await zipFolder.GetFileAsync(Constants.LocalSettings.FileTagSettingsFileName); string importTags = await fileTagsList.ReadTextAsync(); FileTagsSettingsService.ImportSettings(importTags); var fileTagsDB = await zipFolder.GetFileAsync(Path.GetFileName(FileTagsHelper.FileTagsDbPath)); string importTagsDB = await fileTagsDB.ReadTextAsync(); FileTagsHelper.DbInstance.Import(importTagsDB); // Import layout preferences and DB var layoutPrefsDB = await zipFolder.GetFileAsync(Path.GetFileName(FolderSettingsViewModel.LayoutSettingsDbPath)); string importPrefsDB = await layoutPrefsDB.ReadTextAsync(); FolderSettingsViewModel.DbInstance.Import(importPrefsDB); } catch (Exception ex) { App.Logger.Warn(ex, "Error importing settings"); UIHelpers.CloseAllDialogs(); await DialogDisplayHelper.ShowDialogAsync("SettingsImportErrorTitle".GetLocalized(), "SettingsImportErrorDescription".GetLocalized()); } } }