public static unsafe ResourceNode FromSource(ResourceNode parent, DataSource source) { ResourceNode n = null; if ((n = GetRaw(source)) != null) { n.Initialize(parent, source); } else { //Check for compression? if (Compressor.IsDataCompressed(source.Address, source.Length)) { if ((*(uint *)source.Address) == YAZ0.Tag) { YAZ0 *cmpr = (YAZ0 *)source.Address; try { //Expand the whole resource and initialize FileMap map = FileMap.FromTempFile((int)cmpr->_unCompDataLen); Compressor.Expand(cmpr, map.Address, map.Length); source.Compression = CompressionType.RunLength; //Check for a match if ((n = GetRaw(new DataSource(map.Address, map.Length))) != null) { n.Initialize(parent, source, new DataSource(map)); } } catch (InvalidCompressionException e) { MessageBox.Show(e.ToString()); } } else { CompressionHeader *cmpr = (CompressionHeader *)source.Address; if (Compressor.Supports(cmpr->Algorithm)) { try { //Expand a portion of the data byte *buffer = stackalloc byte[CompressBufferLen]; Compressor.Expand(cmpr, buffer, CompressBufferLen); //Check for a match if ((n = GetRaw(new DataSource(buffer, CompressBufferLen))) != null) { //Expand the whole resource and initialize FileMap map = FileMap.FromTempFile(cmpr->ExpandedSize); Compressor.Expand(cmpr, map.Address, map.Length); source.Compression = cmpr->Algorithm; n.Initialize(parent, source, new DataSource(map)); } } catch (InvalidCompressionException e) { MessageBox.Show(e.ToString()); } } } } } return(n); }
public static void ExpandYAZ0(YAZ0 *header, VoidPtr dstAddress, int dstLen) { byte control = 0, bit = 0; byte *srcPtr = (byte *)header->Data, dstPtr = (byte *)dstAddress, ceiling = dstPtr + dstLen; while (dstPtr < ceiling) { if (bit == 0) { control = *srcPtr++; bit = 8; } bit--; if ((control & 0x80) == 0x80) { *dstPtr++ = *srcPtr++; } else { byte b1 = *srcPtr++, b2 = *srcPtr++; byte *cpyPtr = (byte *)((VoidPtr)dstPtr - ((b1 & 0x0f) << 8 | b2) - 1); int n = b1 >> 4; if (n == 0) { n = *srcPtr++ + 0x12; } else { n += 2; } //if (!(n >= 3 && n <= 0x111)) return; while (n-- > 0) { *dstPtr++ = *cpyPtr++; } } control <<= 1; } }
public static void Expand(YAZ0 *header, VoidPtr dstAddr, int dstLen) { RunLength.ExpandYAZ0(header, dstAddr, dstLen); }
public static void ExpandYAZ0(YAZ0 *header, VoidPtr dstAddress, int dstLen) { Expand(header->Data, dstAddress, dstLen); }