other-licenses/7zstub/src/7zip/Archive/7z/7zMethods.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/other-licenses/7zstub/src/7zip/Archive/7z/7zMethods.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,174 @@
     1.4 +// 7zMethods.cpp
     1.5 +
     1.6 +#include "StdAfx.h"
     1.7 +
     1.8 +#include "7zMethods.h"
     1.9 +
    1.10 +#include "../../../Windows/FileFind.h"
    1.11 +#include "../../../Windows/DLL.h"
    1.12 +#include "../../../Windows/PropVariant.h"
    1.13 +#include "../../../Windows/Synchronization.h"
    1.14 +
    1.15 +#include "../../ICoder.h"
    1.16 +#include "../Common/CodecsPath.h"
    1.17 +
    1.18 +using namespace NWindows;
    1.19 +
    1.20 +namespace NArchive {
    1.21 +namespace N7z {
    1.22 +
    1.23 +static CObjectVector<CMethodInfo2> g_Methods;
    1.24 +static bool g_Loaded = false;
    1.25 +
    1.26 +typedef UInt32 (WINAPI *GetNumberOfMethodsFunc)(UInt32 *numMethods);
    1.27 +
    1.28 +typedef UInt32 (WINAPI *GetMethodPropertyFunc)(
    1.29 +    UInt32 index, PROPID propID, PROPVARIANT *value);
    1.30 +
    1.31 +static void Load(const CSysString &folderPrefix)
    1.32 +{
    1.33 +  NFile::NFind::CEnumerator enumerator(folderPrefix + CSysString(TEXT("*")));
    1.34 +  NFile::NFind::CFileInfo fileInfo;
    1.35 +  while (enumerator.Next(fileInfo))
    1.36 +  {
    1.37 +    if (fileInfo.IsDirectory())
    1.38 +      continue;
    1.39 +    CSysString filePath = folderPrefix + fileInfo.Name;
    1.40 +    {
    1.41 +      NDLL::CLibrary library;
    1.42 +      if (!library.LoadEx(filePath, LOAD_LIBRARY_AS_DATAFILE))
    1.43 +        continue;
    1.44 +    }
    1.45 +    NDLL::CLibrary library;
    1.46 +    if (!library.Load(filePath))
    1.47 +      continue;
    1.48 +    GetMethodPropertyFunc getMethodProperty = (GetMethodPropertyFunc)
    1.49 +        library.GetProcAddress("GetMethodProperty");
    1.50 +    if (getMethodProperty == NULL)
    1.51 +      continue;
    1.52 +
    1.53 +    UInt32 numMethods = 1;
    1.54 +    GetNumberOfMethodsFunc getNumberOfMethodsFunc = (GetNumberOfMethodsFunc)
    1.55 +        library.GetProcAddress("GetNumberOfMethods");
    1.56 +    if (getNumberOfMethodsFunc != NULL)
    1.57 +      if (getNumberOfMethodsFunc(&numMethods) != S_OK)
    1.58 +        continue;
    1.59 +
    1.60 +    for(UInt32 i = 0; i < numMethods; i++)
    1.61 +    {
    1.62 +      CMethodInfo2 info;
    1.63 +      info.FilePath = filePath;
    1.64 +      
    1.65 +      NWindows::NCOM::CPropVariant propVariant;
    1.66 +      if (getMethodProperty(i, NMethodPropID::kID, &propVariant) != S_OK)
    1.67 +        continue;
    1.68 +      if (propVariant.vt != VT_BSTR)
    1.69 +        continue;
    1.70 +      info.MethodID.IDSize = SysStringByteLen(propVariant.bstrVal);
    1.71 +      memmove(info.MethodID.ID, propVariant.bstrVal, info.MethodID.IDSize);
    1.72 +      propVariant.Clear();
    1.73 +      
    1.74 +      if (getMethodProperty(i, NMethodPropID::kName, &propVariant) != S_OK)
    1.75 +        continue;
    1.76 +      if (propVariant.vt == VT_EMPTY)
    1.77 +      {
    1.78 +      }
    1.79 +      else if (propVariant.vt == VT_BSTR)
    1.80 +        info.Name = propVariant.bstrVal;
    1.81 +      else
    1.82 +        continue;
    1.83 +      propVariant.Clear();
    1.84 +      
    1.85 +      if (getMethodProperty (i, NMethodPropID::kEncoder, &propVariant) != S_OK)
    1.86 +        continue;
    1.87 +      if (propVariant.vt == VT_EMPTY)
    1.88 +        info.EncoderIsAssigned = false;
    1.89 +      else if (propVariant.vt == VT_BSTR)
    1.90 +      {
    1.91 +        info.EncoderIsAssigned = true;
    1.92 +        info.Encoder = *(const GUID *)propVariant.bstrVal;
    1.93 +      }
    1.94 +      else
    1.95 +        continue;
    1.96 +      propVariant.Clear();
    1.97 +      
    1.98 +      if (getMethodProperty (i, NMethodPropID::kDecoder, &propVariant) != S_OK)
    1.99 +        continue;
   1.100 +      if (propVariant.vt == VT_EMPTY)
   1.101 +        info.DecoderIsAssigned = false;
   1.102 +      else if (propVariant.vt == VT_BSTR)
   1.103 +      {
   1.104 +        info.DecoderIsAssigned = true;
   1.105 +        info.Decoder = *(const GUID *)propVariant.bstrVal;
   1.106 +      }
   1.107 +      else
   1.108 +        continue;
   1.109 +      propVariant.Clear();
   1.110 +      
   1.111 +      if (getMethodProperty (i, NMethodPropID::kInStreams, &propVariant) != S_OK)
   1.112 +        continue;
   1.113 +      if (propVariant.vt == VT_EMPTY)
   1.114 +        info.NumInStreams = 1;
   1.115 +      else if (propVariant.vt == VT_UI4)
   1.116 +        info.NumInStreams = propVariant.ulVal;
   1.117 +      else
   1.118 +        continue;
   1.119 +      propVariant.Clear();
   1.120 +      
   1.121 +      if (getMethodProperty (i, NMethodPropID::kOutStreams, &propVariant) != S_OK)
   1.122 +        continue;
   1.123 +      if (propVariant.vt == VT_EMPTY)
   1.124 +        info.NumOutStreams = 1;
   1.125 +      else if (propVariant.vt == VT_UI4)
   1.126 +        info.NumOutStreams = propVariant.ulVal;
   1.127 +      else
   1.128 +        continue;
   1.129 +      propVariant.Clear();
   1.130 +      
   1.131 +      g_Methods.Add(info);
   1.132 +    }
   1.133 +  }
   1.134 +}
   1.135 +
   1.136 +static NSynchronization::CCriticalSection g_CriticalSection;
   1.137 +
   1.138 +void LoadMethodMap()
   1.139 +{
   1.140 +  NSynchronization::CCriticalSectionLock lock(g_CriticalSection);
   1.141 +  if (g_Loaded)
   1.142 +    return;
   1.143 +  g_Loaded = true;
   1.144 +  Load(GetCodecsFolderPrefix());
   1.145 +}
   1.146 +
   1.147 +bool GetMethodInfo(const CMethodID &methodID, CMethodInfo &methodInfo)
   1.148 +{
   1.149 +  for(int i = 0; i < g_Methods.Size(); i++)
   1.150 +  {
   1.151 +    const CMethodInfo2 &method = g_Methods[i];
   1.152 +    if (method.MethodID == methodID)
   1.153 +    {
   1.154 +      methodInfo = (CMethodInfo)method;
   1.155 +      return true;
   1.156 +    }
   1.157 +  }
   1.158 +  return false;
   1.159 +}
   1.160 +
   1.161 +bool GetMethodInfo(const UString &name, CMethodInfo2 &methodInfo)
   1.162 +{
   1.163 +  for(int i = 0; i < g_Methods.Size(); i++)
   1.164 +  {
   1.165 +    const CMethodInfo2 &method = g_Methods[i];
   1.166 +    if (method.Name.CompareNoCase(name) == 0)
   1.167 +    {
   1.168 +      methodInfo = method;
   1.169 +      return true;
   1.170 +    }
   1.171 +  }
   1.172 +  return false;
   1.173 +}
   1.174 +
   1.175 +}}
   1.176 +
   1.177 +

mercurial