Skip to content

Commit

Permalink
BugReportTool polishing (#8733)
Browse files Browse the repository at this point in the history
* Removed unused project folder

* Update error messages

* Rename 'del' -> 'deleteFolder'

* Rename variable
  • Loading branch information
enricogior committed Dec 24, 2020
1 parent 0ffa919 commit 9ab3cb4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@
<Filter Include="ZipTools">
<UniqueIdentifier>{3ae1b6aa-4134-47b1-afdf-dfb3b5901dcc}</UniqueIdentifier>
</Filter>
<Filter Include="MonitorReportTool">
<UniqueIdentifier>{83b7e7d9-49b7-4fc8-9853-9dbb8f2c0e76}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="ZipTools\zipfolder.h">
Expand Down
36 changes: 19 additions & 17 deletions tools/BugReportTool/BugReportTool/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ void hideForFile(const path& dir, const wstring& relativePath)
auto jObject = json::from_file(jsonPath.wstring());
if (!jObject.has_value())
{
wprintf(L"Can not parse file %s\n", jsonPath.c_str());
wprintf(L"Failed to parse file %s\n", jsonPath.c_str());
return;
}

Expand All @@ -117,13 +117,13 @@ void hideForFile(const path& dir, const wstring& relativePath)
json::to_file(jsonPath.wstring(), jObject.value());
}

bool del(wstring path)
bool deleteFolder(wstring path)
{
error_code err;
remove_all(path, err);
if (err.value() != 0)
{
wprintf_s(L"Can not delete %s. Error code: %d", path.c_str(), err.value());
wprintf_s(L"Failed to delete %s. Error code: %d\n", path.c_str(), err.value());
return false;
}

Expand All @@ -143,7 +143,7 @@ void hideUserPrivateInfo(const filesystem::path& dir)
{
auto path = dir;
path = path.append(it);
del(path);
deleteFolder(path);
}
}

Expand All @@ -160,11 +160,11 @@ void reportMonitorInfo(const filesystem::path& tmpDir)
}
catch (std::exception& ex)
{
printf("Can not report monitor info. %s\n", ex.what());
printf("Failed to report monitor info. %s\n", ex.what());
}
catch (...)
{
printf("Can not report monitor info\n");
printf("Failed to report monitor info\n");
}
}

Expand All @@ -187,7 +187,7 @@ void reportWindowsVersion(const filesystem::path& tmpDir)
}
catch (...)
{
printf("Cannot get windows version info\n");
printf("Failed to get windows version info\n");
return;
}

Expand All @@ -200,7 +200,7 @@ void reportWindowsVersion(const filesystem::path& tmpDir)
}
catch(...)
{
printf("Can not write to %s", versionReportPath.string().c_str());
printf("Failed to write to %s\n", versionReportPath.string().c_str());
}
}

Expand All @@ -221,30 +221,32 @@ int wmain(int argc, wchar_t* argv[], wchar_t*)
}
else
{
printf("Can not retrieve a desktop path. Error code: %d", GetLastError());
printf("Failed to retrieve the desktop path. Error code: %d\n", GetLastError());
return 1;
}
}

auto powerToys = PTSettingsHelper::get_root_save_folder_location();
auto settingsRootPath = PTSettingsHelper::get_root_save_folder_location();
settingsRootPath = settingsRootPath + L"\\";

// Copy to a temp folder
auto tmpDir = temp_directory_path();
tmpDir = tmpDir.append("PowerToys\\");
powerToys = powerToys + L"\\";
if (!del(tmpDir))
if (!deleteFolder(tmpDir))
{
printf("Failed to delete temp folder\n");
return 1;
}

try
{
copy(powerToys, tmpDir, copy_options::recursive);
copy(settingsRootPath, tmpDir, copy_options::recursive);
// Remove updates folder contents
del(tmpDir / "Updates");
deleteFolder(tmpDir / "Updates");
}
catch (...)
{
printf("Copy PowerToys directory failed");
printf("Failed to copy PowerToys folder\n");
return 1;
}

Expand All @@ -270,10 +272,10 @@ int wmain(int argc, wchar_t* argv[], wchar_t*)
}
catch (...)
{
printf("Zip folder failed");
printf("Failed to zip folder\n");
return 1;
}

del(tmpDir);
deleteFolder(tmpDir);
return 0;
}

0 comments on commit 9ab3cb4

Please sign in to comment.