• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // HashCalc.h
2 
3 #ifndef __HASH_CALC_H
4 #define __HASH_CALC_H
5 
6 #include "../../../Common/Wildcard.h"
7 
8 #include "../../Common/CreateCoder.h"
9 #include "../../Common/MethodProps.h"
10 
11 #include "DirItem.h"
12 #include "Property.h"
13 
14 const unsigned k_HashCalc_DigestSize_Max = 64;
15 
16 const unsigned k_HashCalc_NumGroups = 4;
17 
18 enum
19 {
20   k_HashCalc_Index_Current,
21   k_HashCalc_Index_DataSum,
22   k_HashCalc_Index_NamesSum,
23   k_HashCalc_Index_StreamsSum
24 };
25 
26 struct CHasherState
27 {
28   CMyComPtr<IHasher> Hasher;
29   AString Name;
30   UInt32 DigestSize;
31   Byte Digests[k_HashCalc_NumGroups][k_HashCalc_DigestSize_Max];
32 };
33 
34 struct IHashCalc
35 {
36   virtual void InitForNewFile() = 0;
37   virtual void Update(const void *data, UInt32 size) = 0;
38   virtual void SetSize(UInt64 size) = 0;
39   virtual void Final(bool isDir, bool isAltStream, const UString &path) = 0;
40 };
41 
42 struct CHashBundle: public IHashCalc
43 {
44   CObjectVector<CHasherState> Hashers;
45 
46   UInt64 NumDirs;
47   UInt64 NumFiles;
48   UInt64 NumAltStreams;
49   UInt64 FilesSize;
50   UInt64 AltStreamsSize;
51   UInt64 NumErrors;
52 
53   UInt64 CurSize;
54 
55   HRESULT SetMethods(DECL_EXTERNAL_CODECS_LOC_VARS const UStringVector &methods);
56 
InitCHashBundle57   void Init()
58   {
59     NumDirs = NumFiles = NumAltStreams = FilesSize = AltStreamsSize = NumErrors = 0;
60   }
61 
62   void InitForNewFile();
63   void Update(const void *data, UInt32 size);
64   void SetSize(UInt64 size);
65   void Final(bool isDir, bool isAltStream, const UString &path);
66 };
67 
68 #define INTERFACE_IHashCallbackUI(x) \
69   INTERFACE_IDirItemsCallback(x) \
70   virtual HRESULT StartScanning() x; \
71   virtual HRESULT FinishScanning(const CDirItemsStat &st) x; \
72   virtual HRESULT SetNumFiles(UInt64 numFiles) x; \
73   virtual HRESULT SetTotal(UInt64 size) x; \
74   virtual HRESULT SetCompleted(const UInt64 *completeValue) x; \
75   virtual HRESULT CheckBreak() x; \
76   virtual HRESULT BeforeFirstFile(const CHashBundle &hb) x; \
77   virtual HRESULT GetStream(const wchar_t *name, bool isFolder) x; \
78   virtual HRESULT OpenFileError(const FString &path, DWORD systemError) x; \
79   virtual HRESULT SetOperationResult(UInt64 fileSize, const CHashBundle &hb, bool showHash) x; \
80   virtual HRESULT AfterLastFile(const CHashBundle &hb) x; \
81 
82 struct IHashCallbackUI: public IDirItemsCallback
83 {
84   INTERFACE_IHashCallbackUI(=0)
85 };
86 
87 struct CHashOptions
88 {
89   UStringVector Methods;
90   bool OpenShareForWrite;
91   bool StdInMode;
92   bool AltStreamsMode;
93   NWildcard::ECensorPathMode PathMode;
94 
CHashOptionsCHashOptions95   CHashOptions(): StdInMode(false), OpenShareForWrite(false), AltStreamsMode(false), PathMode(NWildcard::k_RelatPath) {};
96 };
97 
98 HRESULT HashCalc(
99     DECL_EXTERNAL_CODECS_LOC_VARS
100     const NWildcard::CCensor &censor,
101     const CHashOptions &options,
102     AString &errorInfo,
103     IHashCallbackUI *callback);
104 
105 void AddHashHexToString(char *dest, const Byte *data, UInt32 size);
106 
107 #endif
108