diff --git a/sources/import/edz/README.md b/sources/import/edz/README.md new file mode 100644 index 000000000..e5d409613 --- /dev/null +++ b/sources/import/edz/README.md @@ -0,0 +1,52 @@ +# EPLAN `.edz` part import + +Imports a part from the **EPLAN Data Portal** (`.edz`) into a QElectroTech +element collection. The EPLAN Data Portal is the de-facto parts catalogue for +electrical CAD (ifm, Phoenix Contact, Siemens, Rittal, Weidmüller, Schneider…), +and components ship as `.edz`; this lets a QET user drop one straight into a +project. + +## Using it + +Right-click a writable collection folder in the elements panel → +**Import an EPLAN part (.edz)…** → choose the file. The generated element is +written into that folder and the panel reloads. + +## What is imported + +A `.edz` is a 7-Zip archive containing a part definition (`*.part.xml`), an EPLAN +macro (`*.ema`), a product image and metadata. Only the **portable** part data is +used: + +- **Terminals** — each `` with a physical connection + designation becomes a QET terminal, labelled from its connection description. +- **Element information** — manufacturer, order number, designation and comment + fill the QET element-information fields used by the BOM / nomenclature. +- **Localized names** — one `` per language the part provides, so + the element labels itself in any QET UI language. +- **Symbol** — a generic symbol is generated (a body rectangle with one + west-facing terminal per pin). The EPLAN `.ema` macro geometry is **not** + reproduced: it is tokenised EPLAN PXF that references EPLAN's own symbol + libraries. A generic symbol is sufficient for wiring and BOM; swap in a nicer + symbol in the element editor afterwards if desired. + +## Structure + +| File | Role | +|------|------| +| `edzarchive.*` | Extract the `.edz` to a temp dir; locate `part.xml` | +| `edzsevenzip.*` | 7-Zip extraction via the bundled LZMA SDK (no external 7-Zip) | +| `edzpart.*` | Parse `part.xml` into a portable model | +| `edzelementbuilder.*` | Build the `.elmt` element from the model | +| `edzimporter.*` | Orchestrate the above and write into a collection folder | +| `lzma/` | Vendored public-domain LZMA SDK (decode-only subset) | + +The non-UI classes are deliberately decoupled from the widget so they can be +tested headless. + +## Bundled LZMA SDK + +`lzma/` contains the decode-only subset of Igor Pavlov's **LZMA SDK** (public +domain — see `lzma/LZMA-SDK-LICENSE.txt`), so a `.edz` can be unpacked without an +external 7-Zip install. Only 7-Zip-format `.edz` files are supported; zip-format +packages are detected and reported but not yet handled. diff --git a/sources/import/edz/edzarchive.cpp b/sources/import/edz/edzarchive.cpp index f30d5f835..5c7b3526f 100644 --- a/sources/import/edz/edzarchive.cpp +++ b/sources/import/edz/edzarchive.cpp @@ -21,6 +21,7 @@ #include #include +#include #include #include @@ -41,6 +42,29 @@ bool EdzArchive::extract(const QString &edz_path) return false; } + // A .edz is a 7-Zip archive (magic "7z\xBC\xAF\x27\x1C"). Some EPLAN exports + // are instead zip-format ("PK\x03\x04"); the bundled reader only does 7z, so + // detect that up front and say so clearly rather than failing opaquely. + QFile probe(fi.absoluteFilePath()); + if (!probe.open(QIODevice::ReadOnly)) { + m_error = QStringLiteral("Cannot read %1").arg(edz_path); + return false; + } + const QByteArray magic = probe.read(6); + probe.close(); + static const QByteArray k7z("7z\xBC\xAF\x27\x1C", 6); + if (!magic.startsWith(k7z)) { + if (magic.startsWith(QByteArray("PK\x03\x04", 4))) { + m_error = QStringLiteral( + "This .edz is a zip-format package, which is not yet " + "supported (only 7-Zip .edz files can be imported)."); + } else { + m_error = QStringLiteral( + "Not a valid .edz package (unrecognised archive format)."); + } + return false; + } + m_dir.reset(new QTemporaryDir); if (!m_dir->isValid()) { m_error = QStringLiteral("Could not create a temporary directory: %1") diff --git a/sources/import/edz/lzma/7zVersion.h b/sources/import/edz/lzma/7zVersion.h deleted file mode 100644 index 754923961..000000000 --- a/sources/import/edz/lzma/7zVersion.h +++ /dev/null @@ -1,27 +0,0 @@ -#define MY_VER_MAJOR 23 -#define MY_VER_MINOR 01 -#define MY_VER_BUILD 0 -#define MY_VERSION_NUMBERS "23.01" -#define MY_VERSION MY_VERSION_NUMBERS - -#ifdef MY_CPU_NAME - #define MY_VERSION_CPU MY_VERSION " (" MY_CPU_NAME ")" -#else - #define MY_VERSION_CPU MY_VERSION -#endif - -#define MY_DATE "2023-06-20" -#undef MY_COPYRIGHT -#undef MY_VERSION_COPYRIGHT_DATE -#define MY_AUTHOR_NAME "Igor Pavlov" -#define MY_COPYRIGHT_PD "Igor Pavlov : Public domain" -#define MY_COPYRIGHT_CR "Copyright (c) 1999-2023 Igor Pavlov" - -#ifdef USE_COPYRIGHT_CR - #define MY_COPYRIGHT MY_COPYRIGHT_CR -#else - #define MY_COPYRIGHT MY_COPYRIGHT_PD -#endif - -#define MY_COPYRIGHT_DATE MY_COPYRIGHT " : " MY_DATE -#define MY_VERSION_COPYRIGHT_DATE MY_VERSION_CPU " : " MY_COPYRIGHT " : " MY_DATE diff --git a/sources/import/edz/lzma/Aes.h b/sources/import/edz/lzma/Aes.h deleted file mode 100644 index 7f0182ac0..000000000 --- a/sources/import/edz/lzma/Aes.h +++ /dev/null @@ -1,60 +0,0 @@ -/* Aes.h -- AES encryption / decryption -2023-04-02 : Igor Pavlov : Public domain */ - -#ifndef ZIP7_INC_AES_H -#define ZIP7_INC_AES_H - -#include "7zTypes.h" - -EXTERN_C_BEGIN - -#define AES_BLOCK_SIZE 16 - -/* Call AesGenTables one time before other AES functions */ -void AesGenTables(void); - -/* UInt32 pointers must be 16-byte aligned */ - -/* 16-byte (4 * 32-bit words) blocks: 1 (IV) + 1 (keyMode) + 15 (AES-256 roundKeys) */ -#define AES_NUM_IVMRK_WORDS ((1 + 1 + 15) * 4) - -/* aes - 16-byte aligned pointer to keyMode+roundKeys sequence */ -/* keySize = 16 or 24 or 32 (bytes) */ -typedef void (Z7_FASTCALL *AES_SET_KEY_FUNC)(UInt32 *aes, const Byte *key, unsigned keySize); -void Z7_FASTCALL Aes_SetKey_Enc(UInt32 *aes, const Byte *key, unsigned keySize); -void Z7_FASTCALL Aes_SetKey_Dec(UInt32 *aes, const Byte *key, unsigned keySize); - -/* ivAes - 16-byte aligned pointer to iv+keyMode+roundKeys sequence: UInt32[AES_NUM_IVMRK_WORDS] */ -void AesCbc_Init(UInt32 *ivAes, const Byte *iv); /* iv size is AES_BLOCK_SIZE */ - -/* data - 16-byte aligned pointer to data */ -/* numBlocks - the number of 16-byte blocks in data array */ -typedef void (Z7_FASTCALL *AES_CODE_FUNC)(UInt32 *ivAes, Byte *data, size_t numBlocks); - -extern AES_CODE_FUNC g_AesCbc_Decode; -#ifndef Z7_SFX -extern AES_CODE_FUNC g_AesCbc_Encode; -extern AES_CODE_FUNC g_AesCtr_Code; -#define k_Aes_SupportedFunctions_HW (1 << 2) -#define k_Aes_SupportedFunctions_HW_256 (1 << 3) -extern UInt32 g_Aes_SupportedFunctions_Flags; -#endif - - -#define Z7_DECLARE_AES_CODE_FUNC(funcName) \ - void Z7_FASTCALL funcName(UInt32 *ivAes, Byte *data, size_t numBlocks); - -Z7_DECLARE_AES_CODE_FUNC (AesCbc_Encode) -Z7_DECLARE_AES_CODE_FUNC (AesCbc_Decode) -Z7_DECLARE_AES_CODE_FUNC (AesCtr_Code) - -Z7_DECLARE_AES_CODE_FUNC (AesCbc_Encode_HW) -Z7_DECLARE_AES_CODE_FUNC (AesCbc_Decode_HW) -Z7_DECLARE_AES_CODE_FUNC (AesCtr_Code_HW) - -Z7_DECLARE_AES_CODE_FUNC (AesCbc_Decode_HW_256) -Z7_DECLARE_AES_CODE_FUNC (AesCtr_Code_HW_256) - -EXTERN_C_END - -#endif diff --git a/sources/import/edz/lzma/Alloc.h b/sources/import/edz/lzma/Alloc.h deleted file mode 100644 index fac5b62fb..000000000 --- a/sources/import/edz/lzma/Alloc.h +++ /dev/null @@ -1,71 +0,0 @@ -/* Alloc.h -- Memory allocation functions -2023-03-04 : Igor Pavlov : Public domain */ - -#ifndef ZIP7_INC_ALLOC_H -#define ZIP7_INC_ALLOC_H - -#include "7zTypes.h" - -EXTERN_C_BEGIN - -/* - MyFree(NULL) : is allowed, as free(NULL) - MyAlloc(0) : returns NULL : but malloc(0) is allowed to return NULL or non_NULL - MyRealloc(NULL, 0) : returns NULL : but realloc(NULL, 0) is allowed to return NULL or non_NULL -MyRealloc() is similar to realloc() for the following cases: - MyRealloc(non_NULL, 0) : returns NULL and always calls MyFree(ptr) - MyRealloc(NULL, non_ZERO) : returns NULL, if allocation failed - MyRealloc(non_NULL, non_ZERO) : returns NULL, if reallocation failed -*/ - -void *MyAlloc(size_t size); -void MyFree(void *address); -void *MyRealloc(void *address, size_t size); - -#ifdef _WIN32 - -#ifdef Z7_LARGE_PAGES -void SetLargePageSize(void); -#endif - -void *MidAlloc(size_t size); -void MidFree(void *address); -void *BigAlloc(size_t size); -void BigFree(void *address); - -#else - -#define MidAlloc(size) MyAlloc(size) -#define MidFree(address) MyFree(address) -#define BigAlloc(size) MyAlloc(size) -#define BigFree(address) MyFree(address) - -#endif - -extern const ISzAlloc g_Alloc; - -#ifdef _WIN32 -extern const ISzAlloc g_BigAlloc; -extern const ISzAlloc g_MidAlloc; -#else -#define g_BigAlloc g_AlignedAlloc -#define g_MidAlloc g_AlignedAlloc -#endif - -extern const ISzAlloc g_AlignedAlloc; - - -typedef struct -{ - ISzAlloc vt; - ISzAllocPtr baseAlloc; - unsigned numAlignBits; /* ((1 << numAlignBits) >= sizeof(void *)) */ - size_t offset; /* (offset == (k * sizeof(void *)) && offset < (1 << numAlignBits) */ -} CAlignOffsetAlloc; - -void AlignOffsetAlloc_CreateVTable(CAlignOffsetAlloc *p); - - -EXTERN_C_END - -#endif diff --git a/sources/import/edz/lzma/DllSecur.h b/sources/import/edz/lzma/DllSecur.h deleted file mode 100644 index 9fa415382..000000000 --- a/sources/import/edz/lzma/DllSecur.h +++ /dev/null @@ -1,20 +0,0 @@ -/* DllSecur.h -- DLL loading for security -2023-03-03 : Igor Pavlov : Public domain */ - -#ifndef ZIP7_INC_DLL_SECUR_H -#define ZIP7_INC_DLL_SECUR_H - -#include "7zTypes.h" - -EXTERN_C_BEGIN - -#ifdef _WIN32 - -void My_SetDefaultDllDirectories(void); -void LoadSecurityDlls(void); - -#endif - -EXTERN_C_END - -#endif diff --git a/sources/import/edz/lzma/LzFind.h b/sources/import/edz/lzma/LzFind.h deleted file mode 100644 index a3f72c987..000000000 --- a/sources/import/edz/lzma/LzFind.h +++ /dev/null @@ -1,159 +0,0 @@ -/* LzFind.h -- Match finder for LZ algorithms -2023-03-04 : Igor Pavlov : Public domain */ - -#ifndef ZIP7_INC_LZ_FIND_H -#define ZIP7_INC_LZ_FIND_H - -#include "7zTypes.h" - -EXTERN_C_BEGIN - -typedef UInt32 CLzRef; - -typedef struct -{ - const Byte *buffer; - UInt32 pos; - UInt32 posLimit; - UInt32 streamPos; /* wrap over Zero is allowed (streamPos < pos). Use (UInt32)(streamPos - pos) */ - UInt32 lenLimit; - - UInt32 cyclicBufferPos; - UInt32 cyclicBufferSize; /* it must be = (historySize + 1) */ - - Byte streamEndWasReached; - Byte btMode; - Byte bigHash; - Byte directInput; - - UInt32 matchMaxLen; - CLzRef *hash; - CLzRef *son; - UInt32 hashMask; - UInt32 cutValue; - - Byte *bufBase; - ISeqInStreamPtr stream; - - UInt32 blockSize; - UInt32 keepSizeBefore; - UInt32 keepSizeAfter; - - UInt32 numHashBytes; - size_t directInputRem; - UInt32 historySize; - UInt32 fixedHashSize; - Byte numHashBytes_Min; - Byte numHashOutBits; - Byte _pad2_[2]; - SRes result; - UInt32 crc[256]; - size_t numRefs; - - UInt64 expectedDataSize; -} CMatchFinder; - -#define Inline_MatchFinder_GetPointerToCurrentPos(p) ((const Byte *)(p)->buffer) - -#define Inline_MatchFinder_GetNumAvailableBytes(p) ((UInt32)((p)->streamPos - (p)->pos)) - -/* -#define Inline_MatchFinder_IsFinishedOK(p) \ - ((p)->streamEndWasReached \ - && (p)->streamPos == (p)->pos \ - && (!(p)->directInput || (p)->directInputRem == 0)) -*/ - -int MatchFinder_NeedMove(CMatchFinder *p); -/* Byte *MatchFinder_GetPointerToCurrentPos(CMatchFinder *p); */ -void MatchFinder_MoveBlock(CMatchFinder *p); -void MatchFinder_ReadIfRequired(CMatchFinder *p); - -void MatchFinder_Construct(CMatchFinder *p); - -/* (directInput = 0) is default value. - It's required to provide correct (directInput) value - before calling MatchFinder_Create(). - You can set (directInput) by any of the following calls: - - MatchFinder_SET_DIRECT_INPUT_BUF() - - MatchFinder_SET_STREAM() - - MatchFinder_SET_STREAM_MODE() -*/ - -#define MatchFinder_SET_DIRECT_INPUT_BUF(p, _src_, _srcLen_) { \ - (p)->stream = NULL; \ - (p)->directInput = 1; \ - (p)->buffer = (_src_); \ - (p)->directInputRem = (_srcLen_); } - -/* -#define MatchFinder_SET_STREAM_MODE(p) { \ - (p)->directInput = 0; } -*/ - -#define MatchFinder_SET_STREAM(p, _stream_) { \ - (p)->stream = _stream_; \ - (p)->directInput = 0; } - - -int MatchFinder_Create(CMatchFinder *p, UInt32 historySize, - UInt32 keepAddBufferBefore, UInt32 matchMaxLen, UInt32 keepAddBufferAfter, - ISzAllocPtr alloc); -void MatchFinder_Free(CMatchFinder *p, ISzAllocPtr alloc); -void MatchFinder_Normalize3(UInt32 subValue, CLzRef *items, size_t numItems); - -/* -#define MatchFinder_INIT_POS(p, val) \ - (p)->pos = (val); \ - (p)->streamPos = (val); -*/ - -// void MatchFinder_ReduceOffsets(CMatchFinder *p, UInt32 subValue); -#define MatchFinder_REDUCE_OFFSETS(p, subValue) \ - (p)->pos -= (subValue); \ - (p)->streamPos -= (subValue); - - -UInt32 * GetMatchesSpec1(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *buffer, CLzRef *son, - size_t _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 _cutValue, - UInt32 *distances, UInt32 maxLen); - -/* -Conditions: - Mf_GetNumAvailableBytes_Func must be called before each Mf_GetMatchLen_Func. - Mf_GetPointerToCurrentPos_Func's result must be used only before any other function -*/ - -typedef void (*Mf_Init_Func)(void *object); -typedef UInt32 (*Mf_GetNumAvailableBytes_Func)(void *object); -typedef const Byte * (*Mf_GetPointerToCurrentPos_Func)(void *object); -typedef UInt32 * (*Mf_GetMatches_Func)(void *object, UInt32 *distances); -typedef void (*Mf_Skip_Func)(void *object, UInt32); - -typedef struct -{ - Mf_Init_Func Init; - Mf_GetNumAvailableBytes_Func GetNumAvailableBytes; - Mf_GetPointerToCurrentPos_Func GetPointerToCurrentPos; - Mf_GetMatches_Func GetMatches; - Mf_Skip_Func Skip; -} IMatchFinder2; - -void MatchFinder_CreateVTable(CMatchFinder *p, IMatchFinder2 *vTable); - -void MatchFinder_Init_LowHash(CMatchFinder *p); -void MatchFinder_Init_HighHash(CMatchFinder *p); -void MatchFinder_Init_4(CMatchFinder *p); -void MatchFinder_Init(CMatchFinder *p); - -UInt32* Bt3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances); -UInt32* Hc3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances); - -void Bt3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num); -void Hc3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num); - -void LzFindPrepare(void); - -EXTERN_C_END - -#endif diff --git a/sources/import/edz/lzma/LzFindMt.h b/sources/import/edz/lzma/LzFindMt.h deleted file mode 100644 index db5923ea0..000000000 --- a/sources/import/edz/lzma/LzFindMt.h +++ /dev/null @@ -1,109 +0,0 @@ -/* LzFindMt.h -- multithreaded Match finder for LZ algorithms -2023-03-05 : Igor Pavlov : Public domain */ - -#ifndef ZIP7_INC_LZ_FIND_MT_H -#define ZIP7_INC_LZ_FIND_MT_H - -#include "LzFind.h" -#include "Threads.h" - -EXTERN_C_BEGIN - -typedef struct -{ - UInt32 numProcessedBlocks; - CThread thread; - UInt64 affinity; - - BoolInt wasCreated; - BoolInt needStart; - BoolInt csWasInitialized; - BoolInt csWasEntered; - - BoolInt exit; - BoolInt stopWriting; - - CAutoResetEvent canStart; - CAutoResetEvent wasStopped; - CSemaphore freeSemaphore; - CSemaphore filledSemaphore; - CCriticalSection cs; - // UInt32 numBlocks_Sent; -} CMtSync; - -typedef UInt32 * (*Mf_Mix_Matches)(void *p, UInt32 matchMinPos, UInt32 *distances); - -/* kMtCacheLineDummy must be >= size_of_CPU_cache_line */ -#define kMtCacheLineDummy 128 - -typedef void (*Mf_GetHeads)(const Byte *buffer, UInt32 pos, - UInt32 *hash, UInt32 hashMask, UInt32 *heads, UInt32 numHeads, const UInt32 *crc); - -typedef struct -{ - /* LZ */ - const Byte *pointerToCurPos; - UInt32 *btBuf; - const UInt32 *btBufPos; - const UInt32 *btBufPosLimit; - UInt32 lzPos; - UInt32 btNumAvailBytes; - - UInt32 *hash; - UInt32 fixedHashSize; - // UInt32 hash4Mask; - UInt32 historySize; - const UInt32 *crc; - - Mf_Mix_Matches MixMatchesFunc; - UInt32 failure_LZ_BT; // failure in BT transfered to LZ - // UInt32 failure_LZ_LZ; // failure in LZ tables - UInt32 failureBuf[1]; - // UInt32 crc[256]; - - /* LZ + BT */ - CMtSync btSync; - Byte btDummy[kMtCacheLineDummy]; - - /* BT */ - UInt32 *hashBuf; - UInt32 hashBufPos; - UInt32 hashBufPosLimit; - UInt32 hashNumAvail; - UInt32 failure_BT; - - - CLzRef *son; - UInt32 matchMaxLen; - UInt32 numHashBytes; - UInt32 pos; - const Byte *buffer; - UInt32 cyclicBufferPos; - UInt32 cyclicBufferSize; /* it must be = (historySize + 1) */ - UInt32 cutValue; - - /* BT + Hash */ - CMtSync hashSync; - /* Byte hashDummy[kMtCacheLineDummy]; */ - - /* Hash */ - Mf_GetHeads GetHeadsFunc; - CMatchFinder *MatchFinder; - // CMatchFinder MatchFinder; -} CMatchFinderMt; - -// only for Mt part -void MatchFinderMt_Construct(CMatchFinderMt *p); -void MatchFinderMt_Destruct(CMatchFinderMt *p, ISzAllocPtr alloc); - -SRes MatchFinderMt_Create(CMatchFinderMt *p, UInt32 historySize, UInt32 keepAddBufferBefore, - UInt32 matchMaxLen, UInt32 keepAddBufferAfter, ISzAllocPtr alloc); -void MatchFinderMt_CreateVTable(CMatchFinderMt *p, IMatchFinder2 *vTable); - -/* call MatchFinderMt_InitMt() before IMatchFinder::Init() */ -SRes MatchFinderMt_InitMt(CMatchFinderMt *p); -void MatchFinderMt_ReleaseStream(CMatchFinderMt *p); - -EXTERN_C_END - -#endif diff --git a/sources/import/edz/lzma/LzHash.h b/sources/import/edz/lzma/LzHash.h deleted file mode 100644 index 2b6290b64..000000000 --- a/sources/import/edz/lzma/LzHash.h +++ /dev/null @@ -1,34 +0,0 @@ -/* LzHash.h -- HASH constants for LZ algorithms -2023-03-05 : Igor Pavlov : Public domain */ - -#ifndef ZIP7_INC_LZ_HASH_H -#define ZIP7_INC_LZ_HASH_H - -/* - (kHash2Size >= (1 << 8)) : Required - (kHash3Size >= (1 << 16)) : Required -*/ - -#define kHash2Size (1 << 10) -#define kHash3Size (1 << 16) -// #define kHash4Size (1 << 20) - -#define kFix3HashSize (kHash2Size) -#define kFix4HashSize (kHash2Size + kHash3Size) -// #define kFix5HashSize (kHash2Size + kHash3Size + kHash4Size) - -/* - We use up to 3 crc values for hash: - crc0 - crc1 << Shift_1 - crc2 << Shift_2 - (Shift_1 = 5) and (Shift_2 = 10) is good tradeoff. - Small values for Shift are not good for collision rate. - Big value for Shift_2 increases the minimum size - of hash table, that will be slow for small files. -*/ - -#define kLzHash_CrcShift_1 5 -#define kLzHash_CrcShift_2 10 - -#endif diff --git a/sources/import/edz/lzma/Lzma2DecMt.h b/sources/import/edz/lzma/Lzma2DecMt.h deleted file mode 100644 index 93a5cd59e..000000000 --- a/sources/import/edz/lzma/Lzma2DecMt.h +++ /dev/null @@ -1,81 +0,0 @@ -/* Lzma2DecMt.h -- LZMA2 Decoder Multi-thread -2023-04-13 : Igor Pavlov : Public domain */ - -#ifndef ZIP7_INC_LZMA2_DEC_MT_H -#define ZIP7_INC_LZMA2_DEC_MT_H - -#include "7zTypes.h" - -EXTERN_C_BEGIN - -typedef struct -{ - size_t inBufSize_ST; - size_t outStep_ST; - - #ifndef Z7_ST - unsigned numThreads; - size_t inBufSize_MT; - size_t outBlockMax; - size_t inBlockMax; - #endif -} CLzma2DecMtProps; - -/* init to single-thread mode */ -void Lzma2DecMtProps_Init(CLzma2DecMtProps *p); - - -/* ---------- CLzma2DecMtHandle Interface ---------- */ - -/* Lzma2DecMt_ * functions can return the following exit codes: -SRes: - SZ_OK - OK - SZ_ERROR_MEM - Memory allocation error - SZ_ERROR_PARAM - Incorrect paramater in props - SZ_ERROR_WRITE - ISeqOutStream write callback error - // SZ_ERROR_OUTPUT_EOF - output buffer overflow - version with (Byte *) output - SZ_ERROR_PROGRESS - some break from progress callback - SZ_ERROR_THREAD - error in multithreading functions (only for Mt version) -*/ - -typedef struct CLzma2DecMt CLzma2DecMt; -typedef CLzma2DecMt * CLzma2DecMtHandle; -// Z7_DECLARE_HANDLE(CLzma2DecMtHandle) - -CLzma2DecMtHandle Lzma2DecMt_Create(ISzAllocPtr alloc, ISzAllocPtr allocMid); -void Lzma2DecMt_Destroy(CLzma2DecMtHandle p); - -SRes Lzma2DecMt_Decode(CLzma2DecMtHandle p, - Byte prop, - const CLzma2DecMtProps *props, - ISeqOutStreamPtr outStream, - const UInt64 *outDataSize, // NULL means undefined - int finishMode, // 0 - partial unpacking is allowed, 1 - if lzma2 stream must be finished - // Byte *outBuf, size_t *outBufSize, - ISeqInStreamPtr inStream, - // const Byte *inData, size_t inDataSize, - - // out variables: - UInt64 *inProcessed, - int *isMT, /* out: (*isMT == 0), if single thread decoding was used */ - - // UInt64 *outProcessed, - ICompressProgressPtr progress); - - -/* ---------- Read from CLzma2DecMtHandle Interface ---------- */ - -SRes Lzma2DecMt_Init(CLzma2DecMtHandle pp, - Byte prop, - const CLzma2DecMtProps *props, - const UInt64 *outDataSize, int finishMode, - ISeqInStreamPtr inStream); - -SRes Lzma2DecMt_Read(CLzma2DecMtHandle pp, - Byte *data, size_t *outSize, - UInt64 *inStreamProcessed); - - -EXTERN_C_END - -#endif diff --git a/sources/import/edz/lzma/Lzma2Enc.h b/sources/import/edz/lzma/Lzma2Enc.h deleted file mode 100644 index cb25275c6..000000000 --- a/sources/import/edz/lzma/Lzma2Enc.h +++ /dev/null @@ -1,57 +0,0 @@ -/* Lzma2Enc.h -- LZMA2 Encoder -2023-04-13 : Igor Pavlov : Public domain */ - -#ifndef ZIP7_INC_LZMA2_ENC_H -#define ZIP7_INC_LZMA2_ENC_H - -#include "LzmaEnc.h" - -EXTERN_C_BEGIN - -#define LZMA2_ENC_PROPS_BLOCK_SIZE_AUTO 0 -#define LZMA2_ENC_PROPS_BLOCK_SIZE_SOLID ((UInt64)(Int64)-1) - -typedef struct -{ - CLzmaEncProps lzmaProps; - UInt64 blockSize; - int numBlockThreads_Reduced; - int numBlockThreads_Max; - int numTotalThreads; -} CLzma2EncProps; - -void Lzma2EncProps_Init(CLzma2EncProps *p); -void Lzma2EncProps_Normalize(CLzma2EncProps *p); - -/* ---------- CLzmaEnc2Handle Interface ---------- */ - -/* Lzma2Enc_* functions can return the following exit codes: -SRes: - SZ_OK - OK - SZ_ERROR_MEM - Memory allocation error - SZ_ERROR_PARAM - Incorrect paramater in props - SZ_ERROR_WRITE - ISeqOutStream write callback error - SZ_ERROR_OUTPUT_EOF - output buffer overflow - version with (Byte *) output - SZ_ERROR_PROGRESS - some break from progress callback - SZ_ERROR_THREAD - error in multithreading functions (only for Mt version) -*/ - -typedef struct CLzma2Enc CLzma2Enc; -typedef CLzma2Enc * CLzma2EncHandle; -// Z7_DECLARE_HANDLE(CLzma2EncHandle) - -CLzma2EncHandle Lzma2Enc_Create(ISzAllocPtr alloc, ISzAllocPtr allocBig); -void Lzma2Enc_Destroy(CLzma2EncHandle p); -SRes Lzma2Enc_SetProps(CLzma2EncHandle p, const CLzma2EncProps *props); -void Lzma2Enc_SetDataSize(CLzma2EncHandle p, UInt64 expectedDataSiize); -Byte Lzma2Enc_WriteProperties(CLzma2EncHandle p); -SRes Lzma2Enc_Encode2(CLzma2EncHandle p, - ISeqOutStreamPtr outStream, - Byte *outBuf, size_t *outBufSize, - ISeqInStreamPtr inStream, - const Byte *inData, size_t inDataSize, - ICompressProgressPtr progress); - -EXTERN_C_END - -#endif diff --git a/sources/import/edz/lzma/Lzma86.h b/sources/import/edz/lzma/Lzma86.h deleted file mode 100644 index e7707e2c4..000000000 --- a/sources/import/edz/lzma/Lzma86.h +++ /dev/null @@ -1,111 +0,0 @@ -/* Lzma86.h -- LZMA + x86 (BCJ) Filter -2023-03-03 : Igor Pavlov : Public domain */ - -#ifndef ZIP7_INC_LZMA86_H -#define ZIP7_INC_LZMA86_H - -#include "7zTypes.h" - -EXTERN_C_BEGIN - -#define LZMA86_SIZE_OFFSET (1 + 5) -#define LZMA86_HEADER_SIZE (LZMA86_SIZE_OFFSET + 8) - -/* -It's an example for LZMA + x86 Filter use. -You can use .lzma86 extension, if you write that stream to file. -.lzma86 header adds one additional byte to standard .lzma header. -.lzma86 header (14 bytes): - Offset Size Description - 0 1 = 0 - no filter, pure LZMA - = 1 - x86 filter + LZMA - 1 1 lc, lp and pb in encoded form - 2 4 dictSize (little endian) - 6 8 uncompressed size (little endian) - - -Lzma86_Encode -------------- -level - compression level: 0 <= level <= 9, the default value for "level" is 5. - -dictSize - The dictionary size in bytes. The maximum value is - 128 MB = (1 << 27) bytes for 32-bit version - 1 GB = (1 << 30) bytes for 64-bit version - The default value is 16 MB = (1 << 24) bytes, for level = 5. - It's recommended to use the dictionary that is larger than 4 KB and - that can be calculated as (1 << N) or (3 << N) sizes. - For better compression ratio dictSize must be >= inSize. - -filterMode: - SZ_FILTER_NO - no Filter - SZ_FILTER_YES - x86 Filter - SZ_FILTER_AUTO - it tries both alternatives to select best. - Encoder will use 2 or 3 passes: - 2 passes when FILTER_NO provides better compression. - 3 passes when FILTER_YES provides better compression. - -Lzma86Encode allocates Data with MyAlloc functions. -RAM Requirements for compressing: - RamSize = dictionarySize * 11.5 + 6MB + FilterBlockSize - filterMode FilterBlockSize - SZ_FILTER_NO 0 - SZ_FILTER_YES inSize - SZ_FILTER_AUTO inSize - - -Return code: - SZ_OK - OK - SZ_ERROR_MEM - Memory allocation error - SZ_ERROR_PARAM - Incorrect paramater - SZ_ERROR_OUTPUT_EOF - output buffer overflow - SZ_ERROR_THREAD - errors in multithreading functions (only for Mt version) -*/ - -enum ESzFilterMode -{ - SZ_FILTER_NO, - SZ_FILTER_YES, - SZ_FILTER_AUTO -}; - -SRes Lzma86_Encode(Byte *dest, size_t *destLen, const Byte *src, size_t srcLen, - int level, UInt32 dictSize, int filterMode); - - -/* -Lzma86_GetUnpackSize: - In: - src - input data - srcLen - input data size - Out: - unpackSize - size of uncompressed stream - Return code: - SZ_OK - OK - SZ_ERROR_INPUT_EOF - Error in headers -*/ - -SRes Lzma86_GetUnpackSize(const Byte *src, SizeT srcLen, UInt64 *unpackSize); - -/* -Lzma86_Decode: - In: - dest - output data - destLen - output data size - src - input data - srcLen - input data size - Out: - destLen - processed output size - srcLen - processed input size - Return code: - SZ_OK - OK - SZ_ERROR_DATA - Data error - SZ_ERROR_MEM - Memory allocation error - SZ_ERROR_UNSUPPORTED - unsupported file - SZ_ERROR_INPUT_EOF - it needs more bytes in input buffer -*/ - -SRes Lzma86_Decode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen); - -EXTERN_C_END - -#endif diff --git a/sources/import/edz/lzma/LzmaEnc.h b/sources/import/edz/lzma/LzmaEnc.h deleted file mode 100644 index 9f8039a10..000000000 --- a/sources/import/edz/lzma/LzmaEnc.h +++ /dev/null @@ -1,83 +0,0 @@ -/* LzmaEnc.h -- LZMA Encoder -2023-04-13 : Igor Pavlov : Public domain */ - -#ifndef ZIP7_INC_LZMA_ENC_H -#define ZIP7_INC_LZMA_ENC_H - -#include "7zTypes.h" - -EXTERN_C_BEGIN - -#define LZMA_PROPS_SIZE 5 - -typedef struct -{ - int level; /* 0 <= level <= 9 */ - UInt32 dictSize; /* (1 << 12) <= dictSize <= (1 << 27) for 32-bit version - (1 << 12) <= dictSize <= (3 << 29) for 64-bit version - default = (1 << 24) */ - int lc; /* 0 <= lc <= 8, default = 3 */ - int lp; /* 0 <= lp <= 4, default = 0 */ - int pb; /* 0 <= pb <= 4, default = 2 */ - int algo; /* 0 - fast, 1 - normal, default = 1 */ - int fb; /* 5 <= fb <= 273, default = 32 */ - int btMode; /* 0 - hashChain Mode, 1 - binTree mode - normal, default = 1 */ - int numHashBytes; /* 2, 3 or 4, default = 4 */ - unsigned numHashOutBits; /* default = ? */ - UInt32 mc; /* 1 <= mc <= (1 << 30), default = 32 */ - unsigned writeEndMark; /* 0 - do not write EOPM, 1 - write EOPM, default = 0 */ - int numThreads; /* 1 or 2, default = 2 */ - - // int _pad; - - UInt64 reduceSize; /* estimated size of data that will be compressed. default = (UInt64)(Int64)-1. - Encoder uses this value to reduce dictionary size */ - - UInt64 affinity; -} CLzmaEncProps; - -void LzmaEncProps_Init(CLzmaEncProps *p); -void LzmaEncProps_Normalize(CLzmaEncProps *p); -UInt32 LzmaEncProps_GetDictSize(const CLzmaEncProps *props2); - - -/* ---------- CLzmaEncHandle Interface ---------- */ - -/* LzmaEnc* functions can return the following exit codes: -SRes: - SZ_OK - OK - SZ_ERROR_MEM - Memory allocation error - SZ_ERROR_PARAM - Incorrect paramater in props - SZ_ERROR_WRITE - ISeqOutStream write callback error - SZ_ERROR_OUTPUT_EOF - output buffer overflow - version with (Byte *) output - SZ_ERROR_PROGRESS - some break from progress callback - SZ_ERROR_THREAD - error in multithreading functions (only for Mt version) -*/ - -typedef struct CLzmaEnc CLzmaEnc; -typedef CLzmaEnc * CLzmaEncHandle; -// Z7_DECLARE_HANDLE(CLzmaEncHandle) - -CLzmaEncHandle LzmaEnc_Create(ISzAllocPtr alloc); -void LzmaEnc_Destroy(CLzmaEncHandle p, ISzAllocPtr alloc, ISzAllocPtr allocBig); - -SRes LzmaEnc_SetProps(CLzmaEncHandle p, const CLzmaEncProps *props); -void LzmaEnc_SetDataSize(CLzmaEncHandle p, UInt64 expectedDataSiize); -SRes LzmaEnc_WriteProperties(CLzmaEncHandle p, Byte *properties, SizeT *size); -unsigned LzmaEnc_IsWriteEndMark(CLzmaEncHandle p); - -SRes LzmaEnc_Encode(CLzmaEncHandle p, ISeqOutStreamPtr outStream, ISeqInStreamPtr inStream, - ICompressProgressPtr progress, ISzAllocPtr alloc, ISzAllocPtr allocBig); -SRes LzmaEnc_MemEncode(CLzmaEncHandle p, Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen, - int writeEndMark, ICompressProgressPtr progress, ISzAllocPtr alloc, ISzAllocPtr allocBig); - - -/* ---------- One Call Interface ---------- */ - -SRes LzmaEncode(Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen, - const CLzmaEncProps *props, Byte *propsEncoded, SizeT *propsSize, int writeEndMark, - ICompressProgressPtr progress, ISzAllocPtr alloc, ISzAllocPtr allocBig); - -EXTERN_C_END - -#endif diff --git a/sources/import/edz/lzma/LzmaLib.h b/sources/import/edz/lzma/LzmaLib.h deleted file mode 100644 index d7c0724de..000000000 --- a/sources/import/edz/lzma/LzmaLib.h +++ /dev/null @@ -1,138 +0,0 @@ -/* LzmaLib.h -- LZMA library interface -2023-04-02 : Igor Pavlov : Public domain */ - -#ifndef ZIP7_INC_LZMA_LIB_H -#define ZIP7_INC_LZMA_LIB_H - -#include "7zTypes.h" - -EXTERN_C_BEGIN - -#define Z7_STDAPI int Z7_STDCALL - -#define LZMA_PROPS_SIZE 5 - -/* -RAM requirements for LZMA: - for compression: (dictSize * 11.5 + 6 MB) + state_size - for decompression: dictSize + state_size - state_size = (4 + (1.5 << (lc + lp))) KB - by default (lc=3, lp=0), state_size = 16 KB. - -LZMA properties (5 bytes) format - Offset Size Description - 0 1 lc, lp and pb in encoded form. - 1 4 dictSize (little endian). -*/ - -/* -LzmaCompress ------------- - -outPropsSize - - In: the pointer to the size of outProps buffer; *outPropsSize = LZMA_PROPS_SIZE = 5. - Out: the pointer to the size of written properties in outProps buffer; *outPropsSize = LZMA_PROPS_SIZE = 5. - - LZMA Encoder will use defult values for any parameter, if it is - -1 for any from: level, loc, lp, pb, fb, numThreads - 0 for dictSize - -level - compression level: 0 <= level <= 9; - - level dictSize algo fb - 0: 64 KB 0 32 - 1: 256 KB 0 32 - 2: 1 MB 0 32 - 3: 4 MB 0 32 - 4: 16 MB 0 32 - 5: 16 MB 1 32 - 6: 32 MB 1 32 - 7: 32 MB 1 64 - 8: 64 MB 1 64 - 9: 64 MB 1 64 - - The default value for "level" is 5. - - algo = 0 means fast method - algo = 1 means normal method - -dictSize - The dictionary size in bytes. The maximum value is - 128 MB = (1 << 27) bytes for 32-bit version - 1 GB = (1 << 30) bytes for 64-bit version - The default value is 16 MB = (1 << 24) bytes. - It's recommended to use the dictionary that is larger than 4 KB and - that can be calculated as (1 << N) or (3 << N) sizes. - -lc - The number of literal context bits (high bits of previous literal). - It can be in the range from 0 to 8. The default value is 3. - Sometimes lc=4 gives the gain for big files. - -lp - The number of literal pos bits (low bits of current position for literals). - It can be in the range from 0 to 4. The default value is 0. - The lp switch is intended for periodical data when the period is equal to 2^lp. - For example, for 32-bit (4 bytes) periodical data you can use lp=2. Often it's - better to set lc=0, if you change lp switch. - -pb - The number of pos bits (low bits of current position). - It can be in the range from 0 to 4. The default value is 2. - The pb switch is intended for periodical data when the period is equal 2^pb. - -fb - Word size (the number of fast bytes). - It can be in the range from 5 to 273. The default value is 32. - Usually, a big number gives a little bit better compression ratio and - slower compression process. - -numThreads - The number of thereads. 1 or 2. The default value is 2. - Fast mode (algo = 0) can use only 1 thread. - -In: - dest - output data buffer - destLen - output data buffer size - src - input data - srcLen - input data size -Out: - destLen - processed output size -Returns: - SZ_OK - OK - SZ_ERROR_MEM - Memory allocation error - SZ_ERROR_PARAM - Incorrect paramater - SZ_ERROR_OUTPUT_EOF - output buffer overflow - SZ_ERROR_THREAD - errors in multithreading functions (only for Mt version) -*/ - -Z7_STDAPI LzmaCompress(unsigned char *dest, size_t *destLen, const unsigned char *src, size_t srcLen, - unsigned char *outProps, size_t *outPropsSize, /* *outPropsSize must be = 5 */ - int level, /* 0 <= level <= 9, default = 5 */ - unsigned dictSize, /* default = (1 << 24) */ - int lc, /* 0 <= lc <= 8, default = 3 */ - int lp, /* 0 <= lp <= 4, default = 0 */ - int pb, /* 0 <= pb <= 4, default = 2 */ - int fb, /* 5 <= fb <= 273, default = 32 */ - int numThreads /* 1 or 2, default = 2 */ - ); - -/* -LzmaUncompress --------------- -In: - dest - output data buffer - destLen - output data buffer size - src - input data - srcLen - input data size -Out: - destLen - processed output size - srcLen - processed input size -Returns: - SZ_OK - OK - SZ_ERROR_DATA - Data error - SZ_ERROR_MEM - Memory allocation arror - SZ_ERROR_UNSUPPORTED - Unsupported properties - SZ_ERROR_INPUT_EOF - it needs more bytes in input buffer (src) -*/ - -Z7_STDAPI LzmaUncompress(unsigned char *dest, size_t *destLen, const unsigned char *src, SizeT *srcLen, - const unsigned char *props, size_t propsSize); - -EXTERN_C_END - -#endif diff --git a/sources/import/edz/lzma/MtCoder.h b/sources/import/edz/lzma/MtCoder.h deleted file mode 100644 index 1231d3c2a..000000000 --- a/sources/import/edz/lzma/MtCoder.h +++ /dev/null @@ -1,141 +0,0 @@ -/* MtCoder.h -- Multi-thread Coder -2023-04-13 : Igor Pavlov : Public domain */ - -#ifndef ZIP7_INC_MT_CODER_H -#define ZIP7_INC_MT_CODER_H - -#include "MtDec.h" - -EXTERN_C_BEGIN - -/* - if ( defined MTCODER_USE_WRITE_THREAD) : main thread writes all data blocks to output stream - if (not defined MTCODER_USE_WRITE_THREAD) : any coder thread can write data blocks to output stream -*/ -/* #define MTCODER_USE_WRITE_THREAD */ - -#ifndef Z7_ST - #define MTCODER_GET_NUM_BLOCKS_FROM_THREADS(numThreads) ((numThreads) + (numThreads) / 8 + 1) - #define MTCODER_THREADS_MAX 64 - #define MTCODER_BLOCKS_MAX (MTCODER_GET_NUM_BLOCKS_FROM_THREADS(MTCODER_THREADS_MAX) + 3) -#else - #define MTCODER_THREADS_MAX 1 - #define MTCODER_BLOCKS_MAX 1 -#endif - - -#ifndef Z7_ST - - -typedef struct -{ - ICompressProgress vt; - CMtProgress *mtProgress; - UInt64 inSize; - UInt64 outSize; -} CMtProgressThunk; - -void MtProgressThunk_CreateVTable(CMtProgressThunk *p); - -#define MtProgressThunk_INIT(p) { (p)->inSize = 0; (p)->outSize = 0; } - - -struct CMtCoder_; - - -typedef struct -{ - struct CMtCoder_ *mtCoder; - unsigned index; - int stop; - Byte *inBuf; - - CAutoResetEvent startEvent; - CThread thread; -} CMtCoderThread; - - -typedef struct -{ - SRes (*Code)(void *p, unsigned coderIndex, unsigned outBufIndex, - const Byte *src, size_t srcSize, int finished); - SRes (*Write)(void *p, unsigned outBufIndex); -} IMtCoderCallback2; - - -typedef struct -{ - SRes res; - unsigned bufIndex; - BoolInt finished; -} CMtCoderBlock; - - -typedef struct CMtCoder_ -{ - /* input variables */ - - size_t blockSize; /* size of input block */ - unsigned numThreadsMax; - UInt64 expectedDataSize; - - ISeqInStreamPtr inStream; - const Byte *inData; - size_t inDataSize; - - ICompressProgressPtr progress; - ISzAllocPtr allocBig; - - IMtCoderCallback2 *mtCallback; - void *mtCallbackObject; - - - /* internal variables */ - - size_t allocatedBufsSize; - - CAutoResetEvent readEvent; - CSemaphore blocksSemaphore; - - BoolInt stopReading; - SRes readRes; - - #ifdef MTCODER_USE_WRITE_THREAD - CAutoResetEvent writeEvents[MTCODER_BLOCKS_MAX]; - #else - CAutoResetEvent finishedEvent; - SRes writeRes; - unsigned writeIndex; - Byte ReadyBlocks[MTCODER_BLOCKS_MAX]; - LONG numFinishedThreads; - #endif - - unsigned numStartedThreadsLimit; - unsigned numStartedThreads; - - unsigned numBlocksMax; - unsigned blockIndex; - UInt64 readProcessed; - - CCriticalSection cs; - - unsigned freeBlockHead; - unsigned freeBlockList[MTCODER_BLOCKS_MAX]; - - CMtProgress mtProgress; - CMtCoderBlock blocks[MTCODER_BLOCKS_MAX]; - CMtCoderThread threads[MTCODER_THREADS_MAX]; -} CMtCoder; - - -void MtCoder_Construct(CMtCoder *p); -void MtCoder_Destruct(CMtCoder *p); -SRes MtCoder_Code(CMtCoder *p); - - -#endif - - -EXTERN_C_END - -#endif diff --git a/sources/import/edz/lzma/MtDec.h b/sources/import/edz/lzma/MtDec.h deleted file mode 100644 index c28e8d9ac..000000000 --- a/sources/import/edz/lzma/MtDec.h +++ /dev/null @@ -1,202 +0,0 @@ -/* MtDec.h -- Multi-thread Decoder -2023-04-02 : Igor Pavlov : Public domain */ - -#ifndef ZIP7_INC_MT_DEC_H -#define ZIP7_INC_MT_DEC_H - -#include "7zTypes.h" - -#ifndef Z7_ST -#include "Threads.h" -#endif - -EXTERN_C_BEGIN - -#ifndef Z7_ST - -#ifndef Z7_ST - #define MTDEC_THREADS_MAX 32 -#else - #define MTDEC_THREADS_MAX 1 -#endif - - -typedef struct -{ - ICompressProgressPtr progress; - SRes res; - UInt64 totalInSize; - UInt64 totalOutSize; - CCriticalSection cs; -} CMtProgress; - -void MtProgress_Init(CMtProgress *p, ICompressProgressPtr progress); -SRes MtProgress_Progress_ST(CMtProgress *p); -SRes MtProgress_ProgressAdd(CMtProgress *p, UInt64 inSize, UInt64 outSize); -SRes MtProgress_GetError(CMtProgress *p); -void MtProgress_SetError(CMtProgress *p, SRes res); - -struct CMtDec; - -typedef struct -{ - struct CMtDec_ *mtDec; - unsigned index; - void *inBuf; - - size_t inDataSize_Start; // size of input data in start block - UInt64 inDataSize; // total size of input data in all blocks - - CThread thread; - CAutoResetEvent canRead; - CAutoResetEvent canWrite; - void *allocaPtr; -} CMtDecThread; - -void MtDecThread_FreeInBufs(CMtDecThread *t); - - -typedef enum -{ - MTDEC_PARSE_CONTINUE, // continue this block with more input data - MTDEC_PARSE_OVERFLOW, // MT buffers overflow, need switch to single-thread - MTDEC_PARSE_NEW, // new block - MTDEC_PARSE_END // end of block threading. But we still can return to threading after Write(&needContinue) -} EMtDecParseState; - -typedef struct -{ - // in - int startCall; - const Byte *src; - size_t srcSize; - // in : (srcSize == 0) is allowed - // out : it's allowed to return less that actually was used ? - int srcFinished; - - // out - EMtDecParseState state; - BoolInt canCreateNewThread; - UInt64 outPos; // check it (size_t) -} CMtDecCallbackInfo; - - -typedef struct -{ - void (*Parse)(void *p, unsigned coderIndex, CMtDecCallbackInfo *ci); - - // PreCode() and Code(): - // (SRes_return_result != SZ_OK) means stop decoding, no need another blocks - SRes (*PreCode)(void *p, unsigned coderIndex); - SRes (*Code)(void *p, unsigned coderIndex, - const Byte *src, size_t srcSize, int srcFinished, - UInt64 *inCodePos, UInt64 *outCodePos, int *stop); - // stop - means stop another Code calls - - - /* Write() must be called, if Parse() was called - set (needWrite) if - { - && (was not interrupted by progress) - && (was not interrupted in previous block) - } - - out: - if (*needContinue), decoder still need to continue decoding with new iteration, - even after MTDEC_PARSE_END - if (*canRecode), we didn't flush current block data, so we still can decode current block later. - */ - SRes (*Write)(void *p, unsigned coderIndex, - BoolInt needWriteToStream, - const Byte *src, size_t srcSize, BoolInt isCross, - // int srcFinished, - BoolInt *needContinue, - BoolInt *canRecode); - -} IMtDecCallback2; - - - -typedef struct CMtDec_ -{ - /* input variables */ - - size_t inBufSize; /* size of input block */ - unsigned numThreadsMax; - // size_t inBlockMax; - unsigned numThreadsMax_2; - - ISeqInStreamPtr inStream; - // const Byte *inData; - // size_t inDataSize; - - ICompressProgressPtr progress; - ISzAllocPtr alloc; - - IMtDecCallback2 *mtCallback; - void *mtCallbackObject; - - - /* internal variables */ - - size_t allocatedBufsSize; - - BoolInt exitThread; - WRes exitThreadWRes; - - UInt64 blockIndex; - BoolInt isAllocError; - BoolInt overflow; - SRes threadingErrorSRes; - - BoolInt needContinue; - - // CAutoResetEvent finishedEvent; - - SRes readRes; - SRes codeRes; - - BoolInt wasInterrupted; - - unsigned numStartedThreads_Limit; - unsigned numStartedThreads; - - Byte *crossBlock; - size_t crossStart; - size_t crossEnd; - UInt64 readProcessed; - BoolInt readWasFinished; - UInt64 inProcessed; - - unsigned filledThreadStart; - unsigned numFilledThreads; - - #ifndef Z7_ST - BoolInt needInterrupt; - UInt64 interruptIndex; - CMtProgress mtProgress; - CMtDecThread threads[MTDEC_THREADS_MAX]; - #endif -} CMtDec; - - -void MtDec_Construct(CMtDec *p); -void MtDec_Destruct(CMtDec *p); - -/* -MtDec_Code() returns: - SZ_OK - in most cases - MY_SRes_HRESULT_FROM_WRes(WRes_error) - in case of unexpected error in threading function -*/ - -SRes MtDec_Code(CMtDec *p); -Byte *MtDec_GetCrossBuff(CMtDec *p); - -int MtDec_PrepareRead(CMtDec *p); -const Byte *MtDec_Read(CMtDec *p, size_t *inLim); - -#endif - -EXTERN_C_END - -#endif diff --git a/sources/import/edz/lzma/Sha256.h b/sources/import/edz/lzma/Sha256.h deleted file mode 100644 index 9e0422320..000000000 --- a/sources/import/edz/lzma/Sha256.h +++ /dev/null @@ -1,76 +0,0 @@ -/* Sha256.h -- SHA-256 Hash -2023-04-02 : Igor Pavlov : Public domain */ - -#ifndef ZIP7_INC_SHA256_H -#define ZIP7_INC_SHA256_H - -#include "7zTypes.h" - -EXTERN_C_BEGIN - -#define SHA256_NUM_BLOCK_WORDS 16 -#define SHA256_NUM_DIGEST_WORDS 8 - -#define SHA256_BLOCK_SIZE (SHA256_NUM_BLOCK_WORDS * 4) -#define SHA256_DIGEST_SIZE (SHA256_NUM_DIGEST_WORDS * 4) - -typedef void (Z7_FASTCALL *SHA256_FUNC_UPDATE_BLOCKS)(UInt32 state[8], const Byte *data, size_t numBlocks); - -/* - if (the system supports different SHA256 code implementations) - { - (CSha256::func_UpdateBlocks) will be used - (CSha256::func_UpdateBlocks) can be set by - Sha256_Init() - to default (fastest) - Sha256_SetFunction() - to any algo - } - else - { - (CSha256::func_UpdateBlocks) is ignored. - } -*/ - -typedef struct -{ - SHA256_FUNC_UPDATE_BLOCKS func_UpdateBlocks; - UInt64 count; - UInt64 _pad_2[2]; - UInt32 state[SHA256_NUM_DIGEST_WORDS]; - - Byte buffer[SHA256_BLOCK_SIZE]; -} CSha256; - - -#define SHA256_ALGO_DEFAULT 0 -#define SHA256_ALGO_SW 1 -#define SHA256_ALGO_HW 2 - -/* -Sha256_SetFunction() -return: - 0 - (algo) value is not supported, and func_UpdateBlocks was not changed - 1 - func_UpdateBlocks was set according (algo) value. -*/ - -BoolInt Sha256_SetFunction(CSha256 *p, unsigned algo); - -void Sha256_InitState(CSha256 *p); -void Sha256_Init(CSha256 *p); -void Sha256_Update(CSha256 *p, const Byte *data, size_t size); -void Sha256_Final(CSha256 *p, Byte *digest); - - - - -// void Z7_FASTCALL Sha256_UpdateBlocks(UInt32 state[8], const Byte *data, size_t numBlocks); - -/* -call Sha256Prepare() once at program start. -It prepares all supported implementations, and detects the fastest implementation. -*/ - -void Sha256Prepare(void); - -EXTERN_C_END - -#endif diff --git a/sources/import/edz/lzma/Sort.h b/sources/import/edz/lzma/Sort.h deleted file mode 100644 index 1817b652f..000000000 --- a/sources/import/edz/lzma/Sort.h +++ /dev/null @@ -1,18 +0,0 @@ -/* Sort.h -- Sort functions -2023-03-05 : Igor Pavlov : Public domain */ - -#ifndef ZIP7_INC_SORT_H -#define ZIP7_INC_SORT_H - -#include "7zTypes.h" - -EXTERN_C_BEGIN - -void HeapSort(UInt32 *p, size_t size); -void HeapSort64(UInt64 *p, size_t size); - -/* void HeapSortRef(UInt32 *p, UInt32 *vals, size_t size); */ - -EXTERN_C_END - -#endif diff --git a/sources/import/edz/lzma/SwapBytes.h b/sources/import/edz/lzma/SwapBytes.h deleted file mode 100644 index d44246738..000000000 --- a/sources/import/edz/lzma/SwapBytes.h +++ /dev/null @@ -1,17 +0,0 @@ -/* SwapBytes.h -- Byte Swap conversion filter -2023-04-02 : Igor Pavlov : Public domain */ - -#ifndef ZIP7_INC_SWAP_BYTES_H -#define ZIP7_INC_SWAP_BYTES_H - -#include "7zTypes.h" - -EXTERN_C_BEGIN - -void z7_SwapBytes2(UInt16 *data, size_t numItems); -void z7_SwapBytes4(UInt32 *data, size_t numItems); -void z7_SwapBytesPrepare(void); - -EXTERN_C_END - -#endif diff --git a/sources/import/edz/lzma/Threads.h b/sources/import/edz/lzma/Threads.h deleted file mode 100644 index 4028464a3..000000000 --- a/sources/import/edz/lzma/Threads.h +++ /dev/null @@ -1,240 +0,0 @@ -/* Threads.h -- multithreading library -2023-04-02 : Igor Pavlov : Public domain */ - -#ifndef ZIP7_INC_THREADS_H -#define ZIP7_INC_THREADS_H - -#ifdef _WIN32 -#include "7zWindows.h" - -#else - -#if defined(__linux__) -#if !defined(__APPLE__) && !defined(_AIX) && !defined(__ANDROID__) -#ifndef Z7_AFFINITY_DISABLE -#define Z7_AFFINITY_SUPPORTED -// #pragma message(" ==== Z7_AFFINITY_SUPPORTED") -// #define _GNU_SOURCE -#endif -#endif -#endif - -#include - -#endif - -#include "7zTypes.h" - -EXTERN_C_BEGIN - -#ifdef _WIN32 - -WRes HandlePtr_Close(HANDLE *h); -WRes Handle_WaitObject(HANDLE h); - -typedef HANDLE CThread; - -#define Thread_CONSTRUCT(p) { *(p) = NULL; } -#define Thread_WasCreated(p) (*(p) != NULL) -#define Thread_Close(p) HandlePtr_Close(p) -// #define Thread_Wait(p) Handle_WaitObject(*(p)) - -#ifdef UNDER_CE - // if (USE_THREADS_CreateThread is defined), we use _beginthreadex() - // if (USE_THREADS_CreateThread is not definned), we use CreateThread() - #define USE_THREADS_CreateThread -#endif - -typedef - #ifdef USE_THREADS_CreateThread - DWORD - #else - unsigned - #endif - THREAD_FUNC_RET_TYPE; - -#define THREAD_FUNC_RET_ZERO 0 - -typedef DWORD_PTR CAffinityMask; -typedef DWORD_PTR CCpuSet; - -#define CpuSet_Zero(p) *(p) = (0) -#define CpuSet_Set(p, cpu) *(p) |= ((DWORD_PTR)1 << (cpu)) - -#else // _WIN32 - -typedef struct -{ - pthread_t _tid; - int _created; -} CThread; - -#define Thread_CONSTRUCT(p) { (p)->_tid = 0; (p)->_created = 0; } -#define Thread_WasCreated(p) ((p)->_created != 0) -WRes Thread_Close(CThread *p); -// #define Thread_Wait Thread_Wait_Close - -typedef void * THREAD_FUNC_RET_TYPE; -#define THREAD_FUNC_RET_ZERO NULL - - -typedef UInt64 CAffinityMask; - -#ifdef Z7_AFFINITY_SUPPORTED - -typedef cpu_set_t CCpuSet; -#define CpuSet_Zero(p) CPU_ZERO(p) -#define CpuSet_Set(p, cpu) CPU_SET(cpu, p) -#define CpuSet_IsSet(p, cpu) CPU_ISSET(cpu, p) - -#else - -typedef UInt64 CCpuSet; -#define CpuSet_Zero(p) *(p) = (0) -#define CpuSet_Set(p, cpu) *(p) |= ((UInt64)1 << (cpu)) -#define CpuSet_IsSet(p, cpu) ((*(p) & ((UInt64)1 << (cpu))) != 0) - -#endif - - -#endif // _WIN32 - - -#define THREAD_FUNC_CALL_TYPE Z7_STDCALL - -#if defined(_WIN32) && defined(__GNUC__) -/* GCC compiler for x86 32-bit uses the rule: - the stack is 16-byte aligned before CALL instruction for function calling. - But only root function main() contains instructions that - set 16-byte alignment for stack pointer. And another functions - just keep alignment, if it was set in some parent function. - - The problem: - if we create new thread in MinGW (GCC) 32-bit x86 via _beginthreadex() or CreateThread(), - the root function of thread doesn't set 16-byte alignment. - And stack frames in all child functions also will be unaligned in that case. - - Here we set (force_align_arg_pointer) attribute for root function of new thread. - Do we need (force_align_arg_pointer) also for another systems? */ - - #define THREAD_FUNC_ATTRIB_ALIGN_ARG __attribute__((force_align_arg_pointer)) - // #define THREAD_FUNC_ATTRIB_ALIGN_ARG // for debug : bad alignment in SSE functions -#else - #define THREAD_FUNC_ATTRIB_ALIGN_ARG -#endif - -#define THREAD_FUNC_DECL THREAD_FUNC_ATTRIB_ALIGN_ARG THREAD_FUNC_RET_TYPE THREAD_FUNC_CALL_TYPE - -typedef THREAD_FUNC_RET_TYPE (THREAD_FUNC_CALL_TYPE * THREAD_FUNC_TYPE)(void *); -WRes Thread_Create(CThread *p, THREAD_FUNC_TYPE func, LPVOID param); -WRes Thread_Create_With_Affinity(CThread *p, THREAD_FUNC_TYPE func, LPVOID param, CAffinityMask affinity); -WRes Thread_Wait_Close(CThread *p); - -#ifdef _WIN32 -#define Thread_Create_With_CpuSet(p, func, param, cs) \ - Thread_Create_With_Affinity(p, func, param, *cs) -#else -WRes Thread_Create_With_CpuSet(CThread *p, THREAD_FUNC_TYPE func, LPVOID param, const CCpuSet *cpuSet); -#endif - - -#ifdef _WIN32 - -typedef HANDLE CEvent; -typedef CEvent CAutoResetEvent; -typedef CEvent CManualResetEvent; -#define Event_Construct(p) *(p) = NULL -#define Event_IsCreated(p) (*(p) != NULL) -#define Event_Close(p) HandlePtr_Close(p) -#define Event_Wait(p) Handle_WaitObject(*(p)) -WRes Event_Set(CEvent *p); -WRes Event_Reset(CEvent *p); -WRes ManualResetEvent_Create(CManualResetEvent *p, int signaled); -WRes ManualResetEvent_CreateNotSignaled(CManualResetEvent *p); -WRes AutoResetEvent_Create(CAutoResetEvent *p, int signaled); -WRes AutoResetEvent_CreateNotSignaled(CAutoResetEvent *p); - -typedef HANDLE CSemaphore; -#define Semaphore_Construct(p) *(p) = NULL -#define Semaphore_IsCreated(p) (*(p) != NULL) -#define Semaphore_Close(p) HandlePtr_Close(p) -#define Semaphore_Wait(p) Handle_WaitObject(*(p)) -WRes Semaphore_Create(CSemaphore *p, UInt32 initCount, UInt32 maxCount); -WRes Semaphore_OptCreateInit(CSemaphore *p, UInt32 initCount, UInt32 maxCount); -WRes Semaphore_ReleaseN(CSemaphore *p, UInt32 num); -WRes Semaphore_Release1(CSemaphore *p); - -typedef CRITICAL_SECTION CCriticalSection; -WRes CriticalSection_Init(CCriticalSection *p); -#define CriticalSection_Delete(p) DeleteCriticalSection(p) -#define CriticalSection_Enter(p) EnterCriticalSection(p) -#define CriticalSection_Leave(p) LeaveCriticalSection(p) - - -#else // _WIN32 - -typedef struct _CEvent -{ - int _created; - int _manual_reset; - int _state; - pthread_mutex_t _mutex; - pthread_cond_t _cond; -} CEvent; - -typedef CEvent CAutoResetEvent; -typedef CEvent CManualResetEvent; - -#define Event_Construct(p) (p)->_created = 0 -#define Event_IsCreated(p) ((p)->_created) - -WRes ManualResetEvent_Create(CManualResetEvent *p, int signaled); -WRes ManualResetEvent_CreateNotSignaled(CManualResetEvent *p); -WRes AutoResetEvent_Create(CAutoResetEvent *p, int signaled); -WRes AutoResetEvent_CreateNotSignaled(CAutoResetEvent *p); - -WRes Event_Set(CEvent *p); -WRes Event_Reset(CEvent *p); -WRes Event_Wait(CEvent *p); -WRes Event_Close(CEvent *p); - - -typedef struct _CSemaphore -{ - int _created; - UInt32 _count; - UInt32 _maxCount; - pthread_mutex_t _mutex; - pthread_cond_t _cond; -} CSemaphore; - -#define Semaphore_Construct(p) (p)->_created = 0 -#define Semaphore_IsCreated(p) ((p)->_created) - -WRes Semaphore_Create(CSemaphore *p, UInt32 initCount, UInt32 maxCount); -WRes Semaphore_OptCreateInit(CSemaphore *p, UInt32 initCount, UInt32 maxCount); -WRes Semaphore_ReleaseN(CSemaphore *p, UInt32 num); -#define Semaphore_Release1(p) Semaphore_ReleaseN(p, 1) -WRes Semaphore_Wait(CSemaphore *p); -WRes Semaphore_Close(CSemaphore *p); - - -typedef struct _CCriticalSection -{ - pthread_mutex_t _mutex; -} CCriticalSection; - -WRes CriticalSection_Init(CCriticalSection *p); -void CriticalSection_Delete(CCriticalSection *cs); -void CriticalSection_Enter(CCriticalSection *cs); -void CriticalSection_Leave(CCriticalSection *cs); - -LONG InterlockedIncrement(LONG volatile *addend); - -#endif // _WIN32 - -WRes AutoResetEvent_OptCreate_And_Reset(CAutoResetEvent *p); - -EXTERN_C_END - -#endif diff --git a/sources/import/edz/lzma/Xz.h b/sources/import/edz/lzma/Xz.h deleted file mode 100644 index d5001f6ca..000000000 --- a/sources/import/edz/lzma/Xz.h +++ /dev/null @@ -1,535 +0,0 @@ -/* Xz.h - Xz interface -2023-04-13 : Igor Pavlov : Public domain */ - -#ifndef ZIP7_INC_XZ_H -#define ZIP7_INC_XZ_H - -#include "Sha256.h" -#include "Delta.h" - -EXTERN_C_BEGIN - -#define XZ_ID_Subblock 1 -#define XZ_ID_Delta 3 -#define XZ_ID_X86 4 -#define XZ_ID_PPC 5 -#define XZ_ID_IA64 6 -#define XZ_ID_ARM 7 -#define XZ_ID_ARMT 8 -#define XZ_ID_SPARC 9 -#define XZ_ID_ARM64 0xa -#define XZ_ID_LZMA2 0x21 - -unsigned Xz_ReadVarInt(const Byte *p, size_t maxSize, UInt64 *value); -unsigned Xz_WriteVarInt(Byte *buf, UInt64 v); - -/* ---------- xz block ---------- */ - -#define XZ_BLOCK_HEADER_SIZE_MAX 1024 - -#define XZ_NUM_FILTERS_MAX 4 -#define XZ_BF_NUM_FILTERS_MASK 3 -#define XZ_BF_PACK_SIZE (1 << 6) -#define XZ_BF_UNPACK_SIZE (1 << 7) - -#define XZ_FILTER_PROPS_SIZE_MAX 20 - -typedef struct -{ - UInt64 id; - UInt32 propsSize; - Byte props[XZ_FILTER_PROPS_SIZE_MAX]; -} CXzFilter; - -typedef struct -{ - UInt64 packSize; - UInt64 unpackSize; - Byte flags; - CXzFilter filters[XZ_NUM_FILTERS_MAX]; -} CXzBlock; - -#define XzBlock_GetNumFilters(p) (((unsigned)(p)->flags & XZ_BF_NUM_FILTERS_MASK) + 1) -#define XzBlock_HasPackSize(p) (((p)->flags & XZ_BF_PACK_SIZE) != 0) -#define XzBlock_HasUnpackSize(p) (((p)->flags & XZ_BF_UNPACK_SIZE) != 0) -#define XzBlock_HasUnsupportedFlags(p) (((p)->flags & ~(XZ_BF_NUM_FILTERS_MASK | XZ_BF_PACK_SIZE | XZ_BF_UNPACK_SIZE)) != 0) - -SRes XzBlock_Parse(CXzBlock *p, const Byte *header); -SRes XzBlock_ReadHeader(CXzBlock *p, ISeqInStreamPtr inStream, BoolInt *isIndex, UInt32 *headerSizeRes); - -/* ---------- xz stream ---------- */ - -#define XZ_SIG_SIZE 6 -#define XZ_FOOTER_SIG_SIZE 2 - -extern const Byte XZ_SIG[XZ_SIG_SIZE]; - -/* -extern const Byte XZ_FOOTER_SIG[XZ_FOOTER_SIG_SIZE]; -*/ - -#define XZ_FOOTER_SIG_0 'Y' -#define XZ_FOOTER_SIG_1 'Z' - -#define XZ_STREAM_FLAGS_SIZE 2 -#define XZ_STREAM_CRC_SIZE 4 - -#define XZ_STREAM_HEADER_SIZE (XZ_SIG_SIZE + XZ_STREAM_FLAGS_SIZE + XZ_STREAM_CRC_SIZE) -#define XZ_STREAM_FOOTER_SIZE (XZ_FOOTER_SIG_SIZE + XZ_STREAM_FLAGS_SIZE + XZ_STREAM_CRC_SIZE + 4) - -#define XZ_CHECK_MASK 0xF -#define XZ_CHECK_NO 0 -#define XZ_CHECK_CRC32 1 -#define XZ_CHECK_CRC64 4 -#define XZ_CHECK_SHA256 10 - -typedef struct -{ - unsigned mode; - UInt32 crc; - UInt64 crc64; - CSha256 sha; -} CXzCheck; - -void XzCheck_Init(CXzCheck *p, unsigned mode); -void XzCheck_Update(CXzCheck *p, const void *data, size_t size); -int XzCheck_Final(CXzCheck *p, Byte *digest); - -typedef UInt16 CXzStreamFlags; - -#define XzFlags_IsSupported(f) ((f) <= XZ_CHECK_MASK) -#define XzFlags_GetCheckType(f) ((f) & XZ_CHECK_MASK) -#define XzFlags_HasDataCrc32(f) (Xz_GetCheckType(f) == XZ_CHECK_CRC32) -unsigned XzFlags_GetCheckSize(CXzStreamFlags f); - -SRes Xz_ParseHeader(CXzStreamFlags *p, const Byte *buf); -SRes Xz_ReadHeader(CXzStreamFlags *p, ISeqInStreamPtr inStream); - -typedef struct -{ - UInt64 unpackSize; - UInt64 totalSize; -} CXzBlockSizes; - -typedef struct -{ - CXzStreamFlags flags; - // Byte _pad[6]; - size_t numBlocks; - CXzBlockSizes *blocks; - UInt64 startOffset; -} CXzStream; - -void Xz_Construct(CXzStream *p); -void Xz_Free(CXzStream *p, ISzAllocPtr alloc); - -#define XZ_SIZE_OVERFLOW ((UInt64)(Int64)-1) - -UInt64 Xz_GetUnpackSize(const CXzStream *p); -UInt64 Xz_GetPackSize(const CXzStream *p); - -typedef struct -{ - size_t num; - size_t numAllocated; - CXzStream *streams; -} CXzs; - -void Xzs_Construct(CXzs *p); -void Xzs_Free(CXzs *p, ISzAllocPtr alloc); -SRes Xzs_ReadBackward(CXzs *p, ILookInStreamPtr inStream, Int64 *startOffset, ICompressProgressPtr progress, ISzAllocPtr alloc); - -UInt64 Xzs_GetNumBlocks(const CXzs *p); -UInt64 Xzs_GetUnpackSize(const CXzs *p); - - -// ECoderStatus values are identical to ELzmaStatus values of LZMA2 decoder - -typedef enum -{ - CODER_STATUS_NOT_SPECIFIED, /* use main error code instead */ - CODER_STATUS_FINISHED_WITH_MARK, /* stream was finished with end mark. */ - CODER_STATUS_NOT_FINISHED, /* stream was not finished */ - CODER_STATUS_NEEDS_MORE_INPUT /* you must provide more input bytes */ -} ECoderStatus; - - -// ECoderFinishMode values are identical to ELzmaFinishMode - -typedef enum -{ - CODER_FINISH_ANY, /* finish at any point */ - CODER_FINISH_END /* block must be finished at the end */ -} ECoderFinishMode; - - -typedef struct -{ - void *p; // state object; - void (*Free)(void *p, ISzAllocPtr alloc); - SRes (*SetProps)(void *p, const Byte *props, size_t propSize, ISzAllocPtr alloc); - void (*Init)(void *p); - SRes (*Code2)(void *p, Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen, - int srcWasFinished, ECoderFinishMode finishMode, - // int *wasFinished, - ECoderStatus *status); - SizeT (*Filter)(void *p, Byte *data, SizeT size); -} IStateCoder; - - -typedef struct -{ - UInt32 methodId; - UInt32 delta; - UInt32 ip; - UInt32 X86_State; - Byte delta_State[DELTA_STATE_SIZE]; -} CXzBcFilterStateBase; - -typedef SizeT (*Xz_Func_BcFilterStateBase_Filter)(CXzBcFilterStateBase *p, Byte *data, SizeT size); - -SRes Xz_StateCoder_Bc_SetFromMethod_Func(IStateCoder *p, UInt64 id, - Xz_Func_BcFilterStateBase_Filter func, ISzAllocPtr alloc); - - -#define MIXCODER_NUM_FILTERS_MAX 4 - -typedef struct -{ - ISzAllocPtr alloc; - Byte *buf; - unsigned numCoders; - - Byte *outBuf; - size_t outBufSize; - size_t outWritten; // is equal to lzmaDecoder.dicPos (in outBuf mode) - BoolInt wasFinished; - SRes res; - ECoderStatus status; - // BoolInt SingleBufMode; - - int finished[MIXCODER_NUM_FILTERS_MAX - 1]; - size_t pos[MIXCODER_NUM_FILTERS_MAX - 1]; - size_t size[MIXCODER_NUM_FILTERS_MAX - 1]; - UInt64 ids[MIXCODER_NUM_FILTERS_MAX]; - SRes results[MIXCODER_NUM_FILTERS_MAX]; - IStateCoder coders[MIXCODER_NUM_FILTERS_MAX]; -} CMixCoder; - - -typedef enum -{ - XZ_STATE_STREAM_HEADER, - XZ_STATE_STREAM_INDEX, - XZ_STATE_STREAM_INDEX_CRC, - XZ_STATE_STREAM_FOOTER, - XZ_STATE_STREAM_PADDING, - XZ_STATE_BLOCK_HEADER, - XZ_STATE_BLOCK, - XZ_STATE_BLOCK_FOOTER -} EXzState; - - -typedef struct -{ - EXzState state; - UInt32 pos; - unsigned alignPos; - unsigned indexPreSize; - - CXzStreamFlags streamFlags; - - UInt32 blockHeaderSize; - UInt64 packSize; - UInt64 unpackSize; - - UInt64 numBlocks; // number of finished blocks in current stream - UInt64 indexSize; - UInt64 indexPos; - UInt64 padSize; - - UInt64 numStartedStreams; - UInt64 numFinishedStreams; - UInt64 numTotalBlocks; - - UInt32 crc; - CMixCoder decoder; - CXzBlock block; - CXzCheck check; - CSha256 sha; - - BoolInt parseMode; - BoolInt headerParsedOk; - BoolInt decodeToStreamSignature; - unsigned decodeOnlyOneBlock; - - Byte *outBuf; - size_t outBufSize; - size_t outDataWritten; // the size of data in (outBuf) that were fully unpacked - - Byte shaDigest[SHA256_DIGEST_SIZE]; - Byte buf[XZ_BLOCK_HEADER_SIZE_MAX]; -} CXzUnpacker; - -/* alloc : aligned for cache line allocation is better */ -void XzUnpacker_Construct(CXzUnpacker *p, ISzAllocPtr alloc); -void XzUnpacker_Init(CXzUnpacker *p); -void XzUnpacker_SetOutBuf(CXzUnpacker *p, Byte *outBuf, size_t outBufSize); -void XzUnpacker_Free(CXzUnpacker *p); - -/* - XzUnpacker - The sequence for decoding functions: - { - XzUnpacker_Construct() - [Decoding_Calls] - XzUnpacker_Free() - } - - [Decoding_Calls] - - There are 3 types of interfaces for [Decoding_Calls] calls: - - Interface-1 : Partial output buffers: - { - XzUnpacker_Init() - for() - { - XzUnpacker_Code(); - } - XzUnpacker_IsStreamWasFinished() - } - - Interface-2 : Direct output buffer: - Use it, if you know exact size of decoded data, and you need - whole xz unpacked data in one output buffer. - xz unpacker doesn't allocate additional buffer for lzma2 dictionary in that mode. - { - XzUnpacker_Init() - XzUnpacker_SetOutBufMode(); // to set output buffer and size - for() - { - XzUnpacker_Code(); // (dest = NULL) in XzUnpacker_Code() - } - XzUnpacker_IsStreamWasFinished() - } - - Interface-3 : Direct output buffer : One call full decoding - It unpacks whole input buffer to output buffer in one call. - It uses Interface-2 internally. - { - XzUnpacker_CodeFull() - XzUnpacker_IsStreamWasFinished() - } -*/ - -/* -finishMode: - It has meaning only if the decoding reaches output limit (*destLen). - CODER_FINISH_ANY - use smallest number of input bytes - CODER_FINISH_END - read EndOfStream marker after decoding - -Returns: - SZ_OK - status: - CODER_STATUS_NOT_FINISHED, - CODER_STATUS_NEEDS_MORE_INPUT - the decoder can return it in two cases: - 1) it needs more input data to finish current xz stream - 2) xz stream was finished successfully. But the decoder supports multiple - concatented xz streams. So it expects more input data for new xz streams. - Call XzUnpacker_IsStreamWasFinished() to check that latest xz stream was finished successfully. - - SZ_ERROR_MEM - Memory allocation error - SZ_ERROR_DATA - Data error - SZ_ERROR_UNSUPPORTED - Unsupported method or method properties - SZ_ERROR_CRC - CRC error - // SZ_ERROR_INPUT_EOF - It needs more bytes in input buffer (src). - - SZ_ERROR_NO_ARCHIVE - the error with xz Stream Header with one of the following reasons: - - xz Stream Signature failure - - CRC32 of xz Stream Header is failed - - The size of Stream padding is not multiple of four bytes. - It's possible to get that error, if xz stream was finished and the stream - contains some another data. In that case you can call XzUnpacker_GetExtraSize() - function to get real size of xz stream. -*/ - - -SRes XzUnpacker_Code(CXzUnpacker *p, Byte *dest, SizeT *destLen, - const Byte *src, SizeT *srcLen, int srcFinished, - ECoderFinishMode finishMode, ECoderStatus *status); - -SRes XzUnpacker_CodeFull(CXzUnpacker *p, Byte *dest, SizeT *destLen, - const Byte *src, SizeT *srcLen, - ECoderFinishMode finishMode, ECoderStatus *status); - -/* -If you decode full xz stream(s), then you can call XzUnpacker_IsStreamWasFinished() -after successful XzUnpacker_CodeFull() or after last call of XzUnpacker_Code(). -*/ - -BoolInt XzUnpacker_IsStreamWasFinished(const CXzUnpacker *p); - -/* -XzUnpacker_GetExtraSize() returns then number of unconfirmed bytes, - if it's in (XZ_STATE_STREAM_HEADER) state or in (XZ_STATE_STREAM_PADDING) state. -These bytes can be some data after xz archive, or -it can be start of new xz stream. - -Call XzUnpacker_GetExtraSize() after XzUnpacker_Code() function to detect real size of -xz stream in two cases, if XzUnpacker_Code() returns: - res == SZ_OK && status == CODER_STATUS_NEEDS_MORE_INPUT - res == SZ_ERROR_NO_ARCHIVE -*/ - -UInt64 XzUnpacker_GetExtraSize(const CXzUnpacker *p); - - -/* - for random block decoding: - XzUnpacker_Init(); - set CXzUnpacker::streamFlags - XzUnpacker_PrepareToRandomBlockDecoding() - loop - { - XzUnpacker_Code() - XzUnpacker_IsBlockFinished() - } -*/ - -void XzUnpacker_PrepareToRandomBlockDecoding(CXzUnpacker *p); -BoolInt XzUnpacker_IsBlockFinished(const CXzUnpacker *p); - -#define XzUnpacker_GetPackSizeForIndex(p) ((p)->packSize + (p)->blockHeaderSize + XzFlags_GetCheckSize((p)->streamFlags)) - - - - - - -/* ---- Single-Thread and Multi-Thread xz Decoding with Input/Output Streams ---- */ - -/* - if (CXzDecMtProps::numThreads > 1), the decoder can try to use - Multi-Threading. The decoder analyses xz block header, and if - there are pack size and unpack size values stored in xz block header, - the decoder reads compressed data of block to internal buffers, - and then it can start parallel decoding, if there are another blocks. - The decoder can switch back to Single-Thread decoding after some conditions. - - The sequence of calls for xz decoding with in/out Streams: - { - XzDecMt_Create() - XzDecMtProps_Init(XzDecMtProps) to set default values of properties - // then you can change some XzDecMtProps parameters with required values - // here you can set the number of threads and (memUseMax) - the maximum - Memory usage for multithreading decoding. - for() - { - XzDecMt_Decode() // one call per one file - } - XzDecMt_Destroy() - } -*/ - - -typedef struct -{ - size_t inBufSize_ST; // size of input buffer for Single-Thread decoding - size_t outStep_ST; // size of output buffer for Single-Thread decoding - BoolInt ignoreErrors; // if set to 1, the decoder can ignore some errors and it skips broken parts of data. - - #ifndef Z7_ST - unsigned numThreads; // the number of threads for Multi-Thread decoding. if (umThreads == 1) it will use Single-thread decoding - size_t inBufSize_MT; // size of small input data buffers for Multi-Thread decoding. Big number of such small buffers can be created - size_t memUseMax; // the limit of total memory usage for Multi-Thread decoding. - // it's recommended to set (memUseMax) manually to value that is smaller of total size of RAM in computer. - #endif -} CXzDecMtProps; - -void XzDecMtProps_Init(CXzDecMtProps *p); - -typedef struct CXzDecMt CXzDecMt; -typedef CXzDecMt * CXzDecMtHandle; -// Z7_DECLARE_HANDLE(CXzDecMtHandle) - -/* - alloc : XzDecMt uses CAlignOffsetAlloc internally for addresses allocated by (alloc). - allocMid : for big allocations, aligned allocation is better -*/ - -CXzDecMtHandle XzDecMt_Create(ISzAllocPtr alloc, ISzAllocPtr allocMid); -void XzDecMt_Destroy(CXzDecMtHandle p); - - -typedef struct -{ - Byte UnpackSize_Defined; - Byte NumStreams_Defined; - Byte NumBlocks_Defined; - - Byte DataAfterEnd; // there are some additional data after good xz streams, and that data is not new xz stream. - Byte DecodingTruncated; // Decoding was Truncated, we need only partial output data - - UInt64 InSize; // pack size processed. That value doesn't include the data after - // end of xz stream, if that data was not correct - UInt64 OutSize; - - UInt64 NumStreams; - UInt64 NumBlocks; - - SRes DecodeRes; // the error code of xz streams data decoding - SRes ReadRes; // error code from ISeqInStream:Read() - SRes ProgressRes; // error code from ICompressProgress:Progress() - - SRes CombinedRes; // Combined result error code that shows main rusult - // = S_OK, if there is no error. - // but check also (DataAfterEnd) that can show additional minor errors. - - SRes CombinedRes_Type; // = SZ_ERROR_READ, if error from ISeqInStream - // = SZ_ERROR_PROGRESS, if error from ICompressProgress - // = SZ_ERROR_WRITE, if error from ISeqOutStream - // = SZ_ERROR_* codes for decoding -} CXzStatInfo; - -void XzStatInfo_Clear(CXzStatInfo *p); - -/* - -XzDecMt_Decode() -SRes: it's combined decoding result. It also is equal to stat->CombinedRes. - - SZ_OK - no error - check also output value in (stat->DataAfterEnd) - that can show additional possible error - - SZ_ERROR_MEM - Memory allocation error - SZ_ERROR_NO_ARCHIVE - is not xz archive - SZ_ERROR_ARCHIVE - Headers error - SZ_ERROR_DATA - Data Error - SZ_ERROR_UNSUPPORTED - Unsupported method or method properties - SZ_ERROR_CRC - CRC Error - SZ_ERROR_INPUT_EOF - it needs more input data - SZ_ERROR_WRITE - ISeqOutStream error - (SZ_ERROR_READ) - ISeqInStream errors - (SZ_ERROR_PROGRESS) - ICompressProgress errors - // SZ_ERROR_THREAD - error in multi-threading functions - MY_SRes_HRESULT_FROM_WRes(WRes_error) - error in multi-threading function -*/ - -SRes XzDecMt_Decode(CXzDecMtHandle p, - const CXzDecMtProps *props, - const UInt64 *outDataSize, // NULL means undefined - int finishMode, // 0 - partial unpacking is allowed, 1 - xz stream(s) must be finished - ISeqOutStreamPtr outStream, - // Byte *outBuf, size_t *outBufSize, - ISeqInStreamPtr inStream, - // const Byte *inData, size_t inDataSize, - CXzStatInfo *stat, // out: decoding results and statistics - int *isMT, // out: 0 means that ST (Single-Thread) version was used - // 1 means that MT (Multi-Thread) version was used - ICompressProgressPtr progress); - -EXTERN_C_END - -#endif diff --git a/sources/import/edz/lzma/XzCrc64.h b/sources/import/edz/lzma/XzCrc64.h deleted file mode 100644 index ca46869a6..000000000 --- a/sources/import/edz/lzma/XzCrc64.h +++ /dev/null @@ -1,26 +0,0 @@ -/* XzCrc64.h -- CRC64 calculation -2023-04-02 : Igor Pavlov : Public domain */ - -#ifndef ZIP7_INC_XZ_CRC64_H -#define ZIP7_INC_XZ_CRC64_H - -#include - -#include "7zTypes.h" - -EXTERN_C_BEGIN - -extern UInt64 g_Crc64Table[]; - -void Z7_FASTCALL Crc64GenerateTable(void); - -#define CRC64_INIT_VAL UINT64_CONST(0xFFFFFFFFFFFFFFFF) -#define CRC64_GET_DIGEST(crc) ((crc) ^ CRC64_INIT_VAL) -#define CRC64_UPDATE_BYTE(crc, b) (g_Crc64Table[((crc) ^ (b)) & 0xFF] ^ ((crc) >> 8)) - -UInt64 Z7_FASTCALL Crc64Update(UInt64 crc, const void *data, size_t size); -UInt64 Z7_FASTCALL Crc64Calc(const void *data, size_t size); - -EXTERN_C_END - -#endif diff --git a/sources/import/edz/lzma/XzEnc.h b/sources/import/edz/lzma/XzEnc.h deleted file mode 100644 index 77b78c014..000000000 --- a/sources/import/edz/lzma/XzEnc.h +++ /dev/null @@ -1,61 +0,0 @@ -/* XzEnc.h -- Xz Encode -2023-04-13 : Igor Pavlov : Public domain */ - -#ifndef ZIP7_INC_XZ_ENC_H -#define ZIP7_INC_XZ_ENC_H - -#include "Lzma2Enc.h" - -#include "Xz.h" - -EXTERN_C_BEGIN - - -#define XZ_PROPS_BLOCK_SIZE_AUTO LZMA2_ENC_PROPS_BLOCK_SIZE_AUTO -#define XZ_PROPS_BLOCK_SIZE_SOLID LZMA2_ENC_PROPS_BLOCK_SIZE_SOLID - - -typedef struct -{ - UInt32 id; - UInt32 delta; - UInt32 ip; - int ipDefined; -} CXzFilterProps; - -void XzFilterProps_Init(CXzFilterProps *p); - - -typedef struct -{ - CLzma2EncProps lzma2Props; - CXzFilterProps filterProps; - unsigned checkId; - UInt64 blockSize; - int numBlockThreads_Reduced; - int numBlockThreads_Max; - int numTotalThreads; - int forceWriteSizesInHeader; - UInt64 reduceSize; -} CXzProps; - -void XzProps_Init(CXzProps *p); - -typedef struct CXzEnc CXzEnc; -typedef CXzEnc * CXzEncHandle; -// Z7_DECLARE_HANDLE(CXzEncHandle) - -CXzEncHandle XzEnc_Create(ISzAllocPtr alloc, ISzAllocPtr allocBig); -void XzEnc_Destroy(CXzEncHandle p); -SRes XzEnc_SetProps(CXzEncHandle p, const CXzProps *props); -void XzEnc_SetDataSize(CXzEncHandle p, UInt64 expectedDataSiize); -SRes XzEnc_Encode(CXzEncHandle p, ISeqOutStreamPtr outStream, ISeqInStreamPtr inStream, ICompressProgressPtr progress); - -SRes Xz_Encode(ISeqOutStreamPtr outStream, ISeqInStreamPtr inStream, - const CXzProps *props, ICompressProgressPtr progress); - -SRes Xz_EncodeEmpty(ISeqOutStreamPtr outStream); - -EXTERN_C_END - -#endif