// // opens and parses the file into a Game object public async Task <OldCatanGame> LoadGame(StorageFile file) { string error = ""; OldCatanGame game = null; try { using (var stream = await file.OpenStreamForReadAsync()) { using (var streamReader = new StreamReader(stream)) { string savedGame = streamReader.ReadToEnd(); game = new OldCatanGame(); game.FastDeserialize(savedGame); if (game.Error != null) { await DeleteCurrentGame(file, error); } } } } catch (Exception e) { CurrentGameName = ""; if (await StaticHelpers.AskUserYesNoQuestion($"Error Loading file {file.DisplayName}.\n\nDelete it?\nException: {e.Message}\n\n{e.InnerException}\n\n{e.StackTrace}", "Yes", "No") == true) { await file.DeleteAsync(); } } return(game); }
private async Task DeleteCurrentGame(StorageFile file, string message) { if (await StaticHelpers.AskUserYesNoQuestion($"Error loading \"{file.DisplayName}\"\n\nError: {message}\n\nDelete \"{file.DisplayName}\" ", "Yes", "No") == true) { await file.DeleteAsync(); } }
private async void OnItemRightTapped(object sender, RightTappedRoutedEventArgs e) { PlayerData player = ((Grid)sender).Tag as PlayerData; if (await StaticHelpers.AskUserYesNoQuestion($"Let {player.PlayerName} go first?", "Yes", "No")) { await MainPage.Current.SetFirst(player); } }
public async Task <StorageFile> Save() { try { string saveString = _currentGame.Serialize(); if (saveString == "") { return(null); } string fileName = GameName + ".catangame"; var folder = await StaticHelpers.GetSaveFolder(); IStorageItem isiLocal = await folder.TryGetItemAsync(fileName); if (isiLocal != null) { var ret = await StaticHelpers.AskUserYesNoQuestion($"Overwrite {fileName}?", "yes", "no"); if (!ret) { return(null); } } var option = CreationCollisionOption.ReplaceExisting; var file = await folder.CreateFileAsync(fileName, option); await FileIO.WriteTextAsync(file, saveString); if (CurrentGameName != GameName) { _savedGameNames.Add(GameName); _savedStoragefiles.Add(GameName, file); CurrentGameName = GameName; } return(file); } catch (Exception exception) { string s = StaticHelpers.GetErrorMessage($"Error saving to file {GameName}", exception); MessageDialog dlg = new MessageDialog(s); await dlg.ShowAsync(); } return(null); }