|
| 1 | +/* Copyright (C) 2014-2024 Stefan-Mihai MOGA |
| 2 | +This file is part of IntelliLink application developed by Stefan-Mihai MOGA. |
| 3 | +IntelliLink is an alternative Windows version to Online Link Managers! |
| 4 | +
|
| 5 | +IntelliLink is free software: you can redistribute it and/or modify it |
| 6 | +under the terms of the GNU General Public License as published by the Open |
| 7 | +Source Initiative, either version 3 of the License, or any later version. |
| 8 | +
|
| 9 | +IntelliLink is distributed in the hope that it will be useful, but |
| 10 | +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
| 11 | +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. |
| 12 | +
|
| 13 | +You should have received a copy of the GNU General Public License along with |
| 14 | +IntelliLink. If not, see <http://www.opensource.org/licenses/gpl-3.0.html>*/ |
| 15 | + |
| 16 | +// CheckForUpdatesDlg.cpp : implementation file |
| 17 | +// |
| 18 | + |
| 19 | +#include "stdafx.h" |
| 20 | +#include "IntelliTask.h" |
| 21 | +#include "CheckForUpdatesDlg.h" |
| 22 | + |
| 23 | +#include "genUp4win/genUp4win.h" |
| 24 | +#ifdef _DEBUG |
| 25 | +#pragma comment(lib, "x64/Debug/genUp4win.lib") |
| 26 | +#else |
| 27 | +#pragma comment(lib, "x64/Release/genUp4win.lib") |
| 28 | +#endif |
| 29 | + |
| 30 | +// CCheckForUpdatesDlg dialog |
| 31 | + |
| 32 | +IMPLEMENT_DYNAMIC(CCheckForUpdatesDlg, CDialogEx) |
| 33 | + |
| 34 | +CCheckForUpdatesDlg::CCheckForUpdatesDlg(CWnd* pParent /*=nullptr*/) |
| 35 | + : CDialogEx(IDD_CheckForUpdatesDlg, pParent) |
| 36 | +{ |
| 37 | + m_nUpdateThreadID = 0; |
| 38 | + m_hUpdateThread = nullptr; |
| 39 | +} |
| 40 | + |
| 41 | +CCheckForUpdatesDlg::~CCheckForUpdatesDlg() |
| 42 | +{ |
| 43 | +} |
| 44 | + |
| 45 | +void CCheckForUpdatesDlg::DoDataExchange(CDataExchange* pDX) |
| 46 | +{ |
| 47 | + CDialogEx::DoDataExchange(pDX); |
| 48 | + DDX_Control(pDX, IDC_STATUS, m_ctrlStatusMessage); |
| 49 | + DDX_Control(pDX, IDC_PROGRESS, m_ctrlProgress); |
| 50 | +} |
| 51 | + |
| 52 | +BEGIN_MESSAGE_MAP(CCheckForUpdatesDlg, CDialogEx) |
| 53 | + ON_WM_TIMER() |
| 54 | +END_MESSAGE_MAP() |
| 55 | + |
| 56 | +// CCheckForUpdatesDlg message handlers |
| 57 | +CCheckForUpdatesDlg* g_dlgCheckForUpdates = nullptr; |
| 58 | +void UI_Callback(int, const std::wstring& strMessage) |
| 59 | +{ |
| 60 | + if (g_dlgCheckForUpdates != nullptr) |
| 61 | + { |
| 62 | + g_dlgCheckForUpdates->m_ctrlStatusMessage.SetWindowText(strMessage.c_str()); |
| 63 | + g_dlgCheckForUpdates->m_ctrlStatusMessage.UpdateWindow(); |
| 64 | + } |
| 65 | +} |
| 66 | + |
| 67 | +bool g_bThreadRunning = false; |
| 68 | +bool g_bNewUpdateFound = false; |
| 69 | +DWORD WINAPI UpdateThreadProc(LPVOID lpParam) |
| 70 | +{ |
| 71 | + UNREFERENCED_PARAMETER(lpParam); |
| 72 | + |
| 73 | + g_bThreadRunning = true; |
| 74 | + if (g_dlgCheckForUpdates != nullptr) |
| 75 | + { |
| 76 | + g_dlgCheckForUpdates->m_ctrlProgress.SetMarquee(TRUE, 30); |
| 77 | + } |
| 78 | + const DWORD nLength = _MAX_PATH; |
| 79 | + TCHAR lpszFilePath[nLength] = { 0, }; |
| 80 | + GetModuleFileName(nullptr, lpszFilePath, nLength); |
| 81 | + g_bNewUpdateFound = CheckForUpdates(lpszFilePath, APPLICATION_URL, UI_Callback); |
| 82 | + if (g_dlgCheckForUpdates != nullptr) |
| 83 | + { |
| 84 | + g_dlgCheckForUpdates->m_ctrlProgress.SetMarquee(FALSE, 30); |
| 85 | + } |
| 86 | + g_bThreadRunning = false; |
| 87 | + |
| 88 | + ::ExitThread(0); |
| 89 | + return 0; |
| 90 | +} |
| 91 | + |
| 92 | +BOOL CCheckForUpdatesDlg::OnInitDialog() |
| 93 | +{ |
| 94 | + CDialogEx::OnInitDialog(); |
| 95 | + |
| 96 | +#ifdef _DEBUG |
| 97 | + const DWORD nLength = _MAX_PATH; |
| 98 | + TCHAR lpszFilePath[nLength] = { 0, }; |
| 99 | + GetModuleFileName(nullptr, lpszFilePath, nLength); |
| 100 | + WriteConfigFile(lpszFilePath, INSTALLER_URL); |
| 101 | +#endif |
| 102 | + |
| 103 | + g_dlgCheckForUpdates = this; |
| 104 | + m_hUpdateThread = ::CreateThread(nullptr, 0, (LPTHREAD_START_ROUTINE)UpdateThreadProc, this, 0, &m_nUpdateThreadID); |
| 105 | + m_nTimerID = SetTimer(0x1234, 100, nullptr); |
| 106 | + |
| 107 | + return TRUE; // return TRUE unless you set the focus to a control |
| 108 | + // EXCEPTION: OCX Property Pages should return FALSE |
| 109 | +} |
| 110 | + |
| 111 | +void CCheckForUpdatesDlg::OnCancel() |
| 112 | +{ |
| 113 | + while (g_bThreadRunning) |
| 114 | + Sleep(1000); |
| 115 | + CDialogEx::OnCancel(); |
| 116 | +} |
| 117 | + |
| 118 | +void CCheckForUpdatesDlg::OnTimer(UINT_PTR nIDEvent) |
| 119 | +{ |
| 120 | + CDialogEx::OnTimer(nIDEvent); |
| 121 | + |
| 122 | + if (m_nTimerID == nIDEvent) |
| 123 | + { |
| 124 | + if (!g_bThreadRunning) |
| 125 | + { |
| 126 | + CDialogEx::OnCancel(); |
| 127 | + if (g_bNewUpdateFound) |
| 128 | + { |
| 129 | + PostQuitMessage(0); |
| 130 | + } |
| 131 | + } |
| 132 | + } |
| 133 | +} |
0 commit comments