private async void SaveButton_Click(object sender, RoutedEventArgs e) { if (isSaving) { return; } isSaving = true; try { if (string.IsNullOrEmpty(config.Path)) { var dir = await Utils.GetAdapterConfigDirectory(); var file = await dir.CreateFileAsync(Guid.NewGuid().ToString() + ".json", CreationCollisionOption.GenerateUniqueName); config.Path = file.Path; } CachedFileManager.DeferUpdates(await StorageFile.GetFileFromPathAsync(config.Path)); config.SaveToFile(config.Path); AdapterConfig.SetDefaultConfigFilePath(config.Path); await CachedFileManager.CompleteUpdatesAsync(await StorageFile.GetFileFromPathAsync(config.Path)); Frame.GoBack(); } catch (Exception ex) { await Utils.NotifyUser("Cannot save config: " + ex.Message); } finally { isSaving = false; } }
private async void RemoveButton_Click(object sender, RoutedEventArgs e) { var btn = (MenuFlyoutItem)sender; var config = (IAdapterConfig)btn.DataContext; var(secondaryAsClose, result) = await Utils.NotifyUser("Remove this config?", primaryCommandText : "Yes"); if (result != ContentDialogResult.Primary) { return; } try { File.Delete(config.Path); adapterConfigs.Remove(config); if (config.Path == AdapterConfig.GetDefaultConfigFilePath() && adapterConfigs.Count > 0) { AdapterConfig.SetDefaultConfigFilePath(adapterConfigs[0].Path); } } catch (Exception ex) { await Utils.NotifyUser("Error while deleting config file: " + ex.Message); } }
private async Task SaveAsync(bool setAsDefault) { if (isSaving) { return; } isSaving = true; try { var file = await ConfigUtils.SaveServerAsync(config); config.Path = file.Path; if (setAsDefault) { AdapterConfig.SetDefaultConfigFilePath(config.Path); } await CachedFileManager.CompleteUpdatesAsync(file); Frame.GoBack(); } catch (Exception ex) { await UiUtils.NotifyUser("Cannot save config: " + ex.Message); } finally { isSaving = false; } }
private async void SetDefaultButton_Click(object sender, RoutedEventArgs e) { var btn = (MenuFlyoutItem)sender; var defaultConfig = (IAdapterConfig)btn.DataContext; AdapterConfig.SetDefaultConfigFilePath(defaultConfig.Path); await LoadAdapterConfigs(); }
public static async Task SaveServersAsync(List <IAdapterConfig> configs) { var lastConfig = ""; foreach (var config in configs) { if (string.IsNullOrEmpty(config.Path)) { var dir = await GetAdapterConfigDirectory(); var file = await dir.CreateFileAsync(Guid.NewGuid().ToString() + ".json", CreationCollisionOption.GenerateUniqueName); config.Path = file.Path; } config.SaveToFile(config.Path); lastConfig = config.Path; } if (!string.IsNullOrEmpty(lastConfig)) { AdapterConfig.SetDefaultConfigFilePath(lastConfig); } }