diff options
Diffstat (limited to 'CPP/7zip/UI/GUI/HashGUI.cpp')
-rw-r--r-- | CPP/7zip/UI/GUI/HashGUI.cpp | 187 |
1 files changed, 127 insertions, 60 deletions
diff --git a/CPP/7zip/UI/GUI/HashGUI.cpp b/CPP/7zip/UI/GUI/HashGUI.cpp index cc93f07e..7cb00973 100644 --- a/CPP/7zip/UI/GUI/HashGUI.cpp +++ b/CPP/7zip/UI/GUI/HashGUI.cpp @@ -9,6 +9,7 @@ #include "../FileManager/FormatUtils.h" #include "../FileManager/LangUtils.h" +#include "../FileManager/ListViewDialog.h" #include "../FileManager/OverwriteDialogRes.h" #include "../FileManager/ProgressDialog2.h" #include "../FileManager/ProgressDialog2Res.h" @@ -19,13 +20,18 @@ using namespace NWindows; + + class CHashCallbackGUI: public CProgressThreadVirt, public IHashCallbackUI { UInt64 NumFiles; bool _curIsFolder; UString FirstFileName; + CPropNameValPairs PropNameValPairs; + HRESULT ProcessVirt(); + virtual void ProcessWasFinished_GuiVirt(); public: const NWildcard::CCensor *censor; @@ -40,49 +46,62 @@ public: void AddErrorMessage(DWORD systemError, const wchar_t *name) { - ProgressDialog.Sync.AddError_Code_Name(systemError, name); + Sync.AddError_Code_Name(systemError, name); } }; -static void AddValuePair(UString &s, UINT resourceID, UInt64 value) + +void AddValuePair(CPropNameValPairs &pairs, UINT resourceID, UInt64 value) { - AddLangString(s, resourceID); - s += ": "; + CProperty &pair = pairs.AddNew(); + AddLangString(pair.Name, resourceID); char sz[32]; ConvertUInt64ToString(value, sz); - s += sz; - s.Add_LF(); + pair.Value = sz; } -static void AddSizeValuePair(UString &s, UINT resourceID, UInt64 value) + +void AddSizeValue(UString &s, UInt64 value) { - AddLangString(s, resourceID); - s += ": "; { wchar_t sz[32]; ConvertUInt64ToString(value, sz); s += MyFormatNew(IDS_FILE_SIZE, sz); } + if (value >= (1 << 10)) { + char c; + if (value >= ((UInt64)10 << 30)) { value >>= 30; c = 'G'; } + if (value >= (10 << 20)) { value >>= 20; c = 'M'; } + else { value >>= 10; c = 'K'; } char sz[32]; - ConvertUInt64ToString(value >> 20, sz); + ConvertUInt64ToString(value, sz); s += " ("; s += sz; - s += " MB)"; - s.Add_LF(); + s += " "; + s += (wchar_t)c; + s += "iB)"; } } +void AddSizeValuePair(CPropNameValPairs &pairs, UINT resourceID, UInt64 value) +{ + CProperty &pair = pairs.AddNew(); + LangString(resourceID, pair.Name); + AddSizeValue(pair.Value, value); +} + + HRESULT CHashCallbackGUI::StartScanning() { - CProgressSync &sync = ProgressDialog.Sync; + CProgressSync &sync = 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); + return Sync.ScanProgress(st.NumFiles, st.GetTotalBytes(), path, isDir); } HRESULT CHashCallbackGUI::ScanError(const FString &path, DWORD systemError) @@ -98,26 +117,26 @@ HRESULT CHashCallbackGUI::FinishScanning(const CDirItemsStat &st) HRESULT CHashCallbackGUI::CheckBreak() { - return ProgressDialog.Sync.CheckStop(); + return Sync.CheckStop(); } HRESULT CHashCallbackGUI::SetNumFiles(UInt64 numFiles) { - CProgressSync &sync = ProgressDialog.Sync; + CProgressSync &sync = Sync; sync.Set_NumFilesTotal(numFiles); return CheckBreak(); } HRESULT CHashCallbackGUI::SetTotal(UInt64 size) { - CProgressSync &sync = ProgressDialog.Sync; + CProgressSync &sync = Sync; sync.Set_NumBytesTotal(size); return CheckBreak(); } HRESULT CHashCallbackGUI::SetCompleted(const UInt64 *completed) { - return ProgressDialog.Sync.Set_NumBytesCur(completed); + return Sync.Set_NumBytesCur(completed); } HRESULT CHashCallbackGUI::BeforeFirstFile(const CHashBundle & /* hb */) @@ -130,7 +149,7 @@ HRESULT CHashCallbackGUI::GetStream(const wchar_t *name, bool isFolder) if (NumFiles == 0) FirstFileName = name; _curIsFolder = isFolder; - CProgressSync &sync = ProgressDialog.Sync; + CProgressSync &sync = Sync; sync.Set_FilePath(name, isFolder); return CheckBreak(); } @@ -147,49 +166,47 @@ HRESULT CHashCallbackGUI::OpenFileError(const FString &path, DWORD systemError) HRESULT CHashCallbackGUI::SetOperationResult(UInt64 /* fileSize */, const CHashBundle & /* hb */, bool /* showHash */) { - CProgressSync &sync = ProgressDialog.Sync; + CProgressSync &sync = Sync; if (!_curIsFolder) NumFiles++; sync.Set_NumFilesCur(NumFiles); return CheckBreak(); } -static void AddHashString(UString &s, const CHasherState &h, unsigned digestIndex, const wchar_t *title) +static void AddHashString(CProperty &s, const CHasherState &h, unsigned digestIndex) { - s += title; - s.Add_Space(); char temp[k_HashCalc_DigestSize_Max * 2 + 4]; AddHashHexToString(temp, h.Digests[digestIndex], h.DigestSize); - s += temp; - s.Add_LF(); + s.Value = temp; } -static void AddHashResString(UString &s, const CHasherState &h, unsigned digestIndex, UInt32 resID) +static void AddHashResString(CPropNameValPairs &s, const CHasherState &h, unsigned digestIndex, UInt32 resID) { - UString s2 = LangString(resID); + CProperty &pair = s.AddNew(); + UString &s2 = pair.Name; + LangString(resID, s2); UString name (h.Name); s2.Replace(L"CRC", name); - AddHashString(s, h, digestIndex, s2); + s2.Replace(L":", L""); + AddHashString(pair, h, digestIndex); } -void AddHashBundleRes(UString &s, const CHashBundle &hb, const UString &firstFileName) + +void AddHashBundleRes(CPropNameValPairs &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 += ": "; - s += firstFileName; - s.Add_LF(); + CProperty &pair = s.AddNew(); + LangString(IDS_PROP_NAME, pair.Name); + pair.Value = firstFileName; } else { - AddValuePair(s, IDS_PROP_FOLDERS, hb.NumDirs); + if (hb.NumDirs != 0) + AddValuePair(s, IDS_PROP_FOLDERS, hb.NumDirs); AddValuePair(s, IDS_PROP_FILES, hb.NumFiles); } @@ -197,25 +214,18 @@ void AddHashBundleRes(UString &s, const CHashBundle &hb, const UString &firstFil 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 += h.Name; - AddHashString(s, h, k_HashCalc_Index_DataSum, L":"); + CProperty &pair = s.AddNew(); + pair.Name += h.Name; + AddHashString(pair, h, k_HashCalc_Index_DataSum); } else { @@ -229,32 +239,55 @@ void AddHashBundleRes(UString &s, const CHashBundle &hb, const UString &firstFil } } + +void AddHashBundleRes(UString &s, const CHashBundle &hb, const UString &firstFileName) +{ + CPropNameValPairs pairs; + AddHashBundleRes(pairs, hb, firstFileName); + + FOR_VECTOR (i, pairs) + { + const CProperty &pair = pairs[i]; + s += pair.Name; + s += ": "; + s += pair.Value; + s.Add_LF(); + } + + if (hb.NumErrors == 0 && hb.Hashers.IsEmpty()) + { + s.Add_LF(); + AddLangString(s, IDS_MESSAGE_NO_ERRORS); + s.Add_LF(); + } +} + + HRESULT CHashCallbackGUI::AfterLastFile(const CHashBundle &hb) { - UString s; - AddHashBundleRes(s, hb, FirstFileName); + AddHashBundleRes(PropNameValPairs, hb, FirstFileName); - CProgressSync &sync = ProgressDialog.Sync; + CProgressSync &sync = Sync; sync.Set_NumFilesCur(hb.NumFiles); - CProgressMessageBoxPair &pair = GetMessagePair(hb.NumErrors != 0); - pair.Message = s; - LangString(IDS_CHECKSUM_INFORMATION, pair.Title); + // 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, @@ -268,15 +301,49 @@ HRESULT HashCalcGUI( t.censor = &censor; t.options = &options; - t.ProgressDialog.ShowCompressionInfo = false; + t.ShowCompressionInfo = false; const UString title = LangString(IDS_CHECKSUM_CALCULATING); - t.ProgressDialog.MainTitle = "7-Zip"; // LangString(IDS_APP_TITLE); - t.ProgressDialog.MainAddTitle = title; - t.ProgressDialog.MainAddTitle.Add_Space(); + t.MainTitle = "7-Zip"; // LangString(IDS_APP_TITLE); + t.MainAddTitle = title; + t.MainAddTitle.Add_Space(); RINOK(t.Create(title)); - messageWasDisplayed = t.ThreadFinishedOK && t.ProgressDialog.MessagesDisplayed; + messageWasDisplayed = t.ThreadFinishedOK && t.MessagesDisplayed; return S_OK; } + + +void ShowHashResults(const CPropNameValPairs &propPairs, HWND hwnd) +{ + CListViewDialog lv; + + FOR_VECTOR (i, propPairs) + { + const CProperty &pair = propPairs[i]; + lv.Strings.Add(pair.Name); + lv.Values.Add(pair.Value); + } + + lv.Title = LangString(IDS_CHECKSUM_INFORMATION); + lv.DeleteIsAllowed = true; + lv.SelectFirst = false; + lv.NumColumns = 2; + + lv.Create(hwnd); +} + + +void ShowHashResults(const CHashBundle &hb, const UString &firstFileName, HWND hwnd) +{ + CPropNameValPairs propPairs; + AddHashBundleRes(propPairs, hb, firstFileName); + ShowHashResults(propPairs, hwnd); +} + + +void CHashCallbackGUI::ProcessWasFinished_GuiVirt() +{ + ShowHashResults(PropNameValPairs, *this); +} |