diff options
author | Igor Pavlov <ipavlov@users.sourceforge.net> | 2015-06-15 03:00:00 +0300 |
---|---|---|
committer | Kornel LesiĆski <kornel@geekhood.net> | 2016-05-28 02:16:54 +0300 |
commit | 54490d51d5c6b0d794dcbad2d634d4c95fc25b6c (patch) | |
tree | c3c413656432c0ef87b2841c80e42b55ad17d4e8 /CPP/7zip/UI/Common/HashCalc.cpp | |
parent | 0713a3ab803e57401f18432148b4139e5fe6e5dd (diff) |
15.0515.05
Diffstat (limited to 'CPP/7zip/UI/Common/HashCalc.cpp')
-rw-r--r-- | CPP/7zip/UI/Common/HashCalc.cpp | 74 |
1 files changed, 32 insertions, 42 deletions
diff --git a/CPP/7zip/UI/Common/HashCalc.cpp b/CPP/7zip/UI/Common/HashCalc.cpp index 6abe59ac..c33f837f 100644 --- a/CPP/7zip/UI/Common/HashCalc.cpp +++ b/CPP/7zip/UI/Common/HashCalc.cpp @@ -30,23 +30,17 @@ public: ~CHashMidBuf() { ::MidFree(_data); } }; -struct CEnumDirItemCallback_Hash: public IEnumDirItemCallback -{ - IHashCallbackUI *Callback; - - HRESULT ScanProgress(UInt64 numFolders, UInt64 numFiles, UInt64 totalSize, const wchar_t *path, bool isDir) - { - return Callback->ScanProgress(numFolders, numFiles, totalSize, path, isDir); - } -}; - -static const wchar_t *k_DefaultHashMethod = L"CRC32"; +static const char *k_DefaultHashMethod = "CRC32"; HRESULT CHashBundle::SetMethods(DECL_EXTERNAL_CODECS_LOC_VARS const UStringVector &hashMethods) { UStringVector names = hashMethods; if (names.IsEmpty()) - names.Add(k_DefaultHashMethod); + { + UString s; + s.SetFromAscii(k_DefaultHashMethod); + names.Add(s); + } CRecordVector<CMethodId> ids; CObjectVector<COneMethodInfo> methods; @@ -60,7 +54,7 @@ HRESULT CHashBundle::SetMethods(DECL_EXTERNAL_CODECS_LOC_VARS const UStringVecto if (m.MethodName.IsEmpty()) m.MethodName = k_DefaultHashMethod; - if (m.MethodName == L"*") + if (m.MethodName == "*") { CRecordVector<CMethodId> tempMethods; GetHashMethods(EXTERNAL_CODECS_LOC_VARS tempMethods); @@ -68,7 +62,7 @@ HRESULT CHashBundle::SetMethods(DECL_EXTERNAL_CODECS_LOC_VARS const UStringVecto ids.Clear(); FOR_VECTOR (t, tempMethods) { - int index = ids.AddToUniqueSorted(tempMethods[t]); + unsigned index = ids.AddToUniqueSorted(tempMethods[t]); if (ids.Size() != methods.Size()) methods.Insert(index, m); } @@ -80,7 +74,7 @@ HRESULT CHashBundle::SetMethods(DECL_EXTERNAL_CODECS_LOC_VARS const UStringVecto CMethodId id; if (!FindHashMethod(EXTERNAL_CODECS_LOC_VARS m.MethodName, id)) return E_NOTIMPL; - int index = ids.AddToUniqueSorted(id); + unsigned index = ids.AddToUniqueSorted(id); if (ids.Size() != methods.Size()) methods.Insert(index, m); } @@ -89,7 +83,7 @@ HRESULT CHashBundle::SetMethods(DECL_EXTERNAL_CODECS_LOC_VARS const UStringVecto for (i = 0; i < ids.Size(); i++) { CMyComPtr<IHasher> hasher; - UString name; + AString name; RINOK(CreateHasher(EXTERNAL_CODECS_LOC_VARS ids[i], name, hasher)); if (!hasher) throw "Can't create hasher"; @@ -98,9 +92,7 @@ HRESULT CHashBundle::SetMethods(DECL_EXTERNAL_CODECS_LOC_VARS const UStringVecto CMyComPtr<ICompressSetCoderProperties> scp; hasher.QueryInterface(IID_ICompressSetCoderProperties, &scp); if (scp) - { RINOK(m.SetCoderProps(scp, NULL)); - } } UInt32 digestSize = hasher->GetDigestSize(); if (digestSize > k_HashCalc_DigestSize_Max) @@ -109,9 +101,10 @@ HRESULT CHashBundle::SetMethods(DECL_EXTERNAL_CODECS_LOC_VARS const UStringVecto h.Hasher = hasher; h.Name = name; h.DigestSize = digestSize; - for (int i = 0; i < k_HashCalc_NumGroups; i++) + for (unsigned i = 0; i < k_HashCalc_NumGroups; i++) memset(h.Digests[i], 0, digestSize); } + return S_OK; } @@ -203,13 +196,12 @@ HRESULT HashCalc( DECL_EXTERNAL_CODECS_LOC_VARS const NWildcard::CCensor &censor, const CHashOptions &options, - UString &errorInfo, + AString &errorInfo, IHashCallbackUI *callback) { CDirItems dirItems; + dirItems.Callback = callback; - UInt64 numErrors = 0; - UInt64 totalBytes = 0; if (options.StdInMode) { CDirItem di; @@ -222,34 +214,29 @@ HRESULT HashCalc( } else { - CEnumDirItemCallback_Hash enumCallback; - enumCallback.Callback = callback; RINOK(callback->StartScanning()); dirItems.ScanAltStreams = options.AltStreamsMode; + HRESULT res = EnumerateItems(censor, options.PathMode, UString(), - dirItems, &enumCallback); - totalBytes = dirItems.TotalSize; - FOR_VECTOR (i, dirItems.ErrorPaths) - { - RINOK(callback->CanNotFindError(fs2us(dirItems.ErrorPaths[i]), dirItems.ErrorCodes[i])); - } - numErrors = dirItems.ErrorPaths.Size(); + dirItems); + if (res != S_OK) { if (res != E_ABORT) - errorInfo = L"Scanning error"; + errorInfo = "Scanning error"; return res; } - RINOK(callback->FinishScanning()); + RINOK(callback->FinishScanning(dirItems.Stat)); } unsigned i; CHashBundle hb; RINOK(hb.SetMethods(EXTERNAL_CODECS_LOC_VARS options.Methods)); hb.Init(); - hb.NumErrors = numErrors; + + hb.NumErrors = dirItems.Stat.NumErrors; if (options.StdInMode) { @@ -257,7 +244,7 @@ HRESULT HashCalc( } else { - RINOK(callback->SetTotal(totalBytes)); + RINOK(callback->SetTotal(dirItems.Stat.GetTotalBytes())); } const UInt32 kBufSize = 1 << 15; @@ -289,8 +276,8 @@ HRESULT HashCalc( path = dirItems.GetLogPath(i); if (!isDir) { - UString phyPath = dirItems.GetPhyPath(i); - if (!inStreamSpec->OpenShared(us2fs(phyPath), options.OpenShareForWrite)) + FString phyPath = dirItems.GetPhyPath(i); + if (!inStreamSpec->OpenShared(phyPath, options.OpenShareForWrite)) { HRESULT res = callback->OpenFileError(phyPath, ::GetLastError()); hb.NumErrors++; @@ -327,14 +314,15 @@ HRESULT HashCalc( } -static inline char GetHex(Byte value) +static inline char GetHex(unsigned v) { - return (char)((value < 10) ? ('0' + value) : ('A' + (value - 10))); + return (char)((v < 10) ? ('0' + v) : ('A' + (v - 10))); } void AddHashHexToString(char *dest, const Byte *data, UInt32 size) { dest[size * 2] = 0; + if (!data) { for (UInt32 i = 0; i < size; i++) @@ -345,17 +333,19 @@ void AddHashHexToString(char *dest, const Byte *data, UInt32 size) } return; } + int step = 2; if (size <= 8) { step = -2; dest += size * 2 - 2; } + for (UInt32 i = 0; i < size; i++) { - Byte b = data[i]; - dest[0] = GetHex((Byte)((b >> 4) & 0xF)); - dest[1] = GetHex((Byte)(b & 0xF)); + unsigned b = data[i]; + dest[0] = GetHex((b >> 4) & 0xF); + dest[1] = GetHex(b & 0xF); dest += step; } } |