Slightly cleaned up code

This commit is contained in:
2022-02-12 18:13:19 +03:00
parent b5e040f3d5
commit f58e6a99cb
3 changed files with 37 additions and 22 deletions

View File

@@ -11,13 +11,15 @@ extern WCHAR szTitle[];
extern LPVOID szBuffer;
namespace fs = std::filesystem;
std::wstring PrintTitle() {
std::wstring PrintTitle()
{
wchar_t szWinTitle[2048];
StringCchPrintf(szWinTitle, 2048, L"%s", szBuffer);
return szWinTitle;
}
std::wstring GetTimeStamp() {
std::wstring GetTimeStamp()
{
SYSTEMTIME lt;
GetLocalTime(&lt);
wchar_t ts[TS_LEN];
@@ -25,15 +27,18 @@ std::wstring GetTimeStamp() {
return ts;
}
void OpenLogFile() {
void OpenLogFile()
{
wchar_t lpszPath[PATH_LEN]{};
DWORD dwPathLength = GetModuleFileNameW(NULL, lpszPath, PATH_LEN);
DWORD dwError = GetLastError();
if (ERROR_INSUFFICIENT_BUFFER == dwError) {
if (ERROR_INSUFFICIENT_BUFFER == dwError)
{
MessageBoxW(NULL, L"Path to logfile is too long! Working without logging.", (LPCWSTR)szTitle, MB_OK | MB_ICONWARNING);
return;
}
if (NULL == dwPathLength) {
if (NULL == dwPathLength)
{
MessageBoxW(NULL, L"Can't get module filename! Working without logging.", (LPCWSTR)szTitle, MB_OK | MB_ICONWARNING);
return;
}
@@ -48,18 +53,23 @@ void OpenLogFile() {
log_path = L"d:\\test.log";
#endif
logfile.open(log_path);
if (logfile.is_open()) {
if (logfile.is_open())
{
diag_log(L"Start logging.");
diag_log(L"Logfile:", log_path);
diag_log(log_path, L"successfully opened.");
} else {
}
else
{
MessageBoxW(NULL, L"Can't open logfile! Working without logging.", (LPCWSTR)szTitle, MB_OK | MB_ICONWARNING);
}
return;
}
void CloseLogFile() {
if (logfile) {
void CloseLogFile()
{
if (logfile)
{
diag_log(L"End logging.");
logfile.close();
}