private void WriteSave(string savePath, SaveFile saveFile) { this.General.ExportData(saveFile.SaveGame, out var platform); this.Character.ExportData(saveFile.SaveGame); this.Vehicle.ExportData(saveFile.SaveGame); this.CurrencyOnHand.ExportData(saveFile.SaveGame); this.Backpack.ExportData(saveFile.SaveGame, platform); this.Bank.ExportData(saveFile.SaveGame, platform); this.FastTravel.ExportData(saveFile.SaveGame); if (saveFile.SaveGame != null && saveFile.SaveGame.WeaponData != null) { saveFile.SaveGame.WeaponData.RemoveAll( wd => Blacklisting.IsBlacklistedType(wd.Type) == true || Blacklisting.IsBlacklistedBalance(wd.Balance) == true); } if (saveFile.SaveGame != null && saveFile.SaveGame.ItemData != null) { saveFile.SaveGame.ItemData.RemoveAll( wd => Blacklisting.IsBlacklistedType(wd.Type) == true || Blacklisting.IsBlacklistedBalance(wd.Balance) == true); } using (var output = File.Create(savePath)) { FileFormats.SaveExpansion.AddExpansionSavedataToUnloadableItemData( saveFile.SaveGame); saveFile.Platform = platform; saveFile.Serialize(output); FileFormats.SaveExpansion .ExtractExpansionSavedataFromUnloadableItemData( saveFile.SaveGame); } }
public IEnumerable <IResult> WriteSave() { if (this.SaveFile == null) { yield break; } string fileName = null; foreach (var result in this.SaveLoad.SaveFile(s => fileName = s)) { yield return(result); } if (fileName == null) { yield break; } var saveFile = this.SaveFile; yield return(new DelegateResult( () => { this.General.ExportData(saveFile.SaveGame, out var platform); this.Character.ExportData(saveFile.SaveGame); this.Vehicle.ExportData(saveFile.SaveGame); this.CurrencyOnHand.ExportData(saveFile.SaveGame); this.Backpack.ExportData(saveFile.SaveGame, platform); this.Bank.ExportData(saveFile.SaveGame, platform); this.FastTravel.ExportData(saveFile.SaveGame); if (saveFile.SaveGame != null && saveFile.SaveGame.WeaponData != null) { saveFile.SaveGame.WeaponData.RemoveAll( wd => Blacklisting.IsBlacklistedType(wd.Type) == true || Blacklisting.IsBlacklistedBalance(wd.Balance) == true); } if (saveFile.SaveGame != null && saveFile.SaveGame.ItemData != null) { saveFile.SaveGame.ItemData.RemoveAll( wd => Blacklisting.IsBlacklistedType(wd.Type) == true || Blacklisting.IsBlacklistedBalance(wd.Balance) == true); } using (var output = File.Create(fileName)) { FileFormats.SaveExpansion.AddExpansionSavedataToUnloadableItemData( saveFile.SaveGame); saveFile.Platform = platform; saveFile.Serialize(output); FileFormats.SaveExpansion .ExtractExpansionSavedataFromUnloadableItemData( saveFile.SaveGame); } }).Rescue().Execute( x => new MyMessageBox( $"An exception was thrown (press Ctrl+C to copy):\n\n{x.ToString()}", "Error") .WithIcon(MessageBoxImage.Error).AsCoroutine())); }