public void _DecodeStream(System.IO.Stream inStream, System.IO.Stream outStream) { byte[] properties = new byte[5]; if (inStream.Read(properties, 0, 5) != 5) { throw (new Exception("input .lzma is too short")); } CDecoder decoder = new CDecoder(); decoder.SetDecoderProperties(properties); long outSize = 0; for (int i = 0; i < 8; i++) { int v = inStream.ReadByte(); if (v < 0) { throw (new Exception("Can't Read 1")); } outSize |= ((long)(byte)v) << (8 * i); } long compressedSize = inStream.Length - inStream.Position; decoder.Code(inStream, outStream, compressedSize, outSize, null); }
public static void ExtractResources() { Assembly _Assembly = Assembly.GetExecutingAssembly(); Stream _ResourceStream = _Assembly.GetManifestResourceStream(Core.ProductName + ".Includes.resources"); Stream _MemoryStream = new MemoryStream(); Common.Lzma.CDecoder LZMADecoder = new Common.Lzma.CDecoder(); LZMADecoder._DecodeStream(_ResourceStream, _MemoryStream); _MemoryStream.Seek(0, SeekOrigin.Begin); if (!System.IO.Directory.Exists(Core.IncludesPath)) { System.IO.Directory.CreateDirectory(Core.IncludesPath); } //Common.Lzma.CTarHelper.UntarTo(_MemoryStream, Core.IncludesPath); foreach (var entryStream in Common.Lzma.CTarHelper.Untar(_MemoryStream)) { var outputFile = ""; if (entryStream.FileName.Contains("EnvironmentAssessment.Web.exe") || entryStream.FileName.Contains("index.html")) { outputFile = Path.Combine(Core.TempPath, entryStream.FileName); } else { outputFile = Path.Combine(Core.IncludesPath, entryStream.FileName); } var outputDir = Path.GetDirectoryName(outputFile); Directory.CreateDirectory(outputDir); using (var outputStream = new FileStream(outputFile, FileMode.Create, FileAccess.Write)) { entryStream.CopyTo(outputStream); } File.SetLastWriteTime(outputFile, entryStream.LastModifiedTime); } _MemoryStream.Dispose(); _ResourceStream.Dispose(); }