/// <summary> /// Decompress/Decyrpt the file if the serialization type is not XML. /// </summary> /// <returns></returns> private MclFileStruct GetStruct() { MclFileStruct mclfile = new MclFileStruct(); if (File.Exists(fileName)) { MemoryStream ms = new MemoryStream(); FileStream fs = File.Open(fileName, FileMode.Open, FileAccess.Read); try { byte[] first3 = new byte[MclBytes.Length]; if (MclBytes.Length == fs.Read(first3, 0, first3.Length)) { MclSerialization st = MclSerialization.None; if (first3[0] == MclBytes[0] && first3[1] == MclBytes[1] && first3[2] == MclBytes[2]) { st = MclSerialization.Compression; } else if (first3[0] == MpwBytes[0] && first3[1] == MpwBytes[1] && first3[2] == MpwBytes[2]) { st = MclSerialization.Cryptography; } else if (first3[0] == McpBytes[0] && first3[1] == McpBytes[1] && first3[2] == McpBytes[2]) { st = MclSerialization.Compression | MclSerialization.Cryptography; } else { st = MclSerialization.None; ms.Write(first3, 0, first3.Length); } int read; byte[] tmp = new byte[16384]; while ((read = fs.Read(tmp, 0, tmp.Length)) > 0) { ms.Write(tmp, 0, read); } switch (st) { case MclSerialization.None: mclfile.content = ms.ToArray(); break; case MclSerialization.Compression: mclfile.content = Decompress(ms.ToArray()); break; case MclSerialization.Cryptography: mclfile.content = Decyrpt(ms.ToArray(), sha256Password); break; case MclSerialization.Compression | MclSerialization.Cryptography: byte[] compressed = Decyrpt(ms.ToArray(), sha256Password); mclfile.content = Decompress(compressed); break; } } } catch (Exception exception) { Trace.WriteLineIf(Settings.TraceSwitch.TraceError, exception.Message, GetType().Name); return new MclFileStruct(); } finally { fs.Close(); ms.Close(); } } return mclfile; }
/// <summary> /// Decompress/Decyrpt the file if the serialization type is not XML. /// </summary> /// <returns></returns> private MclFileStruct GetStruct() { MclFileStruct mclfile = new MclFileStruct(); if (File.Exists(fileName)) { MemoryStream ms = new MemoryStream(); FileStream fs = File.Open(fileName, FileMode.Open, FileAccess.Read); try { byte[] first3 = new byte[MclBytes.Length]; if (MclBytes.Length == fs.Read(first3, 0, first3.Length)) { MclSerialization st = MclSerialization.None; if (first3[0] == MclBytes[0] && first3[1] == MclBytes[1] && first3[2] == MclBytes[2]) { st = MclSerialization.Compression; } else if (first3[0] == MpwBytes[0] && first3[1] == MpwBytes[1] && first3[2] == MpwBytes[2]) { st = MclSerialization.Cryptography; } else if (first3[0] == McpBytes[0] && first3[1] == McpBytes[1] && first3[2] == McpBytes[2]) { st = MclSerialization.Compression | MclSerialization.Cryptography; } else { st = MclSerialization.None; ms.Write(first3, 0, first3.Length); } int read; byte[] tmp = new byte[16384]; while ((read = fs.Read(tmp, 0, tmp.Length)) > 0) { ms.Write(tmp, 0, read); } switch (st) { case MclSerialization.None: mclfile.content = ms.ToArray(); break; case MclSerialization.Compression: mclfile.content = Decompress(ms.ToArray()); break; case MclSerialization.Cryptography: mclfile.content = Decyrpt(ms.ToArray(), sha256Password); break; case MclSerialization.Compression | MclSerialization.Cryptography: byte[] compressed = Decyrpt(ms.ToArray(), sha256Password); mclfile.content = Decompress(compressed); break; } } } catch (Exception exception) { Trace.WriteLineIf(Settings.TraceSwitch.TraceError, exception.Message, GetType().Name); return(new MclFileStruct()); } finally { fs.Close(); ms.Close(); } } return(mclfile); }