Skip to content

Commit

Permalink
Make Upper- or lowercase hash output an option. (fix mcmilk#177)
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmilk committed Apr 6, 2021
1 parent 3df8bc1 commit f090495
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 5 deletions.
13 changes: 11 additions & 2 deletions CPP/7zip/UI/Common/HashCalc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions CPP/7zip/UI/Common/HashCalc2.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// HashCalc2.cpp

#include "StdAfx.h"

#define WANT_OPTIONAL_LOWERCASE
#include "HashCalc.cpp"
5 changes: 5 additions & 0 deletions CPP/7zip/UI/FileManager/RegistryUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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);
Expand All @@ -164,6 +166,7 @@ void CFmSettings::Load()
PathHistory = false;
CopyHistory = false;
FolderHistory = false;
LowercaseHashes = false;
// Underline = false;

ShowSystemMenu = false;
Expand All @@ -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 );
Expand All @@ -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)
{
Expand Down
2 changes: 2 additions & 0 deletions CPP/7zip/UI/FileManager/RegistryUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ struct CFmSettings
bool PathHistory;
bool CopyHistory;
bool FolderHistory;
bool LowercaseHashes;
// bool Underline;

bool ShowSystemMenu;
Expand All @@ -45,6 +46,7 @@ bool WantArcHistory();
bool WantPathHistory();
bool WantCopyHistory();
bool WantFolderHistory();
bool WantLowercaseHashes();

void SaveFlatView(UInt32 panelIndex, bool enable);
bool ReadFlatView(UInt32 panelIndex);
Expand Down
6 changes: 5 additions & 1 deletion CPP/7zip/UI/FileManager/SettingsPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;

Expand Down
1 change: 1 addition & 0 deletions CPP/7zip/UI/FileManager/SettingsPage2.rc
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions CPP/7zip/UI/FileManager/SettingsPageRes.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion CPP/7zip/UI/FileManager/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
2 changes: 1 addition & 1 deletion CPP/7zip/UI/GUI/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down

0 comments on commit f090495

Please sign in to comment.