e125ea5f9c
7-Zip 26.01 (ip7z/7zip) never shipped NSIS plugin sources, so they live in a separate bundle directory (versions/26.01-bundle/) that mirrors the layout expected by the shared overlay makefile and by MSBuild. Bundle contents: - CPP/7zip/Bundles/Nsis7z/: NSIS plugin wrapper sources (nsis7z.cpp, pluginapi.cpp, api.h, resource.rc, StdAfx.h, …) and the Windows build project file (Nsis7z_vs2026.vcxproj, adapted from versions/26.00/). The vcxproj references the vendor submodule tree via relative paths (../../../../../26.01/…), keeping the submodule pristine. - CPP/7zip/UI/NSIS/: NSIS UI adapter sources (Main.cpp, MainAr.cpp, NSISBreak.cpp, ExtractCallbackConsole.cpp, UserInputUtils2.cpp and corresponding headers), copied from versions/26.00/. - CPP/7zip/LzmaDec_gcc.mak: forwarding stub; GNU make resolves relative `include` paths against the CWD, so when make runs from Bundles/Nsis7z the upstream Arc_gcc.mak's `include ../../LzmaDec_gcc.mak` lands here. The stub re-includes the real file via $(VENDOR_7ZIP). - Symlinks (C, Asm, CPP/7zip/*, CPP/Common, CPP/Windows, …) pointing into the versions/26.01 submodule. These are required because the vendor makefile uses CWD-relative source paths (../../../../C/…, ../../Common/…). tools/linux/setup_26_01_bundle_symlinks.py recreates them if needed.
192 lines
5.2 KiB
C++
192 lines
5.2 KiB
C++
#include "StdAfx.h"
|
|
|
|
#include "../../UI/NSIS/ExtractCallbackConsole.h"
|
|
#include "Common/StringConvert.h"
|
|
|
|
#pragma warning(disable: 4100)
|
|
|
|
#define IDC_PROGRESS 1004
|
|
#define IDC_INTROTEXT 1006
|
|
|
|
#define EXTRACTFUNC(funcname) extern "C" { \
|
|
void __declspec(dllexport) __cdecl funcname(HWND hwndParent, int string_size, \
|
|
TCHAR *variables, stack_t **stacktop, \
|
|
extra_parameters *extra) \
|
|
{ \
|
|
EXDLL_INIT();\
|
|
g_lastVal = -1; \
|
|
g_hwndParent=hwndParent; \
|
|
HWND hwndDlg = FindWindowEx(g_hwndParent, NULL, TEXT("#32770"), NULL); \
|
|
g_hwndProgress = GetDlgItem(hwndDlg, IDC_PROGRESS); \
|
|
g_hwndText = GetDlgItem(hwndDlg, IDC_INTROTEXT); \
|
|
TCHAR sArchive[1024], *outDir = getuservariable(INST_OUTDIR); \
|
|
popstring(sArchive); \
|
|
g_pluginExtra = extra; \
|
|
|
|
#define EXTRACTFUNCEND } }
|
|
|
|
HINSTANCE g_hInstance2;
|
|
HWND g_hwndParent;
|
|
HWND g_hwndProgress;
|
|
HWND g_hwndText;
|
|
extra_parameters *g_pluginExtra;
|
|
|
|
void DoInitialize();
|
|
int DoExtract(LPTSTR archive, LPTSTR dir, bool overwrite, bool expath, ExtractProgressHandler epc, const UStringVector& skipPatterns);
|
|
int DoExtractWithFile(LPTSTR archive, LPTSTR dir, bool overwrite, bool expath, ExtractProgressWithFileHandler epc, const UStringVector& skipPatterns);
|
|
|
|
int g_progressCallback = -1;
|
|
int g_lastVal = -1;
|
|
TCHAR* g_sDetails;
|
|
|
|
static void PopSkipPatterns(UStringVector& skipPatterns)
|
|
{
|
|
TCHAR *buf = new TCHAR[g_stringsize];
|
|
while (popstring(buf) == 0 && lstrlen(buf) > 0)
|
|
{
|
|
#ifdef UNICODE
|
|
skipPatterns.Add(UString(buf));
|
|
#else
|
|
skipPatterns.Add(MultiByteToUnicodeString(AString(buf)));
|
|
#endif
|
|
}
|
|
delete[] buf;
|
|
}
|
|
|
|
int GetPercentComplete(UInt64 completedSize, UInt64 totalSize)
|
|
{
|
|
if (totalSize == 0) return 0;
|
|
const int nsisProgressMax = 30000;
|
|
int val = (int)((completedSize*nsisProgressMax)/totalSize);
|
|
if (val < 0) return 0;
|
|
if (val > nsisProgressMax) return nsisProgressMax;
|
|
return val;
|
|
}
|
|
|
|
void SimpleProgressHandler(UInt64 completedSize, UInt64 totalSize)
|
|
{
|
|
int val = GetPercentComplete(completedSize, totalSize);
|
|
if (g_lastVal != val)
|
|
SendMessage(g_hwndProgress, PBM_SETPOS, g_lastVal = val, 0);
|
|
}
|
|
|
|
void CallbackProgressHandler(UInt64 completedSize, UInt64 totalSize)
|
|
{
|
|
int val = 0;
|
|
|
|
if (totalSize > 0)
|
|
{
|
|
val = GetPercentComplete(completedSize, totalSize);
|
|
|
|
static TCHAR buf[32];
|
|
wsprintf(buf, TEXT("%lu"), totalSize);
|
|
pushstring(buf);
|
|
wsprintf(buf, TEXT("%lu"), completedSize);
|
|
pushstring(buf);
|
|
g_pluginExtra->ExecuteCodeSegment(g_progressCallback-1, 0);
|
|
}
|
|
|
|
if (g_lastVal != val)
|
|
SendMessage(g_hwndProgress, PBM_SETPOS, g_lastVal = val, 0);
|
|
}
|
|
|
|
void CallbackFileProgressHandler(UInt64 completedSize, UInt64 totalSize, const wchar_t *fileName)
|
|
{
|
|
int val = 0;
|
|
|
|
if (totalSize > 0)
|
|
val = GetPercentComplete(completedSize, totalSize);
|
|
|
|
// Notify NSIS only when a new file starts (filename changes)
|
|
if (fileName && fileName[0])
|
|
{
|
|
static TCHAR fileNameBuf[MAX_PATH];
|
|
static TCHAR prevFileNameBuf[MAX_PATH];
|
|
static TCHAR buf[32];
|
|
|
|
lstrcpyn(fileNameBuf, (const TCHAR*)fileName, MAX_PATH);
|
|
if (lstrcmp(fileNameBuf, prevFileNameBuf) != 0)
|
|
{
|
|
lstrcpy(prevFileNameBuf, fileNameBuf);
|
|
pushstring(fileNameBuf);
|
|
wsprintf(buf, TEXT("%lu"), (DWORD)totalSize);
|
|
pushstring(buf);
|
|
wsprintf(buf, TEXT("%lu"), (DWORD)completedSize);
|
|
pushstring(buf);
|
|
g_pluginExtra->ExecuteCodeSegment(g_progressCallback-1, 0);
|
|
}
|
|
}
|
|
|
|
if (g_lastVal != val)
|
|
SendMessage(g_hwndProgress, PBM_SETPOS, g_lastVal = val, 0);
|
|
}
|
|
|
|
void DetailsProgressHandler(UInt64 completedSize, UInt64 totalSize)
|
|
{
|
|
int val = 0;
|
|
|
|
if (totalSize > 0)
|
|
{
|
|
val = GetPercentComplete(completedSize, totalSize);
|
|
|
|
TCHAR* buf = new TCHAR[g_stringsize];
|
|
TCHAR* buf2 = new TCHAR[g_stringsize];
|
|
wsprintf(buf, TEXT("%d%% (%d / %d MB)"), (int)(val?val/300:0), (int)(completedSize?completedSize/(1024*1024):0), (int)(totalSize/(1024*1024)));
|
|
wsprintf(buf2, g_sDetails, buf);
|
|
SetWindowText(g_hwndText, buf2);
|
|
delete[] buf;
|
|
delete[] buf2;
|
|
}
|
|
|
|
if (g_lastVal != val)
|
|
SendMessage(g_hwndProgress, PBM_SETPOS, g_lastVal = val, 0);
|
|
}
|
|
|
|
EXTRACTFUNC(Extract)
|
|
{
|
|
UStringVector skipPatterns;
|
|
PopSkipPatterns(skipPatterns);
|
|
DoExtract(sArchive, outDir, true, true, (ExtractProgressHandler)SimpleProgressHandler, skipPatterns);
|
|
}
|
|
EXTRACTFUNCEND
|
|
|
|
EXTRACTFUNC(ExtractWithDetails)
|
|
{
|
|
g_sDetails = new TCHAR[string_size];
|
|
popstring(g_sDetails);
|
|
UStringVector skipPatterns;
|
|
PopSkipPatterns(skipPatterns);
|
|
DoExtract(sArchive, outDir, true, true, (ExtractProgressHandler)DetailsProgressHandler, skipPatterns);
|
|
delete[] g_sDetails;
|
|
}
|
|
EXTRACTFUNCEND
|
|
|
|
EXTRACTFUNC(ExtractWithCallback)
|
|
{
|
|
g_progressCallback = popint();
|
|
UStringVector skipPatterns;
|
|
PopSkipPatterns(skipPatterns);
|
|
DoExtract(sArchive, outDir, true, true, (ExtractProgressHandler)CallbackProgressHandler, skipPatterns);
|
|
}
|
|
EXTRACTFUNCEND
|
|
|
|
EXTRACTFUNC(ExtractWithFileCallback)
|
|
{
|
|
g_progressCallback = popint();
|
|
UStringVector skipPatterns;
|
|
PopSkipPatterns(skipPatterns);
|
|
DoExtractWithFile(sArchive, outDir, true, true, CallbackFileProgressHandler, skipPatterns);
|
|
}
|
|
EXTRACTFUNCEND
|
|
|
|
extern "C" BOOL WINAPI DllMain(HANDLE hInst, ULONG ul_reason_for_call, LPVOID lpReserved)
|
|
{
|
|
(void)lpReserved;
|
|
g_hInstance2=(HINSTANCE)hInst;
|
|
if (ul_reason_for_call == DLL_PROCESS_ATTACH)
|
|
{
|
|
DoInitialize();
|
|
}
|
|
return TRUE;
|
|
}
|