Compare commits
56 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 5f6e1cd068 | |||
| 9a9b82b981 | |||
| 8bfa651cb9 | |||
| 3f646683aa | |||
| 75b31b5489 | |||
| 386f2df1da | |||
| 822f0dc7b7 | |||
| 6b0a7265a7 | |||
| 62ae981ff0 | |||
| bd6cabdc6b | |||
| 7d1d7b2456 | |||
| 422284a81d | |||
| 0de71bfe21 | |||
| c81de4f897 | |||
| 29ac0eff94 | |||
| 86bab7a53b | |||
| a141add693 | |||
| 826a9e1c74 | |||
| 2b55035234 | |||
| b09c969798 | |||
| 849689b286 | |||
| dfbf103b2e | |||
| b5ade2a064 | |||
| 82c90d4628 | |||
| 3e8b3b906b | |||
| 016e42bbf2 | |||
| f19e8178d6 | |||
| 181403098c | |||
| 4d230a850f | |||
| 53a70e1ad7 | |||
| bac58b056a | |||
| 6cb3b2aabd | |||
| c5b377b22f | |||
| 4228258e80 | |||
| 21c65369ec | |||
| 34ec99e90b | |||
| 2fea7600fb | |||
| e7609c1a34 | |||
| 2b340791b9 | |||
| b067ea9be4 | |||
| d26aa77af3 | |||
| 450173f0ee | |||
| ce275c0fcc | |||
| 6ba949de4b | |||
| 5b205ad2e4 | |||
| b8ce96ee99 | |||
| 76be5eb941 | |||
| d0f211d931 | |||
| abed2c3fd0 | |||
|
|
a103c80745 | ||
| f558df6bf9 | |||
| 8c570ab1e9 | |||
| 6b592d78c1 | |||
| a6d6527ff3 | |||
| 72158f53d7 | |||
| 4bfcf90e2a |
21
LICENSE
Normal file
21
LICENSE
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2020-2024 Vladislav Salikov aka W0LF
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
33
README.md
33
README.md
@@ -1,23 +1,34 @@
|
|||||||
## wCenterWindow
|
## wCenterWindow
|
||||||
|
|
||||||
This program centers the current active window by a `LCTRL + LWIN + C` hotkey,
|
Copyright (c) 2020-2024 Vladislav Salikov aka W0LF.<br>
|
||||||
or pressing `LCTRL + LWIN + MMB` (Middle Mouse Button).
|
Program icon made by Kirill Topov.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
This program centers the current active window by a `LCTRL + LWIN + C` hotkey, or pressing `LCTRL + LWIN + MMB` (Middle Mouse Button).
|
||||||
|
|
||||||
`LCTRL + LWIN + V` - manual editing of size and position of the window.
|
`LCTRL + LWIN + V` - manual editing of size and position of the window.
|
||||||
|
|
||||||
You can use `LCTRL + LWIN + I` hotkey for hide/show trayicon.
|
`LCTRL + LWIN + I` hotkey is used to hide/show trayicon.
|
||||||
You can also use commandline option `/hide` for hide trayicon at startup.
|
You can also use commandline option `/hide` to hide trayicon at startup.
|
||||||
The `/noupdate` option is used to disable check for updates. By default, the check is repeated once a day.
|
|
||||||
|
|
||||||
`Use workarea` option means that the window is centered without a taskbar, otherwise, the full resolution of the monitor will be used.
|
The `/noupdate` commandline option is used to disable check for updates. By default, the program checks for updates upon startup and once a day.
|
||||||
|
|
||||||
If some windows does not centers you should run wCenterWindow with administrative rights.
|
The `Use workarea` option (at popup menu) means that the window is centered without a taskbar, otherwise, the full resolution of the monitor will be used.
|
||||||
|
|
||||||
|
If some windows does not centers, you should run wCenterWindow with administrative rights.
|
||||||
|
|
||||||
## Automatic startup
|
## Automatic startup
|
||||||
|
|
||||||
Usually, to start the application when Windows starts, it is enough to put the application's shortcut in the "Startup" folder -\
|
Usually, to start the application when Windows starts, it is enough to put the application's shortcut in the "Startup" folder -
|
||||||
"C:\Users\\<*Your user name*>\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup". (The easiest way to get there - press 'WIN + R' and type 'shell:startup').\
|
"C:\Users\\<*Your user name*>\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup".
|
||||||
|
(The easiest way to get there - press 'WIN + R' and type `shell:startup`).<br>
|
||||||
However, in this case wCenterWindow will not be able to work with windows that are open with elevated privileges.
|
However, in this case wCenterWindow will not be able to work with windows that are open with elevated privileges.
|
||||||
And if you enable the "Run as administrator" option in the shortcut, then wCenterWindow will not start. This is related to the security of Windows (maybe only in 10/11, I did not check).\
|
And if you enable the "Run as administrator" option in the shortcut, then wCenterWindow will not start. This is related to the security of Windows (maybe only in 10/11, I did not check).
|
||||||
This behavior can be bypassed by creating a task in the Task Scheduler with the "Run with highest privileges" option.\
|
This behavior can be bypassed by creating a task in the Task Scheduler with the "Run with highest privileges" option.<br>
|
||||||
**Note:** If you run wCenterWindow via the Task Scheduler, I highly recommend enabling the "Delay task for" option for 15-30 seconds, otherwise you may get an error message "Can't create tray icon".
|
**Note:** If you run wCenterWindow via the Task Scheduler, I highly recommend enabling the "Delay task for" option for 15-30 seconds, otherwise you may get an error message "Can't create tray icon".
|
||||||
|
|
||||||
|
## License
|
||||||
|
|
||||||
|
This software is licensed under a [MIT License](https://mit-license.org).<br>
|
||||||
|
This software uses the [PicoJSON](https://github.com/kazuho/picojson) - a C++ JSON parser / serializer by Kazuho Oku.
|
||||||
|
|||||||
@@ -45,6 +45,7 @@ function makeVersionString([string]$vmaj, [string]$vmin, [string]$vbld, [string]
|
|||||||
[string]$buildDateTime = [string]$vs = [string]$vn = [string]$intName = [string]$origName = $null
|
[string]$buildDateTime = [string]$vs = [string]$vn = [string]$intName = [string]$origName = $null
|
||||||
[int]$pys = [int]$spanDays = [int]$spanSecs = $null
|
[int]$pys = [int]$spanDays = [int]$spanSecs = $null
|
||||||
[int]$currentYear = [int]$currentMonth = [int]$currentDay = [int]$currentHour = [int]$currentMinute = [int]$currentSecond = $null
|
[int]$currentYear = [int]$currentMonth = [int]$currentDay = [int]$currentHour = [int]$currentMinute = [int]$currentSecond = $null
|
||||||
|
[string]$platformArch = $args[0]
|
||||||
[string]$iniFile = ".\Version.ini"
|
[string]$iniFile = ".\Version.ini"
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@@ -103,8 +104,8 @@ $currentSecond = $date.Second
|
|||||||
$buildDateTime = "Build date: $($date.GetDateTimeFormats('u').Replace('Z', ''))"
|
$buildDateTime = "Build date: $($date.GetDateTimeFormats('u').Replace('Z', ''))"
|
||||||
$spanDays = [math]::Round((New-TimeSpan -Start $(Get-Date -Month 1 -Day 1 -Year 2000) -End $date).TotalDays)
|
$spanDays = [math]::Round((New-TimeSpan -Start $(Get-Date -Month 1 -Day 1 -Year 2000) -End $date).TotalDays)
|
||||||
$spanSecs = [math]::Round((New-TimeSpan -Start $($date.Date) -End $($date.DateTime)).TotalSeconds)
|
$spanSecs = [math]::Round((New-TimeSpan -Start $($date.Date) -End $($date.DateTime)).TotalSeconds)
|
||||||
if ($pys -eq $currentYear) { $pcf = "Copyright (C) $pys by $pa" } else { $pcf = "Copyright (C) $pys-$currentYear by $pa" }
|
if ($pys -eq $currentYear) { $pcf = "Copyright (c) $pys $pa" } else { $pcf = "Copyright (c) $pys-$currentYear $pa" }
|
||||||
$intName = "$pn-C++"
|
$intName = "$pn-$platformArch-C++"
|
||||||
$origName = "$pn.exe"
|
$origName = "$pn.exe"
|
||||||
$verMajor = getValue $verMajor
|
$verMajor = getValue $verMajor
|
||||||
$verMinor = getValue $verMinor
|
$verMinor = getValue $verMinor
|
||||||
@@ -125,6 +126,8 @@ else {
|
|||||||
$pnf = "$pn v$vs"
|
$pnf = "$pn v$vs"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$pnf = "$pn v$vs ($platformArch)"
|
||||||
|
|
||||||
#region Save all variables to file
|
#region Save all variables to file
|
||||||
"// $pn" | Out-File -FilePath ".\VersionInfo.h" -Encoding unicode
|
"// $pn" | Out-File -FilePath ".\VersionInfo.h" -Encoding unicode
|
||||||
"// VersionInfo.h" | Out-File -FilePath ".\VersionInfo.h" -Encoding unicode -Append
|
"// VersionInfo.h" | Out-File -FilePath ".\VersionInfo.h" -Encoding unicode -Append
|
||||||
@@ -157,6 +160,7 @@ else {
|
|||||||
# echo " verPatch: [$verPatch]"
|
# echo " verPatch: [$verPatch]"
|
||||||
# echo ""
|
# echo ""
|
||||||
# echo " aboutBuild: [$aboutBuild]"
|
# echo " aboutBuild: [$aboutBuild]"
|
||||||
|
# echo " platformArch: [$platformArch]"
|
||||||
# echo " productNameFull: [$pnf]"
|
# echo " productNameFull: [$pnf]"
|
||||||
# echo "productCopyrightFull: [$pcf]"
|
# echo "productCopyrightFull: [$pcf]"
|
||||||
# echo " internalName: [$intName]"
|
# echo " internalName: [$intName]"
|
||||||
|
|||||||
BIN
Version.ini
BIN
Version.ini
Binary file not shown.
@@ -1,16 +1,22 @@
|
|||||||
@ECHO OFF
|
@ECHO OFF
|
||||||
|
|
||||||
|
:: In VisualStudio add to Pre-Build events:
|
||||||
|
:: "$(SolutionDir)pre-build.cmd" "$(SolutionDir)" "$(ProjectDir)"
|
||||||
|
:: Then in "Resource Includes..." add '#include "VersionInfo.rc"' into 'Compile-time Directives'
|
||||||
|
|
||||||
REM In VisualStudio add to Pre-Build events:
|
REM In VisualStudio add to Pre-Build events:
|
||||||
REM "$(SolutionDir)pre-build.cmd" "$(SolutionDir)" "$(ProjectDir)"
|
REM "$(SolutionDir)pre-build.cmd" "$(SolutionDir)" "$(ProjectDir)" "$(PlatformTarget)"
|
||||||
REM Then in "Resource Includes..." add '#include "VersionInfo.rc"' into 'Compile-time Directives'
|
REM Then in "Resource Includes..." add '#include "VersionInfo.rc"' into 'Compile-time Directives'
|
||||||
|
|
||||||
IF "%~1" == "" GOTO :no_args
|
IF "%~1" == "" GOTO :no_args
|
||||||
IF "%~2" == "" GOTO :no_args
|
IF "%~2" == "" GOTO :no_args
|
||||||
|
IF "%~3" == "" GOTO :no_args
|
||||||
SET solutionDir=%1
|
SET solutionDir=%1
|
||||||
SET projectDir=%2
|
SET projectDir=%2
|
||||||
|
SET platformArch=%3
|
||||||
|
|
||||||
CD /D %solutionDir%
|
CD /D %solutionDir%
|
||||||
powershell -ExecutionPolicy RemoteSigned -File Update_Version.ps1
|
powershell -ExecutionPolicy RemoteSigned -File Update_Version.ps1 %platformArch%
|
||||||
MOVE /Y %solutionDir%VersionInfo.h %projectDir%VersionInfo.h
|
MOVE /Y %solutionDir%VersionInfo.h %projectDir%VersionInfo.h
|
||||||
EXIT
|
EXIT
|
||||||
|
|
||||||
|
|||||||
@@ -1,78 +1,83 @@
|
|||||||
// wCenterWindow
|
// wCenterWindow
|
||||||
// CLogger.cpp
|
// CLogger.cpp
|
||||||
|
|
||||||
#include "CLogger.h"
|
#include "CLogger.h"
|
||||||
|
#include <string>
|
||||||
#include <filesystem>
|
#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() {
|
inline wchar_t* CLogger::GetTimeStamp() {
|
||||||
GetLocalTime(<);
|
GetLocalTime(<);
|
||||||
swprintf_s(logTimeBuffer, L"%d-%02d-%02d %02d:%02d:%02d.%03d | ", lt.wYear, lt.wMonth, lt.wDay, lt.wHour, lt.wMinute, lt.wSecond, lt.wMilliseconds);
|
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);
|
||||||
return logTimeBuffer;
|
return logTimeBuffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CLogger::Out(const wchar_t* fmt, ...) {
|
void CLogger::Out(const wchar_t* fmt, ...) {
|
||||||
if (fsLogFile.is_open()) {
|
if (fsLogFile.is_open()) {
|
||||||
va_list args;
|
va_list args;
|
||||||
va_start(args, fmt);
|
va_start(args, fmt);
|
||||||
EnterCriticalSection(&cs);
|
EnterCriticalSection(&cs);
|
||||||
_vsnwprintf_s(logBuffer, _countof(logBuffer), _TRUNCATE, fmt, args);
|
StringCchVPrintfW(logBuffer, _countof(logBuffer), fmt, args);
|
||||||
va_end(args);
|
va_end(args);
|
||||||
fsLogFile << GetTimeStamp() << logBuffer << std::endl;
|
fsLogFile << ConvU16U8(GetTimeStamp()) << ConvU16U8(logBuffer) << std::endl;
|
||||||
LeaveCriticalSection(&cs);
|
LeaveCriticalSection(&cs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CLogger::Init() {
|
void CLogger::Init() {
|
||||||
InitializeCriticalSection(&cs);
|
wchar_t szPath[MAX_PATH] = { 0 };
|
||||||
wchar_t szPath[MAX_PATH] = { 0 };
|
DWORD dwPathLength = GetModuleFileNameW(NULL, szPath, MAX_PATH);
|
||||||
DWORD dwPathLength = GetModuleFileNameW(NULL, szPath, MAX_PATH);
|
DWORD dwError = GetLastError();
|
||||||
DWORD dwError = GetLastError();
|
if (ERROR_INSUFFICIENT_BUFFER == dwError) {
|
||||||
if (ERROR_INSUFFICIENT_BUFFER == dwError) {
|
MessageBoxW(NULL, L"Warning!\nPath to log file is too long! Working without logging.", szAppTitle.c_str(), MB_OK | MB_ICONWARNING | MB_SYSTEMMODAL);
|
||||||
MessageBoxW(NULL, L"Warning!\nPath to log file is too long! Working without logging.", szAppTitle.c_str(), MB_OK | MB_ICONWARNING);
|
return;
|
||||||
return;
|
}
|
||||||
}
|
if (NULL == dwPathLength) {
|
||||||
if (NULL == dwPathLength) {
|
MessageBoxW(NULL, L"Warning!\nCan't get application's filename! Working without logging.", szAppTitle.c_str(), MB_OK | MB_ICONWARNING | MB_SYSTEMMODAL);
|
||||||
MessageBoxW(NULL, L"Warning!\nCan't get application's filename! Working without logging.", szAppTitle.c_str(), MB_OK | MB_ICONWARNING);
|
return;
|
||||||
return;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
std::filesystem::path log_path = szPath;
|
std::filesystem::path log_path = szPath;
|
||||||
log_path.replace_extension(L".log");
|
log_path.replace_extension(L".log");
|
||||||
std::filesystem::path bak_path = log_path;
|
std::filesystem::path bak_path = log_path;
|
||||||
bak_path.replace_extension(L".bak");
|
bak_path.replace_extension(L".bak");
|
||||||
|
|
||||||
if (std::filesystem::exists(log_path)) std::filesystem::rename(log_path, bak_path);
|
if (std::filesystem::exists(log_path)) std::filesystem::rename(log_path, bak_path);
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
log_path = L"D:\\test.log";
|
log_path = L"test.log";
|
||||||
#endif
|
#endif
|
||||||
fsLogFile.open(log_path, std::ios::trunc);
|
fsLogFile.open(log_path, std::ios::trunc);
|
||||||
if (fsLogFile.is_open()) {
|
if (fsLogFile.is_open()) {
|
||||||
fsLogFile << "\xEF\xBB\xBF"; // (0xEF, 0xBB, 0xBF) - UTF-8 BOM
|
InitializeCriticalSection(&cs);
|
||||||
fsLogFile.imbue(std::locale("en-US.utf8"));
|
fsLogFile << "\xEF\xBB\xBF"; // (0xEF, 0xBB, 0xBF) - UTF-8 BOM
|
||||||
fsLogFile << GetTimeStamp() << "[ " << szAppTitleVer.c_str() << " ] Start log." << std::endl;
|
fsLogFile.imbue(std::locale(".UTF-8"));
|
||||||
fsLogFile << GetTimeStamp() << "Logfile: \"" << log_path.native() << "\"" << std::endl;
|
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);
|
else {
|
||||||
}
|
MessageBoxW(NULL, L"Warning!\nCan't create log file! Working without logging.", szAppTitle.c_str(), MB_OK | MB_ICONWARNING | MB_SYSTEMMODAL);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CLogger::CLogger(const wchar_t* _appTitle) {
|
CLogger::CLogger(const wchar_t* _appTitle) {
|
||||||
szAppTitle = _appTitle;
|
szAppTitle = _appTitle;
|
||||||
szAppTitleVer = _appTitle;
|
szAppTitleVer = _appTitle;
|
||||||
Init();
|
Init();
|
||||||
}
|
|
||||||
|
|
||||||
CLogger::CLogger(const wchar_t* _appTitle, const wchar_t* _appVersion) {
|
|
||||||
szAppTitle = _appTitle; szAppVersion = _appVersion;
|
|
||||||
szAppTitleVer = _appTitle;
|
|
||||||
szAppTitleVer.append(L", v").append(_appVersion);
|
|
||||||
Init();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CLogger::~CLogger() {
|
CLogger::~CLogger() {
|
||||||
if (fsLogFile) {
|
if (fsLogFile) {
|
||||||
fsLogFile << GetTimeStamp() << "Stop log." << std::endl;
|
fsLogFile << ConvU16U8(GetTimeStamp()) << "Stop log." << std::endl;
|
||||||
fsLogFile.close();
|
fsLogFile.close();
|
||||||
DeleteCriticalSection(&cs);
|
DeleteCriticalSection(&cs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,31 +1,30 @@
|
|||||||
// wCenterWindow
|
// wCenterWindow
|
||||||
// CLogger.h
|
// CLogger.h
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <Windows.h>
|
#include <Windows.h>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
|
||||||
#define MAX_LOGBUFFER_LENGTH 512
|
#define MAX_LOGBUFFER_LENGTH 512
|
||||||
|
|
||||||
class CLogger
|
class CLogger {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
void Out(const wchar_t*, ...);
|
void Out(const wchar_t*, ...);
|
||||||
CLogger(const wchar_t*);
|
CLogger(const wchar_t*);
|
||||||
CLogger(const wchar_t*, const wchar_t*);
|
~CLogger();
|
||||||
~CLogger();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
SYSTEMTIME lt;
|
SYSTEMTIME lt;
|
||||||
CRITICAL_SECTION cs;
|
CRITICAL_SECTION cs;
|
||||||
HANDLE hLoggerThread = NULL;
|
wchar_t logTimeBuffer[28] { 0 };
|
||||||
HANDLE hLoggerEvent = NULL;
|
wchar_t logBuffer[MAX_LOGBUFFER_LENGTH] { 0 };
|
||||||
wchar_t logTimeBuffer[28]{ 0 };
|
std::ofstream fsLogFile;
|
||||||
wchar_t logBuffer[MAX_LOGBUFFER_LENGTH]{ 0 };
|
std::wstring szAppTitle { 0 };
|
||||||
std::wofstream fsLogFile;
|
std::wstring szAppVersion { 0 };
|
||||||
std::wstring szAppTitle{ 0 };
|
std::wstring szAppPlatform { 0 };
|
||||||
std::wstring szAppVersion{ 0 };
|
std::wstring szAppTitleVer { 0 };
|
||||||
std::wstring szAppTitleVer{ 0 };
|
|
||||||
|
|
||||||
inline wchar_t* GetTimeStamp();
|
std::string ConvU16U8(const std::wstring&);
|
||||||
void Init();
|
inline wchar_t* GetTimeStamp();
|
||||||
|
void Init();
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
// wCenterWindow
|
// wCenterWindow
|
||||||
// framework.h
|
// framework.h
|
||||||
//
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "targetver.h"
|
#include "targetver.h"
|
||||||
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
|
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
|
||||||
|
|||||||
@@ -2,44 +2,38 @@
|
|||||||
// Microsoft Visual C++ generated include file.
|
// Microsoft Visual C++ generated include file.
|
||||||
// Used by wCenterWindow.rc
|
// Used by wCenterWindow.rc
|
||||||
//
|
//
|
||||||
#define IDS_CLASSNAME 102
|
#define IDS_CLASSNAME 100
|
||||||
#define IDS_APP_TITLE 103
|
#define IDS_APP_TITLE 101
|
||||||
#define IDD_ABOUTBOX 104
|
#define IDI_TRAYICON 102
|
||||||
#define IDI_TRAYICON 105
|
#define IDR_MENU 103
|
||||||
#define IDR_MENU 106
|
#define ID_POPUPMENU_ICON 104
|
||||||
#define ID_POPUPMENU_ICON 107
|
#define ID_POPUPMENU_AREA 105
|
||||||
#define ID_POPUPMENU_AREA 108
|
#define ID_POPUPMENU_HELP 106
|
||||||
#define ID_POPUPMENU_ABOUT 110
|
#define ID_POPUPMENU_ABOUT 107
|
||||||
#define ID_POPUPMENU_EXIT 111
|
#define ID_POPUPMENU_EXIT 108
|
||||||
#define IDS_ABOUT 112
|
#define IDS_HELP 109
|
||||||
#define IDS_ERR_MAIN 113
|
#define IDS_ERR_MAIN 110
|
||||||
#define IDS_ERR_CLASS 114
|
#define IDS_ERR_CLASS 111
|
||||||
#define IDS_ERR_WND 115
|
#define IDS_ERR_WND 112
|
||||||
#define IDS_ERR_ICON 116
|
#define IDS_ERR_ICON 113
|
||||||
#define IDS_ERR_MENU 117
|
#define IDS_ERR_MENU 114
|
||||||
#define IDS_ERR_POPUP 118
|
#define IDS_ERR_POPUP 115
|
||||||
#define IDS_ERR_HOOK 119
|
#define IDS_ERR_HOOK 116
|
||||||
#define IDS_ERR_TIMER 120
|
#define IDS_ERR_TIMER 117
|
||||||
#define IDS_ERR_MAXMIN 121
|
#define IDS_ERR_HEAP 118
|
||||||
#define IDS_RUNNING 122
|
#define IDS_ERR_MAXMIN 119
|
||||||
#define IDT_TIMER 123
|
#define IDS_RUNNING 120
|
||||||
#define IDR_MAINFRAME 128
|
#define IDT_TIMER 121
|
||||||
#define IDD_MANUAL_EDITING 129
|
#define IDD_MANUAL_EDITING 1000
|
||||||
#define IDC_EDIT_X 1000
|
#define IDC_EDIT_X 1001
|
||||||
#define IDC_EDIT_Y 1001
|
#define IDC_EDIT_Y 1002
|
||||||
#define IDC_EDIT_WIDTH 1002
|
#define IDC_EDIT_WIDTH 1003
|
||||||
#define IDC_EDIT_HEIGHT 1003
|
#define IDC_EDIT_HEIGHT 1004
|
||||||
#define IDC_EDIT_TITLE 1004
|
#define IDC_EDIT_TITLE 1005
|
||||||
#define IDC_EDIT_CLASS 1005
|
#define IDC_EDIT_CLASS 1006
|
||||||
#define IDC_BUTTON_SET 1006
|
#define IDC_BUTTON_SET 1007
|
||||||
#define IDC_BUTTON_CLOSE 1007
|
#define IDC_BUTTON_CENTER 1008
|
||||||
#define IDC_ABOUTHELP 1008
|
#define IDC_BUTTON_CLOSE 1009
|
||||||
#define IDC_DONATIONLINK 1009
|
|
||||||
#define IDC_DONATIONTEXT 1010
|
|
||||||
#define IDC_ABOUT_PROGNAME 1011
|
|
||||||
#define IDC_ABOUT_COPYRIGHT 1012
|
|
||||||
#define IDC_ABOUT_BUILDTIME 1013
|
|
||||||
#define IDC_ABOUTEDIT 1014
|
|
||||||
#define IDC_STATIC -1
|
#define IDC_STATIC -1
|
||||||
|
|
||||||
// Next default values for new objects
|
// Next default values for new objects
|
||||||
@@ -47,9 +41,9 @@
|
|||||||
#ifdef APSTUDIO_INVOKED
|
#ifdef APSTUDIO_INVOKED
|
||||||
#ifndef APSTUDIO_READONLY_SYMBOLS
|
#ifndef APSTUDIO_READONLY_SYMBOLS
|
||||||
#define _APS_NO_MFC 1
|
#define _APS_NO_MFC 1
|
||||||
#define _APS_NEXT_RESOURCE_VALUE 130
|
#define _APS_NEXT_RESOURCE_VALUE 200
|
||||||
#define _APS_NEXT_COMMAND_VALUE 32771
|
#define _APS_NEXT_COMMAND_VALUE 32771
|
||||||
#define _APS_NEXT_CONTROL_VALUE 1015
|
#define _APS_NEXT_CONTROL_VALUE 1010
|
||||||
#define _APS_NEXT_SYMED_VALUE 124
|
#define _APS_NEXT_SYMED_VALUE 122
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1,6 +1,12 @@
|
|||||||
|
// wCenterWindow
|
||||||
|
// targetver.h
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
// // Including SDKDDKVer.h defines the highest available Windows platform.
|
// // Including SDKDDKVer.h defines the highest available Windows platform.
|
||||||
// If you wish to build your application for a previous Windows platform, include WinSDKVer.h and
|
// If you wish to build your application for a previous Windows platform, include WinSDKVer.h and
|
||||||
// set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h.
|
// set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h.
|
||||||
|
#include <winsdkver.h>
|
||||||
|
#define WINVER 0x0601
|
||||||
|
#define _WIN32_WINNT 0x0601
|
||||||
|
#define _WIN32_IE 0x0601
|
||||||
#include <SDKDDKVer.h>
|
#include <SDKDDKVer.h>
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
// wCenterWindow
|
// wCenterWindow
|
||||||
// updater.h
|
// updater.h
|
||||||
//
|
|
||||||
#include "wCenterWindow.h"
|
#include "wCenterWindow.h"
|
||||||
#include "updater.h"
|
#include "updater.h"
|
||||||
#include "picojson.h"
|
#include "picojson.h"
|
||||||
@@ -11,12 +11,11 @@
|
|||||||
|
|
||||||
picojson::value json;
|
picojson::value json;
|
||||||
|
|
||||||
struct Version
|
struct Version {
|
||||||
{
|
UINT Major = 0;
|
||||||
UINT Major = 0;
|
UINT Minor = 0;
|
||||||
UINT Minor = 0;
|
UINT Build = 0;
|
||||||
UINT Build = 0;
|
UINT Patch = 0;
|
||||||
UINT Patch = 0;
|
|
||||||
} verApp, verGh;
|
} verApp, verGh;
|
||||||
|
|
||||||
bool GetLatestRelease(const std::wstring& urn);
|
bool GetLatestRelease(const std::wstring& urn);
|
||||||
@@ -24,199 +23,182 @@ void FillVersionStructure(Version& ver, const std::wstring& str);
|
|||||||
std::vector<std::wstring> Split(const std::wstring& s, wchar_t delim);
|
std::vector<std::wstring> Split(const std::wstring& s, wchar_t delim);
|
||||||
std::wstring ConvertUtf8ToWide(const std::string& str);
|
std::wstring ConvertUtf8ToWide(const std::string& str);
|
||||||
|
|
||||||
UINT WINAPI Updater(LPVOID)
|
UINT WINAPI Updater(void*) {
|
||||||
{
|
logger.Out(L"Entering the %s() function", TEXT(__FUNCTION__));
|
||||||
logger.Out(L"Entering the %s() function", TEXT(__FUNCTION__));
|
logger.Out(L"[UPDT] Sleeping %d seconds", T0);
|
||||||
|
|
||||||
if (!GetLatestRelease(GITHUB_URI))
|
Sleep(T0 * 1000); // 10 seconds
|
||||||
{
|
|
||||||
logger.Out(L"[UPDT] %s(%d): Failed getting releases!", TEXT(__FUNCTION__), __LINE__);
|
|
||||||
|
|
||||||
MessageBoxW(NULL, L"Failed getting releases!", szTitle, MB_OK | MB_ICONERROR);
|
if (!GetLatestRelease(GITHUB_URI)) {
|
||||||
_endthreadex(101);
|
logger.Out(L"[UPDT] %s(%d): Failed getting releases!", TEXT(__FUNCTION__), __LINE__);
|
||||||
return 101;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::wstring j_tag_name, j_file_name, j_file_ext, j_file_url, j_page_url;
|
MessageBoxW(NULL, L"Failed getting releases!", szTitle, MB_OK | MB_ICONERROR);
|
||||||
int64_t j_file_size = 0;
|
return 101;
|
||||||
picojson::object obj, obj2;
|
_endthreadex(101);
|
||||||
picojson::object::iterator it, it2;
|
}
|
||||||
|
|
||||||
if (json.is<picojson::object>())
|
std::wstring j_tag_name, j_file_name, j_file_ext, j_file_url, j_page_url;
|
||||||
{
|
int64_t j_file_size = 0;
|
||||||
logger.Out(L"[UPDT] %s(%d): Parsing JSON object", TEXT(__FUNCTION__), __LINE__);
|
picojson::object obj, obj2;
|
||||||
|
picojson::object::iterator it, it2;
|
||||||
|
|
||||||
obj = json.get<picojson::object>();
|
if (json.is<picojson::object>()) {
|
||||||
it = obj.find("message"), it2;
|
logger.Out(L"[UPDT] %s(%d): Parsing JSON object", TEXT(__FUNCTION__), __LINE__);
|
||||||
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);
|
|
||||||
_endthreadex(102);
|
|
||||||
return 102;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (it = obj.begin(); it != obj.end(); it++)
|
obj = json.get<picojson::object>();
|
||||||
{
|
|
||||||
if ((*it).first == "tag_name") j_tag_name = ConvertUtf8ToWide((*it).second.to_str());
|
|
||||||
if ((*it).first == "html_url") j_page_url = ConvertUtf8ToWide((*it).second.to_str());
|
|
||||||
if ((*it).first == "assets" && (*it).second.is<picojson::array>())
|
|
||||||
{
|
|
||||||
picojson::array a = (*it).second.get<picojson::array>();
|
|
||||||
obj2 = a[0].get<picojson::object>();
|
|
||||||
for (it2 = obj2.begin(); it2 != obj2.end(); it2++)
|
|
||||||
{
|
|
||||||
if ((*it2).first == "name") j_file_name = ConvertUtf8ToWide((*it2).second.to_str());
|
|
||||||
if ((*it2).first == "browser_download_url") j_file_url = ConvertUtf8ToWide((*it2).second.to_str());
|
|
||||||
if ((*it2).first == "size") j_file_size = static_cast<int64_t>((*it2).second.get<double>());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
logger.Out(L"[UPDT] %s(%d): Error! Cannot recognize JSON object!", TEXT(__FUNCTION__), __LINE__);
|
|
||||||
_endthreadex(103);
|
|
||||||
return 103;
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t pos = 0;
|
for (it = obj.begin(); it != obj.end(); it++) {
|
||||||
while (std::iswdigit(j_tag_name.at(pos)) == 0) pos++;
|
if ((*it).first == "tag_name") j_tag_name = ConvertUtf8ToWide((*it).second.to_str());
|
||||||
std::wstring gh_version = j_tag_name.substr(pos);
|
if ((*it).first == "html_url") j_page_url = ConvertUtf8ToWide((*it).second.to_str());
|
||||||
|
if ((*it).first == "assets" && (*it).second.is<picojson::array>()) {
|
||||||
|
picojson::array a = (*it).second.get<picojson::array>();
|
||||||
|
obj2 = a[0].get<picojson::object>();
|
||||||
|
for (it2 = obj2.begin(); it2 != obj2.end(); it2++) {
|
||||||
|
if ((*it2).first == "name") j_file_name = ConvertUtf8ToWide((*it2).second.to_str());
|
||||||
|
if ((*it2).first == "browser_download_url") j_file_url = ConvertUtf8ToWide((*it2).second.to_str());
|
||||||
|
if ((*it2).first == "size") j_file_size = static_cast<int64_t>((*it2).second.get<double>());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
logger.Out(L"[UPDT] %s(%d): Error! Cannot recognize JSON object!", TEXT(__FUNCTION__), __LINE__);
|
||||||
|
return 102;
|
||||||
|
_endthreadex(102);
|
||||||
|
}
|
||||||
|
|
||||||
logger.Out(L"[UPDT] %s(%d): AppVersion : %s", TEXT(__FUNCTION__), __LINE__, TEXT(VERSION_STR));
|
size_t pos = 0;
|
||||||
logger.Out(L"[UPDT] %s(%d): GitVersion : %s", TEXT(__FUNCTION__), __LINE__, gh_version.c_str());
|
while (std::iswdigit(j_tag_name.at(pos)) == 0) pos++;
|
||||||
//logger.Out(L"[UPDT] %s(%d): FileName : %s", TEXT(__FUNCTION__), __LINE__, j_file_name.c_str());
|
std::wstring gh_version = j_tag_name.substr(pos);
|
||||||
//logger.Out(L"[UPDT] %s(%d): FileSize : %d", TEXT(__FUNCTION__), __LINE__, j_file_size);
|
|
||||||
//logger.Out(L"[UPDT] %s(%d): File Url : %s", TEXT(__FUNCTION__), __LINE__, j_file_url.c_str());
|
|
||||||
//logger.Out(L"[UPDT] %s(%d): Page Url : %s", TEXT(__FUNCTION__), __LINE__, j_page_url.c_str());
|
|
||||||
|
|
||||||
FillVersionStructure(verApp, TEXT(VERSION_STR));
|
logger.Out(L"[UPDT] %s(%d): AppVersion : %s", TEXT(__FUNCTION__), __LINE__, TEXT(VERSION_STR));
|
||||||
FillVersionStructure(verGh, gh_version);
|
logger.Out(L"[UPDT] %s(%d): GitVersion : %s", TEXT(__FUNCTION__), __LINE__, gh_version.c_str());
|
||||||
|
//logger.Out(L"[UPDT] %s(%d): FileName : %s", TEXT(__FUNCTION__), __LINE__, j_file_name.c_str());
|
||||||
|
//logger.Out(L"[UPDT] %s(%d): FileSize : %d", TEXT(__FUNCTION__), __LINE__, j_file_size);
|
||||||
|
//logger.Out(L"[UPDT] %s(%d): File Url : %s", TEXT(__FUNCTION__), __LINE__, j_file_url.c_str());
|
||||||
|
//logger.Out(L"[UPDT] %s(%d): Page Url : %s", TEXT(__FUNCTION__), __LINE__, j_page_url.c_str());
|
||||||
|
|
||||||
if ((verGh.Major > verApp.Major) || (verGh.Minor > verApp.Minor) || (verGh.Build > verApp.Build) || (verGh.Patch > verApp.Patch))
|
FillVersionStructure(verApp, TEXT(VERSION_STR));
|
||||||
{
|
FillVersionStructure(verGh, gh_version);
|
||||||
|
|
||||||
logger.Out(L"[UPDT] %s(%d): An update is available!", TEXT(__FUNCTION__), __LINE__);
|
if ((verGh.Major > verApp.Major) || (verGh.Minor > verApp.Minor) || (verGh.Build > verApp.Build) || (verGh.Patch > verApp.Patch)) {
|
||||||
|
|
||||||
if (IDYES == MessageBoxW(NULL, L"An update is available!\nDo you want to open the download page?", szTitle, MB_YESNO | MB_ICONINFORMATION))
|
logger.Out(L"[UPDT] %s(%d): An update is available!", TEXT(__FUNCTION__), __LINE__);
|
||||||
{
|
|
||||||
logger.Out(L"[UPDT] %s(%d): Opening download page by default browser", TEXT(__FUNCTION__), __LINE__);
|
|
||||||
ShellExecuteW(NULL, L"open", j_page_url.c_str(), NULL, NULL, SW_SHOW);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
logger.Out(L"[UPDT] %s(%d): The user refused the update", TEXT(__FUNCTION__), __LINE__);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
logger.Out(L"[UPDT] %s(%d): No updates is available", TEXT(__FUNCTION__), __LINE__);
|
|
||||||
}
|
|
||||||
|
|
||||||
logger.Out(L"[UPDT] Exit from the %s() function", TEXT(__FUNCTION__));
|
if (IDYES == MessageBoxW(NULL, L"An update is available!\nDo you want to open the download page?", szTitle, MB_YESNO | MB_ICONINFORMATION)) {
|
||||||
|
logger.Out(L"[UPDT] %s(%d): Opening download page by default browser", TEXT(__FUNCTION__), __LINE__);
|
||||||
|
ShellExecuteW(NULL, L"open", j_page_url.c_str(), NULL, NULL, SW_SHOW);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
logger.Out(L"[UPDT] %s(%d): The user refused the update", TEXT(__FUNCTION__), __LINE__);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
logger.Out(L"[UPDT] %s(%d): No updates is available", TEXT(__FUNCTION__), __LINE__);
|
||||||
|
}
|
||||||
|
|
||||||
_endthreadex(0);
|
logger.Out(L"[UPDT] Exit from the %s() function", TEXT(__FUNCTION__));
|
||||||
return 0;
|
|
||||||
|
return 0;
|
||||||
|
_endthreadex(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GetLatestRelease(const std::wstring& urn)
|
bool GetLatestRelease(const std::wstring& urn) {
|
||||||
{
|
std::wstring user_agent = L"User-Agent: ";
|
||||||
std::wstring user_agent = L"User-Agent: ";
|
user_agent.append(szTitle);
|
||||||
user_agent.append(szTitle);
|
const std::wstring url = GITHUB_URL;
|
||||||
const std::wstring url = GITHUB_URL;
|
bool ret = true;
|
||||||
bool ret = true;
|
DWORD err = 0;
|
||||||
DWORD err = 0;
|
|
||||||
|
|
||||||
logger.Out(L"[UPDT] %s(%d): %s", TEXT(__FUNCTION__), __LINE__, user_agent.c_str());
|
logger.Out(L"[UPDT] %s(%d): %s", TEXT(__FUNCTION__), __LINE__, user_agent.c_str());
|
||||||
|
|
||||||
HINTERNET hInternet = InternetOpenW(user_agent.c_str(), INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
|
HINTERNET hInternet = InternetOpenW(user_agent.c_str(), INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
|
||||||
if (hInternet != NULL)
|
if (hInternet != NULL) {
|
||||||
{
|
HINTERNET hConnect = InternetConnectW(hInternet, url.c_str(), INTERNET_DEFAULT_HTTPS_PORT, L"", L"", INTERNET_SERVICE_HTTP, INTERNET_FLAG_SECURE, 0);
|
||||||
HINTERNET hConnect = InternetConnectW(hInternet, url.c_str(), INTERNET_DEFAULT_HTTPS_PORT, L"", L"", INTERNET_SERVICE_HTTP, INTERNET_FLAG_SECURE, 0);
|
if (hConnect != NULL) {
|
||||||
if (hConnect != NULL)
|
HINTERNET hRequest = HttpOpenRequestW(hConnect, L"GET", urn.c_str(), NULL, NULL, NULL, INTERNET_FLAG_SECURE | INTERNET_FLAG_RELOAD | INTERNET_FLAG_NO_UI, 0);
|
||||||
{
|
if (hRequest != NULL) {
|
||||||
HINTERNET hRequest = HttpOpenRequestW(hConnect, L"GET", urn.c_str(), NULL, NULL, NULL, INTERNET_FLAG_SECURE | INTERNET_FLAG_RELOAD | INTERNET_FLAG_NO_UI, 0);
|
BOOL isSend = HttpSendRequestW(hRequest, NULL, 0, 0, 0);
|
||||||
if (hRequest != NULL)
|
if (isSend) {
|
||||||
{
|
char szData[1024] { 0 };
|
||||||
BOOL isSend = HttpSendRequestW(hRequest, NULL, 0, 0, 0);
|
DWORD dwBytesRead = 0;
|
||||||
if (isSend)
|
std::string buffer;
|
||||||
{
|
do {
|
||||||
char szData[1024]{ 0 };
|
InternetReadFile(hRequest, szData, sizeof(szData), &dwBytesRead);
|
||||||
DWORD dwBytesRead = 0;
|
buffer.append(szData, dwBytesRead);
|
||||||
std::string buffer;
|
} while (dwBytesRead != 0);
|
||||||
do
|
|
||||||
{
|
|
||||||
InternetReadFile(hRequest, szData, sizeof(szData), &dwBytesRead);
|
|
||||||
buffer.append(szData, dwBytesRead);
|
|
||||||
} while (dwBytesRead != 0);
|
|
||||||
|
|
||||||
picojson::parse(json, buffer);
|
picojson::parse(json, buffer);
|
||||||
std::string jerr = picojson::get_last_error();
|
std::string jerr = picojson::get_last_error();
|
||||||
if (!jerr.empty())
|
if (!jerr.empty()) {
|
||||||
{
|
logger.Out(L"[UPDT] %s(%d): Error while parsing JSON object: %s", TEXT(__FUNCTION__), __LINE__, ConvertUtf8ToWide(jerr));
|
||||||
std::cout << jerr << std::endl;
|
|
||||||
ret = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
MessageBoxW(NULL, L"Error while parsing JSON object!", szTitle, MB_OK | MB_ICONERROR);
|
||||||
else
|
ret = false;
|
||||||
{
|
}
|
||||||
err = GetLastError();
|
else {
|
||||||
logger.Out(L"[UPDT] %s(%d): HttpSendRequestW() error: %d", TEXT(__FUNCTION__), __LINE__, err);
|
picojson::object obj = json.get<picojson::object>();
|
||||||
ret = false;
|
std::string msg, sts;
|
||||||
}
|
if (auto search = obj.find("message"); search != obj.end()) {
|
||||||
}
|
msg = (search->first) + ": " + (search->second).get<std::string>();
|
||||||
else
|
}
|
||||||
{
|
if (auto search = obj.find("status"); search != obj.end()) {
|
||||||
err = GetLastError();
|
sts = (search->first) + ": " + (search->second).get<std::string>();
|
||||||
logger.Out(L"[UPDT] %s(%d): HttpOpenRequestW() error: %d", TEXT(__FUNCTION__), __LINE__, err);
|
}
|
||||||
ret = false;
|
logger.Out(L"[UPDT] %s(%d): Error! %s", TEXT(__FUNCTION__), __LINE__, ConvertUtf8ToWide(msg + ", " + sts).c_str());
|
||||||
}
|
ret = false;
|
||||||
InternetCloseHandle(hRequest);
|
}
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
err = GetLastError();
|
||||||
err = GetLastError();
|
logger.Out(L"[UPDT] %s(%d): HttpSendRequestW() error: %d", TEXT(__FUNCTION__), __LINE__, err);
|
||||||
logger.Out(L"[UPDT] %s(%d): InternetConnectW() error: %d", TEXT(__FUNCTION__), __LINE__, err);
|
ret = false;
|
||||||
ret = false;
|
}
|
||||||
}
|
}
|
||||||
InternetCloseHandle(hConnect);
|
else {
|
||||||
}
|
err = GetLastError();
|
||||||
else
|
logger.Out(L"[UPDT] %s(%d): HttpOpenRequestW() error: %d", TEXT(__FUNCTION__), __LINE__, err);
|
||||||
{
|
ret = false;
|
||||||
err = GetLastError();
|
}
|
||||||
logger.Out(L"[UPDT] %s(%d): InternetOpenW() error: %d", TEXT(__FUNCTION__), __LINE__, err);
|
InternetCloseHandle(hRequest);
|
||||||
ret = false;
|
}
|
||||||
}
|
else {
|
||||||
InternetCloseHandle(hInternet);
|
err = GetLastError();
|
||||||
return ret;
|
logger.Out(L"[UPDT] %s(%d): InternetConnectW() error: %d", TEXT(__FUNCTION__), __LINE__, err);
|
||||||
|
ret = false;
|
||||||
|
}
|
||||||
|
InternetCloseHandle(hConnect);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
err = GetLastError();
|
||||||
|
logger.Out(L"[UPDT] %s(%d): InternetOpenW() error: %d", TEXT(__FUNCTION__), __LINE__, err);
|
||||||
|
ret = false;
|
||||||
|
}
|
||||||
|
InternetCloseHandle(hInternet);
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::wstring> Split(const std::wstring& s, wchar_t delim)
|
std::vector<std::wstring> Split(const std::wstring& s, wchar_t delim) {
|
||||||
{
|
std::vector<std::wstring> result;
|
||||||
std::vector<std::wstring> result;
|
std::wstringstream ss(s);
|
||||||
std::wstringstream ss(s);
|
std::wstring item;
|
||||||
std::wstring item;
|
while (getline(ss, item, delim)) result.push_back(item);
|
||||||
while (getline(ss, item, delim)) result.push_back(item);
|
return result;
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void FillVersionStructure(Version& ver, const std::wstring& str)
|
void FillVersionStructure(Version& ver, const std::wstring& str) {
|
||||||
{
|
std::vector<std::wstring> v;
|
||||||
std::vector<std::wstring> v;
|
v = Split(str, '.');
|
||||||
v = Split(str, '.');
|
if (v.size() < 4) v.push_back(L"0");
|
||||||
if (v.size() < 4) v.push_back(L"0");
|
ver.Major = std::stoul(v[0]);
|
||||||
ver.Major = std::stoul(v[0]);
|
ver.Minor = std::stoul(v[1]);
|
||||||
ver.Minor = std::stoul(v[1]);
|
ver.Build = std::stoul(v[2]);
|
||||||
ver.Build = std::stoul(v[2]);
|
ver.Patch = std::stoul(v[3]);
|
||||||
ver.Patch = std::stoul(v[3]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::wstring ConvertUtf8ToWide(const std::string& str)
|
std::wstring ConvertUtf8ToWide(const std::string& str) {
|
||||||
{
|
int count = MultiByteToWideChar(CP_UTF8, 0, str.c_str(), str.length(), NULL, 0);
|
||||||
int count = MultiByteToWideChar(CP_UTF8, 0, str.c_str(), str.length(), NULL, 0);
|
std::wstring wstr(count, 0);
|
||||||
std::wstring wstr(count, 0);
|
MultiByteToWideChar(CP_UTF8, 0, str.c_str(), str.length(), &wstr[0], count);
|
||||||
MultiByteToWideChar(CP_UTF8, 0, str.c_str(), str.length(), &wstr[0], count);
|
return wstr;
|
||||||
return wstr;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
// wCenterWindow
|
// wCenterWindow
|
||||||
// updater.h
|
// updater.h
|
||||||
//
|
|
||||||
#pragma once
|
#pragma once
|
||||||
UINT WINAPI Updater(void*);
|
UINT WINAPI Updater(void*);
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -1,10 +1,20 @@
|
|||||||
// wCenterWindow
|
// wCenterWindow
|
||||||
// wCenterWindow.h
|
// wCenterWindow.h
|
||||||
//
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "resource.h"
|
#include "resource.h"
|
||||||
|
|
||||||
#define MAX_LOADSTRING 50
|
#define T0 10
|
||||||
|
#define T1 60
|
||||||
|
#define T2 86400
|
||||||
|
|
||||||
|
#ifdef _WIN64
|
||||||
|
#define ARCH 64
|
||||||
|
#else
|
||||||
|
#define ARCH 86
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define MAX_LOADSTRING 64
|
||||||
|
|
||||||
// Windows Header Files
|
// Windows Header Files
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
@@ -14,6 +24,7 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
#include <strsafe.h>
|
#include <strsafe.h>
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
|
#include <windowsx.h>
|
||||||
#include <wininet.h>
|
#include <wininet.h>
|
||||||
#include <shellapi.h>
|
#include <shellapi.h>
|
||||||
#include <CommCtrl.h>
|
#include <CommCtrl.h>
|
||||||
|
|||||||
Binary file not shown.
@@ -30,26 +30,26 @@
|
|||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||||
<ConfigurationType>Application</ConfigurationType>
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
<UseDebugLibraries>true</UseDebugLibraries>
|
<UseDebugLibraries>true</UseDebugLibraries>
|
||||||
<PlatformToolset>v143</PlatformToolset>
|
<PlatformToolset>v142</PlatformToolset>
|
||||||
<CharacterSet>Unicode</CharacterSet>
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||||
<ConfigurationType>Application</ConfigurationType>
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
<UseDebugLibraries>false</UseDebugLibraries>
|
<UseDebugLibraries>false</UseDebugLibraries>
|
||||||
<PlatformToolset>v143</PlatformToolset>
|
<PlatformToolset>v142</PlatformToolset>
|
||||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||||
<CharacterSet>Unicode</CharacterSet>
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||||
<ConfigurationType>Application</ConfigurationType>
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
<UseDebugLibraries>true</UseDebugLibraries>
|
<UseDebugLibraries>true</UseDebugLibraries>
|
||||||
<PlatformToolset>v143</PlatformToolset>
|
<PlatformToolset>v142</PlatformToolset>
|
||||||
<CharacterSet>Unicode</CharacterSet>
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||||
<ConfigurationType>Application</ConfigurationType>
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
<UseDebugLibraries>false</UseDebugLibraries>
|
<UseDebugLibraries>false</UseDebugLibraries>
|
||||||
<PlatformToolset>v143</PlatformToolset>
|
<PlatformToolset>v142</PlatformToolset>
|
||||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||||
<CharacterSet>Unicode</CharacterSet>
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
@@ -100,6 +100,7 @@
|
|||||||
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
<ConformanceMode>false</ConformanceMode>
|
<ConformanceMode>false</ConformanceMode>
|
||||||
<LanguageStandard>stdcpp17</LanguageStandard>
|
<LanguageStandard>stdcpp17</LanguageStandard>
|
||||||
|
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<Link>
|
<Link>
|
||||||
<SubSystem>Windows</SubSystem>
|
<SubSystem>Windows</SubSystem>
|
||||||
@@ -112,7 +113,7 @@
|
|||||||
</ManifestFromManagedAssembly>
|
</ManifestFromManagedAssembly>
|
||||||
</Manifest>
|
</Manifest>
|
||||||
<PreBuildEvent>
|
<PreBuildEvent>
|
||||||
<Command>"$(SolutionDir)pre-build.cmd" "$(SolutionDir)" "$(ProjectDir)"</Command>
|
<Command>"$(SolutionDir)pre-build.cmd" "$(SolutionDir)" "$(ProjectDir)" "$(PlatformTarget)"</Command>
|
||||||
</PreBuildEvent>
|
</PreBuildEvent>
|
||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||||
@@ -123,7 +124,7 @@
|
|||||||
<SDLCheck>true</SDLCheck>
|
<SDLCheck>true</SDLCheck>
|
||||||
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
<ConformanceMode>false</ConformanceMode>
|
<ConformanceMode>false</ConformanceMode>
|
||||||
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
|
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
|
||||||
<LanguageStandard>stdcpp17</LanguageStandard>
|
<LanguageStandard>stdcpp17</LanguageStandard>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<Link>
|
<Link>
|
||||||
@@ -137,7 +138,7 @@
|
|||||||
<AdditionalManifestFiles>%(AdditionalManifestFiles)</AdditionalManifestFiles>
|
<AdditionalManifestFiles>%(AdditionalManifestFiles)</AdditionalManifestFiles>
|
||||||
</Manifest>
|
</Manifest>
|
||||||
<PreBuildEvent>
|
<PreBuildEvent>
|
||||||
<Command>"$(SolutionDir)pre-build.cmd" "$(SolutionDir)" "$(ProjectDir)"</Command>
|
<Command>"$(SolutionDir)pre-build.cmd" "$(SolutionDir)" "$(ProjectDir)" "$(PlatformTarget)"</Command>
|
||||||
</PreBuildEvent>
|
</PreBuildEvent>
|
||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||||
@@ -147,17 +148,19 @@
|
|||||||
<PreprocessorDefinitions>_DEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
<PreprocessorDefinitions>_DEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
<ConformanceMode>true</ConformanceMode>
|
<ConformanceMode>true</ConformanceMode>
|
||||||
<LanguageStandard>stdcpp17</LanguageStandard>
|
<LanguageStandard>stdcpp17</LanguageStandard>
|
||||||
|
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<Link>
|
<Link>
|
||||||
<SubSystem>Windows</SubSystem>
|
<SubSystem>Windows</SubSystem>
|
||||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
<AdditionalDependencies>comctl32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
<AdditionalDependencies>comctl32.lib;wininet.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||||
|
<OutputFile>$(OutDir)$(TargetName)$(TargetExt)</OutputFile>
|
||||||
</Link>
|
</Link>
|
||||||
<Manifest>
|
<Manifest>
|
||||||
<AdditionalManifestFiles>%(AdditionalManifestFiles)</AdditionalManifestFiles>
|
<AdditionalManifestFiles>%(AdditionalManifestFiles)</AdditionalManifestFiles>
|
||||||
</Manifest>
|
</Manifest>
|
||||||
<PreBuildEvent>
|
<PreBuildEvent>
|
||||||
<Command>powershell -File "$(SolutionDir)Update_Version.ps1" move /y "$(SolutionDir)VersionInfo.h" "$(ProjectDir)"</Command>
|
<Command>"$(SolutionDir)pre-build.cmd" "$(SolutionDir)" "$(ProjectDir)" "$(PlatformTarget)"</Command>
|
||||||
</PreBuildEvent>
|
</PreBuildEvent>
|
||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||||
@@ -169,20 +172,21 @@
|
|||||||
<PreprocessorDefinitions>NDEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
<PreprocessorDefinitions>NDEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
<ConformanceMode>true</ConformanceMode>
|
<ConformanceMode>true</ConformanceMode>
|
||||||
<LanguageStandard>stdcpp17</LanguageStandard>
|
<LanguageStandard>stdcpp17</LanguageStandard>
|
||||||
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
|
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<Link>
|
<Link>
|
||||||
<SubSystem>Windows</SubSystem>
|
<SubSystem>Windows</SubSystem>
|
||||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||||
<OptimizeReferences>true</OptimizeReferences>
|
<OptimizeReferences>true</OptimizeReferences>
|
||||||
<GenerateDebugInformation>false</GenerateDebugInformation>
|
<GenerateDebugInformation>false</GenerateDebugInformation>
|
||||||
<AdditionalDependencies>comctl32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
<AdditionalDependencies>comctl32.lib;wininet.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||||
|
<OutputFile>$(OutDir)$(TargetName)$(TargetExt)</OutputFile>
|
||||||
</Link>
|
</Link>
|
||||||
<Manifest>
|
<Manifest>
|
||||||
<AdditionalManifestFiles>%(AdditionalManifestFiles)</AdditionalManifestFiles>
|
<AdditionalManifestFiles>%(AdditionalManifestFiles)</AdditionalManifestFiles>
|
||||||
</Manifest>
|
</Manifest>
|
||||||
<PreBuildEvent>
|
<PreBuildEvent>
|
||||||
<Command>powershell -File "$(SolutionDir)Update_Version.ps1" move /y "$(SolutionDir)VersionInfo.h" "$(ProjectDir)"</Command>
|
<Command>"$(SolutionDir)pre-build.cmd" "$(SolutionDir)" "$(ProjectDir)" "$(PlatformTarget)"</Command>
|
||||||
</PreBuildEvent>
|
</PreBuildEvent>
|
||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@@ -27,27 +27,24 @@
|
|||||||
<ClInclude Include="wCenterWindow.h">
|
<ClInclude Include="wCenterWindow.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="logger.h">
|
|
||||||
<Filter>Header Files</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="globals.h">
|
|
||||||
<Filter>Header Files</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="picojson.h">
|
<ClInclude Include="picojson.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="updater.h">
|
<ClInclude Include="updater.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="CLogger.h">
|
||||||
|
<Filter>Header Files</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="wCenterWindow.cpp">
|
<ClCompile Include="wCenterWindow.cpp">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<ClCompile Include="logger.cpp">
|
<ClCompile Include="updater.cpp">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<ClCompile Include="updater.cpp">
|
<ClCompile Include="CLogger.cpp">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|||||||
@@ -7,5 +7,17 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||||
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
|
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
|
||||||
|
<LocalDebuggerCommandArguments>
|
||||||
|
</LocalDebuggerCommandArguments>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||||
|
<LocalDebuggerCommandArguments>
|
||||||
|
</LocalDebuggerCommandArguments>
|
||||||
|
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||||
|
<LocalDebuggerCommandArguments>
|
||||||
|
</LocalDebuggerCommandArguments>
|
||||||
|
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
</Project>
|
</Project>
|
||||||
Reference in New Issue
Block a user