コード例 #1
0
ファイル: AboutViewModel.cs プロジェクト: zhuxb711/Files
        private async Task ExportSettings()
        {
            FileSavePicker filePicker = new FileSavePicker();

            filePicker.FileTypeChoices.Add("Zip File", new[] { ".zip" });
            filePicker.SuggestedFileName = $"Files_{App.AppVersion}";

            StorageFile file = await filePicker.PickSaveFileAsync();

            if (file != null)
            {
                try
                {
                    var zipFolder = await ZipStorageFolder.FromStorageFileAsync(file);

                    if (zipFolder == null)
                    {
                        return;
                    }
                    var localFolderPath = ApplicationData.Current.LocalFolder.Path;
                    // Export user settings
                    var userSettings = await zipFolder.CreateFileAsync(Constants.LocalSettings.UserSettingsFileName, CreationCollisionOption.ReplaceExisting);

                    string exportSettings = (string)UserSettingsService.ExportSettings();
                    await userSettings.WriteTextAsync(exportSettings);

                    // Export bundles
                    var bundles = await zipFolder.CreateFileAsync(Constants.LocalSettings.BundlesSettingsFileName, CreationCollisionOption.ReplaceExisting);

                    string exportBundles = (string)BundlesSettingsService.ExportSettings();
                    await bundles.WriteTextAsync(exportBundles);

                    // Export pinned items
                    var pinnedItems = await BaseStorageFile.GetFileFromPathAsync(Path.Combine(localFolderPath, Constants.LocalSettings.SettingsFolderName, App.SidebarPinnedController.JsonFileName));

                    await pinnedItems.CopyAsync(zipFolder, pinnedItems.Name, NameCollisionOption.ReplaceExisting);

                    // Export terminals config
                    var terminals = await BaseStorageFile.GetFileFromPathAsync(Path.Combine(localFolderPath, Constants.LocalSettings.SettingsFolderName, App.TerminalController.JsonFileName));

                    await terminals.CopyAsync(zipFolder, terminals.Name, NameCollisionOption.ReplaceExisting);

                    // Export file tags list and DB
                    var fileTagsList = await zipFolder.CreateFileAsync(Constants.LocalSettings.FileTagSettingsFileName, CreationCollisionOption.ReplaceExisting);

                    string exportTags = (string)FileTagsSettingsService.ExportSettings();
                    await fileTagsList.WriteTextAsync(exportTags);

                    var fileTagsDB = await zipFolder.CreateFileAsync(Path.GetFileName(FileTagsHelper.FileTagsDbPath), CreationCollisionOption.ReplaceExisting);

                    string exportTagsDB = FileTagsHelper.DbInstance.Export();
                    await fileTagsDB.WriteTextAsync(exportTagsDB);
                }
                catch (Exception ex)
                {
                    App.Logger.Warn(ex, "Error exporting settings");
                }
            }
        }
コード例 #2
0
        private async Task ExportSettings()
        {
            FileSavePicker filePicker = new FileSavePicker();

            filePicker.FileTypeChoices.Add("Json File", Path.GetExtension(Constants.LocalSettings.UserSettingsFileName).CreateList());

            StorageFile file = await filePicker.PickSaveFileAsync();

            if (file != null)
            {
                string export = (string)UserSettingsService.ExportSettings();
                await FileIO.WriteTextAsync(file, export);
            }
        }