1baa3858d3f5d128a5c8466b700098109edcad5f2repo sync// 7zHandler.cpp 2baa3858d3f5d128a5c8466b700098109edcad5f2repo sync 3baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#include "StdAfx.h" 4baa3858d3f5d128a5c8466b700098109edcad5f2repo sync 5baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#include "../../../../C/CpuArch.h" 6baa3858d3f5d128a5c8466b700098109edcad5f2repo sync 7baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#include "../../../Common/ComTry.h" 8baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#include "../../../Common/IntToString.h" 9baa3858d3f5d128a5c8466b700098109edcad5f2repo sync 10baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#ifndef __7Z_SET_PROPERTIES 11baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#include "../../../Windows/System.h" 12baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#endif 13baa3858d3f5d128a5c8466b700098109edcad5f2repo sync 14baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#include "../Common/ItemNameUtils.h" 15baa3858d3f5d128a5c8466b700098109edcad5f2repo sync 16baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#include "7zHandler.h" 17baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#include "7zProperties.h" 18baa3858d3f5d128a5c8466b700098109edcad5f2repo sync 19baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#ifdef __7Z_SET_PROPERTIES 20baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#ifdef EXTRACT_ONLY 21baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#include "../Common/ParseProperties.h" 22baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#endif 23baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#endif 24baa3858d3f5d128a5c8466b700098109edcad5f2repo sync 25baa3858d3f5d128a5c8466b700098109edcad5f2repo syncusing namespace NWindows; 26baa3858d3f5d128a5c8466b700098109edcad5f2repo sync 27baa3858d3f5d128a5c8466b700098109edcad5f2repo syncextern UString ConvertMethodIdToString(UInt64 id); 28baa3858d3f5d128a5c8466b700098109edcad5f2repo sync 29baa3858d3f5d128a5c8466b700098109edcad5f2repo syncnamespace NArchive { 30baa3858d3f5d128a5c8466b700098109edcad5f2repo syncnamespace N7z { 31baa3858d3f5d128a5c8466b700098109edcad5f2repo sync 32baa3858d3f5d128a5c8466b700098109edcad5f2repo syncCHandler::CHandler() 33baa3858d3f5d128a5c8466b700098109edcad5f2repo sync{ 34baa3858d3f5d128a5c8466b700098109edcad5f2repo sync _crcSize = 4; 35baa3858d3f5d128a5c8466b700098109edcad5f2repo sync 36baa3858d3f5d128a5c8466b700098109edcad5f2repo sync #ifndef _NO_CRYPTO 37baa3858d3f5d128a5c8466b700098109edcad5f2repo sync _passwordIsDefined = false; 38baa3858d3f5d128a5c8466b700098109edcad5f2repo sync #endif 39baa3858d3f5d128a5c8466b700098109edcad5f2repo sync 40baa3858d3f5d128a5c8466b700098109edcad5f2repo sync #ifdef EXTRACT_ONLY 41baa3858d3f5d128a5c8466b700098109edcad5f2repo sync #ifdef __7Z_SET_PROPERTIES 42baa3858d3f5d128a5c8466b700098109edcad5f2repo sync _numThreads = NSystem::GetNumberOfProcessors(); 43baa3858d3f5d128a5c8466b700098109edcad5f2repo sync #endif 44baa3858d3f5d128a5c8466b700098109edcad5f2repo sync #else 45baa3858d3f5d128a5c8466b700098109edcad5f2repo sync Init(); 46baa3858d3f5d128a5c8466b700098109edcad5f2repo sync #endif 47baa3858d3f5d128a5c8466b700098109edcad5f2repo sync} 48baa3858d3f5d128a5c8466b700098109edcad5f2repo sync 49baa3858d3f5d128a5c8466b700098109edcad5f2repo syncSTDMETHODIMP CHandler::GetNumberOfItems(UInt32 *numItems) 50baa3858d3f5d128a5c8466b700098109edcad5f2repo sync{ 51baa3858d3f5d128a5c8466b700098109edcad5f2repo sync *numItems = _db.Files.Size(); 52baa3858d3f5d128a5c8466b700098109edcad5f2repo sync return S_OK; 53baa3858d3f5d128a5c8466b700098109edcad5f2repo sync} 54baa3858d3f5d128a5c8466b700098109edcad5f2repo sync 55baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#ifdef _SFX 56baa3858d3f5d128a5c8466b700098109edcad5f2repo sync 57baa3858d3f5d128a5c8466b700098109edcad5f2repo syncIMP_IInArchive_ArcProps_NO 58baa3858d3f5d128a5c8466b700098109edcad5f2repo sync 59baa3858d3f5d128a5c8466b700098109edcad5f2repo syncSTDMETHODIMP CHandler::GetNumberOfProperties(UInt32 * /* numProperties */) 60baa3858d3f5d128a5c8466b700098109edcad5f2repo sync{ 61baa3858d3f5d128a5c8466b700098109edcad5f2repo sync return E_NOTIMPL; 62baa3858d3f5d128a5c8466b700098109edcad5f2repo sync} 63baa3858d3f5d128a5c8466b700098109edcad5f2repo sync 64baa3858d3f5d128a5c8466b700098109edcad5f2repo syncSTDMETHODIMP CHandler::GetPropertyInfo(UInt32 /* index */, 65baa3858d3f5d128a5c8466b700098109edcad5f2repo sync BSTR * /* name */, PROPID * /* propID */, VARTYPE * /* varType */) 66baa3858d3f5d128a5c8466b700098109edcad5f2repo sync{ 67baa3858d3f5d128a5c8466b700098109edcad5f2repo sync return E_NOTIMPL; 68baa3858d3f5d128a5c8466b700098109edcad5f2repo sync} 69baa3858d3f5d128a5c8466b700098109edcad5f2repo sync 70baa3858d3f5d128a5c8466b700098109edcad5f2repo sync 71baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#else 72baa3858d3f5d128a5c8466b700098109edcad5f2repo sync 73baa3858d3f5d128a5c8466b700098109edcad5f2repo syncSTATPROPSTG kArcProps[] = 74baa3858d3f5d128a5c8466b700098109edcad5f2repo sync{ 75baa3858d3f5d128a5c8466b700098109edcad5f2repo sync { NULL, kpidMethod, VT_BSTR}, 76baa3858d3f5d128a5c8466b700098109edcad5f2repo sync { NULL, kpidSolid, VT_BOOL}, 77baa3858d3f5d128a5c8466b700098109edcad5f2repo sync { NULL, kpidNumBlocks, VT_UI4}, 78baa3858d3f5d128a5c8466b700098109edcad5f2repo sync { NULL, kpidPhySize, VT_UI8}, 79baa3858d3f5d128a5c8466b700098109edcad5f2repo sync { NULL, kpidHeadersSize, VT_UI8}, 80baa3858d3f5d128a5c8466b700098109edcad5f2repo sync { NULL, kpidOffset, VT_UI8} 81baa3858d3f5d128a5c8466b700098109edcad5f2repo sync}; 82baa3858d3f5d128a5c8466b700098109edcad5f2repo sync 83baa3858d3f5d128a5c8466b700098109edcad5f2repo syncSTDMETHODIMP CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value) 84baa3858d3f5d128a5c8466b700098109edcad5f2repo sync{ 85baa3858d3f5d128a5c8466b700098109edcad5f2repo sync COM_TRY_BEGIN 86baa3858d3f5d128a5c8466b700098109edcad5f2repo sync NCOM::CPropVariant prop; 87baa3858d3f5d128a5c8466b700098109edcad5f2repo sync switch(propID) 88baa3858d3f5d128a5c8466b700098109edcad5f2repo sync { 89baa3858d3f5d128a5c8466b700098109edcad5f2repo sync case kpidMethod: 90baa3858d3f5d128a5c8466b700098109edcad5f2repo sync { 91baa3858d3f5d128a5c8466b700098109edcad5f2repo sync UString resString; 92baa3858d3f5d128a5c8466b700098109edcad5f2repo sync CRecordVector<UInt64> ids; 93baa3858d3f5d128a5c8466b700098109edcad5f2repo sync int i; 94baa3858d3f5d128a5c8466b700098109edcad5f2repo sync for (i = 0; i < _db.Folders.Size(); i++) 95baa3858d3f5d128a5c8466b700098109edcad5f2repo sync { 96baa3858d3f5d128a5c8466b700098109edcad5f2repo sync const CFolder &f = _db.Folders[i]; 97baa3858d3f5d128a5c8466b700098109edcad5f2repo sync for (int j = f.Coders.Size() - 1; j >= 0; j--) 98baa3858d3f5d128a5c8466b700098109edcad5f2repo sync ids.AddToUniqueSorted(f.Coders[j].MethodID); 99baa3858d3f5d128a5c8466b700098109edcad5f2repo sync } 100baa3858d3f5d128a5c8466b700098109edcad5f2repo sync 101baa3858d3f5d128a5c8466b700098109edcad5f2repo sync for (i = 0; i < ids.Size(); i++) 102baa3858d3f5d128a5c8466b700098109edcad5f2repo sync { 103baa3858d3f5d128a5c8466b700098109edcad5f2repo sync UInt64 id = ids[i]; 104baa3858d3f5d128a5c8466b700098109edcad5f2repo sync UString methodName; 105baa3858d3f5d128a5c8466b700098109edcad5f2repo sync /* bool methodIsKnown = */ FindMethod(EXTERNAL_CODECS_VARS id, methodName); 106baa3858d3f5d128a5c8466b700098109edcad5f2repo sync if (methodName.IsEmpty()) 107baa3858d3f5d128a5c8466b700098109edcad5f2repo sync methodName = ConvertMethodIdToString(id); 108baa3858d3f5d128a5c8466b700098109edcad5f2repo sync if (!resString.IsEmpty()) 109baa3858d3f5d128a5c8466b700098109edcad5f2repo sync resString += L' '; 110baa3858d3f5d128a5c8466b700098109edcad5f2repo sync resString += methodName; 111baa3858d3f5d128a5c8466b700098109edcad5f2repo sync } 112baa3858d3f5d128a5c8466b700098109edcad5f2repo sync prop = resString; 113baa3858d3f5d128a5c8466b700098109edcad5f2repo sync break; 114baa3858d3f5d128a5c8466b700098109edcad5f2repo sync } 115baa3858d3f5d128a5c8466b700098109edcad5f2repo sync case kpidSolid: prop = _db.IsSolid(); break; 116baa3858d3f5d128a5c8466b700098109edcad5f2repo sync case kpidNumBlocks: prop = (UInt32)_db.Folders.Size(); break; 117baa3858d3f5d128a5c8466b700098109edcad5f2repo sync case kpidHeadersSize: prop = _db.HeadersSize; break; 118baa3858d3f5d128a5c8466b700098109edcad5f2repo sync case kpidPhySize: prop = _db.PhySize; break; 119baa3858d3f5d128a5c8466b700098109edcad5f2repo sync case kpidOffset: if (_db.ArchiveInfo.StartPosition != 0) prop = _db.ArchiveInfo.StartPosition; break; 120baa3858d3f5d128a5c8466b700098109edcad5f2repo sync } 121baa3858d3f5d128a5c8466b700098109edcad5f2repo sync prop.Detach(value); 122baa3858d3f5d128a5c8466b700098109edcad5f2repo sync return S_OK; 123baa3858d3f5d128a5c8466b700098109edcad5f2repo sync COM_TRY_END 124baa3858d3f5d128a5c8466b700098109edcad5f2repo sync} 125baa3858d3f5d128a5c8466b700098109edcad5f2repo sync 126baa3858d3f5d128a5c8466b700098109edcad5f2repo syncIMP_IInArchive_ArcProps 127baa3858d3f5d128a5c8466b700098109edcad5f2repo sync 128baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#endif 129baa3858d3f5d128a5c8466b700098109edcad5f2repo sync 130baa3858d3f5d128a5c8466b700098109edcad5f2repo syncstatic void SetPropFromUInt64Def(CUInt64DefVector &v, int index, NCOM::CPropVariant &prop) 131baa3858d3f5d128a5c8466b700098109edcad5f2repo sync{ 132baa3858d3f5d128a5c8466b700098109edcad5f2repo sync UInt64 value; 133baa3858d3f5d128a5c8466b700098109edcad5f2repo sync if (v.GetItem(index, value)) 134baa3858d3f5d128a5c8466b700098109edcad5f2repo sync { 135baa3858d3f5d128a5c8466b700098109edcad5f2repo sync FILETIME ft; 136baa3858d3f5d128a5c8466b700098109edcad5f2repo sync ft.dwLowDateTime = (DWORD)value; 137baa3858d3f5d128a5c8466b700098109edcad5f2repo sync ft.dwHighDateTime = (DWORD)(value >> 32); 138baa3858d3f5d128a5c8466b700098109edcad5f2repo sync prop = ft; 139baa3858d3f5d128a5c8466b700098109edcad5f2repo sync } 140baa3858d3f5d128a5c8466b700098109edcad5f2repo sync} 141baa3858d3f5d128a5c8466b700098109edcad5f2repo sync 142baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#ifndef _SFX 143baa3858d3f5d128a5c8466b700098109edcad5f2repo sync 144baa3858d3f5d128a5c8466b700098109edcad5f2repo syncstatic UString ConvertUInt32ToString(UInt32 value) 145baa3858d3f5d128a5c8466b700098109edcad5f2repo sync{ 146baa3858d3f5d128a5c8466b700098109edcad5f2repo sync wchar_t buffer[32]; 147baa3858d3f5d128a5c8466b700098109edcad5f2repo sync ConvertUInt64ToString(value, buffer); 148baa3858d3f5d128a5c8466b700098109edcad5f2repo sync return buffer; 149baa3858d3f5d128a5c8466b700098109edcad5f2repo sync} 150baa3858d3f5d128a5c8466b700098109edcad5f2repo sync 151baa3858d3f5d128a5c8466b700098109edcad5f2repo syncstatic UString GetStringForSizeValue(UInt32 value) 152baa3858d3f5d128a5c8466b700098109edcad5f2repo sync{ 153baa3858d3f5d128a5c8466b700098109edcad5f2repo sync for (int i = 31; i >= 0; i--) 154baa3858d3f5d128a5c8466b700098109edcad5f2repo sync if ((UInt32(1) << i) == value) 155baa3858d3f5d128a5c8466b700098109edcad5f2repo sync return ConvertUInt32ToString(i); 156baa3858d3f5d128a5c8466b700098109edcad5f2repo sync UString result; 157baa3858d3f5d128a5c8466b700098109edcad5f2repo sync if (value % (1 << 20) == 0) 158baa3858d3f5d128a5c8466b700098109edcad5f2repo sync { 159baa3858d3f5d128a5c8466b700098109edcad5f2repo sync result += ConvertUInt32ToString(value >> 20); 160baa3858d3f5d128a5c8466b700098109edcad5f2repo sync result += L"m"; 161baa3858d3f5d128a5c8466b700098109edcad5f2repo sync } 162baa3858d3f5d128a5c8466b700098109edcad5f2repo sync else if (value % (1 << 10) == 0) 163baa3858d3f5d128a5c8466b700098109edcad5f2repo sync { 164baa3858d3f5d128a5c8466b700098109edcad5f2repo sync result += ConvertUInt32ToString(value >> 10); 165baa3858d3f5d128a5c8466b700098109edcad5f2repo sync result += L"k"; 166baa3858d3f5d128a5c8466b700098109edcad5f2repo sync } 167baa3858d3f5d128a5c8466b700098109edcad5f2repo sync else 168baa3858d3f5d128a5c8466b700098109edcad5f2repo sync { 169baa3858d3f5d128a5c8466b700098109edcad5f2repo sync result += ConvertUInt32ToString(value); 170baa3858d3f5d128a5c8466b700098109edcad5f2repo sync result += L"b"; 171baa3858d3f5d128a5c8466b700098109edcad5f2repo sync } 172baa3858d3f5d128a5c8466b700098109edcad5f2repo sync return result; 173baa3858d3f5d128a5c8466b700098109edcad5f2repo sync} 174baa3858d3f5d128a5c8466b700098109edcad5f2repo sync 175baa3858d3f5d128a5c8466b700098109edcad5f2repo syncstatic const UInt64 k_Copy = 0x0; 176baa3858d3f5d128a5c8466b700098109edcad5f2repo syncstatic const UInt64 k_Delta = 3; 177baa3858d3f5d128a5c8466b700098109edcad5f2repo syncstatic const UInt64 k_LZMA2 = 0x21; 178baa3858d3f5d128a5c8466b700098109edcad5f2repo syncstatic const UInt64 k_LZMA = 0x030101; 179baa3858d3f5d128a5c8466b700098109edcad5f2repo syncstatic const UInt64 k_PPMD = 0x030401; 180baa3858d3f5d128a5c8466b700098109edcad5f2repo sync 181baa3858d3f5d128a5c8466b700098109edcad5f2repo syncstatic wchar_t GetHex(Byte value) 182baa3858d3f5d128a5c8466b700098109edcad5f2repo sync{ 183baa3858d3f5d128a5c8466b700098109edcad5f2repo sync return (wchar_t)((value < 10) ? (L'0' + value) : (L'A' + (value - 10))); 184baa3858d3f5d128a5c8466b700098109edcad5f2repo sync} 185baa3858d3f5d128a5c8466b700098109edcad5f2repo syncstatic inline void AddHexToString(UString &res, Byte value) 186baa3858d3f5d128a5c8466b700098109edcad5f2repo sync{ 187baa3858d3f5d128a5c8466b700098109edcad5f2repo sync res += GetHex((Byte)(value >> 4)); 188baa3858d3f5d128a5c8466b700098109edcad5f2repo sync res += GetHex((Byte)(value & 0xF)); 189baa3858d3f5d128a5c8466b700098109edcad5f2repo sync} 190baa3858d3f5d128a5c8466b700098109edcad5f2repo sync 191baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#endif 192baa3858d3f5d128a5c8466b700098109edcad5f2repo sync 193baa3858d3f5d128a5c8466b700098109edcad5f2repo syncbool CHandler::IsEncrypted(UInt32 index2) const 194baa3858d3f5d128a5c8466b700098109edcad5f2repo sync{ 195baa3858d3f5d128a5c8466b700098109edcad5f2repo sync CNum folderIndex = _db.FileIndexToFolderIndexMap[index2]; 196baa3858d3f5d128a5c8466b700098109edcad5f2repo sync if (folderIndex != kNumNoIndex) 197baa3858d3f5d128a5c8466b700098109edcad5f2repo sync return _db.Folders[folderIndex].IsEncrypted(); 198baa3858d3f5d128a5c8466b700098109edcad5f2repo sync return false; 199baa3858d3f5d128a5c8466b700098109edcad5f2repo sync} 200baa3858d3f5d128a5c8466b700098109edcad5f2repo sync 201baa3858d3f5d128a5c8466b700098109edcad5f2repo syncSTDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *value) 202baa3858d3f5d128a5c8466b700098109edcad5f2repo sync{ 203baa3858d3f5d128a5c8466b700098109edcad5f2repo sync COM_TRY_BEGIN 204baa3858d3f5d128a5c8466b700098109edcad5f2repo sync NCOM::CPropVariant prop; 205baa3858d3f5d128a5c8466b700098109edcad5f2repo sync 206baa3858d3f5d128a5c8466b700098109edcad5f2repo sync /* 207baa3858d3f5d128a5c8466b700098109edcad5f2repo sync const CRef2 &ref2 = _refs[index]; 208baa3858d3f5d128a5c8466b700098109edcad5f2repo sync if (ref2.Refs.IsEmpty()) 209baa3858d3f5d128a5c8466b700098109edcad5f2repo sync return E_FAIL; 210baa3858d3f5d128a5c8466b700098109edcad5f2repo sync const CRef &ref = ref2.Refs.Front(); 211baa3858d3f5d128a5c8466b700098109edcad5f2repo sync */ 212baa3858d3f5d128a5c8466b700098109edcad5f2repo sync 213baa3858d3f5d128a5c8466b700098109edcad5f2repo sync const CFileItem &item = _db.Files[index]; 214baa3858d3f5d128a5c8466b700098109edcad5f2repo sync UInt32 index2 = index; 215baa3858d3f5d128a5c8466b700098109edcad5f2repo sync 216baa3858d3f5d128a5c8466b700098109edcad5f2repo sync switch(propID) 217baa3858d3f5d128a5c8466b700098109edcad5f2repo sync { 218baa3858d3f5d128a5c8466b700098109edcad5f2repo sync case kpidPath: 219baa3858d3f5d128a5c8466b700098109edcad5f2repo sync if (!item.Name.IsEmpty()) 220baa3858d3f5d128a5c8466b700098109edcad5f2repo sync prop = NItemName::GetOSName(item.Name); 221baa3858d3f5d128a5c8466b700098109edcad5f2repo sync break; 222baa3858d3f5d128a5c8466b700098109edcad5f2repo sync case kpidIsDir: prop = item.IsDir; break; 223baa3858d3f5d128a5c8466b700098109edcad5f2repo sync case kpidSize: 224baa3858d3f5d128a5c8466b700098109edcad5f2repo sync { 225baa3858d3f5d128a5c8466b700098109edcad5f2repo sync prop = item.Size; 226baa3858d3f5d128a5c8466b700098109edcad5f2repo sync // prop = ref2.Size; 227baa3858d3f5d128a5c8466b700098109edcad5f2repo sync break; 228baa3858d3f5d128a5c8466b700098109edcad5f2repo sync } 229baa3858d3f5d128a5c8466b700098109edcad5f2repo sync case kpidPackSize: 230baa3858d3f5d128a5c8466b700098109edcad5f2repo sync { 231baa3858d3f5d128a5c8466b700098109edcad5f2repo sync // prop = ref2.PackSize; 232baa3858d3f5d128a5c8466b700098109edcad5f2repo sync { 233baa3858d3f5d128a5c8466b700098109edcad5f2repo sync CNum folderIndex = _db.FileIndexToFolderIndexMap[index2]; 234baa3858d3f5d128a5c8466b700098109edcad5f2repo sync if (folderIndex != kNumNoIndex) 235baa3858d3f5d128a5c8466b700098109edcad5f2repo sync { 236baa3858d3f5d128a5c8466b700098109edcad5f2repo sync if (_db.FolderStartFileIndex[folderIndex] == (CNum)index2) 237baa3858d3f5d128a5c8466b700098109edcad5f2repo sync prop = _db.GetFolderFullPackSize(folderIndex); 238baa3858d3f5d128a5c8466b700098109edcad5f2repo sync /* 239baa3858d3f5d128a5c8466b700098109edcad5f2repo sync else 240baa3858d3f5d128a5c8466b700098109edcad5f2repo sync prop = (UInt64)0; 241baa3858d3f5d128a5c8466b700098109edcad5f2repo sync */ 242baa3858d3f5d128a5c8466b700098109edcad5f2repo sync } 243baa3858d3f5d128a5c8466b700098109edcad5f2repo sync else 244baa3858d3f5d128a5c8466b700098109edcad5f2repo sync prop = (UInt64)0; 245baa3858d3f5d128a5c8466b700098109edcad5f2repo sync } 246baa3858d3f5d128a5c8466b700098109edcad5f2repo sync break; 247baa3858d3f5d128a5c8466b700098109edcad5f2repo sync } 248baa3858d3f5d128a5c8466b700098109edcad5f2repo sync case kpidPosition: { UInt64 v; if (_db.StartPos.GetItem(index2, v)) prop = v; break; } 249baa3858d3f5d128a5c8466b700098109edcad5f2repo sync case kpidCTime: SetPropFromUInt64Def(_db.CTime, index2, prop); break; 250baa3858d3f5d128a5c8466b700098109edcad5f2repo sync case kpidATime: SetPropFromUInt64Def(_db.ATime, index2, prop); break; 251baa3858d3f5d128a5c8466b700098109edcad5f2repo sync case kpidMTime: SetPropFromUInt64Def(_db.MTime, index2, prop); break; 252baa3858d3f5d128a5c8466b700098109edcad5f2repo sync case kpidAttrib: if (item.AttribDefined) prop = item.Attrib; break; 253baa3858d3f5d128a5c8466b700098109edcad5f2repo sync case kpidCRC: if (item.CrcDefined) prop = item.Crc; break; 254baa3858d3f5d128a5c8466b700098109edcad5f2repo sync case kpidEncrypted: prop = IsEncrypted(index2); break; 255baa3858d3f5d128a5c8466b700098109edcad5f2repo sync case kpidIsAnti: prop = _db.IsItemAnti(index2); break; 256baa3858d3f5d128a5c8466b700098109edcad5f2repo sync #ifndef _SFX 257baa3858d3f5d128a5c8466b700098109edcad5f2repo sync case kpidMethod: 258baa3858d3f5d128a5c8466b700098109edcad5f2repo sync { 259baa3858d3f5d128a5c8466b700098109edcad5f2repo sync CNum folderIndex = _db.FileIndexToFolderIndexMap[index2]; 260baa3858d3f5d128a5c8466b700098109edcad5f2repo sync if (folderIndex != kNumNoIndex) 261baa3858d3f5d128a5c8466b700098109edcad5f2repo sync { 262baa3858d3f5d128a5c8466b700098109edcad5f2repo sync const CFolder &folderInfo = _db.Folders[folderIndex]; 263baa3858d3f5d128a5c8466b700098109edcad5f2repo sync UString methodsString; 264baa3858d3f5d128a5c8466b700098109edcad5f2repo sync for (int i = folderInfo.Coders.Size() - 1; i >= 0; i--) 265baa3858d3f5d128a5c8466b700098109edcad5f2repo sync { 266baa3858d3f5d128a5c8466b700098109edcad5f2repo sync const CCoderInfo &coder = folderInfo.Coders[i]; 267baa3858d3f5d128a5c8466b700098109edcad5f2repo sync if (!methodsString.IsEmpty()) 268baa3858d3f5d128a5c8466b700098109edcad5f2repo sync methodsString += L' '; 269baa3858d3f5d128a5c8466b700098109edcad5f2repo sync 270baa3858d3f5d128a5c8466b700098109edcad5f2repo sync UString methodName, propsString; 271baa3858d3f5d128a5c8466b700098109edcad5f2repo sync bool methodIsKnown = FindMethod( 272baa3858d3f5d128a5c8466b700098109edcad5f2repo sync EXTERNAL_CODECS_VARS 273baa3858d3f5d128a5c8466b700098109edcad5f2repo sync coder.MethodID, methodName); 274baa3858d3f5d128a5c8466b700098109edcad5f2repo sync 275baa3858d3f5d128a5c8466b700098109edcad5f2repo sync if (!methodIsKnown) 276baa3858d3f5d128a5c8466b700098109edcad5f2repo sync methodsString += ConvertMethodIdToString(coder.MethodID); 277baa3858d3f5d128a5c8466b700098109edcad5f2repo sync else 278baa3858d3f5d128a5c8466b700098109edcad5f2repo sync { 279baa3858d3f5d128a5c8466b700098109edcad5f2repo sync methodsString += methodName; 280baa3858d3f5d128a5c8466b700098109edcad5f2repo sync if (coder.MethodID == k_Delta && coder.Props.GetCapacity() == 1) 281baa3858d3f5d128a5c8466b700098109edcad5f2repo sync propsString = ConvertUInt32ToString((UInt32)coder.Props[0] + 1); 282baa3858d3f5d128a5c8466b700098109edcad5f2repo sync else if (coder.MethodID == k_LZMA && coder.Props.GetCapacity() == 5) 283baa3858d3f5d128a5c8466b700098109edcad5f2repo sync { 284baa3858d3f5d128a5c8466b700098109edcad5f2repo sync UInt32 dicSize = GetUi32((const Byte *)coder.Props + 1); 285baa3858d3f5d128a5c8466b700098109edcad5f2repo sync propsString = GetStringForSizeValue(dicSize); 286baa3858d3f5d128a5c8466b700098109edcad5f2repo sync } 287baa3858d3f5d128a5c8466b700098109edcad5f2repo sync else if (coder.MethodID == k_LZMA2 && coder.Props.GetCapacity() == 1) 288baa3858d3f5d128a5c8466b700098109edcad5f2repo sync { 289baa3858d3f5d128a5c8466b700098109edcad5f2repo sync Byte p = coder.Props[0]; 290baa3858d3f5d128a5c8466b700098109edcad5f2repo sync UInt32 dicSize = (((UInt32)2 | ((p) & 1)) << ((p) / 2 + 11)); 291baa3858d3f5d128a5c8466b700098109edcad5f2repo sync propsString = GetStringForSizeValue(dicSize); 292baa3858d3f5d128a5c8466b700098109edcad5f2repo sync } 293baa3858d3f5d128a5c8466b700098109edcad5f2repo sync else if (coder.MethodID == k_PPMD && coder.Props.GetCapacity() == 5) 294baa3858d3f5d128a5c8466b700098109edcad5f2repo sync { 295baa3858d3f5d128a5c8466b700098109edcad5f2repo sync Byte order = *(const Byte *)coder.Props; 296baa3858d3f5d128a5c8466b700098109edcad5f2repo sync propsString = L'o'; 297baa3858d3f5d128a5c8466b700098109edcad5f2repo sync propsString += ConvertUInt32ToString(order); 298baa3858d3f5d128a5c8466b700098109edcad5f2repo sync propsString += L":mem"; 299baa3858d3f5d128a5c8466b700098109edcad5f2repo sync UInt32 dicSize = GetUi32((const Byte *)coder.Props + 1); 300baa3858d3f5d128a5c8466b700098109edcad5f2repo sync propsString += GetStringForSizeValue(dicSize); 301baa3858d3f5d128a5c8466b700098109edcad5f2repo sync } 302baa3858d3f5d128a5c8466b700098109edcad5f2repo sync else if (coder.MethodID == k_AES && coder.Props.GetCapacity() >= 1) 303baa3858d3f5d128a5c8466b700098109edcad5f2repo sync { 304baa3858d3f5d128a5c8466b700098109edcad5f2repo sync const Byte *data = (const Byte *)coder.Props; 305baa3858d3f5d128a5c8466b700098109edcad5f2repo sync Byte firstByte = *data++; 306baa3858d3f5d128a5c8466b700098109edcad5f2repo sync UInt32 numCyclesPower = firstByte & 0x3F; 307baa3858d3f5d128a5c8466b700098109edcad5f2repo sync propsString = ConvertUInt32ToString(numCyclesPower); 308baa3858d3f5d128a5c8466b700098109edcad5f2repo sync /* 309baa3858d3f5d128a5c8466b700098109edcad5f2repo sync if ((firstByte & 0xC0) != 0) 310baa3858d3f5d128a5c8466b700098109edcad5f2repo sync { 311baa3858d3f5d128a5c8466b700098109edcad5f2repo sync UInt32 saltSize = (firstByte >> 7) & 1; 312baa3858d3f5d128a5c8466b700098109edcad5f2repo sync UInt32 ivSize = (firstByte >> 6) & 1; 313baa3858d3f5d128a5c8466b700098109edcad5f2repo sync if (coder.Props.GetCapacity() >= 2) 314baa3858d3f5d128a5c8466b700098109edcad5f2repo sync { 315baa3858d3f5d128a5c8466b700098109edcad5f2repo sync Byte secondByte = *data++; 316baa3858d3f5d128a5c8466b700098109edcad5f2repo sync saltSize += (secondByte >> 4); 317baa3858d3f5d128a5c8466b700098109edcad5f2repo sync ivSize += (secondByte & 0x0F); 318baa3858d3f5d128a5c8466b700098109edcad5f2repo sync } 319baa3858d3f5d128a5c8466b700098109edcad5f2repo sync } 320baa3858d3f5d128a5c8466b700098109edcad5f2repo sync */ 321baa3858d3f5d128a5c8466b700098109edcad5f2repo sync } 322baa3858d3f5d128a5c8466b700098109edcad5f2repo sync } 323baa3858d3f5d128a5c8466b700098109edcad5f2repo sync if (!propsString.IsEmpty()) 324baa3858d3f5d128a5c8466b700098109edcad5f2repo sync { 325baa3858d3f5d128a5c8466b700098109edcad5f2repo sync methodsString += L':'; 326baa3858d3f5d128a5c8466b700098109edcad5f2repo sync methodsString += propsString; 327baa3858d3f5d128a5c8466b700098109edcad5f2repo sync } 328baa3858d3f5d128a5c8466b700098109edcad5f2repo sync else if (coder.Props.GetCapacity() > 0) 329baa3858d3f5d128a5c8466b700098109edcad5f2repo sync { 330baa3858d3f5d128a5c8466b700098109edcad5f2repo sync methodsString += L":["; 331baa3858d3f5d128a5c8466b700098109edcad5f2repo sync for (size_t bi = 0; bi < coder.Props.GetCapacity(); bi++) 332baa3858d3f5d128a5c8466b700098109edcad5f2repo sync { 333baa3858d3f5d128a5c8466b700098109edcad5f2repo sync if (bi > 5 && bi + 1 < coder.Props.GetCapacity()) 334baa3858d3f5d128a5c8466b700098109edcad5f2repo sync { 335baa3858d3f5d128a5c8466b700098109edcad5f2repo sync methodsString += L".."; 336baa3858d3f5d128a5c8466b700098109edcad5f2repo sync break; 337baa3858d3f5d128a5c8466b700098109edcad5f2repo sync } 338baa3858d3f5d128a5c8466b700098109edcad5f2repo sync else 339baa3858d3f5d128a5c8466b700098109edcad5f2repo sync AddHexToString(methodsString, coder.Props[bi]); 340baa3858d3f5d128a5c8466b700098109edcad5f2repo sync } 341baa3858d3f5d128a5c8466b700098109edcad5f2repo sync methodsString += L']'; 342baa3858d3f5d128a5c8466b700098109edcad5f2repo sync } 343baa3858d3f5d128a5c8466b700098109edcad5f2repo sync } 344baa3858d3f5d128a5c8466b700098109edcad5f2repo sync prop = methodsString; 345baa3858d3f5d128a5c8466b700098109edcad5f2repo sync } 346baa3858d3f5d128a5c8466b700098109edcad5f2repo sync } 347baa3858d3f5d128a5c8466b700098109edcad5f2repo sync break; 348baa3858d3f5d128a5c8466b700098109edcad5f2repo sync case kpidBlock: 349baa3858d3f5d128a5c8466b700098109edcad5f2repo sync { 350baa3858d3f5d128a5c8466b700098109edcad5f2repo sync CNum folderIndex = _db.FileIndexToFolderIndexMap[index2]; 351baa3858d3f5d128a5c8466b700098109edcad5f2repo sync if (folderIndex != kNumNoIndex) 352baa3858d3f5d128a5c8466b700098109edcad5f2repo sync prop = (UInt32)folderIndex; 353baa3858d3f5d128a5c8466b700098109edcad5f2repo sync } 354baa3858d3f5d128a5c8466b700098109edcad5f2repo sync break; 355baa3858d3f5d128a5c8466b700098109edcad5f2repo sync case kpidPackedSize0: 356baa3858d3f5d128a5c8466b700098109edcad5f2repo sync case kpidPackedSize1: 357baa3858d3f5d128a5c8466b700098109edcad5f2repo sync case kpidPackedSize2: 358baa3858d3f5d128a5c8466b700098109edcad5f2repo sync case kpidPackedSize3: 359baa3858d3f5d128a5c8466b700098109edcad5f2repo sync case kpidPackedSize4: 360baa3858d3f5d128a5c8466b700098109edcad5f2repo sync { 361baa3858d3f5d128a5c8466b700098109edcad5f2repo sync CNum folderIndex = _db.FileIndexToFolderIndexMap[index2]; 362baa3858d3f5d128a5c8466b700098109edcad5f2repo sync if (folderIndex != kNumNoIndex) 363baa3858d3f5d128a5c8466b700098109edcad5f2repo sync { 364baa3858d3f5d128a5c8466b700098109edcad5f2repo sync const CFolder &folderInfo = _db.Folders[folderIndex]; 365baa3858d3f5d128a5c8466b700098109edcad5f2repo sync if (_db.FolderStartFileIndex[folderIndex] == (CNum)index2 && 366baa3858d3f5d128a5c8466b700098109edcad5f2repo sync folderInfo.PackStreams.Size() > (int)(propID - kpidPackedSize0)) 367baa3858d3f5d128a5c8466b700098109edcad5f2repo sync { 368baa3858d3f5d128a5c8466b700098109edcad5f2repo sync prop = _db.GetFolderPackStreamSize(folderIndex, propID - kpidPackedSize0); 369baa3858d3f5d128a5c8466b700098109edcad5f2repo sync } 370baa3858d3f5d128a5c8466b700098109edcad5f2repo sync else 371baa3858d3f5d128a5c8466b700098109edcad5f2repo sync prop = (UInt64)0; 372baa3858d3f5d128a5c8466b700098109edcad5f2repo sync } 373baa3858d3f5d128a5c8466b700098109edcad5f2repo sync else 374baa3858d3f5d128a5c8466b700098109edcad5f2repo sync prop = (UInt64)0; 375baa3858d3f5d128a5c8466b700098109edcad5f2repo sync } 376baa3858d3f5d128a5c8466b700098109edcad5f2repo sync break; 377baa3858d3f5d128a5c8466b700098109edcad5f2repo sync #endif 378baa3858d3f5d128a5c8466b700098109edcad5f2repo sync } 379baa3858d3f5d128a5c8466b700098109edcad5f2repo sync prop.Detach(value); 380baa3858d3f5d128a5c8466b700098109edcad5f2repo sync return S_OK; 381baa3858d3f5d128a5c8466b700098109edcad5f2repo sync COM_TRY_END 382baa3858d3f5d128a5c8466b700098109edcad5f2repo sync} 383baa3858d3f5d128a5c8466b700098109edcad5f2repo sync 384baa3858d3f5d128a5c8466b700098109edcad5f2repo syncSTDMETHODIMP CHandler::Open(IInStream *stream, 385baa3858d3f5d128a5c8466b700098109edcad5f2repo sync const UInt64 *maxCheckStartPosition, 386baa3858d3f5d128a5c8466b700098109edcad5f2repo sync IArchiveOpenCallback *openArchiveCallback) 387baa3858d3f5d128a5c8466b700098109edcad5f2repo sync{ 388baa3858d3f5d128a5c8466b700098109edcad5f2repo sync COM_TRY_BEGIN 389baa3858d3f5d128a5c8466b700098109edcad5f2repo sync Close(); 390baa3858d3f5d128a5c8466b700098109edcad5f2repo sync #ifndef _SFX 391baa3858d3f5d128a5c8466b700098109edcad5f2repo sync _fileInfoPopIDs.Clear(); 392baa3858d3f5d128a5c8466b700098109edcad5f2repo sync #endif 393baa3858d3f5d128a5c8466b700098109edcad5f2repo sync try 394baa3858d3f5d128a5c8466b700098109edcad5f2repo sync { 395baa3858d3f5d128a5c8466b700098109edcad5f2repo sync CMyComPtr<IArchiveOpenCallback> openArchiveCallbackTemp = openArchiveCallback; 396baa3858d3f5d128a5c8466b700098109edcad5f2repo sync 397baa3858d3f5d128a5c8466b700098109edcad5f2repo sync #ifndef _NO_CRYPTO 398baa3858d3f5d128a5c8466b700098109edcad5f2repo sync CMyComPtr<ICryptoGetTextPassword> getTextPassword; 399baa3858d3f5d128a5c8466b700098109edcad5f2repo sync if (openArchiveCallback) 400baa3858d3f5d128a5c8466b700098109edcad5f2repo sync { 401baa3858d3f5d128a5c8466b700098109edcad5f2repo sync openArchiveCallbackTemp.QueryInterface( 402baa3858d3f5d128a5c8466b700098109edcad5f2repo sync IID_ICryptoGetTextPassword, &getTextPassword); 403baa3858d3f5d128a5c8466b700098109edcad5f2repo sync } 404baa3858d3f5d128a5c8466b700098109edcad5f2repo sync #endif 405baa3858d3f5d128a5c8466b700098109edcad5f2repo sync CInArchive archive; 406baa3858d3f5d128a5c8466b700098109edcad5f2repo sync RINOK(archive.Open(stream, maxCheckStartPosition)); 407baa3858d3f5d128a5c8466b700098109edcad5f2repo sync #ifndef _NO_CRYPTO 408baa3858d3f5d128a5c8466b700098109edcad5f2repo sync _passwordIsDefined = false; 409baa3858d3f5d128a5c8466b700098109edcad5f2repo sync UString password; 410baa3858d3f5d128a5c8466b700098109edcad5f2repo sync #endif 411baa3858d3f5d128a5c8466b700098109edcad5f2repo sync HRESULT result = archive.ReadDatabase( 412baa3858d3f5d128a5c8466b700098109edcad5f2repo sync EXTERNAL_CODECS_VARS 413baa3858d3f5d128a5c8466b700098109edcad5f2repo sync _db 414baa3858d3f5d128a5c8466b700098109edcad5f2repo sync #ifndef _NO_CRYPTO 415baa3858d3f5d128a5c8466b700098109edcad5f2repo sync , getTextPassword, _passwordIsDefined 416baa3858d3f5d128a5c8466b700098109edcad5f2repo sync #endif 417baa3858d3f5d128a5c8466b700098109edcad5f2repo sync ); 418baa3858d3f5d128a5c8466b700098109edcad5f2repo sync RINOK(result); 419baa3858d3f5d128a5c8466b700098109edcad5f2repo sync _db.Fill(); 420baa3858d3f5d128a5c8466b700098109edcad5f2repo sync _inStream = stream; 421baa3858d3f5d128a5c8466b700098109edcad5f2repo sync } 422baa3858d3f5d128a5c8466b700098109edcad5f2repo sync catch(...) 423baa3858d3f5d128a5c8466b700098109edcad5f2repo sync { 424baa3858d3f5d128a5c8466b700098109edcad5f2repo sync Close(); 425baa3858d3f5d128a5c8466b700098109edcad5f2repo sync return S_FALSE; 426baa3858d3f5d128a5c8466b700098109edcad5f2repo sync } 427baa3858d3f5d128a5c8466b700098109edcad5f2repo sync // _inStream = stream; 428baa3858d3f5d128a5c8466b700098109edcad5f2repo sync #ifndef _SFX 429baa3858d3f5d128a5c8466b700098109edcad5f2repo sync FillPopIDs(); 430baa3858d3f5d128a5c8466b700098109edcad5f2repo sync #endif 431baa3858d3f5d128a5c8466b700098109edcad5f2repo sync return S_OK; 432baa3858d3f5d128a5c8466b700098109edcad5f2repo sync COM_TRY_END 433baa3858d3f5d128a5c8466b700098109edcad5f2repo sync} 434baa3858d3f5d128a5c8466b700098109edcad5f2repo sync 435baa3858d3f5d128a5c8466b700098109edcad5f2repo syncSTDMETHODIMP CHandler::Close() 436baa3858d3f5d128a5c8466b700098109edcad5f2repo sync{ 437baa3858d3f5d128a5c8466b700098109edcad5f2repo sync COM_TRY_BEGIN 438baa3858d3f5d128a5c8466b700098109edcad5f2repo sync _inStream.Release(); 439baa3858d3f5d128a5c8466b700098109edcad5f2repo sync _db.Clear(); 440baa3858d3f5d128a5c8466b700098109edcad5f2repo sync return S_OK; 441baa3858d3f5d128a5c8466b700098109edcad5f2repo sync COM_TRY_END 442baa3858d3f5d128a5c8466b700098109edcad5f2repo sync} 443baa3858d3f5d128a5c8466b700098109edcad5f2repo sync 444baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#ifdef __7Z_SET_PROPERTIES 445baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#ifdef EXTRACT_ONLY 446baa3858d3f5d128a5c8466b700098109edcad5f2repo sync 447baa3858d3f5d128a5c8466b700098109edcad5f2repo syncSTDMETHODIMP CHandler::SetProperties(const wchar_t **names, const PROPVARIANT *values, Int32 numProperties) 448baa3858d3f5d128a5c8466b700098109edcad5f2repo sync{ 449baa3858d3f5d128a5c8466b700098109edcad5f2repo sync COM_TRY_BEGIN 450baa3858d3f5d128a5c8466b700098109edcad5f2repo sync const UInt32 numProcessors = NSystem::GetNumberOfProcessors(); 451baa3858d3f5d128a5c8466b700098109edcad5f2repo sync _numThreads = numProcessors; 452baa3858d3f5d128a5c8466b700098109edcad5f2repo sync 453baa3858d3f5d128a5c8466b700098109edcad5f2repo sync for (int i = 0; i < numProperties; i++) 454baa3858d3f5d128a5c8466b700098109edcad5f2repo sync { 455baa3858d3f5d128a5c8466b700098109edcad5f2repo sync UString name = names[i]; 456baa3858d3f5d128a5c8466b700098109edcad5f2repo sync name.MakeUpper(); 457baa3858d3f5d128a5c8466b700098109edcad5f2repo sync if (name.IsEmpty()) 458baa3858d3f5d128a5c8466b700098109edcad5f2repo sync return E_INVALIDARG; 459baa3858d3f5d128a5c8466b700098109edcad5f2repo sync const PROPVARIANT &value = values[i]; 460baa3858d3f5d128a5c8466b700098109edcad5f2repo sync UInt32 number; 461baa3858d3f5d128a5c8466b700098109edcad5f2repo sync int index = ParseStringToUInt32(name, number); 462baa3858d3f5d128a5c8466b700098109edcad5f2repo sync if (index == 0) 463baa3858d3f5d128a5c8466b700098109edcad5f2repo sync { 464baa3858d3f5d128a5c8466b700098109edcad5f2repo sync if(name.Left(2).CompareNoCase(L"MT") == 0) 465baa3858d3f5d128a5c8466b700098109edcad5f2repo sync { 466baa3858d3f5d128a5c8466b700098109edcad5f2repo sync RINOK(ParseMtProp(name.Mid(2), value, numProcessors, _numThreads)); 467baa3858d3f5d128a5c8466b700098109edcad5f2repo sync continue; 468baa3858d3f5d128a5c8466b700098109edcad5f2repo sync } 469baa3858d3f5d128a5c8466b700098109edcad5f2repo sync else 470baa3858d3f5d128a5c8466b700098109edcad5f2repo sync return E_INVALIDARG; 471baa3858d3f5d128a5c8466b700098109edcad5f2repo sync } 472baa3858d3f5d128a5c8466b700098109edcad5f2repo sync } 473baa3858d3f5d128a5c8466b700098109edcad5f2repo sync return S_OK; 474baa3858d3f5d128a5c8466b700098109edcad5f2repo sync COM_TRY_END 475baa3858d3f5d128a5c8466b700098109edcad5f2repo sync} 476baa3858d3f5d128a5c8466b700098109edcad5f2repo sync 477baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#endif 478baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#endif 479baa3858d3f5d128a5c8466b700098109edcad5f2repo sync 480baa3858d3f5d128a5c8466b700098109edcad5f2repo syncIMPL_ISetCompressCodecsInfo 481baa3858d3f5d128a5c8466b700098109edcad5f2repo sync 482baa3858d3f5d128a5c8466b700098109edcad5f2repo sync}} 483