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