From f090495d25c861b8f872e965b0aacd1c1fd851db Mon Sep 17 00:00:00 2001 From: Tino Reichardt Date: Tue, 6 Apr 2021 12:13:41 +0200 Subject: [PATCH] Make Upper- or lowercase hash output an option. (fix #177) --- CPP/7zip/UI/Common/HashCalc.cpp | 13 +++++++++++-- CPP/7zip/UI/Common/HashCalc2.cpp | 6 ++++++ CPP/7zip/UI/FileManager/RegistryUtils.cpp | 5 +++++ CPP/7zip/UI/FileManager/RegistryUtils.h | 2 ++ CPP/7zip/UI/FileManager/SettingsPage.cpp | 6 +++++- CPP/7zip/UI/FileManager/SettingsPage2.rc | 1 + CPP/7zip/UI/FileManager/SettingsPageRes.h | 1 + CPP/7zip/UI/FileManager/makefile | 2 +- CPP/7zip/UI/GUI/makefile | 2 +- 9 files changed, 33 insertions(+), 5 deletions(-) create mode 100644 CPP/7zip/UI/Common/HashCalc2.cpp diff --git a/CPP/7zip/UI/Common/HashCalc.cpp b/CPP/7zip/UI/Common/HashCalc.cpp index d090ff78..bdca5226 100644 --- a/CPP/7zip/UI/Common/HashCalc.cpp +++ b/CPP/7zip/UI/Common/HashCalc.cpp @@ -9,6 +9,10 @@ #include "../../Common/FileStreams.h" #include "../../Common/StreamUtils.h" +#ifdef WANT_OPTIONAL_LOWERCASE +#include "../FileManager/RegistryUtils.h" +#endif + #include "EnumDirItems.h" #include "HashCalc.h" @@ -309,10 +313,15 @@ HRESULT HashCalc( return callback->AfterLastFile(hb); } - static inline char GetHex(unsigned v) { - return (char)((v < 10) ? ('0' + v) : ('a' + (v - 10))); +#ifdef WANT_OPTIONAL_LOWERCASE + if (WantLowercaseHashes()) + { + return (char)((v < 10) ? ('0' + v) : ('a' + (v - 10))); + } +#endif + return (char)((v < 10) ? ('0' + v) : ('A' + (v - 10))); } void AddHashHexToString(char *dest, const Byte *data, UInt32 size) diff --git a/CPP/7zip/UI/Common/HashCalc2.cpp b/CPP/7zip/UI/Common/HashCalc2.cpp new file mode 100644 index 00000000..40d1026a --- /dev/null +++ b/CPP/7zip/UI/Common/HashCalc2.cpp @@ -0,0 +1,6 @@ +// HashCalc2.cpp + +#include "StdAfx.h" + +#define WANT_OPTIONAL_LOWERCASE +#include "HashCalc.cpp" diff --git a/CPP/7zip/UI/FileManager/RegistryUtils.cpp b/CPP/7zip/UI/FileManager/RegistryUtils.cpp index a3f13b68..ff8ecc6c 100644 --- a/CPP/7zip/UI/FileManager/RegistryUtils.cpp +++ b/CPP/7zip/UI/FileManager/RegistryUtils.cpp @@ -41,6 +41,7 @@ static LPCTSTR const kArcHistory = TEXT("WantArcHistory"); static LPCTSTR const kPathHistory = TEXT("WantPathHistory"); static LPCTSTR const kCopyHistory = TEXT("WantCopyHistory"); static LPCTSTR const kFolderHistory = TEXT("WantFolderHistory"); +static LPCTSTR const kLowercaseHashes = TEXT("LowercaseHashes"); static LPCTSTR const kFlatViewName = TEXT("FlatViewArc"); // static LPCTSTR const kShowDeletedFiles = TEXT("ShowDeleted"); @@ -147,6 +148,7 @@ void CFmSettings::Save() const SaveOption(kPathHistory, PathHistory); SaveOption(kCopyHistory, CopyHistory); SaveOption(kFolderHistory, FolderHistory); + SaveOption(kLowercaseHashes, LowercaseHashes); // SaveOption(kUnderline, Underline); SaveOption(kShowSystemMenu, ShowSystemMenu); @@ -164,6 +166,7 @@ void CFmSettings::Load() PathHistory = false; CopyHistory = false; FolderHistory = false; + LowercaseHashes = false; // Underline = false; ShowSystemMenu = false; @@ -181,6 +184,7 @@ void CFmSettings::Load() ReadOption(key, kPathHistory, PathHistory); ReadOption(key, kCopyHistory, CopyHistory); ReadOption(key, kFolderHistory, FolderHistory); + ReadOption(key, kLowercaseHashes, LowercaseHashes); // ReadOption(key, kUnderline, Underline); ReadOption(key, kShowSystemMenu, ShowSystemMenu ); @@ -198,6 +202,7 @@ bool WantArcHistory() { return ReadFMOption(kArcHistory); } bool WantPathHistory() { return ReadFMOption(kPathHistory); } bool WantCopyHistory() { return ReadFMOption(kCopyHistory); } bool WantFolderHistory() { return ReadFMOption(kFolderHistory); } +bool WantLowercaseHashes() { return ReadFMOption(kLowercaseHashes); } static CSysString GetFlatViewName(UInt32 panelIndex) { diff --git a/CPP/7zip/UI/FileManager/RegistryUtils.h b/CPP/7zip/UI/FileManager/RegistryUtils.h index 95764aea..321850b5 100644 --- a/CPP/7zip/UI/FileManager/RegistryUtils.h +++ b/CPP/7zip/UI/FileManager/RegistryUtils.h @@ -27,6 +27,7 @@ struct CFmSettings bool PathHistory; bool CopyHistory; bool FolderHistory; + bool LowercaseHashes; // bool Underline; bool ShowSystemMenu; @@ -45,6 +46,7 @@ bool WantArcHistory(); bool WantPathHistory(); bool WantCopyHistory(); bool WantFolderHistory(); +bool WantLowercaseHashes(); void SaveFlatView(UInt32 panelIndex, bool enable); bool ReadFlatView(UInt32 panelIndex); diff --git a/CPP/7zip/UI/FileManager/SettingsPage.cpp b/CPP/7zip/UI/FileManager/SettingsPage.cpp index 8e663e16..58fedfa9 100644 --- a/CPP/7zip/UI/FileManager/SettingsPage.cpp +++ b/CPP/7zip/UI/FileManager/SettingsPage.cpp @@ -30,7 +30,8 @@ static const UInt32 kLangIDs[] = IDX_SETTINGS_WANT_ARC_HISTORY, IDX_SETTINGS_WANT_PATH_HISTORY, IDX_SETTINGS_WANT_COPY_HISTORY, - IDX_SETTINGS_WANT_FOLDER_HISTORY + IDX_SETTINGS_WANT_FOLDER_HISTORY, + IDX_SETTINGS_LOWERCASE_HASHES }; #define kSettingsTopic "FM/options.htm#settings" @@ -66,6 +67,7 @@ bool CSettingsPage::OnInit() CheckButton(IDX_SETTINGS_WANT_PATH_HISTORY, st.PathHistory); CheckButton(IDX_SETTINGS_WANT_COPY_HISTORY, st.CopyHistory); CheckButton(IDX_SETTINGS_WANT_FOLDER_HISTORY, st.FolderHistory); + CheckButton(IDX_SETTINGS_LOWERCASE_HASHES, st.LowercaseHashes); // EnableSubItems(); return CPropertyPage::OnInit(); @@ -93,6 +95,7 @@ LONG CSettingsPage::OnApply() st.PathHistory = IsButtonCheckedBool(IDX_SETTINGS_WANT_PATH_HISTORY); st.CopyHistory = IsButtonCheckedBool(IDX_SETTINGS_WANT_COPY_HISTORY); st.FolderHistory = IsButtonCheckedBool(IDX_SETTINGS_WANT_FOLDER_HISTORY); + st.LowercaseHashes = IsButtonCheckedBool(IDX_SETTINGS_LOWERCASE_HASHES); // st.Underline = IsButtonCheckedBool(IDX_SETTINGS_UNDERLINE); st.ShowSystemMenu = IsButtonCheckedBool(IDX_SETTINGS_SHOW_SYSTEM_MENU); @@ -142,6 +145,7 @@ bool CSettingsPage::OnButtonClicked(int buttonID, HWND buttonHWND) case IDX_SETTINGS_WANT_PATH_HISTORY: case IDX_SETTINGS_WANT_COPY_HISTORY: case IDX_SETTINGS_WANT_FOLDER_HISTORY: + case IDX_SETTINGS_LOWERCASE_HASHES: _wasChanged = true; break; diff --git a/CPP/7zip/UI/FileManager/SettingsPage2.rc b/CPP/7zip/UI/FileManager/SettingsPage2.rc index 2d634dde..e04eacf7 100644 --- a/CPP/7zip/UI/FileManager/SettingsPage2.rc +++ b/CPP/7zip/UI/FileManager/SettingsPage2.rc @@ -14,4 +14,5 @@ BEGIN CONTROL "Want PathHistory", IDX_SETTINGS_WANT_PATH_HISTORY, MY_CHECKBOX, m, 144, xc, 10 CONTROL "Want CopyHistory", IDX_SETTINGS_WANT_COPY_HISTORY, MY_CHECKBOX, m, 158, xc, 10 CONTROL "Want FolderHistory", IDX_SETTINGS_WANT_FOLDER_HISTORY, MY_CHECKBOX, m, 172, xc, 10 + CONTROL "Use Lowercase Hashes", IDX_SETTINGS_LOWERCASE_HASHES, MY_CHECKBOX, m, 186, xc, 10 END diff --git a/CPP/7zip/UI/FileManager/SettingsPageRes.h b/CPP/7zip/UI/FileManager/SettingsPageRes.h index a8899455..c2b936ed 100644 --- a/CPP/7zip/UI/FileManager/SettingsPageRes.h +++ b/CPP/7zip/UI/FileManager/SettingsPageRes.h @@ -13,3 +13,4 @@ #define IDX_SETTINGS_WANT_PATH_HISTORY 2510 #define IDX_SETTINGS_WANT_COPY_HISTORY 2511 #define IDX_SETTINGS_WANT_FOLDER_HISTORY 2512 +#define IDX_SETTINGS_LOWERCASE_HASHES 2513 diff --git a/CPP/7zip/UI/FileManager/makefile b/CPP/7zip/UI/FileManager/makefile index 4525d846..73b8216b 100644 --- a/CPP/7zip/UI/FileManager/makefile +++ b/CPP/7zip/UI/FileManager/makefile @@ -69,7 +69,7 @@ UI_COMMON_OBJS = \ $O\DefaultName.obj \ $O\EnumDirItems.obj \ $O\ExtractingFilePath.obj \ - $O\HashCalc.obj \ + $O\HashCalc2.obj \ $O\LoadCodecs.obj \ $O\OpenArchive.obj \ $O\PropIDUtils.obj \ diff --git a/CPP/7zip/UI/GUI/makefile b/CPP/7zip/UI/GUI/makefile index f8416022..fdacbd98 100644 --- a/CPP/7zip/UI/GUI/makefile +++ b/CPP/7zip/UI/GUI/makefile @@ -85,7 +85,7 @@ UI_COMMON_OBJS = \ $O\EnumDirItems.obj \ $O\Extract.obj \ $O\ExtractingFilePath.obj \ - $O\HashCalc.obj \ + $O\HashCalc2.obj \ $O\LoadCodecs.obj \ $O\OpenArchive.obj \ $O\PropIDUtils.obj \