1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235
|
// LoadCodecs.h
#ifndef __LOADCODECS_H
#define __LOADCODECS_H
#include "../../../Common/Types.h"
#include "../../../Common/MyCom.h"
#include "../../../Common/MyString.h"
#include "../../../Common/Buffer.h"
#include "../../ICoder.h"
#ifdef EXTERNAL_CODECS
#include "../../../Windows/DLL.h"
#endif
struct CDllCodecInfo
{
CLSID Encoder;
CLSID Decoder;
bool EncoderIsAssigned;
bool DecoderIsAssigned;
int LibIndex;
UInt32 CodecIndex;
};
#include "../../Archive/IArchive.h"
typedef IInArchive * (*CreateInArchiveP)();
typedef IOutArchive * (*CreateOutArchiveP)();
struct CArcExtInfo
{
UString Ext;
UString AddExt;
CArcExtInfo() {}
CArcExtInfo(const UString &ext): Ext(ext) {}
CArcExtInfo(const UString &ext, const UString &addExt): Ext(ext), AddExt(addExt) {}
};
struct CArcInfoEx
{
#ifdef EXTERNAL_CODECS
int LibIndex;
UInt32 FormatIndex;
CLSID ClassID;
#endif
bool UpdateEnabled;
CreateInArchiveP CreateInArchive;
CreateOutArchiveP CreateOutArchive;
UString Name;
CObjectVector<CArcExtInfo> Exts;
#ifndef _SFX
CByteBuffer StartSignature;
// CByteBuffer FinishSignature;
#ifdef NEW_FOLDER_INTERFACE
UStringVector AssociateExts;
#endif
#endif
bool KeepName;
UString GetMainExt() const
{
if (Exts.IsEmpty())
return UString();
return Exts[0].Ext;
}
int FindExtension(const UString &ext) const
{
for (int i = 0; i < Exts.Size(); i++)
if (ext.CompareNoCase(Exts[i].Ext) == 0)
return i;
return -1;
}
UString GetAllExtensions() const
{
UString s;
for (int i = 0; i < Exts.Size(); i++)
{
if (i > 0)
s += ' ';
s += Exts[i].Ext;
}
return s;
}
void AddExts(const wchar_t* ext, const wchar_t* addExt);
CArcInfoEx():
#ifdef EXTERNAL_CODECS
LibIndex(-1),
#endif
UpdateEnabled(false),
CreateInArchive(0), CreateOutArchive(0),
KeepName(false)
#ifndef _SFX
#endif
{}
};
#ifdef EXTERNAL_CODECS
typedef UInt32 (WINAPI *GetMethodPropertyFunc)(UInt32 index, PROPID propID, PROPVARIANT *value);
typedef UInt32 (WINAPI *CreateObjectFunc)(const GUID *clsID, const GUID *interfaceID, void **outObject);
#ifdef NEW_FOLDER_INTERFACE
struct CCodecIcons
{
struct CIconPair
{
UString Ext;
int IconIndex;
};
CObjectVector<CIconPair> IconPairs;
void LoadIcons(HMODULE m);
bool FindIconIndex(const UString &ext, int &iconIndex) const;
};
#endif
struct CCodecLib
#ifdef NEW_FOLDER_INTERFACE
: public CCodecIcons
#endif
{
NWindows::NDLL::CLibrary Lib;
GetMethodPropertyFunc GetMethodProperty;
CreateObjectFunc CreateObject;
#ifdef NEW_FOLDER_INTERFACE
CSysString Path;
void LoadIcons() { CCodecIcons::LoadIcons((HMODULE)Lib); }
#endif
CCodecLib(): GetMethodProperty(0) {}
};
#endif
class CCodecs:
#ifdef EXTERNAL_CODECS
public ICompressCodecsInfo,
#else
public IUnknown,
#endif
public CMyUnknownImp
{
public:
#ifdef EXTERNAL_CODECS
CObjectVector<CCodecLib> Libs;
CObjectVector<CDllCodecInfo> Codecs;
#ifdef NEW_FOLDER_INTERFACE
CCodecIcons InternalIcons;
#endif
HRESULT LoadCodecs();
HRESULT LoadFormats();
HRESULT LoadDll(const CSysString &path, bool needCheckDll);
HRESULT LoadDllsFromFolder(const CSysString &folderPrefix);
HRESULT CreateArchiveHandler(const CArcInfoEx &ai, void **archive, bool outHandler) const
{
return Libs[ai.LibIndex].CreateObject(&ai.ClassID, outHandler ? &IID_IOutArchive : &IID_IInArchive, (void **)archive);
}
#endif
public:
CObjectVector<CArcInfoEx> Formats;
HRESULT Load();
#ifndef _SFX
int FindFormatForArchiveName(const UString &arcPath) const;
int FindFormatForExtension(const UString &ext) const;
int FindFormatForArchiveType(const UString &arcType) const;
bool FindFormatForArchiveType(const UString &arcType, CIntVector &formatIndices) const;
#endif
MY_UNKNOWN_IMP
#ifdef EXTERNAL_CODECS
STDMETHOD(GetNumberOfMethods)(UInt32 *numMethods);
STDMETHOD(GetProperty)(UInt32 index, PROPID propID, PROPVARIANT *value);
STDMETHOD(CreateDecoder)(UInt32 index, const GUID *interfaceID, void **coder);
STDMETHOD(CreateEncoder)(UInt32 index, const GUID *interfaceID, void **coder);
#endif
int GetCodecLibIndex(UInt32 index);
bool GetCodecEncoderIsAssigned(UInt32 index);
HRESULT GetCodecId(UInt32 index, UInt64 &id);
UString GetCodecName(UInt32 index);
HRESULT CreateInArchive(int formatIndex, CMyComPtr<IInArchive> &archive) const
{
const CArcInfoEx &ai = Formats[formatIndex];
#ifdef EXTERNAL_CODECS
if (ai.LibIndex < 0)
#endif
{
archive = ai.CreateInArchive();
return S_OK;
}
#ifdef EXTERNAL_CODECS
return CreateArchiveHandler(ai, (void **)&archive, false);
#endif
}
HRESULT CreateOutArchive(int formatIndex, CMyComPtr<IOutArchive> &archive) const
{
const CArcInfoEx &ai = Formats[formatIndex];
#ifdef EXTERNAL_CODECS
if (ai.LibIndex < 0)
#endif
{
archive = ai.CreateOutArchive();
return S_OK;
}
#ifdef EXTERNAL_CODECS
return CreateArchiveHandler(ai, (void **)&archive, true);
#endif
}
int FindOutFormatFromName(const UString &name) const
{
for (int i = 0; i < Formats.Size(); i++)
{
const CArcInfoEx &arc = Formats[i];
if (!arc.UpdateEnabled)
continue;
if (arc.Name.CompareNoCase(name) == 0)
return i;
}
return -1;
}
#ifdef EXTERNAL_CODECS
HRESULT CreateCoder(const UString &name, bool encode, CMyComPtr<ICompressCoder> &coder) const;
#endif
};
#endif
|