Skip to content

Commit

Permalink
Removed version macroses. Code cleaning.
Browse files Browse the repository at this point in the history
  • Loading branch information
jovibor committed Apr 23, 2023
1 parent c79fce3 commit 11fc0f9
Show file tree
Hide file tree
Showing 13 changed files with 47 additions and 56 deletions.
13 changes: 6 additions & 7 deletions Pepper/CMainFrm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ BOOL CMainFrame::PreTranslateMessage(MSG* pMsg)

auto pos = tabGroups.GetHeadPosition();
while (pos != nullptr) {
if (auto pTabCtrl = DYNAMIC_DOWNCAST(CMFCTabCtrl, tabGroups.GetNext(pos)); pTabCtrl == pWnd) { //Click on TabCtrl.
if (const auto pTabCtrl = DYNAMIC_DOWNCAST(CMFCTabCtrl, tabGroups.GetNext(pos)); pTabCtrl == pWnd) { //Click on TabCtrl.
pTabCtrl->ScreenToClient(&pt);
if (const auto iTab = pTabCtrl->GetTabFromPoint(pt); iTab != -1) {
if (auto pWndTab = pTabCtrl->GetTabWnd(iTab); pWndTab != nullptr) {
Expand Down Expand Up @@ -205,8 +205,9 @@ BOOL CMainFrame::PreTranslateMessage(MSG* pMsg)
{
pTabCtrl->ScreenToClient(&pt);
if (const auto iTab = pTabCtrl->GetTabFromPoint(pt); iTab != -1) {
if (const auto pTab = pTabCtrl->GetTabWnd(iTab); pTab != nullptr && pTab == pWndMBtnCurrDown)
if (const auto pTab = pTabCtrl->GetTabWnd(iTab); pTab != nullptr && pTab == pWndMBtnCurrDown) {
pTab->SendMessageW(WM_CLOSE);
}
}
}
}
Expand All @@ -231,16 +232,15 @@ LRESULT CMainFrame::MDIClientProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lP
::GetClientRect(hWnd, rc);
CMemDC dcMem(dc, rc);
auto pDC = &dcMem.GetDC();
constexpr auto iLengthText = static_cast<int>(std::size(WSTR_PEPPER_PRODUCT_NAME)) - 1;

pDC->FillSolidRect(rc, RGB(190, 190, 190));
pDC->SelectObject(m_fontMDIClient);
pDC->SetBkMode(TRANSPARENT);
pDC->SetTextColor(RGB(205, 205, 205)); //Shadow color.
pDC->DrawTextW(WSTR_PEPPER_PRODUCT_NAME, iLengthText, rc, DT_CENTER | DT_SINGLELINE | DT_VCENTER);
pDC->DrawTextW(L"Pepper", 6, rc, DT_CENTER | DT_SINGLELINE | DT_VCENTER);
pDC->SetTextColor(RGB(193, 193, 193)); //Text color.
rc.OffsetRect(-3, 2);
pDC->DrawTextW(WSTR_PEPPER_PRODUCT_NAME, iLengthText, rc, DT_CENTER | DT_SINGLELINE | DT_VCENTER);
pDC->DrawTextW(L"Pepper", 6, rc, DT_CENTER | DT_SINGLELINE | DT_VCENTER);
}
break;
case WM_SIZE:
Expand All @@ -256,7 +256,6 @@ LRESULT CMainFrame::MDIClientProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lP

void CMainFrame::MDIClientSize(HWND hWnd, WPARAM /*wParam*/, LPARAM lParam)
{
constexpr auto iLengthText = static_cast<int>(std::size(WSTR_PEPPER_PRODUCT_NAME)) - 1;
const auto pDC = CDC::FromHandle(::GetDC(hWnd));
const auto iWidthNew = LOWORD(lParam);
auto iFontSizeMin = 10;
Expand All @@ -271,7 +270,7 @@ void CMainFrame::MDIClientSize(HWND hWnd, WPARAM /*wParam*/, LPARAM lParam)
lf.lfHeight = -MulDiv(iFontSizeMin, m_iLOGPIXELSY, 72);
m_fontMDIClient.CreateFontIndirectW(&lf);
pDC->SelectObject(m_fontMDIClient);
stSizeText = pDC->GetTextExtent(WSTR_PEPPER_PRODUCT_NAME, iLengthText);
stSizeText = pDC->GetTextExtent(L"Pepper", 6);
}
::ReleaseDC(hWnd, pDC->m_hDC);
::RedrawWindow(hWnd, nullptr, nullptr, RDW_INVALIDATE | RDW_UPDATENOW);
Expand Down
5 changes: 4 additions & 1 deletion Pepper/CPepper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ class CAboutDlg : public CDialogEx
BOOL CAboutDlg::OnInitDialog()
{
CDialogEx::OnInitDialog();
GetDlgItem(IDC_LINK_PEPPER)->SetWindowTextW(WSTR_PEPPER_VERSION);

const auto wstrVerPepper = std::format(L"Pepper: PE32/PE32+ Binaries Analyzer v{}.{}.{}", util::PEPPER_VERSION_MAJOR,
util::PEPPER_VERSION_MINOR, util::PEPPER_VERSION_PATCH);
GetDlgItem(IDC_LINK_PEPPER)->SetWindowTextW(wstrVerPepper.data());
const auto wstrVerLibpe = std::format(L"libpe: PE32/PE32+ Binaries Parsing Library v{}.{}.{}",
libpe::LIBPE_VERSION_MAJOR, libpe::LIBPE_VERSION_MINOR, libpe::LIBPE_VERSION_PATCH);
GetDlgItem(IDC_LINK_LIBPE)->SetWindowTextW(wstrVerLibpe.data());
Expand Down
5 changes: 5 additions & 0 deletions Pepper/CPepperDoc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,11 @@ void CPepperDoc::OnResExtractAllPng()
ExtractAllResToFile(GetResources(), EResType::RTYPE_PNG, m_wstrDocName);
}

auto CPepperDoc::GetFileLoader()->CFileLoader&
{
return m_stFileLoader;
}

void CPepperDoc::SetEditMode(bool fEditMode)
{
if (!m_stFileLoader.IsWritable()) {
Expand Down
18 changes: 9 additions & 9 deletions Pepper/CPepperDoc.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,16 @@
#include <afxcontrolbars.h>
#include "CFileLoader.h"
import Utility;
using namespace util;
import libpe;
using namespace libpe;

class CPepperDoc : public CDocument
{
public:
CFileLoader m_stFileLoader;
[[nodiscard]] auto GetFileLoader() -> CFileLoader&;
void SetEditMode(bool fEditMode);
[[nodiscard]] bool IsEditMode() { return m_fEditMode; }
[[nodiscard]] auto GetFileInfo() -> PEFILEINFO&;
[[nodiscard]] auto GetFileInfo() -> util::PEFILEINFO&;
[[nodiscard]] auto GetOffsetFromVA(ULONGLONG ullVA) -> DWORD;
[[nodiscard]] auto GetOffsetFromRVA(ULONGLONG ullRVA) -> DWORD;
[[nodiscard]] auto GetDOSHeader() -> std::optional<IMAGE_DOS_HEADER>&;
Expand Down Expand Up @@ -53,12 +52,8 @@ class CPepperDoc : public CDocument
DECLARE_DYNCREATE(CPepperDoc);
DECLARE_MESSAGE_MAP();
private:
CFileLoader m_stFileLoader;
std::wstring m_wstrDocName; //Opened document name.
bool m_fEditMode { false };
bool m_fHasCur { false };
bool m_fHasIco { false };
bool m_fHasBmp { false };
bool m_fHasPng { false };
std::optional<IMAGE_DOS_HEADER> m_optDOS;
std::optional<PERICHHDR_VEC> m_optRich;
std::optional<PENTHDR> m_optNTHdr;
Expand All @@ -76,5 +71,10 @@ class CPepperDoc : public CDocument
std::optional<PEBOUNDIMPORT_VEC> m_optBoundImp;
std::optional<PEDELAYIMPORT_VEC> m_optDelayImp;
std::optional<PECOMDESCRIPTOR> m_optComDescr;
PEFILEINFO m_stFileInfo;
util::PEFILEINFO m_stFileInfo;
bool m_fEditMode { false };
bool m_fHasCur { false };
bool m_fHasIco { false };
bool m_fHasBmp { false };
bool m_fHasPng { false };
};
6 changes: 3 additions & 3 deletions Pepper/CSplitterEx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@ END_MESSAGE_MAP()

BOOL CSplitterEx::CreateStatic(CWnd* m_pParent, int nRows, int nCols, DWORD dwStyle, UINT nID)
{
//If already created.
if ((!m_vecRows.empty() && !m_vecCols.empty()) || !(nRows | nCols) || (nRows | nCols) > 16)
return FALSE;
return FALSE; //If already created.

m_vecRows.resize(nRows, true);
m_vecCols.resize(nCols, true);
Expand Down Expand Up @@ -141,7 +140,8 @@ void CSplitterEx::RecalcPanes()
for (auto iterRow = 0U; iterRow < m_vecRows.size(); ++iterRow) {
for (auto iterCol = 0U; iterCol < m_vecCols.size(); ++iterCol) {
//Finding an exact pane.
if (const auto iterPane = std::find_if(m_vecPanes.begin(), m_vecPanes.end(), [=](const SPANES& refData) { return refData.iRow == vecRowsOrdered[iterRow] && refData.iCol == vecColsOrdered[iterCol]; });
if (const auto iterPane = std::find_if(m_vecPanes.begin(), m_vecPanes.end(),
[=](const SPANES& refData) { return refData.iRow == vecRowsOrdered[iterRow] && refData.iCol == vecColsOrdered[iterCol]; });
iterPane != m_vecPanes.end()) {
const auto pPane = iterPane->pPane;
pPane->SetDlgCtrlID(AFX_IDW_PANE_FIRST + iterRow * 16 + iterCol);
Expand Down
7 changes: 3 additions & 4 deletions Pepper/CSplitterEx.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,21 @@
class CSplitterEx : public CSplitterWndEx
{
public:
DECLARE_DYNAMIC(CSplitterEx);
BOOL CreateStatic(CWnd* m_pParent, int nRows, int nCols, DWORD dwStyle = WS_CHILD | WS_VISIBLE, UINT nID = AFX_IDW_PANE_FIRST)override;
BOOL CreateView(int row, int col, CRuntimeClass* pViewClass, SIZE sizeInit, CCreateContext* pContext)override;
bool AddNested(int row, int col, CWnd* pNested);
bool HideRow(UINT nRow);
bool ShowRow(UINT nRow);
bool HideCol(UINT nCol);
bool ShowCol(UINT nCol);
DECLARE_MESSAGE_MAP()
DECLARE_MESSAGE_MAP();
DECLARE_DYNAMIC(CSplitterEx);
private:
void RecalcPanes();
afx_msg void OnMouseMove(UINT nFlags, CPoint pt);
void OnInvertTracker(const CRect& rect)override;
private:
struct SPANES
{
struct SPANES {
int iRow { }; //Row of the pane.
int iCol { }; //Column of the pane.
CWnd* pPane { }; //Pane pointer.
Expand Down
4 changes: 2 additions & 2 deletions Pepper/CViewRightBL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ void CViewRightBL::OnInitialUpdate()

m_pChildFrame = static_cast<CChildFrame*>(GetParentFrame());
m_pMainDoc = static_cast<CPepperDoc*>(GetDocument());
m_pFileLoader = &m_pMainDoc->m_stFileLoader;
m_pFileLoader = &m_pMainDoc->GetFileLoader();
m_stFileInfo = m_pMainDoc->GetFileInfo();

//Hex control for SecurityDir and TLSdir.
Expand Down Expand Up @@ -204,7 +204,7 @@ void CViewRightBL::OnTreeSelChanged(NMHDR* pNMHDR, LRESULT* /*pResult*/)

m_pMainDoc->UpdateAllViews(this, MAKELPARAM(IDC_SHOW_RESOURCE_RBR, 0), reinterpret_cast<CObject*>(&m_stResData));
}
else { //Update by default, with no pData — to clear the view.
else { //Update by default, with no pData — to clear the view.
m_pMainDoc->UpdateAllViews(this, MAKELPARAM(IDC_SHOW_RESOURCE_RBR, 0), nullptr);
}
}
Expand Down
5 changes: 3 additions & 2 deletions Pepper/CViewRightTL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ void CViewRightTL::OnInitialUpdate()

m_pChildFrame = static_cast<CChildFrame*>(GetParentFrame());
m_pMainDoc = static_cast<CPepperDoc*>(GetDocument());
m_pFileLoader = &m_pMainDoc->m_stFileLoader;
m_pFileLoader = &m_pMainDoc->GetFileLoader();

LOGFONTW lf { };
StringCchCopyW(lf.lfFaceName, 9, L"Consolas");
Expand Down Expand Up @@ -59,7 +59,8 @@ void CViewRightTL::OnInitialUpdate()
else {
m_wstrFileType = L"File type: unknown";
}
m_wstrPepperVersion = WSTR_PEPPER_VERSION;
m_wstrPepperVersion = std::format(L"Pepper v{}.{}.{}", util::PEPPER_VERSION_MAJOR,
util::PEPPER_VERSION_MINOR, util::PEPPER_VERSION_PATCH);

m_stlcs.stColor.clrTooltipText = RGB(255, 255, 255);
m_stlcs.stColor.clrTooltipBk = RGB(0, 132, 132);
Expand Down
2 changes: 1 addition & 1 deletion Pepper/CViewRightTR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ void CViewRightTR::OnInitialUpdate()

m_pChildFrame = static_cast<CChildFrame*>(GetParentFrame());
m_pMainDoc = static_cast<CPepperDoc*>(GetDocument());
m_pFileLoader = &m_pMainDoc->m_stFileLoader;
m_pFileLoader = &m_pMainDoc->GetFileLoader();

//Hex control for Resources raw.
m_hcs.hWndParent = m_hWnd;
Expand Down
6 changes: 2 additions & 4 deletions Pepper/Pepper.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
<LanguageStandard>stdcpp20</LanguageStandard>
<ConformanceMode>true</ConformanceMode>
<AdditionalOptions>/utf-8 %(AdditionalOptions)</AdditionalOptions>
<AdditionalIncludeDirectories>dep\libpe\src\;dep\HexCtrl\HexCtrl;dep\HexCtrl\HexCtrl\dep;</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>dep\HexCtrl\HexCtrl;dep\HexCtrl\HexCtrl\dep;</AdditionalIncludeDirectories>
<ProgramDataBaseFileName>$(OutDir)$(PlatformToolsetVersion).pdb</ProgramDataBaseFileName>
</ClCompile>
<Link>
Expand Down Expand Up @@ -111,7 +111,7 @@
<MultiProcessorCompilation>true</MultiProcessorCompilation>
<LanguageStandard>stdcpp20</LanguageStandard>
<ConformanceMode>true</ConformanceMode>
<AdditionalIncludeDirectories>dep\libpe\src\;dep\HexCtrl\HexCtrl;dep\HexCtrl\HexCtrl\dep;</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>dep\HexCtrl\HexCtrl;dep\HexCtrl\HexCtrl\dep;</AdditionalIncludeDirectories>
<AdditionalOptions>/utf-8 %(AdditionalOptions)</AdditionalOptions>
</ClCompile>
<Link>
Expand Down Expand Up @@ -223,8 +223,6 @@
<ClInclude Include="stdafx.h" />
<ClCompile Include="Utility.ixx">
<FileType>Document</FileType>
<CompileAs Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">CompileAsCppModule</CompileAs>
<CompileAs Condition="'$(Configuration)|$(Platform)'=='Release|x64'">CompileAsCppModule</CompileAs>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">NotUsing</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">NotUsing</PrecompiledHeader>
</ClCompile>
Expand Down
6 changes: 3 additions & 3 deletions Pepper/Pepper.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@
<ClCompile Include="CFileLoader.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Utility.ixx">
<Filter>Header Files</Filter>
</ClCompile>
<ClCompile Include="dep\HexCtrl\HexCtrl\dep\ListEx\CListEx.cpp">
<Filter>HexCtrl</Filter>
</ClCompile>
Expand Down Expand Up @@ -88,6 +85,9 @@
<ClCompile Include="dep\libpe\libpe\libpe.ixx">
<Filter>libpe</Filter>
</ClCompile>
<ClCompile Include="Utility.ixx">
<Filter>Header Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="res\resource.h">
Expand Down
24 changes: 5 additions & 19 deletions Pepper/Utility.ixx
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,16 @@ module;
#include <unordered_map>
#include "HexCtrl.h"

#define PEPPER_PRODUCT_NAME L"Pepper"
#define PEPPER_PRODUCT_DESC L"PE files viewer, github.com/jovibor/Pepper"
#define PEPPER_COPYRIGHT_NAME L"(C) Jovibor 2019-2023"
#define PEPPER_MAJOR_VERSION 1
#define PEPPER_MINOR_VERSION 5
#define PEPPER_MAINTENANCE_VERSION 3

#define TO_WSTR_HELPER(x) L## #x
#define TO_WSTR(x) TO_WSTR_HELPER(x)
#define PEPPER_VERSION_WSTR PEPPER_PRODUCT_NAME L" - PE32/PE32+ binaries viewer v" TO_WSTR(PEPPER_MAJOR_VERSION) L"."\
TO_WSTR(PEPPER_MINOR_VERSION) L"." TO_WSTR(PEPPER_MAINTENANCE_VERSION)
#define TO_WSTR_MAP(x) {x, L## #x}
export module Utility;

import libpe;

#define TO_WSTR_MAP(x) {x, L## #x}

export namespace util
{
constexpr const wchar_t WSTR_PEPPER_PRODUCT_NAME[] = PEPPER_PRODUCT_NAME;
#ifdef _WIN64
constexpr const auto WSTR_PEPPER_VERSION = PEPPER_VERSION_WSTR L" (x64)";
#else
constexpr const auto WSTR_PEPPER_VERSION = PEPPER_VERSION_WSTR L" (x86)";
#endif
constexpr auto PEPPER_VERSION_MAJOR = 1;
constexpr auto PEPPER_VERSION_MINOR = 5;
constexpr auto PEPPER_VERSION_PATCH = 3;

[[nodiscard]] inline auto StrToWstr(std::string_view sv, UINT uCodePage = CP_UTF8) -> std::wstring
{
Expand Down
2 changes: 1 addition & 1 deletion Pepper/dep/libpe
Submodule libpe updated 2 files
+38 −36 libpe/libpe.ixx
+25 −14 test/test.cpp

0 comments on commit 11fc0f9

Please sign in to comment.