public void LzmaCompress(SharedSettings s) { switch (s.Variant) { case 1: { long s_WrittenSize = s.Dst.Length; var props = LZMA.CLzmaEncProps.LzmaEncProps_Init(); props.mLevel = s.ActualLevel; props.mDictSize = (uint)s.ActualDictSize; props.mLC = s.ActualLC; props.mLP = s.ActualLP; props.mPB = s.ActualPB; props.mAlgo = s.ActualAlgo; props.mFB = s.ActualFB; props.mBtMode = s.ActualBTMode; props.mNumHashBytes = s.ActualNumHashBytes; props.mMC = s.ActualMC; props.mWriteEndMark = s.ActualWriteEndMark; props.mNumThreads = s.ActualNumThreads; var enc = LZMA.LzmaEnc_Create(LZMA.ISzAlloc.SmallAlloc); var res = enc.LzmaEnc_SetProps(props); if (res != LZMA.SZ_OK) { throw new Exception("SetProps failed: " + res); } res = enc.LzmaEnc_MemEncode(P.From(s.Dst), ref s_WrittenSize, P.From(s.Src), s.Src.Length, s.ActualWriteEndMark != 0, null, LZMA.ISzAlloc.SmallAlloc, LZMA.ISzAlloc.BigAlloc); if (res != LZMA.SZ_OK) { throw new Exception("MemEncode failed: " + res); } s.Enc = new PZ(new byte[LZMA.LZMA_PROPS_SIZE]); long s_Enc_Length = s.Enc.Length; res = enc.LzmaEnc_WriteProperties(P.From(s.Enc), ref s_Enc_Length); if (res != LZMA.SZ_OK) { throw new Exception("WriteProperties failed: " + res); } if (s.Enc.Length != s.Enc.Buffer.Length) { throw new NotSupportedException(); } enc.LzmaEnc_Destroy(LZMA.ISzAlloc.SmallAlloc, LZMA.ISzAlloc.BigAlloc); s.WrittenSize = (int)s_WrittenSize; s.Enc.Length = (int)s_Enc_Length; } break; default: { long s_WrittenSize = s.Dst.Length; s.Enc = new PZ(new byte[LZMA.LZMA_PROPS_SIZE]); long s_Enc_Length = s.Enc.Length; var res = LZMA.LzmaCompress( P.From(s.Dst), ref s_WrittenSize, P.From(s.Src), s.Src.Length, s.Enc.Buffer, ref s_Enc_Length, s.ActualLevel, s.ActualDictSize, s.ActualLC, s.ActualLP, s.ActualPB, s.ActualFB, s.ActualNumThreads); s.WrittenSize = (int)s_WrittenSize; s.Enc.Length = (int)s_Enc_Length; if (res != LZMA.SZ_OK) { throw new Exception("LzmaCompress failed: " + res); } if (s.Enc.Length != s.Enc.Buffer.Length) { throw new NotSupportedException(); } } break; } }