mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-16 11:48:06 +01:00
replace cziplib with tar.exe?
This commit is contained in:
3
.gitmodules
vendored
3
.gitmodules
vendored
@@ -4,6 +4,3 @@
|
|||||||
[submodule "deps/expected-lite"]
|
[submodule "deps/expected-lite"]
|
||||||
path = deps/expected-lite
|
path = deps/expected-lite
|
||||||
url = https://github.com/martinmoene/expected-lite.git
|
url = https://github.com/martinmoene/expected-lite.git
|
||||||
[submodule "deps/cziplib"]
|
|
||||||
path = deps/cziplib
|
|
||||||
url = https://github.com/kuba--/zip.git
|
|
||||||
|
|||||||
1
deps/cziplib
vendored
1
deps/cziplib
vendored
Submodule deps/cziplib deleted from 81314fff0a
@@ -37,10 +37,6 @@
|
|||||||
</Link>
|
</Link>
|
||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="..\..\..\deps\cziplib\src\zip.c">
|
|
||||||
<!-- Disabling warnings for external code -->
|
|
||||||
<DisableSpecificWarnings>4706;26451;4267;4244;%(DisableSpecificWarnings)</DisableSpecificWarnings>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="EventViewer.cpp" />
|
<ClCompile Include="EventViewer.cpp" />
|
||||||
<ClCompile Include="InstallationFolder.cpp" />
|
<ClCompile Include="InstallationFolder.cpp" />
|
||||||
<ClCompile Include="Package.cpp" />
|
<ClCompile Include="Package.cpp" />
|
||||||
@@ -61,8 +57,6 @@
|
|||||||
</ProjectReference>
|
</ProjectReference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="..\..\..\deps\cziplib\src\miniz.h" />
|
|
||||||
<ClInclude Include="..\..\..\deps\cziplib\src\zip.h" />
|
|
||||||
<ClInclude Include="EventViewer.h" />
|
<ClInclude Include="EventViewer.h" />
|
||||||
<ClInclude Include="InstallationFolder.h" />
|
<ClInclude Include="InstallationFolder.h" />
|
||||||
<ClInclude Include="Package.h" />
|
<ClInclude Include="Package.h" />
|
||||||
|
|||||||
@@ -8,7 +8,6 @@
|
|||||||
<ClCompile Include="ZipTools\ZipFolder.cpp">
|
<ClCompile Include="ZipTools\ZipFolder.cpp">
|
||||||
<Filter>ZipTools</Filter>
|
<Filter>ZipTools</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<ClCompile Include="..\..\..\deps\cziplib\src\zip.c" />
|
|
||||||
<ClCompile Include="ReportMonitorInfo.cpp" />
|
<ClCompile Include="ReportMonitorInfo.cpp" />
|
||||||
<ClCompile Include="RegistryUtils.cpp" />
|
<ClCompile Include="RegistryUtils.cpp" />
|
||||||
<ClCompile Include="EventViewer.cpp" />
|
<ClCompile Include="EventViewer.cpp" />
|
||||||
@@ -28,8 +27,6 @@
|
|||||||
<Filter>ZipTools</Filter>
|
<Filter>ZipTools</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="..\..\..\common\utils\json.h" />
|
<ClInclude Include="..\..\..\common\utils\json.h" />
|
||||||
<ClInclude Include="..\..\..\deps\cziplib\src\miniz.h" />
|
|
||||||
<ClInclude Include="..\..\..\deps\cziplib\src\zip.h" />
|
|
||||||
<ClInclude Include="ReportMonitorInfo.h" />
|
<ClInclude Include="ReportMonitorInfo.h" />
|
||||||
<ClInclude Include="RegistryUtils.h" />
|
<ClInclude Include="RegistryUtils.h" />
|
||||||
<ClInclude Include="EventViewer.h" />
|
<ClInclude Include="EventViewer.h" />
|
||||||
|
|||||||
@@ -1,50 +1,50 @@
|
|||||||
#include "ZipFolder.h"
|
#include "ZipFolder.h"
|
||||||
#include "..\..\..\..\deps\cziplib\src\zip.h"
|
|
||||||
#include <common/utils/timeutil.h>
|
#include <common/utils/timeutil.h>
|
||||||
|
|
||||||
|
#define WIN32_LEAN_AND_MEAN
|
||||||
|
#include <Windows.h>
|
||||||
|
|
||||||
void ZipFolder(std::filesystem::path zipPath, std::filesystem::path folderPath)
|
void ZipFolder(std::filesystem::path zipPath, std::filesystem::path folderPath)
|
||||||
{
|
{
|
||||||
std::string reportFilename{ "PowerToysReport_" };
|
std::string reportFilename{ "PowerToysReport_" };
|
||||||
reportFilename += timeutil::format_as_local("%F-%H-%M-%S", timeutil::now());
|
reportFilename += timeutil::format_as_local("%F-%H-%M-%S", timeutil::now());
|
||||||
reportFilename += ".zip";
|
reportFilename += ".zip";
|
||||||
|
auto finalReportFullPath{ zipPath / reportFilename };
|
||||||
|
|
||||||
auto tmpZipPath = std::filesystem::temp_directory_path();
|
std::string tempReportFilename{ reportFilename + ".tmp" };
|
||||||
tmpZipPath /= reportFilename;
|
auto tempReportFullPath{ zipPath / tempReportFilename };
|
||||||
|
|
||||||
struct zip_t* zip = zip_open(tmpZipPath.string().c_str(), ZIP_DEFAULT_COMPRESSION_LEVEL, 'w');
|
// tar -c --format=zip -f "reportzipfile" *
|
||||||
if (!zip)
|
const std::string executable{ R"(c:\windows\system32\tar.exe)" };
|
||||||
|
std::string commandline{ executable + R"( -c --format=zip -f ")" };
|
||||||
|
commandline += tempReportFullPath.string();
|
||||||
|
commandline += R"(" *)";
|
||||||
|
|
||||||
|
const auto folderPathAsString{ folderPath.lexically_normal().string() };
|
||||||
|
|
||||||
|
PROCESS_INFORMATION pi{};
|
||||||
|
STARTUPINFOA si{ .cb = sizeof(STARTUPINFOA) };
|
||||||
|
if (!CreateProcessA(executable.c_str(),
|
||||||
|
commandline.data() /* must be mutable */,
|
||||||
|
nullptr,
|
||||||
|
nullptr,
|
||||||
|
FALSE,
|
||||||
|
DETACHED_PROCESS,
|
||||||
|
nullptr,
|
||||||
|
folderPathAsString.c_str(),
|
||||||
|
&si,
|
||||||
|
&pi))
|
||||||
{
|
{
|
||||||
printf("Cannot open zip.");
|
printf("Cannot open zip.");
|
||||||
throw -1;
|
throw -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
using recursive_directory_iterator = std::filesystem::recursive_directory_iterator;
|
WaitForSingleObject(pi.hProcess, INFINITE);
|
||||||
const size_t rootSize = folderPath.wstring().size();
|
|
||||||
for (const auto& dirEntry : recursive_directory_iterator(folderPath))
|
|
||||||
{
|
|
||||||
if (dirEntry.is_regular_file())
|
|
||||||
{
|
|
||||||
auto path = dirEntry.path().string();
|
|
||||||
auto relativePath = path.substr(rootSize, path.size());
|
|
||||||
zip_entry_open(zip, relativePath.c_str());
|
|
||||||
zip_entry_fwrite(zip, path.c_str());
|
|
||||||
zip_entry_close(zip);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
zip_close(zip);
|
std::error_code err{};
|
||||||
|
std::filesystem::rename(tempReportFullPath, finalReportFullPath, err);
|
||||||
std::error_code err;
|
|
||||||
std::filesystem::copy(tmpZipPath, zipPath, err);
|
|
||||||
if (err.value() != 0)
|
if (err.value() != 0)
|
||||||
{
|
{
|
||||||
wprintf_s(L"Failed to copy %s. Error code: %d\n", tmpZipPath.c_str(), err.value());
|
wprintf_s(L"Failed to rename %s. Error code: %d\n", tempReportFullPath.native().c_str(), err.value());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
err = {};
|
|
||||||
std::filesystem::remove_all(tmpZipPath, err);
|
|
||||||
if (err.value() != 0)
|
|
||||||
{
|
|
||||||
wprintf_s(L"Failed to delete %s. Error code: %d\n", tmpZipPath.c_str(), err.value());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user