LegacyUpdate/launcher/main.c

122 lines
2.3 KiB
C
Raw Normal View History

#include "stdafx.h"
#include "main.h"
#include "resource.h"
#include <windows.h>
#include <commctrl.h>
#include "MsgBox.h"
2024-09-17 05:19:57 -04:00
#include "RegisterServer.h"
#include "Startup.h"
HINSTANCE g_hInstance;
2024-09-14 13:10:26 -04:00
extern void LaunchUpdateSite(int argc, LPWSTR *argv, int nCmdShow);
extern void LaunchOptions(int nCmdShow);
extern void RunOnce();
typedef enum Action {
ActionLaunch,
ActionOptions,
ActionRunOnce,
ActionRegServer,
ActionUnregServer
} Action;
static const LPWSTR actions[] = {
L"/launch",
L"/options",
L"/runonce",
L"/regserver",
L"/unregserver",
NULL
};
EXTERN_C __declspec(dllexport)
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine, int nCmdShow) {
g_hInstance = hInstance;
Startup();
int argc;
2024-09-14 13:10:26 -04:00
LPWSTR *argv = CommandLineToArgvW(GetCommandLineW(), &argc);
LPWSTR actionFlag = L"/launch";
if (argc > 1) {
actionFlag = argv[1];
}
2024-09-14 13:10:26 -04:00
// All remaining args past the action
LPWSTR *flags = {0};
int flagsCount = 0;
if (argc > 2) {
flags = &argv[2];
flagsCount = argc - 2;
}
Action action = -1;
for (int i = 0; actions[i] != NULL; i++) {
if (wcscmp(actionFlag, actions[i]) == 0) {
action = i;
break;
}
}
switch (action) {
case ActionLaunch:
2024-09-14 13:10:26 -04:00
LaunchUpdateSite(flagsCount, flags, nCmdShow);
break;
case ActionOptions:
LaunchOptions(nCmdShow);
break;
case ActionRunOnce:
RunOnce();
break;
case ActionRegServer:
case ActionUnregServer: {
BOOL state = action == ActionRegServer;
2024-09-29 04:52:20 -04:00
HWND hwnd = flagsCount > 0 ? (HWND)(intptr_t)wcstol(flags[0], NULL, 10) : 0;
2024-09-28 13:27:48 -04:00
RegisterServer(hwnd, state, FALSE);
break;
}
default: {
2024-09-17 05:19:57 -04:00
const LPWSTR usage = L""
L"LegacyUpdate.exe [/launch|/regserver|/unregserver]\n"
L"\n"
L"/launch\n"
L" Launch Legacy Update website in Internet Explorer\n"
L"\n"
L"/options\n"
L" Open the Windows Update Options control panel\n"
L"\n"
2024-09-17 05:19:57 -04:00
L"/regserver\n"
L" Register ActiveX control\n"
L"\n"
L"/unregserver\n"
L" Unregister ActiveX control\n"
L"\n"
L"If no parameters are provided, /launch is assumed.";
MsgBox(NULL, L"LegacyUpdate.exe usage", usage, MB_OK);
2024-09-14 13:10:26 -04:00
PostQuitMessage(1);
break;
}
2024-09-14 13:10:26 -04:00
}
MSG msg;
while (GetMessage(&msg, NULL, 0, 0) == 1) {
TranslateMessage(&msg);
DispatchMessage(&msg);
switch (msg.message) {
case WM_QUIT:
case WM_DESTROY:
break;
}
}
2024-09-14 13:10:26 -04:00
ExitProcess(msg.wParam);
return msg.wParam;
}