diff --git a/.appveyor.yml b/.appveyor.yml
index 80a154f..d62927c 100644
--- a/.appveyor.yml
+++ b/.appveyor.yml
@@ -1,10 +1,10 @@
environment:
- vers: "2.1.4"
+ vers: "2.1.6"
type: "develop"
-version: '{branch}/2.1.4.{build}'
+version: '{branch}/2.1.6.{build}'
-image: Visual Studio 2017
+image: Visual Studio 2019
platform:
- x64
diff --git a/Display-Lock/Display-Lock.vcxproj b/Display-Lock/Display-Lock.vcxproj
index 0e47771..e00c205 100644
--- a/Display-Lock/Display-Lock.vcxproj
+++ b/Display-Lock/Display-Lock.vcxproj
@@ -22,32 +22,32 @@
15.0
{293E2BAD-0F56-458B-AF84-718F92CAF6DF}
DisplayLock
- 10.0.17134.0
+ 10.0
Application
true
- v141
+ v142
Unicode
Application
false
- v141
+ v142
true
Unicode
Application
true
- v141
+ v142
Unicode
Application
false
- v141
+ v142
true
Unicode
@@ -144,6 +144,7 @@
+
diff --git a/Display-Lock/DisplayLock.c b/Display-Lock/DisplayLock.c
index 314696f..1462632 100644
--- a/Display-Lock/DisplayLock.c
+++ b/Display-Lock/DisplayLock.c
@@ -34,6 +34,8 @@ WINDOW_VIEW_CONTROLS windowControls = { 0 };
SETTINGS settings = { 0 }; // application settings
ARGS args = {0};
BOOL running = FALSE;
+VERSION gVersion = { 0 };
+BOOL initalUpdate = FALSE;
// Forward declarations of functions included in this code module:
ATOM MyRegisterClass(HINSTANCE hInstance);
@@ -44,6 +46,7 @@ INT_PTR CALLBACK MainWindow(HWND hDlg, UINT message, WPARAM wParam, LPARAM lP
INT_PTR CALLBACK windowViewProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
INT_PTR CALLBACK settingsViewProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
INT_PTR CALLBACK about(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
+INT_PTR CALLBACK updateProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
_In_opt_ HINSTANCE hPrevInstance,
@@ -157,11 +160,17 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
case WM_CREATE:
+ if (settings.checkUpdateStartup) {
+ getVersion(&gVersion);
+ initalUpdate = !compareVersion(&gVersion);
+ }
+
CreateDialog(NULL, MAKEINTRESOURCE(IDD_MAIN_VIEW), hWnd, MainWindow);
invokeReadSettings(&settings);
notifyInit(hWnd, &sysTray);
Shell_NotifyIcon(NIM_ADD, &sysTray);
Shell_NotifyIcon(NIM_SETVERSION, &sysTray);
+
break;
case NOTIFY_MSG:
@@ -190,56 +199,66 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
break;
case WM_COMMAND:
+ {
+ int wmId = LOWORD(wParam);
+ // Parse the menu selections:
+ // item from submenu in notifications
+ if (wParam >= SUBMENU_ITEM_BASE && wParam <= (SUBMENU_ITEM_BASE + 100))
{
- int wmId = LOWORD(wParam);
- // Parse the menu selections:
- // item from submenu in notifications
- if (wParam >= SUBMENU_ITEM_BASE && wParam <= (SUBMENU_ITEM_BASE + 100))
- {
- settings.foreground = TRUE;
- windowsButtonStart(&windowControls, &args, &running, ((int)wParam - SUBMENU_ITEM_BASE));
- settings.foreground = FALSE;
- }
+ settings.foreground = TRUE;
+ windowsButtonStart(&windowControls, &args, &running, ((int)wParam - SUBMENU_ITEM_BASE));
+ settings.foreground = FALSE;
+ }
- switch (wmId)
- {
- case ID_CONTEXTMENU_STOP:
- notifyChildWindows(hWnd, IDC_BUTTON_WINDOWS_STOP);
- break;
- case ID_CONTEXTMENU_SHOWWINDOW:
- ShowWindow(hWnd, TRUE);
- break;
- case ID_CONTEXTMENU_EXIT:
- SendMessage(hWnd, WM_CLOSE, 0, 0);
- break;
- case ID_CONTEXTMENU_SETTINGS_MINIMIZE:
- settings.minimize = !settings.minimize;
- notifyChildWindows(hWnd, NOTIFY_SETTINGS_CHANGED);
- break;
- case ID_CONTEXTMENU_SETTINGS_FOREGROUND:
- settings.foreground = !settings.foreground;
- notifyChildWindows(hWnd, NOTIFY_SETTINGS_CHANGED);
- break;
- case ID_CONTEXTMENU_SETTINGS_BORDERLESS:
- settings.borderless = !settings.borderless;
- notifyChildWindows(hWnd, NOTIFY_SETTINGS_CHANGED);
- break;
- case ID_CONTEXTMENU_SETTINGS_FULLSCREEN:
- settings.fullScreen = !settings.fullScreen;
- notifyChildWindows(hWnd, NOTIFY_SETTINGS_CHANGED);
- break;
- case IDM_ABOUT:
- DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUT), hWnd, about);
- break;
- case IDM_EXIT:
- {
- SendMessage(hWnd, WM_CLOSE, 0, 0);
- break;
- }
- default:
- return DefWindowProc(hWnd, message, wParam, lParam);
- }
+ switch (wmId)
+ {
+ case ID_CONTEXTMENU_STOP:
+ notifyChildWindows(hWnd, IDC_BUTTON_WINDOWS_STOP);
+ break;
+ case ID_CONTEXTMENU_SHOWWINDOW:
+ ShowWindow(hWnd, TRUE);
+ break;
+ case ID_CONTEXTMENU_EXIT:
+ SendMessage(hWnd, WM_CLOSE, 0, 0);
+ break;
+ case ID_CONTEXTMENU_SETTINGS_MINIMIZE:
+ settings.minimize = !settings.minimize;
+ notifyChildWindows(hWnd, NOTIFY_SETTINGS_CHANGED);
+ break;
+ case ID_CONTEXTMENU_SETTINGS_FOREGROUND:
+ settings.foreground = !settings.foreground;
+ notifyChildWindows(hWnd, NOTIFY_SETTINGS_CHANGED);
+ break;
+ case ID_CONTEXTMENU_SETTINGS_BORDERLESS:
+ settings.borderless = !settings.borderless;
+ notifyChildWindows(hWnd, NOTIFY_SETTINGS_CHANGED);
+ break;
+ case ID_CONTEXTMENU_SETTINGS_FULLSCREEN:
+ settings.fullScreen = !settings.fullScreen;
+ notifyChildWindows(hWnd, NOTIFY_SETTINGS_CHANGED);
+ break;
+ case IDM_ABOUT:
+ DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUT), hWnd, about);
+ break;
+ case ID_HELP_CHECKFORUPDATES:
+ {
+ if (gVersion.verArr[0] == 0)
+ getVersion(&gVersion);
+
+ if(!compareVersion(&gVersion))
+ DialogBox(hInst, MAKEINTRESOURCE(IDD_UPDATE), hWnd, updateProc);
+
+ break;
+ }
+ case IDM_EXIT:
+ {
+ SendMessage(hWnd, WM_CLOSE, 0, 0);
+ break;
+ }
+ default:
+ return DefWindowProc(hWnd, message, wParam, lParam);
}
+ }
break;
case WM_PAINT:
{
@@ -247,6 +266,12 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
HDC hdc = BeginPaint(hWnd, &ps);
// TODO: Add any drawing code that uses hdc here...
EndPaint(hWnd, &ps);
+
+ if (initalUpdate)
+ {
+ SendMessage(hWnd, WM_COMMAND, LOWORD(ID_HELP_CHECKFORUPDATES), 0);
+ initalUpdate = FALSE;
+ }
}
break;
case WM_CLOSE:
@@ -282,6 +307,7 @@ INT_PTR CALLBACK MainWindow(HWND hDlg, UINT message, WPARAM wParam, LPARAM lPara
// show the default window
ShowWindow(mainWindowControls.windowView, SW_SHOW);
args.controls = mainWindowControls;
+
return (INT_PTR)TRUE;
case WM_NOTIFY:
@@ -327,6 +353,7 @@ INT_PTR CALLBACK windowViewProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM l
initalizeWindowView(hDlg, &menu, &settings, &running, &windowControls, &args);
parent = GetParent(GetParent(GetParent(hDlg)));
args.hWnd = parent;
+
return (INT_PTR)TRUE;
case WM_COMMAND:
@@ -386,6 +413,7 @@ INT_PTR CALLBACK settingsViewProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM
settings = previousSettings;
else if ((BOOL)wParam == TRUE)
previousSettings = settings;
+
break;
case WM_INITDIALOG:
@@ -422,6 +450,12 @@ INT_PTR CALLBACK settingsViewProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM
settings.minimize = (BOOL)SendMessage(settingsControls.minimize, BM_GETCHECK, 0, 0);
break;
+ case IDC_CHECK_STARTUP_UPDATES:
+ EnableWindow(GetDlgItem(hDlg, IDC_BUTTON_SETTINGS_SAVE), TRUE);
+ settingsControls.settingsChanged = TRUE;
+ settings.checkUpdateStartup = (BOOL)SendMessage(settingsControls.checkForUpdatesStartup, BM_GETCHECK, 0, 0);
+ break;
+
case IDC_HOTKEY:
EnableWindow(GetDlgItem(hDlg, IDC_BUTTON_SETTINGS_SAVE), TRUE);
settingsControls.settingsChanged = TRUE;
@@ -468,6 +502,59 @@ INT_PTR CALLBACK about(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
//ShellExecuteW(NULL, TEXT("open"), TEXT("https://github.com/idietmoran/Display-Lock"), NULL, NULL, SW_SHOWNORMAL);
break;
+ case WM_COMMAND:
+ if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
+ {
+ EndDialog(hDlg, LOWORD(wParam));
+ return (INT_PTR)TRUE;
+ }
+
+ break;
+ default:
+ break;
+ }
+ return (INT_PTR)FALSE;
+}
+
+INT_PTR CALLBACK updateProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
+{
+
+ UNREFERENCED_PARAMETER(lParam);
+ switch (message)
+ {
+ case WM_INITDIALOG:
+ {
+ break;
+ }
+ return (INT_PTR)TRUE;
+
+ case WM_NOTIFY:
+
+ switch (((NMHDR*)lParam)->code)
+ {
+ case NM_CLICK:
+ {
+ if (wParam == IDC_UPDATE_LINK) {
+ NMLINK* pNMLink = (NMLINK*)lParam;
+ LITEM iItem = pNMLink->item;
+ ShellExecuteW(
+ NULL,
+ TEXT("open"),
+ iItem.szUrl,
+ NULL,
+ NULL,
+ SW_HIDE
+ );
+ EndDialog(hDlg, LOWORD(wParam));
+ return (INT_PTR)TRUE;
+ }
+ break;
+ }
+ default:
+ break;
+ }
+ break;
+
case WM_COMMAND:
if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
{
diff --git a/Display-Lock/resources/resource.aps b/Display-Lock/resources/resource.aps
index 2ffe631..4f77592 100644
Binary files a/Display-Lock/resources/resource.aps and b/Display-Lock/resources/resource.aps differ
diff --git a/Display-Lock/resources/resource.h b/Display-Lock/resources/resource.h
index 538e1ed..c312773 100644
Binary files a/Display-Lock/resources/resource.h and b/Display-Lock/resources/resource.h differ
diff --git a/Display-Lock/resources/resource.rc b/Display-Lock/resources/resource.rc
index c9e2c89..5d6e2ad 100644
Binary files a/Display-Lock/resources/resource.rc and b/Display-Lock/resources/resource.rc differ
diff --git a/Display-Lock/resources/resourceRC.h b/Display-Lock/resources/resourceRC.h
new file mode 100644
index 0000000..ab1a896
--- /dev/null
+++ b/Display-Lock/resources/resourceRC.h
@@ -0,0 +1,19 @@
+//{{NO_DEPENDENCIES}}
+// Microsoft Visual C++ generated include file.
+// Used by version.rc
+//
+#define VERSION_MAJOR 0
+#define VERSION_MINOR 0
+#define VERSION_REVISION 0
+#define VERSION_BUILD 0
+
+// Next default values for new objects
+//
+#ifdef APSTUDIO_INVOKED
+#ifndef APSTUDIO_READONLY_SYMBOLS
+#define _APS_NEXT_RESOURCE_VALUE 101
+#define _APS_NEXT_COMMAND_VALUE 40001
+#define _APS_NEXT_CONTROL_VALUE 1001
+#define _APS_NEXT_SYMED_VALUE 101
+#endif
+#endif
diff --git a/Display-Lock/resources/version.aps b/Display-Lock/resources/version.aps
index 8d6ad08..054f25f 100644
Binary files a/Display-Lock/resources/version.aps and b/Display-Lock/resources/version.aps differ
diff --git a/Display-Lock/resources/version.rc b/Display-Lock/resources/version.rc
index ba9a23f..8ae830d 100644
Binary files a/Display-Lock/resources/version.rc and b/Display-Lock/resources/version.rc differ
diff --git a/Display-Lock/ui.c b/Display-Lock/ui.c
index 2fb94fc..f1e24f7 100644
--- a/Display-Lock/ui.c
+++ b/Display-Lock/ui.c
@@ -20,9 +20,11 @@
#include
#include "win.h"
#include "menu.h"
+#include "common.h"
#include "settings.h"
-BOOL getVersionString(wchar_t * buffer, int bufferSize)
+
+BOOL getVersionString(wchar_t *buffer, int bufferSize)
{
wchar_t version[2048];
wchar_t fileName[MAX_PATH];
@@ -40,7 +42,6 @@ BOOL getVersionString(wchar_t * buffer, int bufferSize)
if (!result)
return FALSE;
-
UINT size;
VS_FIXEDFILEINFO *verInfo = NULL;
result = VerQueryValue(version, L"\\", (LPVOID)&verInfo, &size);
@@ -53,24 +54,62 @@ BOOL getVersionString(wchar_t * buffer, int bufferSize)
int build = HIWORD(verInfo->dwFileVersionLS);
int revision = LOWORD(verInfo->dwFileVersionLS);
-
swprintf(buffer, bufferSize, L"Version: %d.%d.%d.%d", major, minor, build, revision);
return TRUE;
}
+BOOL getVersion(VERSION* gVersion)
+{
+ wchar_t version[2048];
+ wchar_t fileName[MAX_PATH];
+ BOOL result;
+ UINT size;
+ VS_FIXEDFILEINFO* verInfo = NULL;
+ DWORD dwVersionBufferSize;
+
+ result = GetModuleFileName(NULL, fileName, MAX_PATH);
+
+ if (!result)
+ return FALSE;
+
+ dwVersionBufferSize = GetFileVersionInfoSizeW(fileName, NULL);
+ result = GetFileVersionInfo(fileName, 0, dwVersionBufferSize, (LPVOID)version);
+
+ if (!result)
+ return FALSE;
+
+ result = VerQueryValue(version, L"\\", (LPVOID)& verInfo, &size);
+
+ if (!result)
+ return FALSE;
+
+ int major = HIWORD(verInfo->dwFileVersionMS);
+ int minor = LOWORD(verInfo->dwFileVersionMS);
+ int build = HIWORD(verInfo->dwFileVersionLS);
+ int revision = LOWORD(verInfo->dwFileVersionLS);
+
+ gVersion->version.major = major;
+ gVersion->version.minor = minor;
+ gVersion->version.patch = build;
+
+ return TRUE;
+}
+
void settingsShowWindow(SETTINGS_VIEW_CONTROLS settingsControls, SETTINGS * settings, SETTINGS * previousSettings, BOOL running)
{
SendMessage(settingsControls.borderless, BM_SETCHECK, settings->borderless, 0);
SendMessage(settingsControls.foreground, BM_SETCHECK, settings->foreground, 0);
SendMessage(settingsControls.fullScreen, BM_SETCHECK, settings->fullScreen, 0);
SendMessage(settingsControls.minimize, BM_SETCHECK, settings->minimize, 0);
+ SendMessage(settingsControls.checkForUpdatesStartup, BM_SETCHECK, settings->checkUpdateStartup, 0);
EnableWindow(settingsControls.borderless, !running);
EnableWindow(settingsControls.foreground, !running);
EnableWindow(settingsControls.fullScreen, !running);
EnableWindow(settingsControls.minimize, !running);
EnableWindow(settingsControls.hotkey, !running);
+ EnableWindow(settingsControls.checkForUpdatesStartup, !running);
}
@@ -80,6 +119,7 @@ void settingsSave(HWND hWnd,SETTINGS_VIEW_CONTROLS settingsControls, SETTINGS se
settings.foreground = (BOOL)SendMessage(settingsControls.foreground, BM_GETCHECK, 0, 0);
settings.fullScreen = (BOOL)SendMessage(settingsControls.fullScreen, BM_GETCHECK, 0, 0);
settings.minimize = (BOOL)SendMessage(settingsControls.minimize, BM_GETCHECK, 0, 0);
+ settings.checkUpdateStartup = (BOOL)SendMessage(settingsControls.checkForUpdatesStartup, BM_GETCHECK, 0, 0);
*previousSettings = settings;
}
@@ -91,7 +131,8 @@ void settingsCancel(SETTINGS_VIEW_CONTROLS settingsControls, SETTINGS *settings,
SendMessage(settingsControls.foreground, BM_SETCHECK, settings->foreground, 0);
SendMessage(settingsControls.fullScreen, BM_SETCHECK, settings->fullScreen, 0);
SendMessage(settingsControls.minimize, BM_SETCHECK, settings->minimize, 0);
- SendMessage(settingsControls.hotkey, HKM_SETHOTKEY, 0, 0);
+ SendMessage(settingsControls.checkForUpdatesStartup, BM_SETCHECK, settings->checkUpdateStartup, 0);
+ //SendMessage(settingsControls.hotkey, HKM_SETHOTKEY, 0, 0);
}
void initalizeWindowView(HWND hDlg, MENU *menu, SETTINGS *settings, BOOL *running, WINDOW_VIEW_CONTROLS *windowControls, ARGS *args)
diff --git a/Display-Lock/ui.h b/Display-Lock/ui.h
index 05ff239..526a318 100644
--- a/Display-Lock/ui.h
+++ b/Display-Lock/ui.h
@@ -19,7 +19,8 @@
#include "common.h"
-BOOL getVersionString(wchar_t *buffer, int bufferSize);
+BOOL getVersionString(wchar_t* buffer, int bufferSize);
+BOOL getVersion(VERSION *version);
void settingsShowWindow(SETTINGS_VIEW_CONTROLS settingsControls, SETTINGS *settings, SETTINGS *previousSettings, BOOL running);
void settingsSave(HWND hWnd, SETTINGS_VIEW_CONTROLS settingsControls, SETTINGS settings, SETTINGS *previousSettings);
void settingsCancel(SETTINGS_VIEW_CONTROLS settingsControls, SETTINGS *settings, SETTINGS previousSettings);
diff --git a/dispLib/dispLib.vcxproj b/dispLib/dispLib.vcxproj
index 698bf87..b9f7526 100644
--- a/dispLib/dispLib.vcxproj
+++ b/dispLib/dispLib.vcxproj
@@ -22,32 +22,32 @@
15.0
{AB25AA47-E252-41AD-A8D0-C7923358817C}
dispLib
- 10.0.17134.0
+ 10.0
StaticLibrary
true
- v141
+ v142
Unicode
StaticLibrary
false
- v141
+ v142
true
Unicode
StaticLibrary
true
- v141
+ v142
Unicode
StaticLibrary
false
- v141
+ v142
true
Unicode
@@ -82,7 +82,7 @@
Default
- Shlwapi.lib;%(AdditionalDependencies)
+ Shlwapi.lib;winhttp.lib;%(AdditionalDependencies)
@@ -97,7 +97,7 @@
Default
- Shlwapi.lib;%(AdditionalDependencies)
+ Shlwapi.lib;winhttp.lib;%(AdditionalDependencies)
@@ -117,7 +117,7 @@
true
- Shlwapi.lib;%(AdditionalDependencies)
+ Shlwapi.lib;winhttp.lib;%(AdditionalDependencies)
@@ -137,7 +137,7 @@
true
- Shlwapi.lib;%(AdditionalDependencies)
+ Shlwapi.lib;winhttp.lib;%(AdditionalDependencies)
@@ -145,6 +145,7 @@
+
@@ -152,6 +153,7 @@
+
diff --git a/dispLib/include/common.h b/dispLib/include/common.h
index 4da2204..571ce4f 100644
--- a/dispLib/include/common.h
+++ b/dispLib/include/common.h
@@ -40,6 +40,7 @@ typedef struct SETTINGS SETTINGS;
typedef struct ARGS ARGS;
typedef struct HOTKEY HOTKEY;
typedef struct WINDOW WINDOW;
+typedef union VERSION VERSION;
struct MAIN_WINDOW_CONTROLS
{
@@ -84,6 +85,7 @@ struct SETTINGS_VIEW_CONTROLS
HWND borderless;
HWND fullScreen;
HWND hotkey;
+ HWND checkForUpdatesStartup;
};
struct MENU
@@ -101,6 +103,7 @@ struct SETTINGS
BOOL foreground;
BOOL borderless;
BOOL fullScreen;
+ BOOL checkUpdateStartup;
};
struct ARGS
@@ -111,3 +114,13 @@ struct ARGS
HWND hWnd;
MAIN_WINDOW_CONTROLS controls;
};
+
+union VERSION {
+ struct _version {
+ unsigned int major;
+ unsigned int minor;
+ unsigned int patch;
+ } version;
+
+ unsigned int verArr[3];
+};
\ No newline at end of file
diff --git a/dispLib/include/update.h b/dispLib/include/update.h
new file mode 100644
index 0000000..7e6338d
--- /dev/null
+++ b/dispLib/include/update.h
@@ -0,0 +1,29 @@
+/*
+ Display Lock
+ Copyright (C) 2018 Dimitrios Apostal
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see .
+*/
+#pragma once
+#include "common.h"
+
+typedef struct STRING {
+ unsigned int size;
+ char* data;
+} STRING;
+
+void getLatestVersion(VERSION* version);
+void resizeString(STRING*, int);
+void parseVersionString(VERSION*, STRING*);
+BOOL compareVersion(const VERSION* current);
\ No newline at end of file
diff --git a/dispLib/src/settings.c b/dispLib/src/settings.c
index c51d91a..96bd0bb 100644
--- a/dispLib/src/settings.c
+++ b/dispLib/src/settings.c
@@ -28,7 +28,9 @@ void initalizeSettings(HWND hDlg, SETTINGS_VIEW_CONTROLS *settingsControls)
settingsControls->borderless = GetDlgItem(hDlg, IDC_CHECK_SETTINGS_BORDERLESS);
settingsControls->fullScreen = GetDlgItem(hDlg, IDC_CHECK_SETTINGS_FULL_SCREEN);
settingsControls->hotkey = GetDlgItem(hDlg, IDC_HOTKEY);
+ settingsControls->checkForUpdatesStartup = GetDlgItem(hDlg, IDC_CHECK_STARTUP_UPDATES);
settingsControls->settingsChanged = FALSE;
+
}
void setSettingsDlg(HWND hDlg, SETTINGS settings)
@@ -50,6 +52,7 @@ void defaultSettings(SETTINGS *settings, wchar_t *versionStr)
settings->foreground = FALSE;
settings->fullScreen = FALSE;
settings->minimize = TRUE;
+ settings->checkUpdateStartup = TRUE;
}
BOOL checkVersion(SETTINGS *settings, wchar_t *versionStr)
@@ -75,14 +78,12 @@ BOOL findPath(wchar_t *outPath)
HRESULT hr = SHGetKnownFolderPath(&FOLDERID_RoamingAppData, 0, NULL, &path);
- if (SUCCEEDED(hr))
- {
+ if (!SUCCEEDED(hr))
+ return FALSE;
+
wcscpy(outPath, path);
LPCWSTR x = L"DisplayLock\\settings.DLOCK";
PathAppend(outPath, x);
- }
- else
- return FALSE;
CoTaskMemFree(path);
return TRUE;
@@ -92,20 +93,18 @@ BOOL createDirectory(wchar_t *outPath)
{
PWSTR path;
- if (SUCCEEDED(SHGetKnownFolderPath(&FOLDERID_RoamingAppData, 0, NULL, &path)))
- {
- wcscpy(outPath, path);
-
- // create directory
- PathAppend(outPath, TEXT("DisplayLock"));
- // TODO: check if directory was created
- CreateDirectory(outPath, NULL);
- // create file
- PathAppend(outPath, TEXT("\\settings.DLOCK"));
- }
- else
+ if (!SUCCEEDED(SHGetKnownFolderPath(&FOLDERID_RoamingAppData, 0, NULL, &path)))
return FALSE;
+ wcscpy(outPath, path);
+
+ // create directory
+ PathAppend(outPath, TEXT("DisplayLock"));
+ // TODO: check if directory was created
+ CreateDirectory(outPath, NULL);
+ // create file
+ PathAppend(outPath, TEXT("\\settings.DLOCK"));
+
CoTaskMemFree(path);
return TRUE;
}
diff --git a/dispLib/src/update.c b/dispLib/src/update.c
new file mode 100644
index 0000000..61bad58
--- /dev/null
+++ b/dispLib/src/update.c
@@ -0,0 +1,193 @@
+/*
+ Display Lock
+ Copyright (C) 2018 Dimitrios Apostal
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see .
+*/
+#include "update.h"
+#include
+#include
+#include
+
+
+void resizeString(STRING* string, int size) {
+ const int newSize = string->size + size;
+ char* data = string->data;
+ if (string->data != NULL) {
+ string->data = (char*)realloc(string->data, ((size_t)newSize + 1));
+ if (string->data == NULL)
+ free(data);
+ string->size = size;
+ }
+}
+
+void parseVersionString(VERSION* version, STRING* response)
+{
+ char major[5] = "";
+ char minor[5] = "";
+ char patch[10] = "";
+
+ memset(major, 0, sizeof(major));
+ memset(minor, 0, sizeof(minor));
+ memset(patch, 0, sizeof(patch));
+
+ char *result;
+
+ result = strtok(response->data, ".");
+
+ int count = 0;
+ while (result)
+ {
+ version->verArr[count] = atoi(result);
+ result = strtok(NULL, ".");
+ count++;
+ }
+}
+
+void getLatestVersion(VERSION* version)
+{
+ HINTERNET hSession;
+ HINTERNET hConnect;
+ HINTERNET hRequest;
+ BOOL bResults;
+ DWORD dwSize;
+ DWORD dwDownloaded;
+
+ STRING response;
+
+ int count = 0;
+ response.size = 0;
+ response.data = (char*)calloc(1024, sizeof(char));
+ response.data[0] = '\0';
+
+ memset(&hSession, 0, sizeof(HINTERNET));
+ memset(&hConnect, 0, sizeof(HINTERNET));
+ memset(&hRequest, 0, sizeof(HINTERNET));
+
+ hSession = WinHttpOpen(
+ TEXT("Example UserAgent/1.0"),
+ WINHTTP_ACCESS_TYPE_DEFAULT_PROXY,
+ WINHTTP_NO_PROXY_NAME,
+ WINHTTP_NO_PROXY_BYPASS,
+ 0
+ );
+
+ if (!hSession)
+ goto CLEANUP;
+
+ hConnect = WinHttpConnect(
+ hSession,
+ TEXT("stateford.github.io"),
+ INTERNET_DEFAULT_HTTPS_PORT,
+ 0
+ );
+
+ if (!hConnect)
+ goto CLEANUP;
+
+ hRequest = WinHttpOpenRequest(
+ hConnect,
+ TEXT("GET"),
+ TEXT("Display-Lock/version"),
+ NULL,
+ WINHTTP_NO_REFERER,
+ WINHTTP_DEFAULT_ACCEPT_TYPES,
+ WINHTTP_FLAG_SECURE
+ );
+
+ if (!hRequest)
+ goto CLEANUP;
+
+ bResults = WinHttpSendRequest(
+ hRequest,
+ WINHTTP_NO_ADDITIONAL_HEADERS,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0
+ );
+
+ if (bResults)
+ {
+ if (WinHttpReceiveResponse(hRequest, NULL))
+ {
+ do
+ {
+ // Check for available data.
+ dwSize = 0;
+ bResults = WinHttpQueryDataAvailable(hRequest, &dwSize);
+ if (!bResults)
+ {
+ break;
+ }
+
+ if (dwSize == 0)
+ break;
+
+ do
+ {
+ // Allocate space for the buffer.
+ DWORD dwOffset = response.size;
+ resizeString(&response, dwSize);
+
+ // Read the data.
+ bResults = WinHttpReadData(hRequest, &response.data[dwOffset], dwSize, &dwDownloaded);
+ if (!bResults)
+ {
+ dwDownloaded = 0;
+ }
+
+ resizeString(&response, dwOffset + dwDownloaded);
+
+ if (dwDownloaded == 0)
+ break;
+
+ dwSize -= dwDownloaded;
+ } while (TRUE);
+ } while (TRUE);
+ }
+ response.data[response.size] = '\0';
+ }
+
+ parseVersionString(version, &response);
+
+
+CLEANUP:
+ if (hConnect)
+ WinHttpCloseHandle(hConnect);
+ if (hSession)
+ WinHttpCloseHandle(hSession);
+ if (hRequest)
+ WinHttpCloseHandle(hRequest);
+ if (response.data != NULL)
+ free(response.data);
+}
+
+BOOL compareVersion(const VERSION* current)
+{
+ VERSION latest;
+ memset(&latest, 0, sizeof(latest));
+
+ getLatestVersion(&latest);
+
+ if (current->version.major < latest.version.major)
+ return FALSE;
+ else if (current->version.minor < latest.version.minor)
+ return FALSE;
+ else if (current->version.patch < latest.version.patch)
+ return FALSE;
+
+ return TRUE;
+}
\ No newline at end of file
diff --git a/tests/tests.vcxproj b/tests/tests.vcxproj
index d97cb0d..ef50b62 100644
--- a/tests/tests.vcxproj
+++ b/tests/tests.vcxproj
@@ -23,21 +23,21 @@
{C1A9B46E-F571-4367-B918-ED7081C41C10}
Win32Proj
tests
- 10.0.17134.0
+ 10.0
NativeUnitTestProject
DynamicLibrary
true
- v141
+ v142
Unicode
false
DynamicLibrary
false
- v141
+ v142
true
Unicode
false
@@ -45,14 +45,14 @@
DynamicLibrary
true
- v141
+ v142
Unicode
false
DynamicLibrary
false
- v141
+ v142
true
Unicode
false