Skip to content

Commit

Permalink
[Bug Report Tool] Zip folder can not be created (#12966)
Browse files Browse the repository at this point in the history
  • Loading branch information
mykhailopylyp committed Sep 1, 2021
1 parent f7333c8 commit f075099
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 deletions.
2 changes: 1 addition & 1 deletion deps/cziplib
6 changes: 2 additions & 4 deletions tools/BugReportTool/BugReportTool/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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
{
Expand Down
24 changes: 23 additions & 1 deletion tools/BugReportTool/BugReportTool/ZipTools/zipfolder.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
#include "ZipFolder.h"
#include "..\..\..\..\deps\cziplib\src\zip.h"
#include <common/utils/timeutil.h>

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.");
Expand All @@ -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());
}
}

0 comments on commit f075099

Please sign in to comment.