Merge branch 'dev'
This commit is contained in:
BIN
Version.ini
BIN
Version.ini
Binary file not shown.
@@ -1,4 +1,4 @@
|
||||
// wCenterWindow
|
||||
// wCenterWindow
|
||||
// CLogger.cpp
|
||||
|
||||
#include "CLogger.h"
|
||||
@@ -6,6 +6,15 @@
|
||||
#include <filesystem>
|
||||
#include <strsafe.h>
|
||||
|
||||
// Convert a wide Unicode string to an UTF8 string
|
||||
std::string CLogger::ConvU16U8(const std::wstring& wstr) {
|
||||
if (wstr.empty()) return std::string();
|
||||
int size = WideCharToMultiByte(CP_UTF8, 0, &wstr[0], wstr.size(), NULL, 0, NULL, NULL);
|
||||
std::string str_out(size, 0);
|
||||
WideCharToMultiByte(CP_UTF8, 0, &wstr[0], wstr.size(), &str_out[0], size, NULL, NULL);
|
||||
return str_out;
|
||||
}
|
||||
|
||||
inline wchar_t* CLogger::GetTimeStamp() {
|
||||
GetLocalTime(<);
|
||||
StringCchPrintfW(logTimeBuffer, _countof(logTimeBuffer), L"%d-%02d-%02d %02d:%02d:%02d.%03d | ", lt.wYear, lt.wMonth, lt.wDay, lt.wHour, lt.wMinute, lt.wSecond, lt.wMilliseconds);
|
||||
@@ -19,7 +28,7 @@ void CLogger::Out(const wchar_t* fmt, ...) {
|
||||
EnterCriticalSection(&cs);
|
||||
StringCchVPrintfW(logBuffer, _countof(logBuffer), fmt, args);
|
||||
va_end(args);
|
||||
fsLogFile << GetTimeStamp() << logBuffer << std::endl;
|
||||
fsLogFile << ConvU16U8(GetTimeStamp()) << ConvU16U8(logBuffer) << std::endl;
|
||||
LeaveCriticalSection(&cs);
|
||||
}
|
||||
}
|
||||
@@ -44,15 +53,15 @@ void CLogger::Init() {
|
||||
|
||||
if (std::filesystem::exists(log_path)) std::filesystem::rename(log_path, bak_path);
|
||||
#ifdef _DEBUG
|
||||
log_path = L"D:\\test.log";
|
||||
log_path = L"test.log";
|
||||
#endif
|
||||
fsLogFile.open(log_path, std::ios::trunc);
|
||||
if (fsLogFile.is_open()) {
|
||||
InitializeCriticalSection(&cs);
|
||||
fsLogFile << "\xEF\xBB\xBF"; // (0xEF, 0xBB, 0xBF) - UTF-8 BOM
|
||||
fsLogFile.imbue(std::locale("en-US.utf8"));
|
||||
fsLogFile << GetTimeStamp() << "[ " << szAppTitleVer.c_str() << " ] Start log." << std::endl;
|
||||
fsLogFile << GetTimeStamp() << "Logfile: \"" << log_path.native() << "\"" << std::endl;
|
||||
fsLogFile.imbue(std::locale(".UTF-8"));
|
||||
fsLogFile << ConvU16U8(GetTimeStamp()) << "[ " << ConvU16U8(szAppTitleVer).c_str() << " ] Start log." << std::endl;
|
||||
fsLogFile << ConvU16U8(GetTimeStamp()) << "Logfile: \"" << ConvU16U8(log_path.native()) << "\"" << std::endl;
|
||||
}
|
||||
else {
|
||||
MessageBoxW(NULL, L"Warning!\nCan't create log file! Working without logging.", szAppTitle.c_str(), MB_OK | MB_ICONWARNING | MB_SYSTEMMODAL);
|
||||
@@ -67,7 +76,7 @@ CLogger::CLogger(const wchar_t* _appTitle) {
|
||||
|
||||
CLogger::~CLogger() {
|
||||
if (fsLogFile) {
|
||||
fsLogFile << GetTimeStamp() << "Stop log." << std::endl;
|
||||
fsLogFile << ConvU16U8(GetTimeStamp()) << "Stop log." << std::endl;
|
||||
fsLogFile.close();
|
||||
DeleteCriticalSection(&cs);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// wCenterWindow
|
||||
// wCenterWindow
|
||||
// CLogger.h
|
||||
|
||||
#pragma once
|
||||
@@ -16,14 +16,15 @@ public:
|
||||
private:
|
||||
SYSTEMTIME lt;
|
||||
CRITICAL_SECTION cs;
|
||||
wchar_t logTimeBuffer[28]{ 0 };
|
||||
wchar_t logBuffer[MAX_LOGBUFFER_LENGTH]{ 0 };
|
||||
std::wofstream fsLogFile;
|
||||
std::wstring szAppTitle{ 0 };
|
||||
std::wstring szAppVersion{ 0 };
|
||||
std::wstring szAppPlatform{ 0 };
|
||||
std::wstring szAppTitleVer{ 0 };
|
||||
wchar_t logTimeBuffer[28] { 0 };
|
||||
wchar_t logBuffer[MAX_LOGBUFFER_LENGTH] { 0 };
|
||||
std::ofstream fsLogFile;
|
||||
std::wstring szAppTitle { 0 };
|
||||
std::wstring szAppVersion { 0 };
|
||||
std::wstring szAppPlatform { 0 };
|
||||
std::wstring szAppTitleVer { 0 };
|
||||
|
||||
std::string ConvU16U8(const std::wstring&);
|
||||
inline wchar_t* GetTimeStamp();
|
||||
void Init();
|
||||
};
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// wCenterWindow
|
||||
// wCenterWindow
|
||||
// updater.h
|
||||
|
||||
#include "wCenterWindow.h"
|
||||
@@ -46,13 +46,6 @@ UINT WINAPI Updater(void*) {
|
||||
logger.Out(L"[UPDT] %s(%d): Parsing JSON object", TEXT(__FUNCTION__), __LINE__);
|
||||
|
||||
obj = json.get<picojson::object>();
|
||||
it = obj.find("message"), it2;
|
||||
if (it != obj.end()) {
|
||||
std::string u = (*it).second.get<std::string>();
|
||||
logger.Out(L"[UPDT] %s(%d): Error! The url is %s", TEXT(__FUNCTION__), __LINE__, u);
|
||||
return 102;
|
||||
_endthreadex(102);
|
||||
}
|
||||
|
||||
for (it = obj.begin(); it != obj.end(); it++) {
|
||||
if ((*it).first == "tag_name") j_tag_name = ConvertUtf8ToWide((*it).second.to_str());
|
||||
@@ -70,8 +63,8 @@ UINT WINAPI Updater(void*) {
|
||||
}
|
||||
else {
|
||||
logger.Out(L"[UPDT] %s(%d): Error! Cannot recognize JSON object!", TEXT(__FUNCTION__), __LINE__);
|
||||
return 103;
|
||||
_endthreadex(103);
|
||||
return 102;
|
||||
_endthreadex(102);
|
||||
}
|
||||
|
||||
size_t pos = 0;
|
||||
@@ -127,14 +120,13 @@ bool GetLatestRelease(const std::wstring& urn) {
|
||||
if (hRequest != NULL) {
|
||||
BOOL isSend = HttpSendRequestW(hRequest, NULL, 0, 0, 0);
|
||||
if (isSend) {
|
||||
char szData[1024]{ 0 };
|
||||
char szData[1024] { 0 };
|
||||
DWORD dwBytesRead = 0;
|
||||
std::string buffer;
|
||||
do {
|
||||
InternetReadFile(hRequest, szData, sizeof(szData), &dwBytesRead);
|
||||
buffer.append(szData, dwBytesRead);
|
||||
}
|
||||
while (dwBytesRead != 0);
|
||||
} while (dwBytesRead != 0);
|
||||
|
||||
picojson::parse(json, buffer);
|
||||
std::string jerr = picojson::get_last_error();
|
||||
@@ -144,7 +136,18 @@ bool GetLatestRelease(const std::wstring& urn) {
|
||||
MessageBoxW(NULL, L"Error while parsing JSON object!", szTitle, MB_OK | MB_ICONERROR);
|
||||
ret = false;
|
||||
}
|
||||
|
||||
else {
|
||||
picojson::object obj = json.get<picojson::object>();
|
||||
std::string msg, sts;
|
||||
if (auto search = obj.find("message"); search != obj.end()) {
|
||||
msg = (search->first) + ": " + (search->second).get<std::string>();
|
||||
}
|
||||
if (auto search = obj.find("status"); search != obj.end()) {
|
||||
sts = (search->first) + ": " + (search->second).get<std::string>();
|
||||
}
|
||||
logger.Out(L"[UPDT] %s(%d): Error! %s", TEXT(__FUNCTION__), __LINE__, ConvertUtf8ToWide(msg + ", " + sts).c_str());
|
||||
ret = false;
|
||||
}
|
||||
}
|
||||
else {
|
||||
err = GetLastError();
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
// wCenterWindow
|
||||
// wCenterWindow
|
||||
// wCenterWindow.cpp
|
||||
|
||||
// TODO: Split main cpp-file to separate files.
|
||||
// TODO: Make Updater's errors as Windows notifications.
|
||||
// TODO: Make the automatic updater (download, unzip and replace executable).
|
||||
// TODO: Change keyboard low-level hook to RegisterHotKey function. (Is it really needed?)
|
||||
|
||||
#pragma warning( disable : 28251 )
|
||||
|
||||
#include "framework.h"
|
||||
#include "wCenterWindow.h"
|
||||
#include "updater.h"
|
||||
@@ -228,7 +231,7 @@ int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmd
|
||||
HeapFree(hHeap, NULL, szWinClassBuffer);
|
||||
HeapFree(hHeap, NULL, szWinTitleBuffer);
|
||||
|
||||
logger.Out(L"Exit from the %s() function, msg.wParam = 0x%0*tX", TEXT(__FUNCTION__), (sizeof(UINT_PTR) * 2), static_cast<UINT_PTR>(msg.wParam));
|
||||
logger.Out(L"Exit from the %s() function, msg.wParam = 0x%p", TEXT(__FUNCTION__), msg.wParam);
|
||||
|
||||
return static_cast<UINT_PTR>(msg.wParam);
|
||||
}
|
||||
|
||||
Binary file not shown.
@@ -30,26 +30,26 @@
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<PlatformToolset>v142</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<PlatformToolset>v142</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<PlatformToolset>v142</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<PlatformToolset>v142</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
@@ -100,6 +100,7 @@
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>false</ConformanceMode>
|
||||
<LanguageStandard>stdcpp17</LanguageStandard>
|
||||
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
@@ -123,7 +124,7 @@
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>false</ConformanceMode>
|
||||
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
|
||||
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
|
||||
<LanguageStandard>stdcpp17</LanguageStandard>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
@@ -147,6 +148,7 @@
|
||||
<PreprocessorDefinitions>_DEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<LanguageStandard>stdcpp17</LanguageStandard>
|
||||
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
@@ -170,7 +172,7 @@
|
||||
<PreprocessorDefinitions>NDEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<LanguageStandard>stdcpp17</LanguageStandard>
|
||||
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
|
||||
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<LocalDebuggerCommandArguments>/noupdate</LocalDebuggerCommandArguments>
|
||||
<LocalDebuggerCommandArguments>
|
||||
</LocalDebuggerCommandArguments>
|
||||
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
@@ -10,7 +11,8 @@
|
||||
</LocalDebuggerCommandArguments>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<LocalDebuggerCommandArguments>/noupdate</LocalDebuggerCommandArguments>
|
||||
<LocalDebuggerCommandArguments>
|
||||
</LocalDebuggerCommandArguments>
|
||||
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
|
||||
Reference in New Issue
Block a user