public static void CharakterSave(out DSAError error) { error = null; try { var saveFile = Charakter.CreateSave(); var filePath = Path.Combine(CharakterSaveFolder, Charakter.ID.ToString() + ".save"); FileManagment.WriteToFile(saveFile.JSONContent, filePath, Windows.Storage.CreationCollisionOption.ReplaceExisting, out error); #region Sicherungskopie var task = new Task(async() => { try { var folder = await StorageFolder.GetFolderFromPathAsync("D:\\Dropbox\\07_DSA_PNP_D&D\\DSA_Save"); var sfile = await folder.CreateFileAsync(Charakter.ID.ToString() + ".save", CreationCollisionOption.ReplaceExisting); await FileIO.AppendTextAsync(sfile, saveFile.JSONContent); } catch (Exception) { Logger.Log(LogLevel.ErrorLog, "Sicherung konnte nicht erstellt werden"); //"https://support.microsoft.com/de-de/help/4468237/windows-10-file-system-access-and-privacy-microsoft-privacy" } }); task.Start(); #endregion } catch (Exception ex) { error = new DSAError { ErrorCode = ErrorCode.Error, Message = ex.Message }; } }
public static void SaveTalent(ITalent talent, GameType gameType, out DSAError error) { error = null; #region Talenttype List <JSONTalent> jTalentList = null; List <ITalent> talentList = null; var talenttype = talent.GetType().ToString(); var lastIndex = talenttype.LastIndexOf("."); talenttype = talenttype.Substring(lastIndex + 1); #endregion #region GameType if (gameType == GameType.DSA) { if (jSON_talentLocal.Talente == null) { jSON_talentLocal.Talente = new List <JSONTalent>(); } jTalentList = jSON_talentLocal.Talente; talentList = TalentList; } else { throw new Exception(); } #endregion try { var jsonTalent = TalentHelper.CreateJSON( talent: talent); #region Doppelte Elemente Entfernen var jdoppledID = jTalentList.Where(x => x.ID == talent.ID).ToList(); if (jdoppledID.Count > 0) { jTalentList.Remove(jdoppledID[0]); } var tdoppledID = talentList.Where(x => x.ID == talent.ID).ToList(); if (tdoppledID.Count > 0) { tdoppledID.Remove(tdoppledID[0]); } #endregion #region Speichern jTalentList.Add(jsonTalent); if (!talentList.Contains(talent)) { talentList.Add(talent); } FileManagment.WriteToFile(jSON_talentLocal.JSONContent, talentSaveFile, Windows.Storage.CreationCollisionOption.ReplaceExisting, out error); #endregion } catch (Exception ex) { error = new DSAError { ErrorCode = ErrorCode.InvalidValue, Message = ex.Message }; } }