Skip to content

Commit dca1080

Browse files
author
Jan Wilmans
committed
clang-formatted and fixed comments, global application of clang-format
is not possible yet, the WTL macros are not formatting the way I would like and ignoring every section sounds like a poor solution.
1 parent 793963a commit dca1080

File tree

8 files changed

+78
-49
lines changed

8 files changed

+78
-49
lines changed

application/DebugViewpp/DebugView++.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
#include "atleverything.h"
1616

1717
#include <filesystem>
18-
#include <cstdlib> // for std::getenv
18+
#include <cstdlib> // for std::getenv
1919

20-
//#define ENABLE_CRASHPAD
20+
// #define ENABLE_CRASHPAD
2121
#ifdef ENABLE_CRASHPAD
2222
#include "crashpad.h"
2323
#endif
@@ -161,8 +161,8 @@ int Main(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, LPWSTR /*lpstrCmdLine
161161
}
162162
else if (boost::iequals(args[i], L"/log"))
163163
{
164-
//wndMain.SetLogging(); // todo: implement: FileWriter needs to concurrently access m_logfile, it now causes a crash if DbgMsgSrc -1 is run
165-
// this should be replaced by the new streaming-to-disk feature we discussed.
164+
// wndMain.SetLogging(); // todo: implement: FileWriter needs to concurrently access m_logfile, it now causes a crash if DbgMsgSrc -1 is run
165+
// this should be replaced by the new streaming-to-disk feature we discussed.
166166
}
167167
else if (boost::icontains(args[i], L"/tab:"))
168168
{
@@ -213,7 +213,8 @@ int Main(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, LPWSTR /*lpstrCmdLine
213213
} // namespace fusion
214214

215215

216-
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpstrCmdLine, int nCmdShow) try
216+
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpstrCmdLine, int nCmdShow)
217+
try
217218
{
218219
#ifdef ENABLE_CRASHPAD
219220
initializeCrashPad();

application/DebugViewpp/DropTargetSupport.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ namespace debugviewpp {
1818
*/
1919

2020
DropTargetSupport::DropTargetSupport()
21-
2221
{
2322
}
2423

application/DebugViewpp/MainFrame.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ LRESULT CMainFrame::OnCreate(const CREATESTRUCT* /*pCreate*/)
234234
HWND hWndCmdBar = m_cmdBar.Create(*this, rcDefault, nullptr, ATL_SIMPLE_CMDBAR_PANE_STYLE);
235235
m_cmdBar.AttachMenu(GetMenu());
236236
m_cmdBar.LoadImages(IDR_MAINFRAME);
237-
SetMenu(nullptr); //disable second menu bar
237+
SetMenu(nullptr); // disable second menu bar
238238

239239
CreateSimpleReBar(ATL_SIMPLE_REBAR_NOBORDER_STYLE);
240240
CReBarCtrl rebar(m_hWndToolBar);
@@ -1492,11 +1492,12 @@ void CMainFrame::Resume()
14921492
catch (std::exception& e)
14931493
{
14941494
const auto message = std::format("Unable to capture Kernel Messages.\n"
1495-
"({})\n\n"
1496-
"Make sure you have appropriate permissions.\n"
1497-
"\n"
1498-
"You may need to start this application by right-clicking it and selecting\n"
1499-
"'Run As Administator' even if you have administrator rights.", e.what());
1495+
"({})\n\n"
1496+
"Make sure you have appropriate permissions.\n"
1497+
"\n"
1498+
"You may need to start this application by right-clicking it and selecting\n"
1499+
"'Run As Administator' even if you have administrator rights.",
1500+
e.what());
15001501
MessageBox(WStr(message), m_applicationName.c_str(), MB_ICONERROR | MB_OK);
15011502
m_tryKernel = false;
15021503
}
@@ -1669,10 +1670,10 @@ void CMainFrame::OnViewDuplicate(UINT /*uNotifyCode*/, int /*nID*/, CWindow /*wn
16691670

16701671
AddFilterView(dlg.GetName(), dlg.GetFilters());
16711672

1672-
//auto &view = GetView();
1673-
//auto newLogView = std::make_shared<CLogView>(view); // no copy constructor available
1674-
//newLogView->SetName(view.GetName() + L" (copy)");
1675-
//AddFilterView(newLogView);
1673+
// auto &view = GetView();
1674+
// auto newLogView = std::make_shared<CLogView>(view); // no copy constructor available
1675+
// newLogView->SetName(view.GetName() + L" (copy)");
1676+
// AddFilterView(newLogView);
16761677

16771678
SaveSettings();
16781679
}

application/DebugViewppLib/Debugview_kernel_client.cpp

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,30 @@ constexpr const char* DRIVER_SERVICE_NAME = "debugviewdriver";
99
constexpr const char* DRIVER_DISPLAY_NAME = "DbgView Kernel Message Driver";
1010
const std::string driverPath = "C:\\Windows\\System32\\drivers\\dbgvpp.sys";
1111

12-
bool FileExists(const std::string& path) {
12+
bool FileExists(const std::string& path)
13+
{
1314
DWORD fileAttributes = GetFileAttributesA(path.c_str());
1415
return (fileAttributes != INVALID_FILE_ATTRIBUTES &&
15-
!(fileAttributes & FILE_ATTRIBUTE_DIRECTORY));
16+
!(fileAttributes & FILE_ATTRIBUTE_DIRECTORY));
1617
}
1718

1819
bool StartDriverSvc()
1920
{
2021
SC_HANDLE hSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
21-
if (!hSCManager) return false;
22+
if (!hSCManager)
23+
return false;
2224

2325
SC_HANDLE hService = OpenServiceA(hSCManager, DRIVER_SERVICE_NAME, SERVICE_START);
24-
if (!hService) {
26+
if (!hService)
27+
{
2528
CloseServiceHandle(hSCManager);
2629
return false;
2730
}
2831

29-
if (!StartService(hService, 0, NULL)) {
30-
if (GetLastError() == ERROR_SERVICE_ALREADY_RUNNING) {
32+
if (!StartService(hService, 0, NULL))
33+
{
34+
if (GetLastError() == ERROR_SERVICE_ALREADY_RUNNING)
35+
{
3136
std::cout << "Service is already running.\n";
3237
CloseServiceHandle(hService);
3338
CloseServiceHandle(hSCManager);
@@ -47,18 +52,22 @@ bool StartDriverSvc()
4752
bool StopDriverSvc()
4853
{
4954
SC_HANDLE hSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
50-
if (!hSCManager) return false;
55+
if (!hSCManager)
56+
return false;
5157

5258
SC_HANDLE hService = OpenServiceA(hSCManager, DRIVER_SERVICE_NAME, SERVICE_STOP);
53-
if (!hService) {
59+
if (!hService)
60+
{
5461
CloseServiceHandle(hSCManager);
5562
return false;
5663
}
5764

5865
SERVICE_STATUS status;
59-
if (!ControlService(hService, SERVICE_CONTROL_STOP, &status)) {
66+
if (!ControlService(hService, SERVICE_CONTROL_STOP, &status))
67+
{
6068
DWORD err = GetLastError();
61-
if (err != ERROR_SERVICE_NOT_ACTIVE) {
69+
if (err != ERROR_SERVICE_NOT_ACTIVE)
70+
{
6271
std::cout << "Failed to stop service. Error: " << err << std::endl;
6372
}
6473
}
@@ -73,12 +82,14 @@ void InstallKernelMessagesDriver(const std::string& driverLocation)
7382
// try to uninstall first, in case the driver is somehow still loaded.
7483
UninstallKernelMessagesDriver();
7584

76-
if (!FileExists(driverPath)) {
85+
if (!FileExists(driverPath))
86+
{
7787
std::cout << "Driver file not found at: " << driverPath << std::endl;
7888
}
7989

8090
SC_HANDLE hSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
81-
if (!hSCManager) {
91+
if (!hSCManager)
92+
{
8293
std::cout << "Failed to open Service Control Manager. Error: " << GetLastError() << std::endl;
8394
}
8495

@@ -91,11 +102,12 @@ void InstallKernelMessagesDriver(const std::string& driverLocation)
91102
SERVICE_DEMAND_START,
92103
SERVICE_ERROR_NORMAL,
93104
driverLocation.c_str(),
94-
NULL, NULL, NULL, NULL, NULL
95-
);
105+
NULL, NULL, NULL, NULL, NULL);
96106

97-
if (!hService) {
98-
if (GetLastError() == ERROR_SERVICE_EXISTS) {
107+
if (!hService)
108+
{
109+
if (GetLastError() == ERROR_SERVICE_EXISTS)
110+
{
99111
std::cout << "Service already exists.\n";
100112
CloseServiceHandle(hSCManager);
101113
}

application/DebugViewppLib/KernelReader.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,10 @@ void KernelReader::Poll()
104104
memset(m_pBuf, 0, kernelMessageBufferSize);
105105
DWORD dwOut = 0;
106106
::DeviceIoControl(m_handle.get(), DBGV_READ_LOG, NULL, 0, m_pBuf, kernelMessageBufferSize, &dwOut, NULL);
107-
if (dwOut == 0) return; // no messages to be read
107+
if (dwOut == 0)
108+
{
109+
return; // no messages to be read
110+
}
108111

109112
PLOG_ITEM pNextItem = m_pBuf;
110113
while (pNextItem->dwIndex != 0)

application/Win32Lib/Win32Lib.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -300,14 +300,14 @@ void SetSecurityInfo(HANDLE hObject, SE_OBJECT_TYPE ObjectType, SECURITY_INFORMA
300300

301301
#ifdef DACL_MODIFY
302302

303-
//delete DACL at all, so permit Full Access for Everyone
303+
// delete DACL at all, so permit Full Access for Everyone
304304
void DeleteObjectDACL(HANDLE hObject)
305305
{
306306
Win32::SetSecurityInfo(hObject, SE_KERNEL_OBJECT, DACL_SECURITY_INFORMATION, nullptr, nullptr, nullptr, nullptr);
307307
}
308308

309-
//add necessary permissions for "Authenticated Users" group (all non-anonymous users)
310-
//and for "All Application Packages", "All Restricted Application Packages" for UWP support
309+
// add necessary permissions for "Authenticated Users" group (all non-anonymous users)
310+
// and for "All Application Packages", "All Restricted Application Packages" for UWP support
311311
void AdjustObjectDACL(HANDLE hObject)
312312
{
313313
ACL* pOldDACL;

application/include/DebugViewppLib/Debugview_kernel_client.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
// (See accompanying file LICENSE_1_0.txt or copy at
44
// http://www.boost.org/LICENSE_1_0.txt)
55

6+
//
7+
// this is the dbgv.sys interface
8+
//
9+
610
#pragma once
711

812
#include <windows.h>
@@ -13,9 +17,9 @@
1317
#include <string>
1418
#include <iostream>
1519

16-
// this is the dbgv.sys interface
1720
#define FILE_DEVICE_DBGV 0x8305
1821

22+
// clang-format off
1923
#define DBGV_CAPTURE_KERNEL CTL_CODE(FILE_DEVICE_DBGV, DWORD(0), METHOD_BUFFERED, FILE_ANY_ACCESS) //0x00 //enable capture kernel
2024
#define DBGV_UNCAPTURE_KERNEL CTL_CODE(FILE_DEVICE_DBGV, DWORD(1), METHOD_BUFFERED, FILE_ANY_ACCESS) //0x04 //
2125
#define DBGV_CLEAR_DISPLAY CTL_CODE(FILE_DEVICE_DBGV, DWORD(2), METHOD_BUFFERED, FILE_ANY_ACCESS) //0x08 //clear display
@@ -28,6 +32,7 @@
2832
#define DBGV_UNSET_CARRIAGE_RETURN CTL_CODE(FILE_DEVICE_DBGV, DWORD(0x0e), METHOD_BUFFERED, FILE_ANY_ACCESS) //0x38 //
2933
#define DBGV_SET_VERBOSE_MESSAGES CTL_CODE(FILE_DEVICE_DBGV, DWORD(0x0f), METHOD_BUFFERED, FILE_ANY_ACCESS) //0x3C //enable log verbose
3034
#define DBGV_UNSET_VERBOSE_MESSAGES CTL_CODE(FILE_DEVICE_DBGV, DWORD(0x10), METHOD_BUFFERED, FILE_ANY_ACCESS) //0x40 //reset log verbose
35+
// clang-format on
3136

3237
inline std::string feature_to_string(DWORD value)
3338
{
@@ -51,7 +56,7 @@ inline std::string feature_to_string(DWORD value)
5156
}
5257

5358
// suppress the non-standard use of zero-sized array in struct/union
54-
#pragma warning(disable:4200)
59+
#pragma warning(disable : 4200)
5560

5661
#pragma pack(1)
5762
typedef struct
@@ -63,7 +68,7 @@ typedef struct
6368
} LOG_ITEM, *PLOG_ITEM;
6469
#pragma pack()
6570

66-
constexpr const wchar_t * strDbgviewKernelDriverDeviceName = L"\\\\.\\dbgv";
71+
constexpr const wchar_t* strDbgviewKernelDriverDeviceName = L"\\\\.\\dbgv";
6772
constexpr const DWORD kernelMessageBufferSize = 0x10000;
6873

6974
void InstallKernelMessagesDriver(const std::string& driverLocation);

utils/apply-clang-format.py

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,20 @@ def IsCppFile(fullname):
3030
return True
3131
if ext.lower().endswith(".hh"):
3232
return True
33-
return False
33+
return False
3434

3535
def IsIgnoredDirectory(dirname):
36-
if dirname.lower().endswith("\gen"):
36+
if dirname.lower().endswith("\\gen"):
37+
return True
38+
if dirname.lower().endswith("\\gen64"):
39+
return True
40+
if dirname.lower().endswith("\\nuget"):
41+
return True
42+
if dirname.lower().endswith("\\packages"):
3743
return True
38-
if dirname.lower().endswith("\gen64"):
44+
if "\\application\\Libraries\\" in dirname.lower():
45+
return True
46+
if "\\nuget\\packages\\" in dirname.lower():
3947
return True
4048
return False
4149

@@ -44,22 +52,22 @@ def GetFiles(filemask, recurse):
4452
result = []
4553
path = os.path.dirname(os.path.abspath(filemask))
4654
for dirName, subdirList, fileList in os.walk(path):
47-
if IsIgnoredDirectory(dirName):
55+
if IsIgnoredDirectory(dirName):
4856
continue
4957
for fname in fileList:
5058
filename = dirName + "\\" + fname
51-
if not IsCppFile(filename):
59+
if not IsCppFile(filename):
5260
continue
5361
result += [filename]
5462
return result
5563
else:
5664
result = []
5765
for filename in glob.glob(filemask):
58-
if not IsCppFile(filename):
66+
if not IsCppFile(filename):
5967
continue
6068
result += [os.path.abspath(filename)]
6169
return result
62-
70+
6371
def filter(keyword):
6472
for line in sys.stdin:
6573
if not keyword in line:
@@ -80,7 +88,7 @@ def HasInvalidArgs():
8088
if sys.argv[1].startswith("/"):
8189
return True
8290
return False
83-
91+
8492
def main():
8593
if HasInvalidArgs():
8694
print ("Usage: " + os.path.basename(sys.argv[0]) + " <filemask> [/s] [/f]")
@@ -105,7 +113,7 @@ def main():
105113
except KeyboardInterrupt:
106114
pass
107115
except Exception:
108-
traceback.print_exc(file=sys.stdout)
116+
traceback.print_exc(file=sys.stdout)
109117
sys.exit(0)
110-
118+
111119

0 commit comments

Comments
 (0)