Compare commits
20 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 1a3e3ef4b1 | |||
| b0a14f731a | |||
| b12bfe08be | |||
| febb3bda2f | |||
| 2d90c60a1c | |||
| 382428e6fa | |||
| 1f8fb92dbe | |||
| 14ee12cb85 | |||
| 56e6a5b6b2 | |||
| 251b965073 | |||
| b855b0d624 | |||
| 0403415607 | |||
| 18959b1ef0 | |||
| 4299d9b89f | |||
| 049375a2d7 | |||
| 5bf973347f | |||
| b71793cfed | |||
| 0150121c02 | |||
|
|
8303665159 | ||
| f2ef0f9bb4 |
4
.gitignore
vendored
4
.gitignore
vendored
@@ -437,5 +437,7 @@ lightgbm.Rcheck/
|
||||
# GraphViz artifacts
|
||||
*.gv
|
||||
*.gv.*
|
||||
/VersionInfo.h
|
||||
|
||||
/wCenterWindow/VersionInfo.h
|
||||
[Pp]atches/
|
||||
*.patch
|
||||
|
||||
@@ -7,6 +7,7 @@ or pressing `LCTRL + LWIN + MMB` (Middle Mouse Button).
|
||||
|
||||
You can use `LCTRL + LWIN + I` hotkey for hide/show trayicon.
|
||||
You can also use commandline option `/hide` for 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.
|
||||
|
||||
@@ -15,7 +16,7 @@ If some windows does not centers you should run wCenterWindow with administrativ
|
||||
## Automatic startup
|
||||
|
||||
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').\
|
||||
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).\
|
||||
This behavior can be bypassed by creating a task in the Task Scheduler with the "Run with highest privileges" option.\
|
||||
|
||||
@@ -40,7 +40,7 @@ function makeVersionString([string]$vmaj, [string]$vmin, [string]$vbld, [string]
|
||||
}
|
||||
|
||||
#region Initializing variables
|
||||
[string]$verMajor = [string]$verMinor = [string]$verBuild = [string]$verRevision = $null
|
||||
[string]$verMajor = [string]$verMinor = [string]$verBuild = [string]$verPatch = $null
|
||||
[string]$pn = [string]$pa = [string]$aboutBuild = [string]$pnf = [string]$pcf = $null
|
||||
[string]$buildDateTime = [string]$vs = [string]$vn = [string]$intName = [string]$origName = $null
|
||||
[int]$pys = [int]$spanDays = [int]$spanSecs = $null
|
||||
@@ -80,7 +80,7 @@ $config = (Get-IniContent -FilePath $iniFile)["Config"]
|
||||
$verMajor = $config.Major
|
||||
$verMinor = $config.Minor
|
||||
$verBuild = $config.Build
|
||||
$verRevision = $config.Revision
|
||||
$verPatch = $config.Patch
|
||||
$pys = $config.ProductYearStart
|
||||
$pn = $config.ProductName
|
||||
$pa = $config.ProductAutors
|
||||
@@ -109,11 +109,11 @@ $origName = "$pn.exe"
|
||||
$verMajor = getValue $verMajor
|
||||
$verMinor = getValue $verMinor
|
||||
$verBuild = getValue $verBuild
|
||||
$verRevision = getValue $verRevision
|
||||
$verPatch = getValue $verPatch
|
||||
#endregion
|
||||
|
||||
$vs = (makeVersionString $verMajor $verMinor $verBuild $verRevision)[0]
|
||||
$vn = (makeVersionString $verMajor $verMinor $verBuild $verRevision)[1]
|
||||
$vs = (makeVersionString $verMajor $verMinor $verBuild $verPatch)[0]
|
||||
$vn = (makeVersionString $verMajor $verMinor $verBuild $verPatch)[1]
|
||||
|
||||
# if ([string]::IsNullOrEmpty($gitVerStr)) { $pnf = "$pn v$vs" } else { $pnf = "$pn $gitVerStr" }
|
||||
if ($isGit) {
|
||||
@@ -154,7 +154,7 @@ else {
|
||||
# echo " verMajor: [$verMajor]"
|
||||
# echo " verMinor: [$verMinor]"
|
||||
# echo " verBuild: [$verBuild]"
|
||||
# echo " verRevision: [$verRevision]"
|
||||
# echo " verPatch: [$verPatch]"
|
||||
# echo ""
|
||||
# echo " aboutBuild: [$aboutBuild]"
|
||||
# echo " productNameFull: [$pnf]"
|
||||
|
||||
BIN
Version.ini
BIN
Version.ini
Binary file not shown.
78
wCenterWindow/CLogger.cpp
Normal file
78
wCenterWindow/CLogger.cpp
Normal file
@@ -0,0 +1,78 @@
|
||||
// wCenterWindow
|
||||
// CLogger.cpp
|
||||
#include "CLogger.h"
|
||||
#include <filesystem>
|
||||
|
||||
inline wchar_t* CLogger::GetTimeStamp() {
|
||||
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);
|
||||
return logTimeBuffer;
|
||||
}
|
||||
|
||||
void CLogger::Out(const wchar_t* fmt, ...) {
|
||||
if (fsLogFile.is_open()) {
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
EnterCriticalSection(&cs);
|
||||
_vsnwprintf_s(logBuffer, _countof(logBuffer), _TRUNCATE, fmt, args);
|
||||
va_end(args);
|
||||
fsLogFile << GetTimeStamp() << logBuffer << std::endl;
|
||||
LeaveCriticalSection(&cs);
|
||||
}
|
||||
}
|
||||
|
||||
void CLogger::Init() {
|
||||
InitializeCriticalSection(&cs);
|
||||
wchar_t szPath[MAX_PATH] = { 0 };
|
||||
DWORD dwPathLength = GetModuleFileNameW(NULL, szPath, MAX_PATH);
|
||||
DWORD dwError = GetLastError();
|
||||
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);
|
||||
return;
|
||||
}
|
||||
if (NULL == dwPathLength) {
|
||||
MessageBoxW(NULL, L"Warning!\nCan't get application's filename! Working without logging.", szAppTitle.c_str(), MB_OK | MB_ICONWARNING);
|
||||
return;
|
||||
}
|
||||
|
||||
std::filesystem::path log_path = szPath;
|
||||
log_path.replace_extension(L".log");
|
||||
std::filesystem::path bak_path = log_path;
|
||||
bak_path.replace_extension(L".bak");
|
||||
|
||||
if (std::filesystem::exists(log_path)) std::filesystem::rename(log_path, bak_path);
|
||||
#ifdef _DEBUG
|
||||
log_path = L"D:\\test.log";
|
||||
#endif
|
||||
fsLogFile.open(log_path, std::ios::trunc);
|
||||
if (fsLogFile.is_open()) {
|
||||
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;
|
||||
}
|
||||
else {
|
||||
MessageBoxW(NULL, L"Warning!\nCan't create log file! Working without logging.", szAppTitle.c_str(), MB_OK | MB_ICONWARNING);
|
||||
}
|
||||
}
|
||||
|
||||
CLogger::CLogger(const wchar_t* _appTitle) {
|
||||
szAppTitle = _appTitle;
|
||||
szAppTitleVer = _appTitle;
|
||||
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() {
|
||||
if (fsLogFile) {
|
||||
fsLogFile << GetTimeStamp() << "Stop log." << std::endl;
|
||||
fsLogFile.close();
|
||||
DeleteCriticalSection(&cs);
|
||||
}
|
||||
}
|
||||
31
wCenterWindow/CLogger.h
Normal file
31
wCenterWindow/CLogger.h
Normal file
@@ -0,0 +1,31 @@
|
||||
// wCenterWindow
|
||||
// CLogger.h
|
||||
#pragma once
|
||||
#include <Windows.h>
|
||||
#include <fstream>
|
||||
|
||||
#define MAX_LOGBUFFER_LENGTH 512
|
||||
|
||||
class CLogger
|
||||
{
|
||||
public:
|
||||
void Out(const wchar_t*, ...);
|
||||
CLogger(const wchar_t*);
|
||||
CLogger(const wchar_t*, const wchar_t*);
|
||||
~CLogger();
|
||||
|
||||
private:
|
||||
SYSTEMTIME lt;
|
||||
CRITICAL_SECTION cs;
|
||||
HANDLE hLoggerThread = NULL;
|
||||
HANDLE hLoggerEvent = NULL;
|
||||
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 szAppTitleVer{ 0 };
|
||||
|
||||
inline wchar_t* GetTimeStamp();
|
||||
void Init();
|
||||
};
|
||||
@@ -1,15 +0,0 @@
|
||||
// wCenterWindow
|
||||
// globals.h
|
||||
//
|
||||
#pragma once
|
||||
#include "wCenterWindow.h"
|
||||
|
||||
#define MAX_LOADSTRING 50
|
||||
#define TBUFLEN 32
|
||||
#define DBUFLEN 256
|
||||
|
||||
extern WCHAR szTitle[];
|
||||
extern SYSTEMTIME lt;
|
||||
extern wchar_t debugBuffer[DBUFLEN];
|
||||
extern std::wofstream logfile;
|
||||
extern CRITICAL_SECTION cs;
|
||||
@@ -1,68 +0,0 @@
|
||||
// wCenterWindow
|
||||
// logger.cpp
|
||||
//
|
||||
#include "globals.h"
|
||||
#include "logger.h"
|
||||
|
||||
SYSTEMTIME lt;
|
||||
wchar_t debugTimeBuffer[TBUFLEN];
|
||||
wchar_t debugBuffer[DBUFLEN];
|
||||
std::wofstream logfile;
|
||||
|
||||
wchar_t* GetTimeStamp()
|
||||
{
|
||||
GetLocalTime(<);
|
||||
StringCchPrintfW(debugTimeBuffer, TBUFLEN, L"%d-%02d-%02d %02d:%02d:%02d.%03d | ", lt.wYear, lt.wMonth, lt.wDay, lt.wHour, lt.wMinute, lt.wSecond, lt.wMilliseconds);
|
||||
return debugTimeBuffer;
|
||||
}
|
||||
|
||||
void OpenLogFile(const wchar_t appTitle[], const wchar_t appVersion[])
|
||||
{
|
||||
WCHAR appTitleVer[MAX_LOADSTRING]{ 0 };
|
||||
StringCchPrintfW(appTitleVer, MAX_LOADSTRING, L"%s v%s", appTitle, appVersion);
|
||||
WCHAR lpszPath[MAX_PATH + 1] = { 0 };
|
||||
DWORD dwPathLength = GetModuleFileNameW(NULL, lpszPath, MAX_PATH);
|
||||
DWORD dwError = GetLastError();
|
||||
if (ERROR_INSUFFICIENT_BUFFER == dwError)
|
||||
{
|
||||
MessageBoxW(NULL, L"Path to logfile is too long! Working without logging", appTitle, MB_OK | MB_ICONWARNING);
|
||||
return;
|
||||
}
|
||||
if (NULL == dwPathLength)
|
||||
{
|
||||
MessageBoxW(NULL, L"Can't get module filename! Working without logging", appTitle, MB_OK | MB_ICONWARNING);
|
||||
return;
|
||||
}
|
||||
|
||||
std::filesystem::path log_path = lpszPath;
|
||||
log_path.replace_extension(L".log");
|
||||
std::filesystem::path bak_path = log_path;
|
||||
bak_path.replace_extension(L".bak");
|
||||
|
||||
if (std::filesystem::exists(log_path)) std::filesystem::rename(log_path, bak_path);
|
||||
#ifdef _DEBUG
|
||||
log_path = L"D:\\test.log";
|
||||
#endif
|
||||
logfile.open(log_path, std::ios::trunc);
|
||||
if (logfile.is_open())
|
||||
{
|
||||
logfile << "\xEF\xBB\xBF"; // (0xEF, 0xBB, 0xBF) - UTF-8 BOM
|
||||
logfile.imbue(std::locale("en-US.utf8"));
|
||||
logfile << GetTimeStamp() << "[ " << appTitleVer << " ] Start log." << std::endl;
|
||||
logfile << GetTimeStamp() << "Logfile: \"" << log_path.native() << "\"" << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBoxW(NULL, L"Can't open logfile! Working without logging", appTitle, MB_OK | MB_ICONWARNING);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
void CloseLogFile()
|
||||
{
|
||||
if (logfile)
|
||||
{
|
||||
logfile << GetTimeStamp() << "Stop log." << std::endl;
|
||||
logfile.close();
|
||||
}
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
// wCenterWindow
|
||||
// logger.h
|
||||
// wLogger v3.3 (Edited version from RBTray project [https://github.com/benbuck/rbtray])
|
||||
//
|
||||
// Usage: LOG_TO_FILE(L"%s(%d): Log message", TEXT(__FUNCTION__), __LINE__);
|
||||
//
|
||||
#pragma once
|
||||
#define LOG_TO_FILE(fmt, ...) do {\
|
||||
EnterCriticalSection(&cs); \
|
||||
StringCchPrintfW(debugBuffer, DBUFLEN, fmt, ##__VA_ARGS__); \
|
||||
logfile << GetTimeStamp() << debugBuffer << std::endl; \
|
||||
LeaveCriticalSection(&cs); \
|
||||
} while (0);
|
||||
|
||||
wchar_t* GetTimeStamp();
|
||||
void OpenLogFile(const wchar_t[], const wchar_t[]);
|
||||
void CloseLogFile();
|
||||
@@ -19,8 +19,10 @@
|
||||
#define IDS_ERR_MENU 117
|
||||
#define IDS_ERR_POPUP 118
|
||||
#define IDS_ERR_HOOK 119
|
||||
#define IDS_ERR_MAXMIN 120
|
||||
#define IDS_RUNNING 121
|
||||
#define IDS_ERR_TIMER 120
|
||||
#define IDS_ERR_MAXMIN 121
|
||||
#define IDS_RUNNING 122
|
||||
#define IDT_TIMER 123
|
||||
#define IDR_MAINFRAME 128
|
||||
#define IDD_MANUAL_EDITING 129
|
||||
#define IDC_EDIT_X 1000
|
||||
@@ -48,6 +50,6 @@
|
||||
#define _APS_NEXT_RESOURCE_VALUE 130
|
||||
#define _APS_NEXT_COMMAND_VALUE 32771
|
||||
#define _APS_NEXT_CONTROL_VALUE 1015
|
||||
#define _APS_NEXT_SYMED_VALUE 122
|
||||
#define _APS_NEXT_SYMED_VALUE 124
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -1,23 +1,22 @@
|
||||
// wCenterWindow
|
||||
// updater.h
|
||||
//
|
||||
#include "globals.h"
|
||||
#include "logger.h"
|
||||
#include "wCenterWindow.h"
|
||||
#include "updater.h"
|
||||
#include "picojson.h"
|
||||
#include <cwctype>
|
||||
|
||||
#define GITHUB_URL TEXT("api.github.com")
|
||||
#define GITHUB_URI TEXT("/repos/dreamforceinc/wCenterWindow/releases/latest")
|
||||
|
||||
picojson::value json;
|
||||
WCHAR errMessageBuffer[DBUFLEN]{ 0 };
|
||||
|
||||
struct Version
|
||||
{
|
||||
UINT Major = 0;
|
||||
UINT Minor = 0;
|
||||
UINT Build = 0;
|
||||
UINT Revision = 0;
|
||||
UINT Patch = 0;
|
||||
} verApp, verGh;
|
||||
|
||||
bool GetLatestRelease(const std::wstring& urn);
|
||||
@@ -25,15 +24,16 @@ void FillVersionStructure(Version& ver, const std::wstring& str);
|
||||
std::vector<std::wstring> Split(const std::wstring& s, wchar_t delim);
|
||||
std::wstring ConvertUtf8ToWide(const std::string& str);
|
||||
|
||||
DWORD WINAPI Updater(LPVOID)
|
||||
UINT WINAPI Updater(LPVOID)
|
||||
{
|
||||
LOG_TO_FILE(L"Entering the %s() function", TEXT(__FUNCTION__));
|
||||
logger.Out(L"Entering the %s() function", TEXT(__FUNCTION__));
|
||||
|
||||
if (!GetLatestRelease(GITHUB_URI))
|
||||
{
|
||||
LOG_TO_FILE(L"[UPDT] %s(%d): Failed getting releases!", TEXT(__FUNCTION__), __LINE__);
|
||||
StringCchPrintfW(errMessageBuffer, DBUFLEN, L"Failed getting releases!");
|
||||
MessageBoxW(NULL, errMessageBuffer, szTitle, MB_OK | MB_ICONERROR);
|
||||
logger.Out(L"[UPDT] %s(%d): Failed getting releases!", TEXT(__FUNCTION__), __LINE__);
|
||||
|
||||
MessageBoxW(NULL, L"Failed getting releases!", szTitle, MB_OK | MB_ICONERROR);
|
||||
_endthreadex(101);
|
||||
return 101;
|
||||
}
|
||||
|
||||
@@ -44,14 +44,15 @@ DWORD WINAPI Updater(LPVOID)
|
||||
|
||||
if (json.is<picojson::object>())
|
||||
{
|
||||
LOG_TO_FILE(L"[UPDT] %s(%d): Parsing JSON object", TEXT(__FUNCTION__), __LINE__);
|
||||
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>();
|
||||
LOG_TO_FILE(L"[UPDT] %s(%d): Error! The url is %s", TEXT(__FUNCTION__), __LINE__, u);
|
||||
logger.Out(L"[UPDT] %s(%d): Error! The url is %s", TEXT(__FUNCTION__), __LINE__, u);
|
||||
_endthreadex(102);
|
||||
return 102;
|
||||
}
|
||||
|
||||
@@ -74,45 +75,48 @@ DWORD WINAPI Updater(LPVOID)
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_TO_FILE(L"[UPDT] %s(%d): Error! Cannot recognize JSON object!", TEXT(__FUNCTION__), __LINE__);
|
||||
logger.Out(L"[UPDT] %s(%d): Error! Cannot recognize JSON object!", TEXT(__FUNCTION__), __LINE__);
|
||||
_endthreadex(103);
|
||||
return 103;
|
||||
}
|
||||
|
||||
std::wstring gh_version = j_tag_name.substr(1);
|
||||
size_t pos = 0;
|
||||
while (std::iswdigit(j_tag_name.at(pos)) == 0) pos++;
|
||||
std::wstring gh_version = j_tag_name.substr(pos);
|
||||
|
||||
LOG_TO_FILE(L"[UPDT] %s(%d): AppVersion : %s", TEXT(__FUNCTION__), __LINE__, TEXT(VERSION_STR));
|
||||
LOG_TO_FILE(L"[UPDT] %s(%d): GitVersion : %s", TEXT(__FUNCTION__), __LINE__, gh_version.c_str());
|
||||
//LOG_TO_FILE(L"[UPDT] %s(%d): FileName : %s", TEXT(__FUNCTION__), __LINE__, j_file_name.c_str());
|
||||
//LOG_TO_FILE(L"[UPDT] %s(%d): FileSize : %d", TEXT(__FUNCTION__), __LINE__, j_file_size);
|
||||
//LOG_TO_FILE(L"[UPDT] %s(%d): File Url : %s", TEXT(__FUNCTION__), __LINE__, j_file_url.c_str());
|
||||
//LOG_TO_FILE(L"[UPDT] %s(%d): Page Url : %s", TEXT(__FUNCTION__), __LINE__, j_page_url.c_str());
|
||||
logger.Out(L"[UPDT] %s(%d): AppVersion : %s", TEXT(__FUNCTION__), __LINE__, TEXT(VERSION_STR));
|
||||
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());
|
||||
|
||||
FillVersionStructure(verApp, TEXT(VERSION_STR));
|
||||
FillVersionStructure(verGh, gh_version);
|
||||
|
||||
if ((verGh.Major > verApp.Major) || (verGh.Minor > verApp.Minor) || (verGh.Build > verApp.Build) || (verGh.Revision > verApp.Revision))
|
||||
if ((verGh.Major > verApp.Major) || (verGh.Minor > verApp.Minor) || (verGh.Build > verApp.Build) || (verGh.Patch > verApp.Patch))
|
||||
{
|
||||
|
||||
LOG_TO_FILE(L"[UPDT] %s(%d): An update is available!", TEXT(__FUNCTION__), __LINE__);
|
||||
logger.Out(L"[UPDT] %s(%d): An update is available!", TEXT(__FUNCTION__), __LINE__);
|
||||
|
||||
if (IDYES == MessageBoxW(NULL, L"An update is available!\nDo you want to open the download page?", szTitle, MB_YESNO | MB_ICONINFORMATION))
|
||||
{
|
||||
LOG_TO_FILE(L"[UPDT] %s(%d): Opening download page by default browser", 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
|
||||
{
|
||||
LOG_TO_FILE(L"[UPDT] %s(%d): The user refused the update", TEXT(__FUNCTION__), __LINE__);
|
||||
logger.Out(L"[UPDT] %s(%d): The user refused the update", TEXT(__FUNCTION__), __LINE__);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_TO_FILE(L"[UPDT] %s(%d): No updates is available", TEXT(__FUNCTION__), __LINE__);
|
||||
return 104;
|
||||
logger.Out(L"[UPDT] %s(%d): No updates is available", TEXT(__FUNCTION__), __LINE__);
|
||||
}
|
||||
|
||||
LOG_TO_FILE(L"[UPDT] Exit from the %s() function", TEXT(__FUNCTION__));
|
||||
logger.Out(L"[UPDT] Exit from the %s() function", TEXT(__FUNCTION__));
|
||||
|
||||
_endthreadex(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -124,6 +128,8 @@ bool GetLatestRelease(const std::wstring& urn)
|
||||
bool ret = true;
|
||||
DWORD err = 0;
|
||||
|
||||
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);
|
||||
if (hInternet != NULL)
|
||||
{
|
||||
@@ -157,14 +163,14 @@ bool GetLatestRelease(const std::wstring& urn)
|
||||
else
|
||||
{
|
||||
err = GetLastError();
|
||||
LOG_TO_FILE(L"[UPDT] %s(%d): HttpSendRequestW() error: %d", TEXT(__FUNCTION__), __LINE__, err);
|
||||
logger.Out(L"[UPDT] %s(%d): HttpSendRequestW() error: %d", TEXT(__FUNCTION__), __LINE__, err);
|
||||
ret = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
err = GetLastError();
|
||||
LOG_TO_FILE(L"[UPDT] %s(%d): HttpOpenRequestW() error: %d", TEXT(__FUNCTION__), __LINE__, err);
|
||||
logger.Out(L"[UPDT] %s(%d): HttpOpenRequestW() error: %d", TEXT(__FUNCTION__), __LINE__, err);
|
||||
ret = false;
|
||||
}
|
||||
InternetCloseHandle(hRequest);
|
||||
@@ -172,7 +178,7 @@ bool GetLatestRelease(const std::wstring& urn)
|
||||
else
|
||||
{
|
||||
err = GetLastError();
|
||||
LOG_TO_FILE(L"[UPDT] %s(%d): InternetConnectW() error: %d", TEXT(__FUNCTION__), __LINE__, err);
|
||||
logger.Out(L"[UPDT] %s(%d): InternetConnectW() error: %d", TEXT(__FUNCTION__), __LINE__, err);
|
||||
ret = false;
|
||||
}
|
||||
InternetCloseHandle(hConnect);
|
||||
@@ -180,7 +186,7 @@ bool GetLatestRelease(const std::wstring& urn)
|
||||
else
|
||||
{
|
||||
err = GetLastError();
|
||||
LOG_TO_FILE(L"[UPDT] %s(%d): InternetOpenW() error: %d", TEXT(__FUNCTION__), __LINE__, err);
|
||||
logger.Out(L"[UPDT] %s(%d): InternetOpenW() error: %d", TEXT(__FUNCTION__), __LINE__, err);
|
||||
ret = false;
|
||||
}
|
||||
InternetCloseHandle(hInternet);
|
||||
@@ -204,7 +210,7 @@ void FillVersionStructure(Version& ver, const std::wstring& str)
|
||||
ver.Major = std::stoul(v[0]);
|
||||
ver.Minor = std::stoul(v[1]);
|
||||
ver.Build = std::stoul(v[2]);
|
||||
ver.Revision = std::stoul(v[3]);
|
||||
ver.Patch = std::stoul(v[3]);
|
||||
}
|
||||
|
||||
std::wstring ConvertUtf8ToWide(const std::string& str)
|
||||
|
||||
@@ -2,4 +2,4 @@
|
||||
// updater.h
|
||||
//
|
||||
#pragma once
|
||||
DWORD WINAPI Updater(LPVOID);
|
||||
UINT WINAPI Updater(void*);
|
||||
|
||||
@@ -6,8 +6,7 @@
|
||||
// TODO: Make x64 version.
|
||||
//
|
||||
#include "framework.h"
|
||||
#include "globals.h"
|
||||
#include "logger.h"
|
||||
#include "wCenterWindow.h"
|
||||
#include "updater.h"
|
||||
|
||||
#define NO_DONATION
|
||||
@@ -15,30 +14,29 @@
|
||||
#define KEY_C 0x43
|
||||
#define KEY_V 0x56
|
||||
|
||||
#define BUF_LEN 1024
|
||||
#define WM_WCW 0x8F00
|
||||
#define MAX_WINTITLE_BUFFER_LENGTH 1024
|
||||
#define WM_WCW (WM_APP + 0x0F00)
|
||||
|
||||
// Global variables:
|
||||
HINSTANCE hInst; // Instance
|
||||
WCHAR szTitle[MAX_LOADSTRING]; // wCenterWindow's title
|
||||
WCHAR szClass[MAX_LOADSTRING]; // Window's class
|
||||
WCHAR szWinTitle[256];
|
||||
WCHAR szWinClass[256];
|
||||
HINSTANCE hInst; // Instance
|
||||
WCHAR szTitle[MAX_LOADSTRING]{ 0 }; // wCenterWindow's title
|
||||
WCHAR szClass[MAX_LOADSTRING]{ 0 }; // Window's class
|
||||
WCHAR szWinTitle[256]{ 0 };
|
||||
WCHAR szWinClass[256]{ 0 };
|
||||
HANDLE hHeap = NULL, hUpdater = NULL;
|
||||
HHOOK hMouseHook = NULL, hKbdHook = NULL; // Hook's handles
|
||||
UINT dwUpdaterID = 0;
|
||||
HHOOK hMouseHook = NULL, hKbdHook = NULL; // Hook's handles
|
||||
HICON hIcon = NULL;
|
||||
HMENU hMenu = NULL, hPopup = NULL;
|
||||
HWND hWnd = NULL, hFgWnd = NULL;
|
||||
BOOL bKPressed = FALSE, bMPressed = FALSE, bShowIcon = TRUE, bWorkArea = TRUE;
|
||||
BOOL bKPressed = FALSE, bMPressed = FALSE, fShowIcon = TRUE, fCheckUpdates = TRUE, bWorkArea = TRUE;
|
||||
BOOL bLCTRL = FALSE, bLWIN = FALSE, bKEYV = FALSE;
|
||||
CLogger logger(TEXT(PRODUCT_NAME), TEXT(VERSION_STR));
|
||||
|
||||
RECT rcFW = { 0 };
|
||||
NOTIFYICONDATAW nid = { 0 };
|
||||
LPKBDLLHOOKSTRUCT pkhs = { 0 };
|
||||
MENUITEMINFO mii = { 0 };
|
||||
|
||||
LPVOID szBuffer;
|
||||
CRITICAL_SECTION cs;
|
||||
|
||||
// {2D7B7F30-4B5F-4380-9807-57D7A2E37F6C}
|
||||
// static const GUID guid = { 0x2d7b7f30, 0x4b5f, 0x4380, { 0x98, 0x7, 0x57, 0xd7, 0xa2, 0xe3, 0x7f, 0x6c } };
|
||||
@@ -55,14 +53,14 @@ INT_PTR CALLBACK About(HWND, UINT, WPARAM, LPARAM);
|
||||
|
||||
VOID MoveWindowToMonitorCenter(HWND hwnd, BOOL bWorkArea, BOOL bResize)
|
||||
{
|
||||
LOG_TO_FILE(L"Entering the %s() function", TEXT(__FUNCTION__));
|
||||
logger.Out(L"Entering the %s() function", TEXT(__FUNCTION__));
|
||||
|
||||
RECT fgwrc = { 0 };
|
||||
GetWindowRect(hwnd, &fgwrc);
|
||||
LONG nWidth = fgwrc.right - fgwrc.left;
|
||||
LONG nHeight = fgwrc.bottom - fgwrc.top;
|
||||
|
||||
LOG_TO_FILE(L"%s(%d): Moving the window from %d, %d", TEXT(__FUNCTION__), __LINE__, fgwrc.left, fgwrc.top);
|
||||
logger.Out(L"%s(%d): Moving the window from %d, %d", TEXT(__FUNCTION__), __LINE__, fgwrc.left, fgwrc.top);
|
||||
|
||||
MONITORINFO mi = { 0 };
|
||||
mi.cbSize = sizeof(MONITORINFO);
|
||||
@@ -92,13 +90,13 @@ VOID MoveWindowToMonitorCenter(HWND hwnd, BOOL bWorkArea, BOOL bResize)
|
||||
int x = (aw - nWidth) / 2;
|
||||
int y = (ah - nHeight) / 2;
|
||||
|
||||
LOG_TO_FILE(L"%s(%d): Moving the window to %d, %d", TEXT(__FUNCTION__), __LINE__, x, y);
|
||||
logger.Out(L"%s(%d): Moving the window to %d, %d", TEXT(__FUNCTION__), __LINE__, x, y);
|
||||
|
||||
SendMessageW(hwnd, WM_ENTERSIZEMOVE, NULL, NULL);
|
||||
MoveWindow(hwnd, x, y, nWidth, nHeight, TRUE);
|
||||
SendMessageW(hwnd, WM_EXITSIZEMOVE, NULL, NULL);
|
||||
|
||||
LOG_TO_FILE(L"Exit from the %s() function", TEXT(__FUNCTION__));
|
||||
logger.Out(L"Exit from the %s() function", TEXT(__FUNCTION__));
|
||||
}
|
||||
|
||||
int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nCmdShow)
|
||||
@@ -114,20 +112,24 @@ int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmd
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
InitializeCriticalSection(&cs);
|
||||
OpenLogFile(szTitle, TEXT(VERSION_STR));
|
||||
logger.Out(L"Entering the %s() function", TEXT(__FUNCTION__));
|
||||
|
||||
LOG_TO_FILE(L"Entering the %s() function", TEXT(__FUNCTION__));
|
||||
int nArgs = 0;
|
||||
LPWSTR* szArglist = CommandLineToArgvW(GetCommandLineW(), &nArgs);
|
||||
|
||||
hUpdater = CreateThread(NULL, 0, &Updater, nullptr, 0, nullptr);
|
||||
if (NULL == hUpdater)
|
||||
logger.Out(L"Arguments count: %d", nArgs - 1);
|
||||
|
||||
if (nArgs > 1)
|
||||
{
|
||||
DWORD dwLastError = GetLastError();
|
||||
LOG_TO_FILE(L"%s(%d): Creating Updater thread failed! Error: %d", TEXT(__FUNCTION__), __LINE__, dwLastError);
|
||||
MessageBoxW(NULL, L"Creating Updater thread failed!", szTitle, MB_OK | MB_ICONERROR);
|
||||
CloseLogFile();
|
||||
return dwLastError;
|
||||
for (int i = 1; i < nArgs; i++)
|
||||
{
|
||||
logger.Out(L"Argument %d: %s", i, szArglist[i]);
|
||||
if (0 == lstrcmpiW(szArglist[i], L"/hide")) fShowIcon = FALSE;
|
||||
if (0 == lstrcmpiW(szArglist[i], L"/noupdate")) fCheckUpdates = FALSE;
|
||||
}
|
||||
|
||||
}
|
||||
LocalFree(szArglist);
|
||||
|
||||
WNDCLASSEX wcex = { 0 };
|
||||
wcex.cbSize = sizeof(WNDCLASSEX);
|
||||
@@ -152,22 +154,10 @@ int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmd
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
int nArgs = 0;
|
||||
LPWSTR* szArglist = CommandLineToArgvW(GetCommandLineW(), &nArgs);
|
||||
|
||||
LOG_TO_FILE(L"Arguments count: %d", nArgs - 1);
|
||||
|
||||
for (int i = 1; i < nArgs; i++)
|
||||
{
|
||||
LOG_TO_FILE(L"Argument %d: %s", i, szArglist[i]);
|
||||
}
|
||||
|
||||
(nArgs >= 2 && 0 == lstrcmpiW(szArglist[1], L"/hide")) ? bShowIcon = FALSE : bShowIcon = TRUE;
|
||||
LocalFree(szArglist);
|
||||
HandlingTrayIcon();
|
||||
|
||||
hHeap = GetProcessHeap();
|
||||
szBuffer = HeapAlloc(hHeap, HEAP_ZERO_MEMORY, BUF_LEN);
|
||||
szBuffer = HeapAlloc(hHeap, HEAP_ZERO_MEMORY, MAX_WINTITLE_BUFFER_LENGTH);
|
||||
|
||||
MSG msg;
|
||||
BOOL bRet;
|
||||
@@ -192,12 +182,10 @@ int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmd
|
||||
Shell_NotifyIconW(NIM_DELETE, &nid);
|
||||
DestroyIcon(hIcon);
|
||||
|
||||
LOG_TO_FILE(L"Exit from the %s() function, msg.wParam = %d", TEXT(__FUNCTION__), (int)msg.wParam);
|
||||
logger.Out(L"Exit from the %s() function, msg.wParam = %d", TEXT(__FUNCTION__), (int)msg.wParam);
|
||||
|
||||
HeapFree(hHeap, NULL, szBuffer);
|
||||
CloseHandle(hUpdater);
|
||||
CloseLogFile();
|
||||
DeleteCriticalSection(&cs);
|
||||
|
||||
return (int)msg.wParam;
|
||||
}
|
||||
@@ -208,25 +196,25 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
case WM_CREATE:
|
||||
{
|
||||
LOG_TO_FILE(L"%s(%d): Recived WM_CREATE message", TEXT(__FUNCTION__), __LINE__);
|
||||
logger.Out(L"%s(%d): Recived WM_CREATE message", TEXT(__FUNCTION__), __LINE__);
|
||||
|
||||
hMenu = LoadMenuW(hInst, MAKEINTRESOURCE(IDR_MENU));
|
||||
if (!hMenu)
|
||||
{
|
||||
LOG_TO_FILE(L"%s(%d): Loading context menu failed!", TEXT(__FUNCTION__), __LINE__);
|
||||
logger.Out(L"%s(%d): Loading context menu failed!", TEXT(__FUNCTION__), __LINE__);
|
||||
ShowError(IDS_ERR_MENU);
|
||||
PostMessageW(hWnd, WM_CLOSE, NULL, NULL);
|
||||
PostQuitMessage(0);
|
||||
}
|
||||
LOG_TO_FILE(L"%s(%d): Context menu successfully loaded", TEXT(__FUNCTION__), __LINE__);
|
||||
logger.Out(L"%s(%d): Context menu successfully loaded", TEXT(__FUNCTION__), __LINE__);
|
||||
|
||||
hPopup = GetSubMenu(hMenu, 0);
|
||||
if (!hPopup)
|
||||
{
|
||||
LOG_TO_FILE(L"%s(%d): Creating popup menu failed!", TEXT(__FUNCTION__), __LINE__);
|
||||
logger.Out(L"%s(%d): Creating popup menu failed!", TEXT(__FUNCTION__), __LINE__);
|
||||
ShowError(IDS_ERR_POPUP);
|
||||
PostMessageW(hWnd, WM_CLOSE, NULL, NULL);
|
||||
PostQuitMessage(0);
|
||||
}
|
||||
LOG_TO_FILE(L"%s(%d): Popup menu successfully created", TEXT(__FUNCTION__), __LINE__);
|
||||
logger.Out(L"%s(%d): Popup menu successfully created", TEXT(__FUNCTION__), __LINE__);
|
||||
|
||||
mii.cbSize = sizeof(MENUITEMINFO);
|
||||
mii.fMask = MIIM_STATE;
|
||||
@@ -242,35 +230,76 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
||||
nid.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;
|
||||
StringCchCopyW(nid.szTip, _countof(nid.szTip), szTitle);
|
||||
|
||||
if (fCheckUpdates)
|
||||
{
|
||||
if (!SetTimer(hWnd, IDT_TIMER, 30000, NULL)) // 30 seconds
|
||||
{
|
||||
logger.Out(L"%s(%d): Creating timer failed!", TEXT(__FUNCTION__), __LINE__);
|
||||
ShowError(IDS_ERR_TIMER);
|
||||
fCheckUpdates = FALSE;
|
||||
}
|
||||
logger.Out(L"%s(%d): Timer successfully created", TEXT(__FUNCTION__), __LINE__);
|
||||
}
|
||||
|
||||
#ifndef _DEBUG
|
||||
hMouseHook = SetWindowsHookExW(WH_MOUSE_LL, MouseHookProc, hInst, NULL);
|
||||
if (!hMouseHook)
|
||||
{
|
||||
LOG_TO_FILE(L"%s(%d): Mouse hook creation failed!", TEXT(__FUNCTION__), __LINE__);
|
||||
logger.Out(L"%s(%d): Mouse hook creation failed!", TEXT(__FUNCTION__), __LINE__);
|
||||
|
||||
ShowError(IDS_ERR_HOOK);
|
||||
PostMessageW(hWnd, WM_CLOSE, NULL, NULL);
|
||||
PostQuitMessage(0);
|
||||
}
|
||||
LOG_TO_FILE(L"%s(%d): The mouse hook was successfully installed", TEXT(__FUNCTION__), __LINE__);
|
||||
logger.Out(L"%s(%d): The mouse hook was successfully installed", TEXT(__FUNCTION__), __LINE__);
|
||||
#endif // !_DEBUG
|
||||
|
||||
hKbdHook = SetWindowsHookExW(WH_KEYBOARD_LL, KeyboardHookProc, hInst, NULL);
|
||||
if (!hKbdHook)
|
||||
{
|
||||
LOG_TO_FILE(L"%s(%d): Keyboard hook creation failed!", TEXT(__FUNCTION__), __LINE__);
|
||||
logger.Out(L"%s(%d): Keyboard hook creation failed!", TEXT(__FUNCTION__), __LINE__);
|
||||
|
||||
ShowError(IDS_ERR_HOOK);
|
||||
PostMessageW(hWnd, WM_CLOSE, NULL, NULL);
|
||||
PostQuitMessage(0);
|
||||
}
|
||||
LOG_TO_FILE(L"%s(%d): The keyboard hook was successfully installed", TEXT(__FUNCTION__), __LINE__);
|
||||
logger.Out(L"%s(%d): The keyboard hook was successfully installed", TEXT(__FUNCTION__), __LINE__);
|
||||
break;
|
||||
}
|
||||
|
||||
case WM_WCW: // Popup menu handler
|
||||
case WM_TIMER:
|
||||
{
|
||||
if (fCheckUpdates)
|
||||
{
|
||||
logger.Out(L"%s(%d): Checking for updates is enabled, fCheckUpdates = %s", TEXT(__FUNCTION__), __LINE__, fCheckUpdates ? L"True" : L"False");
|
||||
|
||||
hUpdater = (HANDLE)_beginthreadex(NULL, 0, &Updater, NULL, 0, &dwUpdaterID);
|
||||
if (NULL == hUpdater)
|
||||
{
|
||||
DWORD dwLastError = GetLastError();
|
||||
logger.Out(L"%s(%d): Creating Updater thread failed! Error: %d", TEXT(__FUNCTION__), __LINE__, dwLastError);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!SetTimer(hWnd, IDT_TIMER, 86400000, NULL)) // 1 day
|
||||
{
|
||||
logger.Out(L"%s(%d): Creating timer failed!", TEXT(__FUNCTION__), __LINE__);
|
||||
ShowError(IDS_ERR_TIMER);
|
||||
fCheckUpdates = FALSE;
|
||||
}
|
||||
logger.Out(L"%s(%d): Timer successfully created", TEXT(__FUNCTION__), __LINE__);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.Out(L"%s(%d): Checking for updates is disabled, fCheckUpdates = %s", TEXT(__FUNCTION__), __LINE__, fCheckUpdates ? L"True" : L"False");
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case WM_WCW: // Popup menu handler
|
||||
{
|
||||
if (IDI_TRAYICON == wParam && (WM_RBUTTONDOWN == lParam || WM_LBUTTONDOWN == lParam))
|
||||
{
|
||||
LOG_TO_FILE(L"%s(%d): Entering the WM_WCW message handler", TEXT(__FUNCTION__), __LINE__);
|
||||
logger.Out(L"%s(%d): Entering the WM_WCW message handler", TEXT(__FUNCTION__), __LINE__);
|
||||
|
||||
SetForegroundWindow(hWnd);
|
||||
POINT pt;
|
||||
@@ -278,23 +307,23 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
||||
int idMenu = TrackPopupMenu(hPopup, TPM_RETURNCMD, pt.x, pt.y, 0, hWnd, NULL);
|
||||
if (ID_POPUPMENU_ICON == idMenu)
|
||||
{
|
||||
LOG_TO_FILE(L"%s(%d): Pressed the 'Hide icon' menuitem", TEXT(__FUNCTION__), __LINE__);
|
||||
logger.Out(L"%s(%d): Pressed the 'Hide icon' menuitem", TEXT(__FUNCTION__), __LINE__);
|
||||
|
||||
bShowIcon = FALSE;
|
||||
fShowIcon = FALSE;
|
||||
HandlingTrayIcon();
|
||||
}
|
||||
if (ID_POPUPMENU_AREA == idMenu)
|
||||
{
|
||||
LOG_TO_FILE(L"%s(%d): Pressed the 'Use workarea' menuitem", TEXT(__FUNCTION__), __LINE__);
|
||||
logger.Out(L"%s(%d): Pressed the 'Use workarea' menuitem", TEXT(__FUNCTION__), __LINE__);
|
||||
|
||||
bWorkArea = !bWorkArea;
|
||||
bWorkArea ? mii.fState = MFS_CHECKED : mii.fState = MFS_UNCHECKED;
|
||||
SetMenuItemInfoW(hPopup, ID_POPUPMENU_AREA, FALSE, &mii);
|
||||
LOG_TO_FILE(L"%s(%d): Changed 'Use workarea' option to %s", TEXT(__FUNCTION__), __LINE__, bWorkArea ? L"True" : L"False");
|
||||
logger.Out(L"%s(%d): Changed 'Use workarea' option to %s", TEXT(__FUNCTION__), __LINE__, bWorkArea ? L"True" : L"False");
|
||||
}
|
||||
if (ID_POPUPMENU_ABOUT == idMenu && !bKPressed)
|
||||
{
|
||||
LOG_TO_FILE(L"%s(%d): Pressed the 'About' menuitem", TEXT(__FUNCTION__), __LINE__);
|
||||
logger.Out(L"%s(%d): Pressed the 'About' menuitem", TEXT(__FUNCTION__), __LINE__);
|
||||
|
||||
bKPressed = TRUE;
|
||||
DialogBoxW(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, (DLGPROC)About);
|
||||
@@ -302,36 +331,34 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
||||
}
|
||||
if (ID_POPUPMENU_EXIT == idMenu)
|
||||
{
|
||||
LOG_TO_FILE(L"%s(%d): Pressed the 'Exit' menuitem", TEXT(__FUNCTION__), __LINE__);
|
||||
logger.Out(L"%s(%d): Pressed the 'Exit' menuitem", TEXT(__FUNCTION__), __LINE__);
|
||||
|
||||
PostMessageW(hWnd, WM_CLOSE, NULL, NULL);
|
||||
PostQuitMessage(0);
|
||||
}
|
||||
|
||||
LOG_TO_FILE(L"%s(%d): Exit from the WM_WCW message handler", TEXT(__FUNCTION__), __LINE__);
|
||||
logger.Out(L"%s(%d): Exit from the WM_WCW message handler", TEXT(__FUNCTION__), __LINE__);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case WM_QUERYENDSESSION:
|
||||
{
|
||||
LOG_TO_FILE(L"%s(%d): Recieved the WM_QUERYENDSESSION message, lParam = 0x%08X", TEXT(__FUNCTION__), __LINE__, (long)lParam);
|
||||
logger.Out(L"%s(%d): Recieved the WM_QUERYENDSESSION message, lParam = 0x%08X", TEXT(__FUNCTION__), __LINE__, (long)lParam);
|
||||
|
||||
CloseLogFile();
|
||||
DeleteCriticalSection(&cs);
|
||||
PostQuitMessage(0);
|
||||
return TRUE;
|
||||
break;
|
||||
}
|
||||
|
||||
case WM_DESTROY:
|
||||
{
|
||||
LOG_TO_FILE(L"%s(%d): Recieved the WM_DESTROY message", TEXT(__FUNCTION__), __LINE__);
|
||||
logger.Out(L"%s(%d): Recieved the WM_DESTROY message", TEXT(__FUNCTION__), __LINE__);
|
||||
|
||||
PostQuitMessage(0);
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
return DefWindowProcW(hWnd, message, wParam, lParam);
|
||||
default: return DefWindowProcW(hWnd, message, wParam, lParam);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -341,7 +368,7 @@ LRESULT CALLBACK MouseHookProc(int nCode, WPARAM wParam, LPARAM lParam)
|
||||
if (WM_MBUTTONUP == wParam) bMPressed = FALSE;
|
||||
if (WM_MBUTTONDOWN == wParam && bLCTRL && bLWIN && !bMPressed)
|
||||
{
|
||||
LOG_TO_FILE(L"%s(%d): Pressed LCTRL + LWIN + MMB", TEXT(__FUNCTION__), __LINE__);
|
||||
logger.Out(L"%s(%d): Pressed LCTRL + LWIN + MMB", TEXT(__FUNCTION__), __LINE__);
|
||||
|
||||
bMPressed = TRUE;
|
||||
hFgWnd = GetForegroundWindow();
|
||||
@@ -353,7 +380,8 @@ LRESULT CALLBACK MouseHookProc(int nCode, WPARAM wParam, LPARAM lParam)
|
||||
|
||||
LRESULT CALLBACK KeyboardHookProc(int nCode, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
pkhs = (KBDLLHOOKSTRUCT*)lParam;
|
||||
LPKBDLLHOOKSTRUCT pkhs = { 0 };
|
||||
pkhs = (LPKBDLLHOOKSTRUCT)lParam;
|
||||
if (WM_KEYUP == wParam)
|
||||
{
|
||||
if (VK_LCONTROL == pkhs->vkCode) bLCTRL = FALSE;
|
||||
@@ -366,19 +394,19 @@ LRESULT CALLBACK KeyboardHookProc(int nCode, WPARAM wParam, LPARAM lParam)
|
||||
if (VK_LCONTROL == pkhs->vkCode) bLCTRL = TRUE;
|
||||
if (VK_LWIN == pkhs->vkCode) bLWIN = TRUE;
|
||||
|
||||
if (KEY_I == pkhs->vkCode && bLCTRL && bLWIN && !bKPressed) // 'I' key
|
||||
if (KEY_I == pkhs->vkCode && bLCTRL && bLWIN && !bKPressed) // 'I' key
|
||||
{
|
||||
LOG_TO_FILE(L"%s(%d): Pressed LCTRL + LWIN + I", TEXT(__FUNCTION__), __LINE__);
|
||||
logger.Out(L"%s(%d): Pressed LCTRL + LWIN + I", TEXT(__FUNCTION__), __LINE__);
|
||||
|
||||
bKPressed = TRUE;
|
||||
bShowIcon = !bShowIcon;
|
||||
fShowIcon = !fShowIcon;
|
||||
HandlingTrayIcon();
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
if (KEY_C == pkhs->vkCode && bLCTRL && bLWIN && !bKPressed && !bKEYV) // 'C' key
|
||||
if (KEY_C == pkhs->vkCode && bLCTRL && bLWIN && !bKPressed && !bKEYV) // 'C' key
|
||||
{
|
||||
LOG_TO_FILE(L"%s(%d): Pressed LCTRL + LWIN + C", TEXT(__FUNCTION__), __LINE__);
|
||||
logger.Out(L"%s(%d): Pressed LCTRL + LWIN + C", TEXT(__FUNCTION__), __LINE__);
|
||||
|
||||
bKPressed = TRUE;
|
||||
hFgWnd = GetForegroundWindow();
|
||||
@@ -387,15 +415,15 @@ LRESULT CALLBACK KeyboardHookProc(int nCode, WPARAM wParam, LPARAM lParam)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
if (KEY_V == pkhs->vkCode && bLCTRL && bLWIN && !bKPressed && !bKEYV) // 'V' key
|
||||
if (KEY_V == pkhs->vkCode && bLCTRL && bLWIN && !bKPressed && !bKEYV) // 'V' key
|
||||
{
|
||||
LOG_TO_FILE(L"%s(%d): Pressed LCTRL + LWIN + V", TEXT(__FUNCTION__), __LINE__);
|
||||
logger.Out(L"%s(%d): Pressed LCTRL + LWIN + V", TEXT(__FUNCTION__), __LINE__);
|
||||
|
||||
bKPressed = TRUE; bKEYV = TRUE;
|
||||
hFgWnd = GetForegroundWindow();
|
||||
if (IsWindowApprooved(hFgWnd))
|
||||
{
|
||||
LOG_TO_FILE(L"%s(%d): Opening the 'Manual editing' dialog", TEXT(__FUNCTION__), __LINE__);
|
||||
logger.Out(L"%s(%d): Opening the 'Manual editing' dialog", TEXT(__FUNCTION__), __LINE__);
|
||||
|
||||
DialogBoxW(hInst, MAKEINTRESOURCE(IDD_MANUAL_EDITING), hFgWnd, (DLGPROC)DlgProc);
|
||||
SetForegroundWindow(hFgWnd);
|
||||
@@ -410,12 +438,13 @@ LRESULT CALLBACK KeyboardHookProc(int nCode, WPARAM wParam, LPARAM lParam)
|
||||
|
||||
BOOL CALLBACK DlgProc(HWND hDlg, UINT dlgmsg, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
RECT rcFW = { 0 };
|
||||
int x, y, w, h;
|
||||
switch (dlgmsg)
|
||||
{
|
||||
case WM_INITDIALOG:
|
||||
{
|
||||
LOG_TO_FILE(L"%s(%d): Initializing the 'Manual editing' dialog", TEXT(__FUNCTION__), __LINE__);
|
||||
logger.Out(L"%s(%d): Initializing the 'Manual editing' dialog", TEXT(__FUNCTION__), __LINE__);
|
||||
|
||||
SetWindowTextW(hDlg, szTitle);
|
||||
GetWindowTextW(hFgWnd, szWinTitle, _countof(szWinTitle));
|
||||
@@ -436,11 +465,12 @@ BOOL CALLBACK DlgProc(HWND hDlg, UINT dlgmsg, WPARAM wParam, LPARAM lParam)
|
||||
}
|
||||
|
||||
case WM_COMMAND:
|
||||
{
|
||||
switch (LOWORD(wParam))
|
||||
{
|
||||
case IDC_BUTTON_SET:
|
||||
{
|
||||
LOG_TO_FILE(L"%s(%d): Pressed the 'Set' button", TEXT(__FUNCTION__), __LINE__);
|
||||
logger.Out(L"%s(%d): Pressed the 'Set' button", TEXT(__FUNCTION__), __LINE__);
|
||||
|
||||
x = GetDlgItemInt(hDlg, IDC_EDIT_X, NULL, TRUE);
|
||||
y = GetDlgItemInt(hDlg, IDC_EDIT_Y, NULL, TRUE);
|
||||
@@ -450,7 +480,7 @@ BOOL CALLBACK DlgProc(HWND hDlg, UINT dlgmsg, WPARAM wParam, LPARAM lParam)
|
||||
MoveWindow(hFgWnd, x, y, w, h, TRUE);
|
||||
SendMessageW(hFgWnd, WM_EXITSIZEMOVE, NULL, NULL);
|
||||
|
||||
LOG_TO_FILE(L"%s(%d): Window with handle 0x%08X was moved to %d, %d", TEXT(__FUNCTION__), __LINE__, hFgWnd, x, y);
|
||||
logger.Out(L"%s(%d): Window with handle 0x%08X was moved to %d, %d", TEXT(__FUNCTION__), __LINE__, hFgWnd, x, y);
|
||||
|
||||
return TRUE;
|
||||
break;
|
||||
@@ -458,36 +488,38 @@ BOOL CALLBACK DlgProc(HWND hDlg, UINT dlgmsg, WPARAM wParam, LPARAM lParam)
|
||||
case IDCANCEL:
|
||||
case IDC_BUTTON_CLOSE:
|
||||
{
|
||||
LOG_TO_FILE(L"%s(%d): Closing the 'Manual editing' dialog", TEXT(__FUNCTION__), __LINE__);
|
||||
logger.Out(L"%s(%d): Closing the 'Manual editing' dialog", TEXT(__FUNCTION__), __LINE__);
|
||||
|
||||
EndDialog(hDlg, LOWORD(wParam));
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
BOOL IsWindowApprooved(HWND hFW)
|
||||
{
|
||||
LOG_TO_FILE(L"Entering the %s() function, handle = 0x%08X", TEXT(__FUNCTION__), hFW);
|
||||
logger.Out(L"Entering the %s() function, handle = 0x%08X", TEXT(__FUNCTION__), hFW);
|
||||
|
||||
bool bApprooved = FALSE;
|
||||
if (hFW)
|
||||
{
|
||||
if (GetWindowTextW(hFW, (LPWSTR)szBuffer, BUF_LEN - sizeof(WCHAR)))
|
||||
if (GetWindowTextW(hFW, (LPWSTR)szBuffer, MAX_WINTITLE_BUFFER_LENGTH))
|
||||
{
|
||||
LOG_TO_FILE(L"%s(%d): Window title: '%s'", TEXT(__FUNCTION__), __LINE__, (LPWSTR)szBuffer);
|
||||
logger.Out(L"%s(%d): Window title: '%s'", TEXT(__FUNCTION__), __LINE__, (LPWSTR)szBuffer);
|
||||
}
|
||||
|
||||
if (IsIconic(hFW))
|
||||
{
|
||||
LOG_TO_FILE(L"%s(%d): The window is iconified", TEXT(__FUNCTION__), __LINE__);
|
||||
logger.Out(L"%s(%d): The window is iconified", TEXT(__FUNCTION__), __LINE__);
|
||||
}
|
||||
|
||||
if (IsZoomed(hFW))
|
||||
{
|
||||
LOG_TO_FILE(L"%s(%d): The window is maximized", TEXT(__FUNCTION__), __LINE__);
|
||||
logger.Out(L"%s(%d): The window is maximized", TEXT(__FUNCTION__), __LINE__);
|
||||
}
|
||||
|
||||
LONG_PTR wlp = GetWindowLongPtrW(hFW, GWL_STYLE);
|
||||
@@ -495,7 +527,7 @@ BOOL IsWindowApprooved(HWND hFW)
|
||||
{
|
||||
if (!IsIconic(hFW) && !IsZoomed(hFW))
|
||||
{
|
||||
LOG_TO_FILE(L"%s(%d): The window is approved!", TEXT(__FUNCTION__), __LINE__);
|
||||
logger.Out(L"%s(%d): The window is approved!", TEXT(__FUNCTION__), __LINE__);
|
||||
|
||||
bApprooved = TRUE;
|
||||
}
|
||||
@@ -503,39 +535,39 @@ BOOL IsWindowApprooved(HWND hFW)
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_TO_FILE(L"%s(%d): The window has no caption!", TEXT(__FUNCTION__), __LINE__);
|
||||
logger.Out(L"%s(%d): The window has no caption!", TEXT(__FUNCTION__), __LINE__);
|
||||
}
|
||||
}
|
||||
|
||||
if (!bApprooved)
|
||||
{
|
||||
LOG_TO_FILE(L"%s(%d): The window is not approved!", TEXT(__FUNCTION__), __LINE__);
|
||||
logger.Out(L"%s(%d): The window is not approved!", TEXT(__FUNCTION__), __LINE__);
|
||||
}
|
||||
|
||||
LOG_TO_FILE(L"Exit from the %s() function", TEXT(__FUNCTION__));
|
||||
logger.Out(L"Exit from the %s() function", TEXT(__FUNCTION__));
|
||||
|
||||
return bApprooved;
|
||||
}
|
||||
|
||||
VOID HandlingTrayIcon()
|
||||
{
|
||||
LOG_TO_FILE(L"Entering the %s() function, bShowIcon = %s", TEXT(__FUNCTION__), bShowIcon ? L"True" : L"False");
|
||||
logger.Out(L"Entering the %s() function, fShowIcon = %s", TEXT(__FUNCTION__), fShowIcon ? L"True" : L"False");
|
||||
|
||||
if (bShowIcon)
|
||||
if (fShowIcon)
|
||||
{
|
||||
bool bResult1 = Shell_NotifyIconW(NIM_ADD, &nid);
|
||||
LOG_TO_FILE(L"%s(%d): Shell_NotifyIconW(NIM_ADD): %s", TEXT(__FUNCTION__), __LINE__, bResult1 ? L"True" : L"False");
|
||||
logger.Out(L"%s(%d): Shell_NotifyIconW(NIM_ADD): %s", TEXT(__FUNCTION__), __LINE__, bResult1 ? L"True" : L"False");
|
||||
|
||||
bool bResult2 = Shell_NotifyIconW(NIM_SETVERSION, &nid);
|
||||
LOG_TO_FILE(L"%s(%d): Shell_NotifyIconW(NIM_SETVERSION): %s", TEXT(__FUNCTION__), __LINE__, bResult2 ? L"True" : L"False");
|
||||
logger.Out(L"%s(%d): Shell_NotifyIconW(NIM_SETVERSION): %s", TEXT(__FUNCTION__), __LINE__, bResult2 ? L"True" : L"False");
|
||||
|
||||
if (!bResult1 || !bResult2)
|
||||
{
|
||||
LOG_TO_FILE(L"%s(%d): Error creating trayicon!", TEXT(__FUNCTION__), __LINE__);
|
||||
logger.Out(L"%s(%d): Error creating trayicon!", TEXT(__FUNCTION__), __LINE__);
|
||||
|
||||
ShowError(IDS_ERR_ICON);
|
||||
Shell_NotifyIconW(NIM_DELETE, &nid);
|
||||
bShowIcon = FALSE;
|
||||
fShowIcon = FALSE;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -547,12 +579,12 @@ VOID HandlingTrayIcon()
|
||||
Shell_NotifyIconW(NIM_DELETE, &nid);
|
||||
}
|
||||
|
||||
LOG_TO_FILE(L"Exit from the %s() function", TEXT(__FUNCTION__));
|
||||
logger.Out(L"Exit from the %s() function", TEXT(__FUNCTION__));
|
||||
}
|
||||
|
||||
VOID ShowError(UINT uID)
|
||||
{
|
||||
WCHAR szErrorText[MAX_LOADSTRING]; // Error's text
|
||||
WCHAR szErrorText[MAX_LOADSTRING]; // Error's text
|
||||
LoadStringW(hInst, uID, szErrorText, _countof(szErrorText));
|
||||
MessageBoxW(NULL, szErrorText, szTitle, MB_OK | MB_ICONERROR | MB_TOPMOST);
|
||||
}
|
||||
@@ -568,7 +600,7 @@ INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
case WM_INITDIALOG:
|
||||
{
|
||||
LOG_TO_FILE(L"%s(%d): Initializing the 'About' dialog", TEXT(__FUNCTION__), __LINE__);
|
||||
logger.Out(L"%s(%d): Initializing the 'About' dialog", TEXT(__FUNCTION__), __LINE__);
|
||||
|
||||
WCHAR szAboutProgName[MAX_LOADSTRING];
|
||||
WCHAR szAboutCopyright[MAX_LOADSTRING];
|
||||
@@ -589,7 +621,7 @@ INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
|
||||
if (hText) DestroyWindow(hText);
|
||||
#endif // !NO_DONATION
|
||||
|
||||
LOG_TO_FILE(L"%s(%d): End of initializing the 'About' dialog", TEXT(__FUNCTION__), __LINE__);
|
||||
logger.Out(L"%s(%d): End of initializing the 'About' dialog", TEXT(__FUNCTION__), __LINE__);
|
||||
|
||||
return (INT_PTR)TRUE;
|
||||
break;
|
||||
@@ -604,7 +636,7 @@ INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
|
||||
LITEM item = pNMLink->item;
|
||||
ShellExecuteW(NULL, L"open", item.szUrl, NULL, NULL, SW_SHOW);
|
||||
|
||||
LOG_TO_FILE(L"%s(%d): Pressed the donation link! :-)", TEXT(__FUNCTION__), __LINE__);
|
||||
logger.Out(L"%s(%d): Pressed the donation link! :-)", TEXT(__FUNCTION__), __LINE__);
|
||||
|
||||
return (INT_PTR)TRUE;
|
||||
}
|
||||
@@ -617,7 +649,7 @@ INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
EndDialog(hDlg, LOWORD(wParam));
|
||||
|
||||
LOG_TO_FILE(L"%s(%d): Closing the 'About' dialog", TEXT(__FUNCTION__), __LINE__);
|
||||
logger.Out(L"%s(%d): Closing the 'About' dialog", TEXT(__FUNCTION__), __LINE__);
|
||||
|
||||
return (INT_PTR)TRUE;
|
||||
}
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
#pragma once
|
||||
#include "resource.h"
|
||||
|
||||
#define MAX_LOADSTRING 50
|
||||
|
||||
// Windows Header Files
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
@@ -15,7 +17,16 @@
|
||||
#include <wininet.h>
|
||||
#include <shellapi.h>
|
||||
#include <CommCtrl.h>
|
||||
#include <process.h>
|
||||
|
||||
// Logger header file
|
||||
#include "CLogger.h"
|
||||
|
||||
// VerionInfo header file
|
||||
#include "VersionInfo.h"
|
||||
|
||||
// wCenterWindow's title
|
||||
extern WCHAR szTitle[MAX_LOADSTRING];
|
||||
|
||||
// An instance of the "CLogger" class
|
||||
extern CLogger logger;
|
||||
|
||||
Binary file not shown.
@@ -186,9 +186,8 @@
|
||||
</PreBuildEvent>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="CLogger.h" />
|
||||
<ClInclude Include="framework.h" />
|
||||
<ClInclude Include="globals.h" />
|
||||
<ClInclude Include="logger.h" />
|
||||
<ClInclude Include="picojson.h" />
|
||||
<ClInclude Include="resource.h" />
|
||||
<ClInclude Include="targetver.h" />
|
||||
@@ -196,7 +195,7 @@
|
||||
<ClInclude Include="wCenterWindow.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="logger.cpp" />
|
||||
<ClCompile Include="CLogger.cpp" />
|
||||
<ClCompile Include="updater.cpp" />
|
||||
<ClCompile Include="wCenterWindow.cpp" />
|
||||
</ItemGroup>
|
||||
|
||||
Reference in New Issue
Block a user