diff --git a/include/loot/error.h b/include/loot/error.h index ba840de0..5a67c476 100644 --- a/include/loot/error.h +++ b/include/loot/error.h @@ -66,8 +66,6 @@ public: * repository. */ git_error = 12, - /** A miscellaneous error occurred when using an operating system API. */ - windows_error = 13, /** An error occurred while trying to sort the load order. */ sorting_error = 14, }; diff --git a/src/backend/app/loot_paths.cpp b/src/backend/app/loot_paths.cpp index 8e69c26c..a64b1078 100644 --- a/src/backend/app/loot_paths.cpp +++ b/src/backend/app/loot_paths.cpp @@ -82,7 +82,7 @@ boost::filesystem::path LootPaths::getLocalAppDataPath() { PWSTR path; if (SHGetKnownFolderPath(FOLDERID_LocalAppData, 0, NULL, &path) != S_OK) - throw Error(Error::Code::windows_error, boost::locale::translate("Failed to get %LOCALAPPDATA% path.")); + throw std::system_error(GetLastError(), std::system_category(), boost::locale::translate("Failed to get %LOCALAPPDATA% path.")); boost::filesystem::path localAppDataPath(FromWinWide(path)); CoTaskMemFree(path); diff --git a/src/backend/helpers/helpers.cpp b/src/backend/helpers/helpers.cpp index 83462e2a..bd458027 100644 --- a/src/backend/helpers/helpers.cpp +++ b/src/backend/helpers/helpers.cpp @@ -119,10 +119,10 @@ void OpenInDefaultApplication(const boost::filesystem::path& file) { #ifdef _WIN32 HINSTANCE ret = ShellExecute(0, NULL, ToWinWide(file.string()).c_str(), NULL, NULL, SW_SHOWNORMAL); if ((int)ret <= 32) - throw Error(Error::Code::windows_error, translate("Failed to open file in its default application.")); + throw std::system_error(GetLastError(), std::system_category(), translate("Failed to open file in its default application.")); #else if (system(("/usr/bin/xdg-open" + file.string()).c_str()) != 0) - throw Error(Error::Code::windows_error, translate("Failed to open file in its default application.")); + throw std::system_error(errno, std::system_category(), translate("Failed to open file in its default application.")); #endif } diff --git a/src/gui/query/clipboard_query.h b/src/gui/query/clipboard_query.h index 6eb0e076..3650f87b 100644 --- a/src/gui/query/clipboard_query.h +++ b/src/gui/query/clipboard_query.h @@ -35,11 +35,11 @@ protected: void copyToClipboard(const std::string& text) { #ifdef _WIN32 if (!OpenClipboard(NULL)) { - throw Error(Error::Code::windows_error, "Failed to open the Windows clipboard."); + throw std::system_error(GetLastError(), std::system_category(), "Failed to open the Windows clipboard."); } if (!EmptyClipboard()) { - throw Error(Error::Code::windows_error, "Failed to empty the Windows clipboard."); + throw std::system_error(GetLastError(), std::system_category(), "Failed to empty the Windows clipboard."); } // The clipboard takes a Unicode (ie. UTF-16) string that it then owns and must not @@ -50,11 +50,11 @@ protected: wcscpy(wcstr, wtext.c_str()); if (SetClipboardData(CF_UNICODETEXT, wcstr) == NULL) { - throw Error(Error::Code::windows_error, "Failed to copy metadata to the Windows clipboard."); + throw std::system_error(GetLastError(), std::system_category(), "Failed to copy metadata to the Windows clipboard."); } if (!CloseClipboard()) { - throw Error(Error::Code::windows_error, "Failed to close the Windows clipboard."); + throw std::system_error(GetLastError(), std::system_category(), "Failed to close the Windows clipboard."); } #endif }