Add files via upload
This commit is contained in:
41
nsisplugin/EnableMicrosoftUpdate.c
Normal file
41
nsisplugin/EnableMicrosoftUpdate.c
Normal file
@@ -0,0 +1,41 @@
|
||||
#define CINTERFACE
|
||||
#define COBJMACROS
|
||||
#include <windows.h>
|
||||
#include <nsis/pluginapi.h>
|
||||
#include <wuapi.h>
|
||||
#include "main.h"
|
||||
|
||||
static const GUID our_CLSID_UpdateServiceManager = { 0xf8d253d9, 0x89a4, 0x4daa, { 0x87, 0xb6, 0x11, 0x68, 0x36, 0x9f, 0x0b, 0x21 } };
|
||||
static const GUID our_IID_IUpdateServiceManager2 = { 0x0bb8531d, 0x7e8d, 0x424f, { 0x98, 0x6c, 0xa0, 0xb8, 0xf6, 0x0a, 0x3e, 0x7b } };
|
||||
|
||||
static const LPWSTR MicrosoftUpdateServiceID = L"7971f918-a847-4430-9279-4a52d1efe18d";
|
||||
|
||||
EXTERN_C __declspec(dllexport)
|
||||
void __cdecl EnableMicrosoftUpdate(HWND hwndParent, int string_size, TCHAR *variables, stack_t **stacktop, extra_parameters *extra) {
|
||||
EXDLL_INIT();
|
||||
g_hwndParent = hwndParent;
|
||||
|
||||
IUpdateServiceManager2 *serviceManager;
|
||||
IUpdateServiceRegistration *registration;
|
||||
|
||||
HRESULT hr = CoCreateInstance(our_CLSID_UpdateServiceManager, NULL, CLSCTX_INPROC_SERVER, our_IID_IUpdateServiceManager2, (void **)&serviceManager);
|
||||
if (!SUCCEEDED(hr)) {
|
||||
goto end;
|
||||
}
|
||||
|
||||
hr = IUpdateServiceManager2_AddService2(serviceManager, SysAllocString(MicrosoftUpdateServiceID), asfAllowPendingRegistration | asfAllowOnlineRegistration | asfRegisterServiceWithAU, SysAllocString(L""), ®istration);
|
||||
if (!SUCCEEDED(hr)) {
|
||||
goto end;
|
||||
}
|
||||
|
||||
end:
|
||||
if (registration != NULL) {
|
||||
IUpdateServiceManager2_Release(registration);
|
||||
}
|
||||
|
||||
if (serviceManager != NULL) {
|
||||
IUpdateServiceManager2_Release(serviceManager);
|
||||
}
|
||||
|
||||
pushint(hr);
|
||||
}
|
45
nsisplugin/IsProcessRunning.c
Normal file
45
nsisplugin/IsProcessRunning.c
Normal file
@@ -0,0 +1,45 @@
|
||||
#include <windows.h>
|
||||
#include <nsis/pluginapi.h>
|
||||
#include <psapi.h>
|
||||
#include "main.h"
|
||||
|
||||
EXTERN_C __declspec(dllexport)
|
||||
void __cdecl IsProcessRunning(HWND hwndParent, int string_size, TCHAR *variables, stack_t **stacktop, extra_parameters *extra) {
|
||||
EXDLL_INIT();
|
||||
g_hwndParent = hwndParent;
|
||||
|
||||
LPTSTR process = (LPTSTR)malloc(string_size * sizeof(TCHAR));
|
||||
popstring(process);
|
||||
CharLowerBuffW(process, wcslen(process));
|
||||
|
||||
// Yes, eat all of our SHRTs!
|
||||
DWORD pids[SHRT_MAX];
|
||||
DWORD bytesReturned;
|
||||
if (!EnumProcesses(pids, sizeof(pids), &bytesReturned)) {
|
||||
pushstring(L"0");
|
||||
return;
|
||||
}
|
||||
|
||||
DWORD count = bytesReturned / sizeof(DWORD);
|
||||
for (DWORD i = 0; i < count; ++i) {
|
||||
HANDLE handle = OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION | PROCESS_VM_READ, FALSE, pids[i]);
|
||||
if (handle) {
|
||||
WCHAR path[MAX_PATH];
|
||||
if (GetProcessImageFileName(handle, path, ARRAYSIZE(path))) {
|
||||
LPWSTR basename = wcsrchr(path, L'\\');
|
||||
if (basename != NULL) {
|
||||
basename += 1;
|
||||
CharLowerBuffW(basename, wcslen(basename));
|
||||
if (_wcsicmp(process, basename) == 0) {
|
||||
pushstring(L"1");
|
||||
CloseHandle(handle);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
CloseHandle(handle);
|
||||
}
|
||||
}
|
||||
|
||||
pushstring(L"0");
|
||||
}
|
110
nsisplugin/Makefile
Normal file
110
nsisplugin/Makefile
Normal file
@@ -0,0 +1,110 @@
|
||||
FILES = \
|
||||
$(wildcard *.c) \
|
||||
../include/nsis/pluginapi.c \
|
||||
../Shared/HResult.c \
|
||||
../Shared/WUErrors.c
|
||||
RCFILES = resource.rc
|
||||
|
||||
BIN = obj/LegacyUpdateNSIS.dll
|
||||
DEF = $(patsubst %.dll,%.def,$(BIN))
|
||||
STATIC = $(patsubst %.dll,%.a,$(BIN))
|
||||
OBJ = $(foreach file,$(FILES),obj/$(notdir $(basename $(file)).o))
|
||||
RES = $(foreach file,$(RCFILES),obj/$(notdir $(basename $(file)).res))
|
||||
|
||||
PREFIX = i686-w64-mingw32-
|
||||
|
||||
CC = $(PREFIX)g++
|
||||
RC = $(PREFIX)windres
|
||||
|
||||
override DEBUG := $(or $(DEBUG),1)
|
||||
|
||||
CFLAGS = \
|
||||
-std=c++11 \
|
||||
-march=i486 \
|
||||
-mdll \
|
||||
-municode \
|
||||
-DUNICODE \
|
||||
-D_UNICODE \
|
||||
$(if $(filter 1,$(DEBUG)),-D_DEBUG -g,-DNDEBUG -Os) \
|
||||
-D__USE_MINGW_ANSI_STDIO=0 \
|
||||
-D_USRDLL \
|
||||
-s \
|
||||
-fPIE \
|
||||
-ffunction-sections \
|
||||
-fdata-sections \
|
||||
-fno-unwind-tables \
|
||||
-fno-asynchronous-unwind-tables \
|
||||
-fno-exceptions \
|
||||
-fno-rtti \
|
||||
-flto \
|
||||
-Wno-write-strings \
|
||||
-I../include \
|
||||
-I../shared \
|
||||
-include stdafx.h
|
||||
|
||||
LDFLAGS = \
|
||||
-nodefaultlibs \
|
||||
-nostartfiles \
|
||||
-nostdlib \
|
||||
-Wl,--gc-sections \
|
||||
-Wl,--no-seh \
|
||||
-Wl,--nxcompat \
|
||||
-Wl,--enable-auto-image-base \
|
||||
-Wl,--enable-stdcall-fixup \
|
||||
-Wl,--output-def,$(DEF) \
|
||||
-Wl,--out-implib,$(STATIC) \
|
||||
-Wl,--strip-all \
|
||||
-Wl,-e_DllMain \
|
||||
-lmsvcrt \
|
||||
-lgcc \
|
||||
-lpsapi \
|
||||
-lkernel32 \
|
||||
-luser32 \
|
||||
-lole32 \
|
||||
-loleaut32
|
||||
|
||||
RCFLAGS = \
|
||||
-F pe-i386 \
|
||||
-O coff
|
||||
|
||||
all: before-all $(BIN) after-all
|
||||
|
||||
before-all:
|
||||
mkdir -p obj
|
||||
|
||||
after-all:
|
||||
ifeq ($(SIGN),1)
|
||||
../build/sign.sh $(BIN)
|
||||
endif
|
||||
cp $(BIN) ../setup/x86-unicode/
|
||||
|
||||
$(BIN): $(OBJ) $(RES)
|
||||
$(CC) $^ $(CFLAGS) $(LDFLAGS) -o $@
|
||||
|
||||
obj/%.o: %.c
|
||||
$(CC) $< $(CFLAGS) -c -o $@
|
||||
|
||||
obj/%.o: %.cpp
|
||||
$(CC) $< $(CFLAGS) -c -o $@
|
||||
|
||||
obj/%.o: ../shared/%.c
|
||||
$(CC) $< $(CFLAGS) -c -o $@
|
||||
|
||||
obj/%.o: ../shared/%.cpp
|
||||
$(CC) $< $(CFLAGS) -c -o $@
|
||||
|
||||
obj/%.o: ../include/nsis/%.c
|
||||
$(CC) $< $(CFLAGS) -c -o $@
|
||||
|
||||
obj/%.res: %.rc
|
||||
$(RC) $< $(RCFLAGS) -o $@
|
||||
|
||||
clean:
|
||||
rm -rf obj
|
||||
|
||||
test:
|
||||
$(MAKE) DEBUG=$(DEBUG)
|
||||
cd ../setup && makensis test.nsi
|
||||
cd ../setup && explorer.exe test.exe
|
||||
|
||||
.PHONY: all before-all after-all clean test
|
14
nsisplugin/MessageForHresult.c
Normal file
14
nsisplugin/MessageForHresult.c
Normal file
@@ -0,0 +1,14 @@
|
||||
#include <windows.h>
|
||||
#include <nsis/pluginapi.h>
|
||||
#include "../shared/HResult.h"
|
||||
|
||||
EXTERN_C __declspec(dllexport)
|
||||
void __cdecl MessageForHresult(HWND hwndParent, int string_size, TCHAR *variables, stack_t **stacktop, extra_parameters *extra) {
|
||||
EXDLL_INIT();
|
||||
g_hwndParent = hwndParent;
|
||||
|
||||
HRESULT hr = popint();
|
||||
LPWSTR message = GetMessageForHresult(hr);
|
||||
pushstring(message);
|
||||
LocalFree(message);
|
||||
}
|
109
nsisplugin/TaskbarProgress.c
Normal file
109
nsisplugin/TaskbarProgress.c
Normal file
@@ -0,0 +1,109 @@
|
||||
// Based on https://nsis.sourceforge.io/TaskbarProgress_plug-in - zlib licensed
|
||||
// Cleaned up and refactored into C by Legacy Update
|
||||
#define CINTERFACE
|
||||
#define COBJMACROS
|
||||
#include <windows.h>
|
||||
#include <nsis/pluginapi.h>
|
||||
#include <commctrl.h>
|
||||
#include <objbase.h>
|
||||
#include <shobjidl.h>
|
||||
#include "main.h"
|
||||
|
||||
static const GUID our_CLSID_ITaskbarList = { 0x56fdf344, 0xfd6d, 0x11d0, { 0x95, 0x8a, 0x00, 0x60, 0x97, 0xc9, 0xa0, 0x90 } };
|
||||
static const GUID our_IID_ITaskbarList3 = { 0xea1afb91, 0x9e28, 0x4b86, { 0x90, 0xe9, 0x9e, 0x9f, 0x8a, 0x5e, 0xef, 0xaf } };
|
||||
|
||||
ITaskbarList3 *g_taskbarList;
|
||||
UINT g_totalRange;
|
||||
WNDPROC g_origWndProc;
|
||||
|
||||
LRESULT ProgressBarWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
|
||||
if (g_origWndProc == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
switch (uMsg) {
|
||||
case PBM_SETRANGE:
|
||||
g_totalRange = LOWORD(lParam) + HIWORD(lParam);
|
||||
break;
|
||||
|
||||
case PBM_SETRANGE32:
|
||||
g_totalRange = wParam + lParam;
|
||||
break;
|
||||
|
||||
case PBM_SETPOS:
|
||||
if (g_taskbarList != NULL) {
|
||||
ITaskbarList3_SetProgressValue(g_taskbarList, g_hwndParent, wParam, g_totalRange);
|
||||
}
|
||||
break;
|
||||
|
||||
case WM_DESTROY:
|
||||
SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR)g_origWndProc);
|
||||
|
||||
if (g_taskbarList != NULL) {
|
||||
ITaskbarList3_SetProgressState(g_taskbarList, g_hwndParent, TBPF_NOPROGRESS);
|
||||
ITaskbarList3_Release(g_taskbarList);
|
||||
g_taskbarList = NULL;
|
||||
}
|
||||
|
||||
g_origWndProc = NULL;
|
||||
break;
|
||||
}
|
||||
|
||||
return CallWindowProc(g_origWndProc, hwnd, uMsg, wParam, lParam);
|
||||
}
|
||||
|
||||
UINT_PTR NSISPluginCallback(enum NSPIM event) {
|
||||
// Does nothing, but keeping a callback registered prevents NSIS from unloading the plugin
|
||||
return 0;
|
||||
}
|
||||
|
||||
EXTERN_C __declspec(dllexport)
|
||||
void __cdecl InitTaskbarProgress(HWND hwndParent, int string_size, TCHAR *variables, stack_t **stacktop, extra_parameters *extra) {
|
||||
EXDLL_INIT();
|
||||
g_hwndParent = hwndParent;
|
||||
|
||||
extra->RegisterPluginCallback(g_hInstance, NSISPluginCallback);
|
||||
|
||||
if (g_taskbarList != NULL && g_origWndProc != NULL) {
|
||||
// Already initialised
|
||||
return;
|
||||
}
|
||||
|
||||
HWND innerWindow = FindWindowEx(g_hwndParent, NULL, L"#32770", NULL);
|
||||
HWND progressBar = FindWindowEx(innerWindow, NULL, L"msctls_progress32", NULL);
|
||||
PBRANGE range;
|
||||
HRESULT hr;
|
||||
|
||||
if (progressBar == NULL) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
hr = CoCreateInstance(our_CLSID_ITaskbarList, NULL, CLSCTX_INPROC_SERVER, our_IID_ITaskbarList3, (void**)&g_taskbarList);
|
||||
if (!SUCCEEDED(hr)) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
hr = ITaskbarList3_HrInit(g_taskbarList);
|
||||
if (!SUCCEEDED(hr)) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
// Get the initial progress bar range
|
||||
SendMessage(progressBar, PBM_GETRANGE, 0, (LPARAM)&range);
|
||||
g_totalRange = range.iLow + range.iHigh;
|
||||
|
||||
// Add our own window procedure so we can respond to progress bar updates
|
||||
g_origWndProc = (WNDPROC)SetWindowLongPtr(progressBar, GWLP_WNDPROC, (LONG_PTR)ProgressBarWndProc);
|
||||
if (g_origWndProc == NULL) {
|
||||
goto fail;
|
||||
}
|
||||
return;
|
||||
|
||||
fail:
|
||||
if (g_taskbarList != NULL) {
|
||||
ITaskbarList3_Release(g_taskbarList);
|
||||
g_taskbarList = NULL;
|
||||
}
|
||||
|
||||
g_origWndProc = NULL;
|
||||
}
|
10
nsisplugin/main.c
Normal file
10
nsisplugin/main.c
Normal file
@@ -0,0 +1,10 @@
|
||||
#include <windows.h>
|
||||
#include <nsis/pluginapi.h>
|
||||
|
||||
HMODULE g_hInstance;
|
||||
HWND g_hwndParent;
|
||||
|
||||
EXTERN_C BOOL WINAPI DllMain(HMODULE hInstance, UINT iReason, LPVOID lpReserved) {
|
||||
g_hInstance = hInstance;
|
||||
return TRUE;
|
||||
}
|
4
nsisplugin/main.h
Normal file
4
nsisplugin/main.h
Normal file
@@ -0,0 +1,4 @@
|
||||
#include <windows.h>
|
||||
|
||||
EXTERN_C HMODULE g_hInstance;
|
||||
EXTERN_C HWND g_hwndParent;
|
0
nsisplugin/resource.h
Normal file
0
nsisplugin/resource.h
Normal file
53
nsisplugin/resource.rc
Normal file
53
nsisplugin/resource.rc
Normal file
@@ -0,0 +1,53 @@
|
||||
#include "resource.h"
|
||||
|
||||
#define APSTUDIO_READONLY_SYMBOLS
|
||||
#include <windows.h>
|
||||
#undef APSTUDIO_READONLY_SYMBOLS
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// English (United States) resources
|
||||
|
||||
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
|
||||
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
|
||||
#pragma code_page(65001)
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Version
|
||||
//
|
||||
|
||||
VS_VERSION_INFO VERSIONINFO
|
||||
FILEVERSION 1,9,0,0
|
||||
PRODUCTVERSION 1,9,0,0
|
||||
FILEFLAGSMASK 0x3fL
|
||||
#ifdef _DEBUG
|
||||
FILEFLAGS 0x1L
|
||||
#else
|
||||
FILEFLAGS 0x0L
|
||||
#endif
|
||||
FILEOS 0x40004L
|
||||
FILETYPE 0x2L
|
||||
FILESUBTYPE 0x0L
|
||||
BEGIN
|
||||
BLOCK "StringFileInfo"
|
||||
BEGIN
|
||||
BLOCK "040904b0"
|
||||
BEGIN
|
||||
VALUE "CompanyName", "Hashbang Productions"
|
||||
VALUE "FileDescription", "Legacy Update Setup Helper"
|
||||
VALUE "FileVersion", "1.9.0.0"
|
||||
VALUE "InternalName", "LegacyUpdateNSIS.dll"
|
||||
VALUE "LegalCopyright", "© Hashbang Productions. All rights reserved."
|
||||
VALUE "OriginalFilename", "LegacyUpdateNSIS.dll"
|
||||
VALUE "ProductName", "Legacy Update"
|
||||
VALUE "ProductVersion", "1.9.0.0"
|
||||
END
|
||||
END
|
||||
BLOCK "VarFileInfo"
|
||||
BEGIN
|
||||
VALUE "Translation", 0x409, 1200
|
||||
END
|
||||
END
|
||||
|
||||
#endif // English (United States) resources
|
||||
/////////////////////////////////////////////////////////////////////////////
|
16
nsisplugin/stdafx.h
Normal file
16
nsisplugin/stdafx.h
Normal file
@@ -0,0 +1,16 @@
|
||||
#pragma once
|
||||
|
||||
#ifndef STRICT
|
||||
#define STRICT
|
||||
#endif
|
||||
|
||||
#define WINVER 0x0500
|
||||
#define _WIN32_WINNT 0x0500
|
||||
|
||||
#define ISOLATION_AWARE_ENABLED 1 // Enable comctl 6.0 (visual styles)
|
||||
|
||||
#include "resource.h"
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
EXTERN_C HWND g_hwndParent;
|
Reference in New Issue
Block a user