Updater: code reorganize

git-svn-id: svn://svn.code.sf.net/p/processhacker/code@4703 21ef857c-d57f-4fe0-8362-d861dc6d29cd
This commit is contained in:
dmex
2011-09-20 14:55:51 +00:00
parent cce219315a
commit 768d580479
3 changed files with 41 additions and 81 deletions
+1 -2
View File
@@ -82,8 +82,7 @@
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>EditAndContinue</DebugInformationFormat>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<CallingConvention>StdCall</CallingConvention>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
</ClCompile>
+12 -15
View File
@@ -199,7 +199,9 @@ static void __cdecl WorkerThreadStart(
LocalFileNameString = PhFormatString(L"processhacker-%u.%u-setup.exe", xmlData.MajorVersion, xmlData.MinorVersion);
Updater_EnableUI(hwndDlg);
Edit_Enable(GetDlgItem(hwndDlg, IDC_RELDATE), TRUE);
Edit_Enable(GetDlgItem(hwndDlg, IDC_DLSIZE), TRUE);
Button_Enable(GetDlgItem(hwndDlg, IDC_DOWNLOAD), TRUE);
}
else if (result == 0)
{
@@ -279,8 +281,8 @@ static void __cdecl DownloadWorkerThreadStart(
return;
}
Updater_SetStatusText(hwndDlg, L"Connecting");
Edit_SetText(GetDlgItem(hwndDlg, IDC_STATUSTEXT), L"Connecting");
if (HttpSendRequest(NetRequest, NULL, 0, NULL, 0))
{
CHAR buffer[BUFFER_LEN];
@@ -360,9 +362,9 @@ static void __cdecl DownloadWorkerThreadStart(
PPH_STRING dlLength = PhFormatSize(dwContentLen, -1);
PPH_STRING str = PhFormatString(L"Downloaded: %s of %s (%d%%)", dlCurrent->Buffer, dlLength->Buffer, dlProgress);
Updater_SetStatusText(hwndDlg, str->Buffer);
Edit_SetText(GetDlgItem(hwndDlg, IDC_STATUSTEXT), str->Buffer);
PostMessage(hwndProgress, PBM_SETPOS, dlProgress, 0);
PhDereferenceObject(str);
PhDereferenceObject(dlLength);
PhDereferenceObject(dlCurrent);
@@ -480,8 +482,10 @@ static void __cdecl DownloadWorkerThreadStart(
PostMessage(hwndProgress, PBM_SETPOS, 100, 0);
// Enable Install button
SetDlgItemText(hwndDlg, IDC_DOWNLOAD, L"Install");
Updater_EnableUI(hwndDlg);
Button_SetText(GetDlgItem(hwndDlg, IDC_DOWNLOAD), L"Install");
Edit_Enable(GetDlgItem(hwndDlg, IDC_RELDATE), TRUE);
Edit_Enable(GetDlgItem(hwndDlg, IDC_DLSIZE), TRUE);
Button_Enable(GetDlgItem(hwndDlg, IDC_DOWNLOAD), TRUE);
if (!PhElevated)
{
@@ -503,13 +507,6 @@ INT_PTR CALLBACK MainWndProc(
{
switch (uMsg)
{
case ENABLE_UI:
{
Edit_Enable(GetDlgItem(hwndDlg, IDC_RELDATE), TRUE);
Edit_Enable(GetDlgItem(hwndDlg, IDC_DLSIZE), TRUE);
Button_Enable(GetDlgItem(hwndDlg, IDC_DOWNLOAD), TRUE);
}
break;
case WM_INITDIALOG:
{
DisposeConnection();
@@ -560,7 +557,7 @@ INT_PTR CALLBACK MainWndProc(
if (PhInstalledUsingSetup())
{
Updater_SetStatusText(hwndDlg, L"Initializing");
Edit_SetText(GetDlgItem(hwndDlg, IDC_STATUSTEXT), L"Initializing");
// Show the status text
ShowWindow(GetDlgItem(hwndDlg, IDC_STATUSTEXT), SW_SHOW);
+28 -64
View File
@@ -3,24 +3,22 @@
#pragma comment(lib, "Wininet.lib")
#pragma comment(lib, "Shell32.lib")
typedef enum _PH_UPDATER_STATE
{
Default,
Downloading,
Installing
} PH_UPDATER_STATE;
#include "phdk.h"
#include "resource.h"
#include "wininet.h"
#include "mxml.h"
#include "windowsx.h"
#include <wininet.h>
#include <windowsx.h>
#include <ShellAPI.h>
#include <ShlObj.h>
#include <stdint.h>
#pragma region Defines
#define BUFFER_LEN 512
#define UPDATE_MENUITEM 1
#define UPDATE_URL L"processhacker.sourceforge.net"
#define UPDATE_FILE L"/update.php"
#define DOWNLOAD_SERVER L"sourceforge.net"
#define DOWNLOAD_PATH L"/projects/processhacker/files/processhacker2/%s/download" /* ?use_mirror=waix" */
#define TDIF_SIZE_TO_CONTENT 0x1000000
#define SecurityStop UINT16_MAX - 1
@@ -33,22 +31,12 @@ typedef enum _PH_UPDATER_STATE
#define SecurityShieldGray UINT16_MAX - 8
#define ASecurityWarning UINT16_MAX
#define UPDATE_URL L"processhacker.sourceforge.net"
#define UPDATE_FILE L"/update.php"
#define DOWNLOAD_SERVER L"sourceforge.net"
#define DOWNLOAD_PATH L"/projects/processhacker/files/processhacker2/%s/download" /* ?use_mirror=waix" */
#define BUFFER_LEN 512
#define UPDATE_MENUITEM 1
#define ENABLE_UI WM_APP + 1
#define Updater_SetStatusText(hwndDlg, lpString) \
SetDlgItemText(hwndDlg, IDC_STATUSTEXT, lpString)
#define Updater_EnableUI(hwndDlg) \
PostMessage(hwndDlg, ENABLE_UI, 0, 0)
PPH_PLUGIN PluginInstance;
PH_CALLBACK_REGISTRATION PluginLoadCallbackRegistration;
PH_CALLBACK_REGISTRATION PluginMenuItemCallbackRegistration;
PH_CALLBACK_REGISTRATION MainWindowShowingCallbackRegistration;
PH_CALLBACK_REGISTRATION PluginShowOptionsCallbackRegistration;
_TaskDialogIndirect TaskDialogIndirect_I;
typedef struct _UPDATER_XML_DATA
{
@@ -59,35 +47,22 @@ typedef struct _UPDATER_XML_DATA
PPH_STRING Hash;
} UPDATER_XML_DATA, *PUPDATER_XML_DATA;
#pragma endregion
#pragma region Instances
PPH_PLUGIN PluginInstance;
PH_CALLBACK_REGISTRATION PluginLoadCallbackRegistration;
PH_CALLBACK_REGISTRATION PluginMenuItemCallbackRegistration;
PH_CALLBACK_REGISTRATION MainWindowShowingCallbackRegistration;
PH_CALLBACK_REGISTRATION PluginShowOptionsCallbackRegistration;
#pragma endregion
#pragma region Functions
typedef enum _PH_UPDATER_STATE
{
Default,
Downloading,
Hashing,
Installing
} PH_UPDATER_STATE;
VOID StartInitialCheck(VOID);
VOID ShowUpdateDialog(VOID);
VOID DisposeConnection(VOID);
VOID DisposeStrings(VOID);
VOID DisposeFileHandles(VOID);
BOOL PhInstalledUsingSetup(VOID);
BOOL ConnectionAvailable(VOID);
BOOL InitializeConnection(
__in PCWSTR host,
__in PCWSTR path
);
BOOL ParseVersionString(
__in PWSTR String,
__out PULONG MajorVersion,
@@ -101,6 +76,11 @@ LONG CompareVersions(
__in ULONG MinorVersion2
);
BOOL InitializeConnection(
__in PCWSTR host,
__in PCWSTR path
);
BOOL ReadRequestString(
__in HINTERNET Handle,
__out PSTR *Data,
@@ -116,11 +96,6 @@ VOID FreeXmlData(
__in PUPDATER_XML_DATA XmlData
);
BOOL InitializeConnection(
__in PCWSTR host,
__in PCWSTR path
);
VOID LogEvent(
__in PPH_STRING str
);
@@ -157,15 +132,4 @@ INT_PTR CALLBACK OptionsDlgProc(
__in UINT uMsg,
__in WPARAM wParam,
__in LPARAM lParam
);
typedef HRESULT (WINAPI *_TaskDialogIndirect)(
__in const TASKDIALOGCONFIG *pTaskConfig,
__in int *pnButton,
__in int *pnRadioButton,
__in BOOL *pfVerificationFlagChecked
);
_TaskDialogIndirect TaskDialogIndirect_I;
#pragma endregion
);