private static string MxDBuildSaveStringShared( ref CompressionData cData, bool includeAltEnh, bool @break) { var numArray = Array.Empty <byte>(); string str; if (!MxDBuildSaveBuffer(ref numArray, includeAltEnh)) { str = string.Empty; } else { var asciiEncoding = new ASCIIEncoding(); cData.SzUncompressed = numArray.Length; var iBytes = Zlib.CompressChunk(ref numArray); cData.SzCompressed = iBytes.Length; var bytes = Zlib.HexEncodeBytes(iBytes); cData.SzEncoded = bytes.Length; str = @break ? Zlib.BreakString(asciiEncoding.GetString(bytes), 67, true) : asciiEncoding.GetString(bytes); } return(str); }
public static eLoadReturnCode MxDExtractAndLoad(Stream iStream) { StreamReader streamReader; try { streamReader = new StreamReader(iStream); streamReader.BaseStream.Seek(0L, SeekOrigin.Begin); } catch (Exception ex) { var num = (int)MessageBox.Show("Unable to read data - " + ex.Message, "ExtractAndLoad Failed"); return(MidsCharacterFileFormat.eLoadReturnCode.Failure); } string[] strArray1 = { "ABCD", "0", "0", "0" }; var a = ""; eLoadReturnCode eLoadReturnCode; try { var str = streamReader.ReadToEnd().Replace("||", "|\n|"); streamReader.Close(); var strArray2 = str.Split('\n'); var num1 = -1; if (strArray2.Length < 1) { var num2 = (int)MessageBox.Show("Unable to locate data header - Zero-Length Input!", "ExtractAndLoad Failed"); eLoadReturnCode = eLoadReturnCode.Failure; } else { for (var index = 0; index < strArray2.Length; ++index) { var startIndex = strArray2[index].IndexOf(MagicUncompressed, StringComparison.Ordinal); if (startIndex < 0) { startIndex = strArray2[index].IndexOf(MagicCompressed, StringComparison.Ordinal); } if (startIndex < 0) { startIndex = strArray2[index].IndexOf(Files.Headers.Save.Compressed, StringComparison.OrdinalIgnoreCase); } if (startIndex <= -1) { continue; } strArray1 = strArray2[index].Substring(startIndex).Split(';'); a = strArray1.Length > 0 ? strArray1[0] : string.Empty; num1 = index; break; } if (num1 < 0) { MessageBox.Show("Unable to locate data header - Magic Number not found!", "ExtractAndLoad Failed"); eLoadReturnCode = eLoadReturnCode.Failure; } else if (string.Equals(a, Files.Headers.Save.Compressed, StringComparison.OrdinalIgnoreCase)) { eLoadReturnCode = eLoadReturnCode.IsOldFormat; } else if (num1 + 1 == strArray2.Length) { MessageBox.Show("Unable to locate data - Nothing beyond header!", "ExtractAndLoad Failed"); eLoadReturnCode = eLoadReturnCode.Failure; } else { var iString = string.Empty; for (var index = num1 + 1; index <= strArray2.Length - 1; ++index) { iString = iString + strArray2[index] + "\n"; } var int32_1 = Convert.ToInt32(strArray1[1]); var int32_2 = Convert.ToInt32(strArray1[2]); var int32_3 = Convert.ToInt32(strArray1[3]); var isHex = false; if (strArray1.Length > 4) { isHex = string.Equals(strArray1[4], "HEX", StringComparison.OrdinalIgnoreCase); } var iBytes = new ASCIIEncoding().GetBytes(isHex ? Zlib.UnbreakHex(iString) : Zlib.UnbreakString(iString, true)); streamReader.Close(); if (iBytes.Length < int32_3) { MessageBox.Show( "Data chunk was incomplete! Check that the entire chunk was copied to the clipboard.", "ExtractAndLoad Failed"); eLoadReturnCode = eLoadReturnCode.Failure; } else { if (iBytes.Length > int32_3) { Array.Resize(ref iBytes, int32_3); } iBytes = isHex ? Zlib.HexDecodeBytes(iBytes) : Zlib.UUDecodeBytes(iBytes); if (iBytes.Length == 0) { eLoadReturnCode = eLoadReturnCode.Failure; } else { if (a == MagicCompressed) { Array.Resize(ref iBytes, int32_2); var tempByteArray = iBytes; // Pine iBytes = Zlib.UncompressChunk(ref tempByteArray, int32_1); } eLoadReturnCode = iBytes.Length != 0 ? MxDReadSaveData(ref iBytes, false) ? eLoadReturnCode.Success : eLoadReturnCode.Failure : eLoadReturnCode.Failure; } } } } } catch (Exception ex) { MessageBox.Show("Unable to read data - " + ex.Message, "ExtractAndLoad Failed"); streamReader.Close(); eLoadReturnCode = eLoadReturnCode.Failure; } return(eLoadReturnCode); }