mirror of
https://github.com/loot/libloot.git
synced 2026-07-27 14:16:01 -07:00
Replace windows_error code
Throw system_error instead, using GetLastError() to get the error code
This commit is contained in:
@@ -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,
|
||||
};
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user