1370b324cSopenharmony_ci// LoadCodecs.h 2370b324cSopenharmony_ci 3370b324cSopenharmony_ci#ifndef ZIP7_INC_LOAD_CODECS_H 4370b324cSopenharmony_ci#define ZIP7_INC_LOAD_CODECS_H 5370b324cSopenharmony_ci 6370b324cSopenharmony_ci/* 7370b324cSopenharmony_ciClient application uses LoadCodecs.* to load plugins to 8370b324cSopenharmony_ciCCodecs object, that contains 3 lists of plugins: 9370b324cSopenharmony_ci 1) Formats - internal and external archive handlers 10370b324cSopenharmony_ci 2) Codecs - external codecs 11370b324cSopenharmony_ci 3) Hashers - external hashers 12370b324cSopenharmony_ci 13370b324cSopenharmony_ciZ7_EXTERNAL_CODECS 14370b324cSopenharmony_ci--------------- 15370b324cSopenharmony_ci 16370b324cSopenharmony_ci if Z7_EXTERNAL_CODECS is defined, then the code tries to load external 17370b324cSopenharmony_ci plugins from DLL files (shared libraries). 18370b324cSopenharmony_ci 19370b324cSopenharmony_ci There are two types of executables in 7-Zip: 20370b324cSopenharmony_ci 21370b324cSopenharmony_ci 1) Executable that uses external plugins must be compiled 22370b324cSopenharmony_ci with Z7_EXTERNAL_CODECS defined: 23370b324cSopenharmony_ci - 7z.exe, 7zG.exe, 7zFM.exe 24370b324cSopenharmony_ci 25370b324cSopenharmony_ci Note: Z7_EXTERNAL_CODECS is used also in CPP/7zip/Common/CreateCoder.h 26370b324cSopenharmony_ci that code is used in plugin module (7z.dll). 27370b324cSopenharmony_ci 28370b324cSopenharmony_ci 2) Standalone modules are compiled without Z7_EXTERNAL_CODECS: 29370b324cSopenharmony_ci - SFX modules: 7z.sfx, 7zCon.sfx 30370b324cSopenharmony_ci - standalone versions of console 7-Zip: 7za.exe, 7zr.exe 31370b324cSopenharmony_ci 32370b324cSopenharmony_ci if Z7_EXTERNAL_CODECS is defined, CCodecs class implements interfaces: 33370b324cSopenharmony_ci - ICompressCodecsInfo : for Codecs 34370b324cSopenharmony_ci - IHashers : for Hashers 35370b324cSopenharmony_ci 36370b324cSopenharmony_ci The client application can send CCodecs object to each plugin module. 37370b324cSopenharmony_ci And plugin module can use ICompressCodecsInfo or IHashers interface to access 38370b324cSopenharmony_ci another plugins. 39370b324cSopenharmony_ci 40370b324cSopenharmony_ci There are 2 ways to send (ICompressCodecsInfo * compressCodecsInfo) to plugin 41370b324cSopenharmony_ci 1) for old versions: 42370b324cSopenharmony_ci a) request ISetCompressCodecsInfo from created archive handler. 43370b324cSopenharmony_ci b) call ISetCompressCodecsInfo::SetCompressCodecsInfo(compressCodecsInfo) 44370b324cSopenharmony_ci 2) for new versions: 45370b324cSopenharmony_ci a) request "SetCodecs" function from DLL file 46370b324cSopenharmony_ci b) call SetCodecs(compressCodecsInfo) function from DLL file 47370b324cSopenharmony_ci*/ 48370b324cSopenharmony_ci 49370b324cSopenharmony_ci#include "../../../Common/MyBuffer.h" 50370b324cSopenharmony_ci#include "../../../Common/MyCom.h" 51370b324cSopenharmony_ci#include "../../../Common/MyString.h" 52370b324cSopenharmony_ci#include "../../../Common/ComTry.h" 53370b324cSopenharmony_ci 54370b324cSopenharmony_ci#ifdef Z7_EXTERNAL_CODECS 55370b324cSopenharmony_ci#include "../../../Windows/DLL.h" 56370b324cSopenharmony_ci#endif 57370b324cSopenharmony_ci 58370b324cSopenharmony_ci#include "../../ICoder.h" 59370b324cSopenharmony_ci 60370b324cSopenharmony_ci#include "../../Archive/IArchive.h" 61370b324cSopenharmony_ci 62370b324cSopenharmony_ci 63370b324cSopenharmony_ci#ifdef Z7_EXTERNAL_CODECS 64370b324cSopenharmony_ci 65370b324cSopenharmony_cistruct CDllCodecInfo 66370b324cSopenharmony_ci{ 67370b324cSopenharmony_ci unsigned LibIndex; 68370b324cSopenharmony_ci UInt32 CodecIndex; 69370b324cSopenharmony_ci bool EncoderIsAssigned; 70370b324cSopenharmony_ci bool DecoderIsAssigned; 71370b324cSopenharmony_ci bool IsFilter; 72370b324cSopenharmony_ci bool IsFilter_Assigned; 73370b324cSopenharmony_ci CLSID Encoder; 74370b324cSopenharmony_ci CLSID Decoder; 75370b324cSopenharmony_ci}; 76370b324cSopenharmony_ci 77370b324cSopenharmony_cistruct CDllHasherInfo 78370b324cSopenharmony_ci{ 79370b324cSopenharmony_ci unsigned LibIndex; 80370b324cSopenharmony_ci UInt32 HasherIndex; 81370b324cSopenharmony_ci}; 82370b324cSopenharmony_ci 83370b324cSopenharmony_ci#endif 84370b324cSopenharmony_ci 85370b324cSopenharmony_cistruct CArcExtInfo 86370b324cSopenharmony_ci{ 87370b324cSopenharmony_ci UString Ext; 88370b324cSopenharmony_ci UString AddExt; 89370b324cSopenharmony_ci 90370b324cSopenharmony_ci CArcExtInfo() {} 91370b324cSopenharmony_ci CArcExtInfo(const UString &ext): Ext(ext) {} 92370b324cSopenharmony_ci CArcExtInfo(const UString &ext, const UString &addExt): Ext(ext), AddExt(addExt) {} 93370b324cSopenharmony_ci}; 94370b324cSopenharmony_ci 95370b324cSopenharmony_ci 96370b324cSopenharmony_cistruct CArcInfoEx 97370b324cSopenharmony_ci{ 98370b324cSopenharmony_ci UInt32 Flags; 99370b324cSopenharmony_ci UInt32 TimeFlags; 100370b324cSopenharmony_ci 101370b324cSopenharmony_ci Func_CreateInArchive CreateInArchive; 102370b324cSopenharmony_ci Func_IsArc IsArcFunc; 103370b324cSopenharmony_ci 104370b324cSopenharmony_ci UString Name; 105370b324cSopenharmony_ci CObjectVector<CArcExtInfo> Exts; 106370b324cSopenharmony_ci 107370b324cSopenharmony_ci #ifndef Z7_SFX 108370b324cSopenharmony_ci Func_CreateOutArchive CreateOutArchive; 109370b324cSopenharmony_ci bool UpdateEnabled; 110370b324cSopenharmony_ci bool NewInterface; 111370b324cSopenharmony_ci // UInt32 Version; 112370b324cSopenharmony_ci UInt32 SignatureOffset; 113370b324cSopenharmony_ci CObjectVector<CByteBuffer> Signatures; 114370b324cSopenharmony_ci /* 115370b324cSopenharmony_ci #ifdef NEW_FOLDER_INTERFACE 116370b324cSopenharmony_ci UStringVector AssociateExts; 117370b324cSopenharmony_ci #endif 118370b324cSopenharmony_ci */ 119370b324cSopenharmony_ci #endif 120370b324cSopenharmony_ci 121370b324cSopenharmony_ci #ifdef Z7_EXTERNAL_CODECS 122370b324cSopenharmony_ci int LibIndex; 123370b324cSopenharmony_ci UInt32 FormatIndex; 124370b324cSopenharmony_ci CLSID ClassID; 125370b324cSopenharmony_ci #endif 126370b324cSopenharmony_ci 127370b324cSopenharmony_ci int Compare(const CArcInfoEx &a) const 128370b324cSopenharmony_ci { 129370b324cSopenharmony_ci const int res = Name.Compare(a.Name); 130370b324cSopenharmony_ci if (res != 0) 131370b324cSopenharmony_ci return res; 132370b324cSopenharmony_ci #ifdef Z7_EXTERNAL_CODECS 133370b324cSopenharmony_ci return MyCompare(LibIndex, a.LibIndex); 134370b324cSopenharmony_ci #else 135370b324cSopenharmony_ci return 0; 136370b324cSopenharmony_ci #endif 137370b324cSopenharmony_ci /* 138370b324cSopenharmony_ci if (LibIndex < a.LibIndex) return -1; 139370b324cSopenharmony_ci if (LibIndex > a.LibIndex) return 1; 140370b324cSopenharmony_ci return 0; 141370b324cSopenharmony_ci */ 142370b324cSopenharmony_ci } 143370b324cSopenharmony_ci 144370b324cSopenharmony_ci bool Flags_KeepName() const { return (Flags & NArcInfoFlags::kKeepName) != 0; } 145370b324cSopenharmony_ci bool Flags_FindSignature() const { return (Flags & NArcInfoFlags::kFindSignature) != 0; } 146370b324cSopenharmony_ci 147370b324cSopenharmony_ci bool Flags_AltStreams() const { return (Flags & NArcInfoFlags::kAltStreams) != 0; } 148370b324cSopenharmony_ci bool Flags_NtSecurity() const { return (Flags & NArcInfoFlags::kNtSecure) != 0; } 149370b324cSopenharmony_ci bool Flags_SymLinks() const { return (Flags & NArcInfoFlags::kSymLinks) != 0; } 150370b324cSopenharmony_ci bool Flags_HardLinks() const { return (Flags & NArcInfoFlags::kHardLinks) != 0; } 151370b324cSopenharmony_ci 152370b324cSopenharmony_ci bool Flags_UseGlobalOffset() const { return (Flags & NArcInfoFlags::kUseGlobalOffset) != 0; } 153370b324cSopenharmony_ci bool Flags_StartOpen() const { return (Flags & NArcInfoFlags::kStartOpen) != 0; } 154370b324cSopenharmony_ci bool Flags_BackwardOpen() const { return (Flags & NArcInfoFlags::kBackwardOpen) != 0; } 155370b324cSopenharmony_ci bool Flags_PreArc() const { return (Flags & NArcInfoFlags::kPreArc) != 0; } 156370b324cSopenharmony_ci bool Flags_PureStartOpen() const { return (Flags & NArcInfoFlags::kPureStartOpen) != 0; } 157370b324cSopenharmony_ci bool Flags_ByExtOnlyOpen() const { return (Flags & NArcInfoFlags::kByExtOnlyOpen) != 0; } 158370b324cSopenharmony_ci bool Flags_HashHandler() const { return (Flags & NArcInfoFlags::kHashHandler) != 0; } 159370b324cSopenharmony_ci 160370b324cSopenharmony_ci bool Flags_CTime() const { return (Flags & NArcInfoFlags::kCTime) != 0; } 161370b324cSopenharmony_ci bool Flags_ATime() const { return (Flags & NArcInfoFlags::kATime) != 0; } 162370b324cSopenharmony_ci bool Flags_MTime() const { return (Flags & NArcInfoFlags::kMTime) != 0; } 163370b324cSopenharmony_ci 164370b324cSopenharmony_ci bool Flags_CTime_Default() const { return (Flags & NArcInfoFlags::kCTime_Default) != 0; } 165370b324cSopenharmony_ci bool Flags_ATime_Default() const { return (Flags & NArcInfoFlags::kATime_Default) != 0; } 166370b324cSopenharmony_ci bool Flags_MTime_Default() const { return (Flags & NArcInfoFlags::kMTime_Default) != 0; } 167370b324cSopenharmony_ci 168370b324cSopenharmony_ci UInt32 Get_TimePrecFlags() const 169370b324cSopenharmony_ci { 170370b324cSopenharmony_ci return (TimeFlags >> NArcInfoTimeFlags::kTime_Prec_Mask_bit_index) & 171370b324cSopenharmony_ci (((UInt32)1 << NArcInfoTimeFlags::kTime_Prec_Mask_num_bits) - 1); 172370b324cSopenharmony_ci } 173370b324cSopenharmony_ci 174370b324cSopenharmony_ci UInt32 Get_DefaultTimePrec() const 175370b324cSopenharmony_ci { 176370b324cSopenharmony_ci return (TimeFlags >> NArcInfoTimeFlags::kTime_Prec_Default_bit_index) & 177370b324cSopenharmony_ci (((UInt32)1 << NArcInfoTimeFlags::kTime_Prec_Default_num_bits) - 1); 178370b324cSopenharmony_ci } 179370b324cSopenharmony_ci 180370b324cSopenharmony_ci 181370b324cSopenharmony_ci UString GetMainExt() const 182370b324cSopenharmony_ci { 183370b324cSopenharmony_ci if (Exts.IsEmpty()) 184370b324cSopenharmony_ci return UString(); 185370b324cSopenharmony_ci return Exts[0].Ext; 186370b324cSopenharmony_ci } 187370b324cSopenharmony_ci int FindExtension(const UString &ext) const; 188370b324cSopenharmony_ci 189370b324cSopenharmony_ci bool Is_7z() const { return Name.IsEqualTo_Ascii_NoCase("7z"); } 190370b324cSopenharmony_ci bool Is_Split() const { return Name.IsEqualTo_Ascii_NoCase("Split"); } 191370b324cSopenharmony_ci bool Is_Xz() const { return Name.IsEqualTo_Ascii_NoCase("xz"); } 192370b324cSopenharmony_ci bool Is_BZip2() const { return Name.IsEqualTo_Ascii_NoCase("bzip2"); } 193370b324cSopenharmony_ci bool Is_GZip() const { return Name.IsEqualTo_Ascii_NoCase("gzip"); } 194370b324cSopenharmony_ci bool Is_Tar() const { return Name.IsEqualTo_Ascii_NoCase("tar"); } 195370b324cSopenharmony_ci bool Is_Zip() const { return Name.IsEqualTo_Ascii_NoCase("zip"); } 196370b324cSopenharmony_ci bool Is_Rar() const { return Name.IsEqualTo_Ascii_NoCase("rar"); } 197370b324cSopenharmony_ci bool Is_Zstd() const { return Name.IsEqualTo_Ascii_NoCase("zstd"); } 198370b324cSopenharmony_ci 199370b324cSopenharmony_ci /* 200370b324cSopenharmony_ci UString GetAllExtensions() const 201370b324cSopenharmony_ci { 202370b324cSopenharmony_ci UString s; 203370b324cSopenharmony_ci for (int i = 0; i < Exts.Size(); i++) 204370b324cSopenharmony_ci { 205370b324cSopenharmony_ci if (i > 0) 206370b324cSopenharmony_ci s.Add_Space(); 207370b324cSopenharmony_ci s += Exts[i].Ext; 208370b324cSopenharmony_ci } 209370b324cSopenharmony_ci return s; 210370b324cSopenharmony_ci } 211370b324cSopenharmony_ci */ 212370b324cSopenharmony_ci 213370b324cSopenharmony_ci void AddExts(const UString &ext, const UString &addExt); 214370b324cSopenharmony_ci 215370b324cSopenharmony_ci 216370b324cSopenharmony_ci CArcInfoEx(): 217370b324cSopenharmony_ci Flags(0), 218370b324cSopenharmony_ci TimeFlags(0), 219370b324cSopenharmony_ci CreateInArchive(NULL), 220370b324cSopenharmony_ci IsArcFunc(NULL) 221370b324cSopenharmony_ci #ifndef Z7_SFX 222370b324cSopenharmony_ci , CreateOutArchive(NULL) 223370b324cSopenharmony_ci , UpdateEnabled(false) 224370b324cSopenharmony_ci , NewInterface(false) 225370b324cSopenharmony_ci // , Version(0) 226370b324cSopenharmony_ci , SignatureOffset(0) 227370b324cSopenharmony_ci #endif 228370b324cSopenharmony_ci #ifdef Z7_EXTERNAL_CODECS 229370b324cSopenharmony_ci , LibIndex(-1) 230370b324cSopenharmony_ci #endif 231370b324cSopenharmony_ci {} 232370b324cSopenharmony_ci}; 233370b324cSopenharmony_ci 234370b324cSopenharmony_ci 235370b324cSopenharmony_ci#ifdef Z7_EXTERNAL_CODECS 236370b324cSopenharmony_ci 237370b324cSopenharmony_cistruct CCodecLib 238370b324cSopenharmony_ci{ 239370b324cSopenharmony_ci NWindows::NDLL::CLibrary Lib; 240370b324cSopenharmony_ci FString Path; 241370b324cSopenharmony_ci 242370b324cSopenharmony_ci Func_CreateObject CreateObject; 243370b324cSopenharmony_ci Func_GetMethodProperty GetMethodProperty; 244370b324cSopenharmony_ci Func_CreateDecoder CreateDecoder; 245370b324cSopenharmony_ci Func_CreateEncoder CreateEncoder; 246370b324cSopenharmony_ci Func_SetCodecs SetCodecs; 247370b324cSopenharmony_ci 248370b324cSopenharmony_ci CMyComPtr<IHashers> ComHashers; 249370b324cSopenharmony_ci 250370b324cSopenharmony_ci UInt32 Version; 251370b324cSopenharmony_ci 252370b324cSopenharmony_ci /* 253370b324cSopenharmony_ci #ifdef NEW_FOLDER_INTERFACE 254370b324cSopenharmony_ci CCodecIcons CodecIcons; 255370b324cSopenharmony_ci void LoadIcons() { CodecIcons.LoadIcons((HMODULE)Lib); } 256370b324cSopenharmony_ci #endif 257370b324cSopenharmony_ci */ 258370b324cSopenharmony_ci 259370b324cSopenharmony_ci CCodecLib(): 260370b324cSopenharmony_ci CreateObject(NULL), 261370b324cSopenharmony_ci GetMethodProperty(NULL), 262370b324cSopenharmony_ci CreateDecoder(NULL), 263370b324cSopenharmony_ci CreateEncoder(NULL), 264370b324cSopenharmony_ci SetCodecs(NULL), 265370b324cSopenharmony_ci Version(0) 266370b324cSopenharmony_ci {} 267370b324cSopenharmony_ci}; 268370b324cSopenharmony_ci 269370b324cSopenharmony_ci#endif 270370b324cSopenharmony_ci 271370b324cSopenharmony_cistruct CCodecError 272370b324cSopenharmony_ci{ 273370b324cSopenharmony_ci FString Path; 274370b324cSopenharmony_ci HRESULT ErrorCode; 275370b324cSopenharmony_ci AString Message; 276370b324cSopenharmony_ci CCodecError(): ErrorCode(0) {} 277370b324cSopenharmony_ci}; 278370b324cSopenharmony_ci 279370b324cSopenharmony_ci 280370b324cSopenharmony_cistruct CCodecInfoUser 281370b324cSopenharmony_ci{ 282370b324cSopenharmony_ci // unsigned LibIndex; 283370b324cSopenharmony_ci // UInt32 CodecIndex; 284370b324cSopenharmony_ci // UInt64 id; 285370b324cSopenharmony_ci bool EncoderIsAssigned; 286370b324cSopenharmony_ci bool DecoderIsAssigned; 287370b324cSopenharmony_ci bool IsFilter; 288370b324cSopenharmony_ci bool IsFilter_Assigned; 289370b324cSopenharmony_ci UInt32 NumStreams; 290370b324cSopenharmony_ci AString Name; 291370b324cSopenharmony_ci}; 292370b324cSopenharmony_ci 293370b324cSopenharmony_ci 294370b324cSopenharmony_ciclass CCodecs Z7_final: 295370b324cSopenharmony_ci #ifdef Z7_EXTERNAL_CODECS 296370b324cSopenharmony_ci public ICompressCodecsInfo, 297370b324cSopenharmony_ci public IHashers, 298370b324cSopenharmony_ci #else 299370b324cSopenharmony_ci public IUnknown, 300370b324cSopenharmony_ci #endif 301370b324cSopenharmony_ci public CMyUnknownImp 302370b324cSopenharmony_ci{ 303370b324cSopenharmony_ci#ifdef Z7_EXTERNAL_CODECS 304370b324cSopenharmony_ci Z7_IFACES_IMP_UNK_2(ICompressCodecsInfo, IHashers) 305370b324cSopenharmony_ci#else 306370b324cSopenharmony_ci Z7_COM_UNKNOWN_IMP_0 307370b324cSopenharmony_ci#endif // Z7_EXTERNAL_CODECS 308370b324cSopenharmony_ci 309370b324cSopenharmony_ci Z7_CLASS_NO_COPY(CCodecs) 310370b324cSopenharmony_cipublic: 311370b324cSopenharmony_ci #ifdef Z7_EXTERNAL_CODECS 312370b324cSopenharmony_ci 313370b324cSopenharmony_ci CObjectVector<CCodecLib> Libs; 314370b324cSopenharmony_ci FString MainDll_ErrorPath; 315370b324cSopenharmony_ci CObjectVector<CCodecError> Errors; 316370b324cSopenharmony_ci 317370b324cSopenharmony_ci void AddLastError(const FString &path); 318370b324cSopenharmony_ci void CloseLibs(); 319370b324cSopenharmony_ci 320370b324cSopenharmony_ci class CReleaser 321370b324cSopenharmony_ci { 322370b324cSopenharmony_ci Z7_CLASS_NO_COPY(CReleaser) 323370b324cSopenharmony_ci 324370b324cSopenharmony_ci /* CCodecsReleaser object releases CCodecs links. 325370b324cSopenharmony_ci 1) CCodecs is COM object that is deleted when all links to that object will be released/ 326370b324cSopenharmony_ci 2) CCodecs::Libs[i] can hold (ICompressCodecsInfo *) link to CCodecs object itself. 327370b324cSopenharmony_ci To break that reference loop, we must close all CCodecs::Libs in CCodecsReleaser desttructor. */ 328370b324cSopenharmony_ci 329370b324cSopenharmony_ci CCodecs *_codecs; 330370b324cSopenharmony_ci 331370b324cSopenharmony_ci public: 332370b324cSopenharmony_ci CReleaser(): _codecs(NULL) {} 333370b324cSopenharmony_ci void Set(CCodecs *codecs) { _codecs = codecs; } 334370b324cSopenharmony_ci ~CReleaser() { if (_codecs) _codecs->CloseLibs(); } 335370b324cSopenharmony_ci }; 336370b324cSopenharmony_ci 337370b324cSopenharmony_ci bool NeedSetLibCodecs; // = false, if we don't need to set codecs for archive handler via ISetCompressCodecsInfo 338370b324cSopenharmony_ci 339370b324cSopenharmony_ci HRESULT LoadCodecs(); 340370b324cSopenharmony_ci HRESULT LoadFormats(); 341370b324cSopenharmony_ci HRESULT LoadDll(const FString &path, bool needCheckDll, bool *loadedOK = NULL); 342370b324cSopenharmony_ci HRESULT LoadDllsFromFolder(const FString &folderPrefix); 343370b324cSopenharmony_ci 344370b324cSopenharmony_ci HRESULT CreateArchiveHandler(const CArcInfoEx &ai, bool outHandler, void **archive) const 345370b324cSopenharmony_ci { 346370b324cSopenharmony_ci return Libs[(unsigned)ai.LibIndex].CreateObject(&ai.ClassID, outHandler ? &IID_IOutArchive : &IID_IInArchive, (void **)archive); 347370b324cSopenharmony_ci } 348370b324cSopenharmony_ci 349370b324cSopenharmony_ci #endif 350370b324cSopenharmony_ci 351370b324cSopenharmony_ci /* 352370b324cSopenharmony_ci #ifdef NEW_FOLDER_INTERFACE 353370b324cSopenharmony_ci CCodecIcons InternalIcons; 354370b324cSopenharmony_ci #endif 355370b324cSopenharmony_ci */ 356370b324cSopenharmony_ci 357370b324cSopenharmony_ci CObjectVector<CArcInfoEx> Formats; 358370b324cSopenharmony_ci 359370b324cSopenharmony_ci #ifdef Z7_EXTERNAL_CODECS 360370b324cSopenharmony_ci CRecordVector<CDllCodecInfo> Codecs; 361370b324cSopenharmony_ci CRecordVector<CDllHasherInfo> Hashers; 362370b324cSopenharmony_ci #endif 363370b324cSopenharmony_ci 364370b324cSopenharmony_ci bool CaseSensitive_Change; 365370b324cSopenharmony_ci bool CaseSensitive; 366370b324cSopenharmony_ci 367370b324cSopenharmony_ci CCodecs(): 368370b324cSopenharmony_ci #ifdef Z7_EXTERNAL_CODECS 369370b324cSopenharmony_ci NeedSetLibCodecs(true), 370370b324cSopenharmony_ci #endif 371370b324cSopenharmony_ci CaseSensitive_Change(false), 372370b324cSopenharmony_ci CaseSensitive(false) 373370b324cSopenharmony_ci {} 374370b324cSopenharmony_ci 375370b324cSopenharmony_ci ~CCodecs() 376370b324cSopenharmony_ci { 377370b324cSopenharmony_ci // OutputDebugStringA("~CCodecs"); 378370b324cSopenharmony_ci } 379370b324cSopenharmony_ci 380370b324cSopenharmony_ci const wchar_t *GetFormatNamePtr(int formatIndex) const 381370b324cSopenharmony_ci { 382370b324cSopenharmony_ci return formatIndex < 0 ? L"#" : (const wchar_t *)Formats[(unsigned)formatIndex].Name; 383370b324cSopenharmony_ci } 384370b324cSopenharmony_ci 385370b324cSopenharmony_ci HRESULT Load(); 386370b324cSopenharmony_ci 387370b324cSopenharmony_ci #ifndef Z7_SFX 388370b324cSopenharmony_ci int FindFormatForArchiveName(const UString &arcPath) const; 389370b324cSopenharmony_ci int FindFormatForExtension(const UString &ext) const; 390370b324cSopenharmony_ci int FindFormatForArchiveType(const UString &arcType) const; 391370b324cSopenharmony_ci bool FindFormatForArchiveType(const UString &arcType, CIntVector &formatIndices) const; 392370b324cSopenharmony_ci #endif 393370b324cSopenharmony_ci 394370b324cSopenharmony_ci #ifdef Z7_EXTERNAL_CODECS 395370b324cSopenharmony_ci 396370b324cSopenharmony_ci int GetCodec_LibIndex(UInt32 index) const; 397370b324cSopenharmony_ci bool GetCodec_DecoderIsAssigned(UInt32 index) const; 398370b324cSopenharmony_ci bool GetCodec_EncoderIsAssigned(UInt32 index) const; 399370b324cSopenharmony_ci bool GetCodec_IsFilter(UInt32 index, bool &isAssigned) const; 400370b324cSopenharmony_ci UInt32 GetCodec_NumStreams(UInt32 index); 401370b324cSopenharmony_ci HRESULT GetCodec_Id(UInt32 index, UInt64 &id); 402370b324cSopenharmony_ci AString GetCodec_Name(UInt32 index); 403370b324cSopenharmony_ci 404370b324cSopenharmony_ci int GetHasherLibIndex(UInt32 index); 405370b324cSopenharmony_ci UInt64 GetHasherId(UInt32 index); 406370b324cSopenharmony_ci AString GetHasherName(UInt32 index); 407370b324cSopenharmony_ci UInt32 GetHasherDigestSize(UInt32 index); 408370b324cSopenharmony_ci 409370b324cSopenharmony_ci void GetCodecsErrorMessage(UString &s); 410370b324cSopenharmony_ci 411370b324cSopenharmony_ci #endif 412370b324cSopenharmony_ci 413370b324cSopenharmony_ci HRESULT CreateInArchive(unsigned formatIndex, CMyComPtr<IInArchive> &archive) const 414370b324cSopenharmony_ci { 415370b324cSopenharmony_ci const CArcInfoEx &ai = Formats[formatIndex]; 416370b324cSopenharmony_ci #ifdef Z7_EXTERNAL_CODECS 417370b324cSopenharmony_ci if (ai.LibIndex < 0) 418370b324cSopenharmony_ci #endif 419370b324cSopenharmony_ci { 420370b324cSopenharmony_ci COM_TRY_BEGIN 421370b324cSopenharmony_ci archive = ai.CreateInArchive(); 422370b324cSopenharmony_ci return S_OK; 423370b324cSopenharmony_ci COM_TRY_END 424370b324cSopenharmony_ci } 425370b324cSopenharmony_ci #ifdef Z7_EXTERNAL_CODECS 426370b324cSopenharmony_ci return CreateArchiveHandler(ai, false, (void **)&archive); 427370b324cSopenharmony_ci #endif 428370b324cSopenharmony_ci } 429370b324cSopenharmony_ci 430370b324cSopenharmony_ci #ifndef Z7_SFX 431370b324cSopenharmony_ci 432370b324cSopenharmony_ci HRESULT CreateOutArchive(unsigned formatIndex, CMyComPtr<IOutArchive> &archive) const 433370b324cSopenharmony_ci { 434370b324cSopenharmony_ci const CArcInfoEx &ai = Formats[formatIndex]; 435370b324cSopenharmony_ci #ifdef Z7_EXTERNAL_CODECS 436370b324cSopenharmony_ci if (ai.LibIndex < 0) 437370b324cSopenharmony_ci #endif 438370b324cSopenharmony_ci { 439370b324cSopenharmony_ci COM_TRY_BEGIN 440370b324cSopenharmony_ci archive = ai.CreateOutArchive(); 441370b324cSopenharmony_ci return S_OK; 442370b324cSopenharmony_ci COM_TRY_END 443370b324cSopenharmony_ci } 444370b324cSopenharmony_ci 445370b324cSopenharmony_ci #ifdef Z7_EXTERNAL_CODECS 446370b324cSopenharmony_ci return CreateArchiveHandler(ai, true, (void **)&archive); 447370b324cSopenharmony_ci #endif 448370b324cSopenharmony_ci } 449370b324cSopenharmony_ci 450370b324cSopenharmony_ci int FindOutFormatFromName(const UString &name) const 451370b324cSopenharmony_ci { 452370b324cSopenharmony_ci FOR_VECTOR (i, Formats) 453370b324cSopenharmony_ci { 454370b324cSopenharmony_ci const CArcInfoEx &arc = Formats[i]; 455370b324cSopenharmony_ci if (!arc.UpdateEnabled) 456370b324cSopenharmony_ci continue; 457370b324cSopenharmony_ci if (arc.Name.IsEqualTo_NoCase(name)) 458370b324cSopenharmony_ci return (int)i; 459370b324cSopenharmony_ci } 460370b324cSopenharmony_ci return -1; 461370b324cSopenharmony_ci } 462370b324cSopenharmony_ci 463370b324cSopenharmony_ci void Get_CodecsInfoUser_Vector(CObjectVector<CCodecInfoUser> &v); 464370b324cSopenharmony_ci 465370b324cSopenharmony_ci #endif // Z7_SFX 466370b324cSopenharmony_ci}; 467370b324cSopenharmony_ci 468370b324cSopenharmony_ci#ifdef Z7_EXTERNAL_CODECS 469370b324cSopenharmony_ci #define CREATE_CODECS_OBJECT \ 470370b324cSopenharmony_ci CCodecs *codecs = new CCodecs; \ 471370b324cSopenharmony_ci CExternalCodecs _externalCodecs; \ 472370b324cSopenharmony_ci _externalCodecs.GetCodecs = codecs; \ 473370b324cSopenharmony_ci _externalCodecs.GetHashers = codecs; \ 474370b324cSopenharmony_ci CCodecs::CReleaser codecsReleaser; \ 475370b324cSopenharmony_ci codecsReleaser.Set(codecs); 476370b324cSopenharmony_ci#else 477370b324cSopenharmony_ci #define CREATE_CODECS_OBJECT \ 478370b324cSopenharmony_ci CCodecs *codecs = new CCodecs; \ 479370b324cSopenharmony_ci CMyComPtr<IUnknown> _codecsRef = codecs; 480370b324cSopenharmony_ci#endif 481370b324cSopenharmony_ci 482370b324cSopenharmony_ci#endif 483