Skip to content
This repository has been archived by the owner on Jul 5, 2024. It is now read-only.

Commit

Permalink
Replace 'unzip' with 'miniz' to support long paths (>260char)
Browse files Browse the repository at this point in the history
  • Loading branch information
caesay committed Apr 13, 2022
1 parent aa78576 commit dcdeda9
Show file tree
Hide file tree
Showing 9 changed files with 9,202 additions and 4,430 deletions.
51 changes: 2 additions & 49 deletions src/Setup/Setup.cpp
Original file line number Diff line number Diff line change
@@ -1,55 +1,13 @@
#include <windows.h>
#include <versionhelpers.h>
#include <string>
#include <functional>
#include <fstream>
#include "unzip.h"
#include "bundle_marker.h"
#include "platform_util.h"

using namespace std;
namespace fs = std::filesystem;

// https://stackoverflow.com/a/874160/184746
bool hasEnding(std::wstring const& fullString, std::wstring const& ending)
{
if (fullString.length() >= ending.length()) {
return (0 == fullString.compare(fullString.length() - ending.length(), ending.length(), ending));
}
return false;
}

void unzipSingleFile(BYTE* zipBuf, DWORD cZipBuf, wstring fileLocation, std::function<bool(ZIPENTRY&)>& predicate)
{
HZIP zipFile = OpenZip(zipBuf, cZipBuf, NULL);

bool unzipSuccess = false;

ZRESULT zr;
int index = 0;
do {
ZIPENTRY zentry;
zr = GetZipItem(zipFile, index, &zentry);
if (zr != ZR_OK && zr != ZR_MORE) {
break;
}

if (predicate(zentry)) {
auto zaunz = UnzipItem(zipFile, index, fileLocation.c_str());
if (zaunz == ZR_OK) {
unzipSuccess = true;
}
break;
}

index++;
} while (zr == ZR_MORE || zr == ZR_OK);

CloseZip(zipFile);

if (!unzipSuccess) throw wstring(L"Unable to extract embedded package (Squirrel.exe not found).");
}

// Prints to the provided buffer a nice number of bytes (KB, MB, GB, etc)
wstring pretty_bytes(uint64_t bytes)
{
Expand Down Expand Up @@ -111,13 +69,8 @@ int WINAPI wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance,
throw wstring(L"Insufficient disk space. This application requires at least " + pretty_bytes(requiredSpace) + L" free space to be installed.");
}

// extract Squirrel installer from package
std::function<bool(ZIPENTRY&)> endsWithSquirrel([](ZIPENTRY& z) {
return hasEnding(std::wstring(z.name), L"Squirrel.exe");
});
unzipSingleFile(pkgStart, packageLength, updaterPath, endsWithSquirrel);

// extract whole package
// extract Update.exe and embedded nuget package
util::extractUpdateExe(pkgStart, packageLength, updaterPath);
std::ofstream(packagePath, std::ios::binary).write((char*)pkgStart, packageLength);

// run installer and forward our command line arguments
Expand Down
4 changes: 2 additions & 2 deletions src/Setup/Setup.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,14 @@
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="bundle_marker.cpp" />
<ClCompile Include="miniz.c" />
<ClCompile Include="platform_util.cpp" />
<ClCompile Include="Setup.cpp" />
<ClCompile Include="unzip.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="bundle_marker.h" />
<ClInclude Include="miniz.h" />
<ClInclude Include="platform_util.h" />
<ClInclude Include="unzip.h" />
</ItemGroup>
<ItemGroup>
<Text Include="compatibility.manifest" />
Expand Down
12 changes: 6 additions & 6 deletions src/Setup/Setup.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,26 @@
<ClCompile Include="Setup.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="unzip.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="bundle_marker.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="platform_util.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="miniz.c">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="unzip.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="bundle_marker.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="platform_util.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="miniz.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<Text Include="compatibility.manifest">
Expand Down
Loading

0 comments on commit dcdeda9

Please sign in to comment.