From f0750997de08f21105e0f7aebf2c7ab4615419e7 Mon Sep 17 00:00:00 2001 From: Mykhailo Pylyp Date: Wed, 1 Sep 2021 18:12:28 +0300 Subject: [PATCH] [Bug Report Tool] Zip folder can not be created (#12966) --- deps/cziplib | 2 +- tools/BugReportTool/BugReportTool/Main.cpp | 6 ++--- .../BugReportTool/ZipTools/zipfolder.cpp | 24 ++++++++++++++++++- 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/deps/cziplib b/deps/cziplib index f9e0959eb2..692cbcf8ca 160000 --- a/deps/cziplib +++ b/deps/cziplib @@ -1 +1 @@ -Subproject commit f9e0959eb212262aff67e8425aceb62d7a518f62 +Subproject commit 692cbcf8ca3cd90c43d7159da098e0763ecdab38 diff --git a/tools/BugReportTool/BugReportTool/Main.cpp b/tools/BugReportTool/BugReportTool/Main.cpp index 011f8e6029..46c88e92dd 100644 --- a/tools/BugReportTool/BugReportTool/Main.cpp +++ b/tools/BugReportTool/BugReportTool/Main.cpp @@ -299,7 +299,9 @@ int wmain(int argc, wchar_t* argv[], wchar_t*) return 1; } +#ifndef _DEBUG InstallationFolder::ReportStructure(reportDir); +#endif // Hide sensitive information HideUserPrivateInfo(reportDir); @@ -329,10 +331,6 @@ int wmain(int argc, wchar_t* argv[], wchar_t*) // Zip folder auto zipPath = path::path(saveZipPath); - std::string reportFilename{"PowerToysReport_"}; - reportFilename += timeutil::format_as_local("%F-%H-%M-%S", timeutil::now()); - reportFilename += ".zip"; - zipPath /= reportFilename; try { diff --git a/tools/BugReportTool/BugReportTool/ZipTools/zipfolder.cpp b/tools/BugReportTool/BugReportTool/ZipTools/zipfolder.cpp index 4d5c781c27..42e5fe2b0d 100644 --- a/tools/BugReportTool/BugReportTool/ZipTools/zipfolder.cpp +++ b/tools/BugReportTool/BugReportTool/ZipTools/zipfolder.cpp @@ -1,9 +1,17 @@ #include "ZipFolder.h" #include "..\..\..\..\deps\cziplib\src\zip.h" +#include void ZipFolder(std::filesystem::path zipPath, std::filesystem::path folderPath) { - struct zip_t* zip = zip_open(zipPath.string().c_str(), ZIP_DEFAULT_COMPRESSION_LEVEL, 'w'); + std::string reportFilename{ "PowerToysReport_" }; + reportFilename += timeutil::format_as_local("%F-%H-%M-%S", timeutil::now()); + reportFilename += ".zip"; + + auto tmpZipPath = std::filesystem::temp_directory_path(); + tmpZipPath /= reportFilename; + + struct zip_t* zip = zip_open(tmpZipPath.string().c_str(), ZIP_DEFAULT_COMPRESSION_LEVEL, 'w'); if (!zip) { printf("Can not open zip."); @@ -25,4 +33,18 @@ void ZipFolder(std::filesystem::path zipPath, std::filesystem::path folderPath) } zip_close(zip); + + std::error_code err; + std::filesystem::copy(tmpZipPath, zipPath, err); + if (err.value() != 0) + { + wprintf_s(L"Failed to copy %s. Error code: %d\n", tmpZipPath.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()); + } } \ No newline at end of file