BugReportTool polishing (#8733)

* Removed unused project folder

* Update error messages

* Rename 'del' -> 'deleteFolder'

* Rename variable
This commit is contained in:
Enrico Giordani
2020-12-24 12:27:49 +01:00
committed by GitHub
parent 0ffa9198f5
commit 9ab3cb4e9f
2 changed files with 19 additions and 20 deletions

View File

@@ -15,9 +15,6 @@
<Filter Include="ZipTools"> <Filter Include="ZipTools">
<UniqueIdentifier>{3ae1b6aa-4134-47b1-afdf-dfb3b5901dcc}</UniqueIdentifier> <UniqueIdentifier>{3ae1b6aa-4134-47b1-afdf-dfb3b5901dcc}</UniqueIdentifier>
</Filter> </Filter>
<Filter Include="MonitorReportTool">
<UniqueIdentifier>{83b7e7d9-49b7-4fc8-9853-9dbb8f2c0e76}</UniqueIdentifier>
</Filter>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="ZipTools\zipfolder.h"> <ClInclude Include="ZipTools\zipfolder.h">

View File

@@ -103,7 +103,7 @@ void hideForFile(const path& dir, const wstring& relativePath)
auto jObject = json::from_file(jsonPath.wstring()); auto jObject = json::from_file(jsonPath.wstring());
if (!jObject.has_value()) 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; return;
} }
@@ -117,13 +117,13 @@ void hideForFile(const path& dir, const wstring& relativePath)
json::to_file(jsonPath.wstring(), jObject.value()); json::to_file(jsonPath.wstring(), jObject.value());
} }
bool del(wstring path) bool deleteFolder(wstring path)
{ {
error_code err; error_code err;
remove_all(path, err); remove_all(path, err);
if (err.value() != 0) 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; return false;
} }
@@ -143,7 +143,7 @@ void hideUserPrivateInfo(const filesystem::path& dir)
{ {
auto path = dir; auto path = dir;
path = path.append(it); path = path.append(it);
del(path); deleteFolder(path);
} }
} }
@@ -160,11 +160,11 @@ void reportMonitorInfo(const filesystem::path& tmpDir)
} }
catch (std::exception& ex) 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 (...) catch (...)
{ {
printf("Can not report monitor info\n"); printf("Failed to report monitor info\n");
} }
} }
@@ -187,7 +187,7 @@ void reportWindowsVersion(const filesystem::path& tmpDir)
} }
catch (...) catch (...)
{ {
printf("Cannot get windows version info\n"); printf("Failed to get windows version info\n");
return; return;
} }
@@ -200,7 +200,7 @@ void reportWindowsVersion(const filesystem::path& tmpDir)
} }
catch(...) catch(...)
{ {
printf("Can not write to %s", versionReportPath.string().c_str()); printf("Failed to write to %s\n", versionReportPath.string().c_str());
} }
} }
@@ -221,30 +221,32 @@ int wmain(int argc, wchar_t* argv[], wchar_t*)
} }
else 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 // Copy to a temp folder
auto tmpDir = temp_directory_path(); auto tmpDir = temp_directory_path();
tmpDir = tmpDir.append("PowerToys\\"); tmpDir = tmpDir.append("PowerToys\\");
powerToys = powerToys + L"\\"; if (!deleteFolder(tmpDir))
if (!del(tmpDir))
{ {
printf("Failed to delete temp folder\n");
return 1; return 1;
} }
try try
{ {
copy(powerToys, tmpDir, copy_options::recursive); copy(settingsRootPath, tmpDir, copy_options::recursive);
// Remove updates folder contents // Remove updates folder contents
del(tmpDir / "Updates"); deleteFolder(tmpDir / "Updates");
} }
catch (...) catch (...)
{ {
printf("Copy PowerToys directory failed"); printf("Failed to copy PowerToys folder\n");
return 1; return 1;
} }
@@ -270,10 +272,10 @@ int wmain(int argc, wchar_t* argv[], wchar_t*)
} }
catch (...) catch (...)
{ {
printf("Zip folder failed"); printf("Failed to zip folder\n");
return 1; return 1;
} }
del(tmpDir); deleteFolder(tmpDir);
return 0; return 0;
} }