public SaveHandler(string _pathToFile) { _pathBase = Path.GetTempPath() + _editPath; ZIPHelper.DecompressToDirectory(_pathToFile, _pathBase); _playerSave = PlayerSave.PlayerSave.FromJson(File.ReadAllText(_pathBase + Database.SelectFile(Database.SAVE_SELECTOR.SAVE_PLAYER))); _stateSave = GeneralSave.Save.FromJson(File.ReadAllText(_pathBase + Database.SelectFile(Database.SAVE_SELECTOR.SAVE_STATE))); }
public static byte[] DecompressToFileBytes(string archive, string filename) { using (FileStream compressedStream = new FileStream(archive, FileMode.Open, FileAccess.Read, FileShare.None)) { using (GZipStream zipStream = new GZipStream(compressedStream, CompressionMode.Decompress, true)) { return(ZIPHelper.DecompressFileToBytes(filename, zipStream)); } } }
public static void DecompressToDirectory(string sCompressedFile, string sDir) { using (FileStream compressedStream = new FileStream(sCompressedFile, FileMode.Open, FileAccess.Read, FileShare.None)) { using (GZipStream zipStream = new GZipStream(compressedStream, CompressionMode.Decompress, true)) { while (ZIPHelper.DecompressFile(sDir, zipStream)) { } } } }
public static byte[] CompressDirectory(string sInDir) { string[] files = Directory.GetFiles(sInDir, "*.*", SearchOption.AllDirectories); int startIndex = (sInDir[sInDir.Length - 1] != Path.DirectorySeparatorChar) ? (sInDir.Length + 1) : sInDir.Length; MemoryStream memoryStream = new MemoryStream(); using (GZipStream zipStream = new GZipStream(memoryStream, CompressionMode.Compress)) { string[] array = files; foreach (string text in array) { string sRelativePath = text.Substring(startIndex); ZIPHelper.CompressFile(sInDir, sRelativePath, zipStream); } } return(memoryStream.ToArray()); }
public static void CompressDirectory(string sInDir, string sOutFile) { string[] files = Directory.GetFiles(sInDir, "*.*", SearchOption.AllDirectories); int startIndex = (sInDir[sInDir.Length - 1] != Path.DirectorySeparatorChar) ? (sInDir.Length + 1) : sInDir.Length; using (FileStream compressedStream = new FileStream(sOutFile, FileMode.Create, FileAccess.Write, FileShare.None)) { using (GZipStream zipStream = new GZipStream(compressedStream, CompressionMode.Compress)) { string[] array = files; foreach (string text in array) { string sRelativePath = text.Substring(startIndex); ZIPHelper.CompressFile(sInDir, sRelativePath, zipStream); } } } }
public byte[] Pack() { File.Delete(_pathBase + Database.SelectFile(Database.SAVE_SELECTOR.SAVE_STATE)); File.Delete(_pathBase + Database.SelectFile(Database.SAVE_SELECTOR.SAVE_PLAYER)); // Ugly hotfix...but if the player changes the character name it's a problem... foreach (var character in this._playerSave) { if (character.Name.Equals("Player")) { this._stateSave.Stats = this.ConvertAsGS(character.Stats); break; } } File.WriteAllBytes(_pathBase + Database.SelectFile(Database.SAVE_SELECTOR.SAVE_STATE), GeneralSave.Serialize.ToJson(this._stateSave).ToArray().Select(character => (byte)character).ToArray()); File.WriteAllBytes(_pathBase + Database.SelectFile(Database.SAVE_SELECTOR.SAVE_PLAYER), PlayerSave.Serialize.ToJson(this._playerSave).ToArray().Select(character => (byte)character).ToArray()); return(ZIPHelper.CompressDirectory(_pathBase)); }