From 1bd1376cea273a5437f8a9cc1fc5f223245fe9b3 Mon Sep 17 00:00:00 2001 From: mjk Date: Fri, 5 Mar 2021 21:29:43 +0000 Subject: [PATCH] stop exceptions from crossing ABI boundary in a few places --- .../api/src/shortcutcreator.cpp | 26 +++++++++---------- .../windows-notification/api/src/win32.cpp | 17 ++++++------ 2 files changed, 22 insertions(+), 21 deletions(-) diff --git a/plugins/windows-notification/api/src/shortcutcreator.cpp b/plugins/windows-notification/api/src/shortcutcreator.cpp index 8084d218..f6a91e78 100644 --- a/plugins/windows-notification/api/src/shortcutcreator.cpp +++ b/plugins/windows-notification/api/src/shortcutcreator.cpp @@ -4,6 +4,7 @@ #include "shortcutcreator.h" #include "win32.hpp" #include "converter.hpp" +#include "ginvoke.hpp" #ifdef UNICODE #define _UNICODE @@ -124,8 +125,14 @@ int32_t ValidateShortcut(const std::wstring& shortcut_path, const std::wstring& return hr; } -int32_t TryCreateShortcutInternal(const std::wstring& aumid) +bool TryCreateShortcutInternal(const char *const aumid) { + auto waumid = sview_to_wstr(aumid); + if (waumid.empty()) + { + return false; + } + auto exePath = GetCurrentModulePath(); auto shortcutPath = GetShortcutPath(); @@ -134,27 +141,20 @@ int32_t TryCreateShortcutInternal(const std::wstring& aumid) auto path = shortcutPath.value() + LR"(\Microsoft\Windows\Start Menu\Programs\Dino.lnk)"; if (!std::filesystem::exists(path)) { - return InstallShortcut(exePath.value(), aumid, path); + return SUCCEEDED(InstallShortcut(exePath.value(), waumid, path)); } else { - return ValidateShortcut(path, aumid); + return SUCCEEDED(ValidateShortcut(path, waumid)); } - - return S_OK; } - return S_FALSE; + return false; } extern "C" { gboolean TryCreateShortcut(const gchar* aumid) { - auto result = sview_to_wstr(aumid); - if (result.empty()) - { - return FALSE; - } - return SUCCEEDED(TryCreateShortcutInternal(result)); + return g_try_invoke(TryCreateShortcutInternal, aumid); } -} \ No newline at end of file +} diff --git a/plugins/windows-notification/api/src/win32.cpp b/plugins/windows-notification/api/src/win32.cpp index 711ba385..baa03d0f 100644 --- a/plugins/windows-notification/api/src/win32.cpp +++ b/plugins/windows-notification/api/src/win32.cpp @@ -3,6 +3,7 @@ #include "win32.hpp" #include "converter.hpp" +#include "ginvoke.hpp" std::optional GetCurrentModulePath() { @@ -28,9 +29,14 @@ std::optional GetShortcutPath() return std::nullopt; } -bool SetAppModelIDInternal(const std::wstring& aumid) +bool SetAppModelIDInternal(const char *const aumid) { - return SUCCEEDED(SetCurrentProcessExplicitAppUserModelID(aumid.c_str())); + auto waumid = sview_to_wstr(aumid); + if (waumid.empty()) + { + return false; + } + return SUCCEEDED(SetCurrentProcessExplicitAppUserModelID(waumid.c_str())); } extern "C" @@ -51,12 +57,7 @@ extern "C" gboolean SetAppModelID(const gchar* aumid) { - auto result = sview_to_wstr(aumid); - if (result.empty()) - { - return FALSE; - } - return SetAppModelIDInternal(result); + return g_try_invoke(SetAppModelIDInternal, aumid); } }