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