mirror of
https://github.com/velopack/velopack.git
synced 2025-10-25 15:19:22 +00:00
Actually run the extract
This commit is contained in:
@@ -92,10 +92,12 @@
|
||||
<ClInclude Include="stdafx.h" />
|
||||
<ClInclude Include="targetver.h" />
|
||||
<ClInclude Include="unzip.h" />
|
||||
<ClInclude Include="UpdateRunner.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="FxHelper.cpp" />
|
||||
<ClCompile Include="unzip.cpp" />
|
||||
<ClCompile Include="UpdateRunner.cpp" />
|
||||
<ClCompile Include="winmain.cpp" />
|
||||
<ClCompile Include="stdafx.cpp">
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
|
||||
|
||||
@@ -33,6 +33,9 @@
|
||||
<ClInclude Include="unzip.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="UpdateRunner.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="stdafx.cpp">
|
||||
@@ -47,6 +50,9 @@
|
||||
<ClCompile Include="unzip.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="UpdateRunner.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ResourceCompile Include="Setup.rc">
|
||||
|
||||
91
src/Setup/UpdateRunner.cpp
Normal file
91
src/Setup/UpdateRunner.cpp
Normal file
@@ -0,0 +1,91 @@
|
||||
#include "stdafx.h"
|
||||
#include "unzip.h"
|
||||
#include "Resource.h"
|
||||
#include "UpdateRunner.h"
|
||||
|
||||
void CUpdateRunner::DisplayErrorMessage(CString& errorMessage)
|
||||
{
|
||||
CTaskDialog dlg;
|
||||
|
||||
// TODO: Something about contacting support?
|
||||
dlg.SetCommonButtons(TDCBF_OK_BUTTON);
|
||||
dlg.SetMainInstructionText(L"Installation has failed");
|
||||
dlg.SetContentText(errorMessage);
|
||||
dlg.SetMainIcon(TD_ERROR_ICON);
|
||||
|
||||
dlg.DoModal();
|
||||
}
|
||||
|
||||
int CUpdateRunner::ExtractUpdaterAndRun(wchar_t* lpCommandLine)
|
||||
{
|
||||
wchar_t targetDir[MAX_PATH];
|
||||
|
||||
ExpandEnvironmentStrings(L"%LocalAppData%\SquirrelTemp", targetDir, MAX_PATH);
|
||||
if (GetFileAttributes(targetDir) == INVALID_FILE_ATTRIBUTES) {
|
||||
if (!CreateDirectory(targetDir, NULL)) {
|
||||
goto failedExtract;
|
||||
}
|
||||
}
|
||||
|
||||
CResource zipResource;
|
||||
if (!zipResource.Load(L"DATA", IDR_UPDATE_ZIP)) {
|
||||
goto failedExtract;
|
||||
}
|
||||
|
||||
DWORD dwSize = zipResource.GetSize();
|
||||
if (dwSize < 0x100) {
|
||||
goto failedExtract;
|
||||
}
|
||||
|
||||
BYTE* pData = (BYTE*)zipResource.Lock();
|
||||
HZIP zipFile = OpenZip(pData, dwSize, NULL);
|
||||
SetUnzipBaseDir(zipFile, targetDir);
|
||||
|
||||
// NB: This library is kind of a disaster
|
||||
ZRESULT zr;
|
||||
ZIPENTRY zentry;
|
||||
int index = 0;
|
||||
do {
|
||||
zr = GetZipItem(zipFile, index++, &zentry);
|
||||
if (zr != ZR_OK && zr != ZR_MORE) {
|
||||
break;
|
||||
}
|
||||
zr = UnzipItem(zipFile, index, zentry.name);
|
||||
} while (zr == ZR_MORE);
|
||||
|
||||
CloseZip(zipFile);
|
||||
zipResource.Release();
|
||||
|
||||
// nfi if the zip extract actually worked, check for Update.exe
|
||||
wchar_t updateExePath[MAX_PATH];
|
||||
swprintf_s(updateExePath, sizeof(wchar_t)*MAX_PATH, L"%s\\%s", targetDir, L"Update.exe");
|
||||
|
||||
if (GetFileAttributes(updateExePath) == INVALID_FILE_ATTRIBUTES) {
|
||||
goto failedExtract;
|
||||
}
|
||||
|
||||
// Run Update.exe
|
||||
PROCESS_INFORMATION pi = { 0 };
|
||||
STARTUPINFO si = { 0 };
|
||||
si.cb = sizeof(STARTUPINFO);
|
||||
si.wShowWindow = SW_SHOW;
|
||||
si.dwFlags = STARTF_USESHOWWINDOW;
|
||||
|
||||
if (!CreateProcess(updateExePath, lpCommandLine, NULL, NULL, false, 0, NULL, NULL, &si, &pi)) {
|
||||
goto failedExtract;
|
||||
}
|
||||
|
||||
WaitForSingleObject(pi.hProcess, INFINITE);
|
||||
|
||||
DWORD dwExitCode;
|
||||
if (!GetExitCodeProcess(pi.hProcess, &dwExitCode)) {
|
||||
dwExitCode = (DWORD)-1;
|
||||
}
|
||||
|
||||
CloseHandle(pi.hProcess);
|
||||
CloseHandle(pi.hThread);
|
||||
return (int) dwExitCode;
|
||||
|
||||
failedExtract:
|
||||
DisplayErrorMessage(CString(L"Failed to extract installer"));
|
||||
}
|
||||
8
src/Setup/UpdateRunner.h
Normal file
8
src/Setup/UpdateRunner.h
Normal file
@@ -0,0 +1,8 @@
|
||||
#pragma once
|
||||
class CUpdateRunner
|
||||
{
|
||||
private:
|
||||
static void DisplayErrorMessage(CString& errorMessage);
|
||||
public:
|
||||
static int ExtractUpdaterAndRun(wchar_t* lpCommandLine);
|
||||
};
|
||||
@@ -4,6 +4,7 @@
|
||||
#include "stdafx.h"
|
||||
#include "Setup.h"
|
||||
#include "FxHelper.h"
|
||||
#include "UpdateRunner.h"
|
||||
|
||||
CAppModule _Module;
|
||||
|
||||
@@ -12,6 +13,7 @@ int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
|
||||
_In_ LPWSTR lpCmdLine,
|
||||
_In_ int nCmdShow)
|
||||
{
|
||||
int exitCode = -1;
|
||||
HRESULT hr = ::CoInitialize(NULL);
|
||||
ATLASSERT(SUCCEEDED(hr));
|
||||
|
||||
@@ -26,10 +28,10 @@ int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
|
||||
goto out;
|
||||
}
|
||||
|
||||
// TODO: Unpack and run
|
||||
exitCode = CUpdateRunner::ExtractUpdaterAndRun(lpCmdLine);
|
||||
|
||||
out:
|
||||
_Module.Term();
|
||||
::CoUninitialize();
|
||||
return 0;
|
||||
return exitCode;
|
||||
}
|
||||
Reference in New Issue
Block a user