1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278
|
// HashGUI.cpp
#include "StdAfx.h"
#include "../../../Common/IntToString.h"
#include "../../../Common/StringConvert.h"
#include "../../../Windows/ErrorMsg.h"
#include "../FileManager/FormatUtils.h"
#include "../FileManager/LangUtils.h"
#include "../FileManager/OverwriteDialogRes.h"
#include "../FileManager/ProgressDialog2.h"
#include "../FileManager/ProgressDialog2Res.h"
#include "../FileManager/PropertyNameRes.h"
#include "../FileManager/resourceGui.h"
#include "HashGUI.h"
using namespace NWindows;
class CHashCallbackGUI: public CProgressThreadVirt, public IHashCallbackUI
{
UInt64 NumFiles;
bool _curIsFolder;
UString FirstFileName;
HRESULT ProcessVirt();
public:
const NWildcard::CCensor *censor;
const CHashOptions *options;
DECL_EXTERNAL_CODECS_LOC_VARS2;
CHashCallbackGUI() {}
~CHashCallbackGUI() { }
INTERFACE_IHashCallbackUI(;)
void AddErrorMessage(DWORD systemError, const wchar_t *name)
{
ProgressDialog.Sync.AddError_Code_Name(systemError, name);
}
};
static void AddValuePair(UString &s, UINT resourceID, UInt64 value)
{
AddLangString(s, resourceID);
s.AddAscii(": ");
char sz[32];
ConvertUInt64ToString(value, sz);
s.AddAscii(sz);
s.Add_LF();
}
static void AddSizeValuePair(UString &s, UINT resourceID, UInt64 value)
{
AddLangString(s, resourceID);
s.AddAscii(": ");
wchar_t sz[32];
ConvertUInt64ToString(value, sz);
s += MyFormatNew(IDS_FILE_SIZE, sz);
ConvertUInt64ToString(value >> 20, sz);
s.AddAscii(" (");
s += sz;
s.AddAscii(" MB)");
s.Add_LF();
}
HRESULT CHashCallbackGUI::StartScanning()
{
CProgressSync &sync = ProgressDialog.Sync;
sync.Set_Status(LangString(IDS_SCANNING));
return CheckBreak();
}
HRESULT CHashCallbackGUI::ScanProgress(const CDirItemsStat &st, const FString &path, bool isDir)
{
return ProgressDialog.Sync.ScanProgress(st.NumFiles, st.GetTotalBytes(), path, isDir);
}
HRESULT CHashCallbackGUI::ScanError(const FString &path, DWORD systemError)
{
AddErrorMessage(systemError, fs2us(path));
return CheckBreak();
}
HRESULT CHashCallbackGUI::FinishScanning(const CDirItemsStat &st)
{
return ScanProgress(st, FString(), false);
}
HRESULT CHashCallbackGUI::CheckBreak()
{
return ProgressDialog.Sync.CheckStop();
}
HRESULT CHashCallbackGUI::SetNumFiles(UInt64 numFiles)
{
CProgressSync &sync = ProgressDialog.Sync;
sync.Set_NumFilesTotal(numFiles);
return CheckBreak();
}
HRESULT CHashCallbackGUI::SetTotal(UInt64 size)
{
CProgressSync &sync = ProgressDialog.Sync;
sync.Set_NumBytesTotal(size);
return CheckBreak();
}
HRESULT CHashCallbackGUI::SetCompleted(const UInt64 *completed)
{
return ProgressDialog.Sync.Set_NumBytesCur(completed);
}
HRESULT CHashCallbackGUI::BeforeFirstFile(const CHashBundle & /* hb */)
{
return S_OK;
}
HRESULT CHashCallbackGUI::GetStream(const wchar_t *name, bool isFolder)
{
if (NumFiles == 0)
FirstFileName = name;
_curIsFolder = isFolder;
CProgressSync &sync = ProgressDialog.Sync;
sync.Set_FilePath(name, isFolder);
return CheckBreak();
}
HRESULT CHashCallbackGUI::OpenFileError(const FString &path, DWORD systemError)
{
// if (systemError == ERROR_SHARING_VIOLATION)
{
AddErrorMessage(systemError, fs2us(path));
return S_FALSE;
}
// return systemError;
}
HRESULT CHashCallbackGUI::SetOperationResult(UInt64 /* fileSize */, const CHashBundle & /* hb */, bool /* showHash */)
{
CProgressSync &sync = ProgressDialog.Sync;
if (!_curIsFolder)
NumFiles++;
sync.Set_NumFilesCur(NumFiles);
return CheckBreak();
}
static void AddHashString(UString &s, const CHasherState &h, unsigned digestIndex, const wchar_t *title)
{
s += title;
s.Add_Space();
char temp[k_HashCalc_DigestSize_Max * 2 + 4];
AddHashHexToString(temp, h.Digests[digestIndex], h.DigestSize);
s.AddAscii(temp);
s.Add_LF();
}
static void AddHashResString(UString &s, const CHasherState &h, unsigned digestIndex, UInt32 resID)
{
UString s2 = LangString(resID);
UString name;
name.SetFromAscii(h.Name);
s2.Replace(L"CRC", name);
AddHashString(s, h, digestIndex, s2);
}
void AddHashBundleRes(UString &s, const CHashBundle &hb, const UString &firstFileName)
{
if (hb.NumErrors != 0)
{
AddValuePair(s, IDS_PROP_NUM_ERRORS, hb.NumErrors);
s.Add_LF();
}
if (hb.NumFiles == 1 && hb.NumDirs == 0 && !firstFileName.IsEmpty())
{
AddLangString(s, IDS_PROP_NAME);
s.AddAscii(": ");
s += firstFileName;
s.Add_LF();
}
else
{
AddValuePair(s, IDS_PROP_FOLDERS, hb.NumDirs);
AddValuePair(s, IDS_PROP_FILES, hb.NumFiles);
}
AddSizeValuePair(s, IDS_PROP_SIZE, hb.FilesSize);
if (hb.NumAltStreams != 0)
{
s.Add_LF();
AddValuePair(s, IDS_PROP_NUM_ALT_STREAMS, hb.NumAltStreams);
AddSizeValuePair(s, IDS_PROP_ALT_STREAMS_SIZE, hb.AltStreamsSize);
}
if (hb.NumErrors == 0 && hb.Hashers.IsEmpty())
{
s.Add_LF();
AddLangString(s, IDS_MESSAGE_NO_ERRORS);
}
FOR_VECTOR (i, hb.Hashers)
{
s.Add_LF();
const CHasherState &h = hb.Hashers[i];
if (hb.NumFiles == 1 && hb.NumDirs == 0)
{
s.AddAscii(h.Name);
AddHashString(s, h, k_HashCalc_Index_DataSum, L":");
}
else
{
AddHashResString(s, h, k_HashCalc_Index_DataSum, IDS_CHECKSUM_CRC_DATA);
AddHashResString(s, h, k_HashCalc_Index_NamesSum, IDS_CHECKSUM_CRC_DATA_NAMES);
}
if (hb.NumAltStreams != 0)
{
AddHashResString(s, h, k_HashCalc_Index_StreamsSum, IDS_CHECKSUM_CRC_STREAMS_NAMES);
}
}
}
HRESULT CHashCallbackGUI::AfterLastFile(const CHashBundle &hb)
{
UString s;
AddHashBundleRes(s, hb, FirstFileName);
CProgressSync &sync = ProgressDialog.Sync;
sync.Set_NumFilesCur(hb.NumFiles);
CProgressMessageBoxPair &pair = GetMessagePair(hb.NumErrors != 0);
pair.Message = s;
LangString(IDS_CHECKSUM_INFORMATION, pair.Title);
return S_OK;
}
HRESULT CHashCallbackGUI::ProcessVirt()
{
NumFiles = 0;
AString errorInfo;
HRESULT res = HashCalc(EXTERNAL_CODECS_LOC_VARS
*censor, *options, errorInfo, this);
return res;
}
HRESULT HashCalcGUI(
DECL_EXTERNAL_CODECS_LOC_VARS
const NWildcard::CCensor &censor,
const CHashOptions &options,
bool &messageWasDisplayed)
{
CHashCallbackGUI t;
#ifdef EXTERNAL_CODECS
t.__externalCodecs = __externalCodecs;
#endif
t.censor = &censor;
t.options = &options;
t.ProgressDialog.ShowCompressionInfo = false;
const UString title = LangString(IDS_CHECKSUM_CALCULATING);
t.ProgressDialog.MainTitle = L"7-Zip"; // LangString(IDS_APP_TITLE);
t.ProgressDialog.MainAddTitle = title;
t.ProgressDialog.MainAddTitle.Add_Space();
RINOK(t.Create(title));
messageWasDisplayed = t.ThreadFinishedOK && t.ProgressDialog.MessagesDisplayed;
return S_OK;
}
|