stop exceptions from crossing ABI boundary in a few places

This commit is contained in:
mjk 2021-03-05 21:29:43 +00:00 committed by LAGonauta
parent f1b5633ce6
commit 1bd1376cea
2 changed files with 22 additions and 21 deletions

View file

@ -4,6 +4,7 @@
#include "shortcutcreator.h" #include "shortcutcreator.h"
#include "win32.hpp" #include "win32.hpp"
#include "converter.hpp" #include "converter.hpp"
#include "ginvoke.hpp"
#ifdef UNICODE #ifdef UNICODE
#define _UNICODE #define _UNICODE
@ -124,8 +125,14 @@ int32_t ValidateShortcut(const std::wstring& shortcut_path, const std::wstring&
return hr; 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 exePath = GetCurrentModulePath();
auto shortcutPath = GetShortcutPath(); 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)"; auto path = shortcutPath.value() + LR"(\Microsoft\Windows\Start Menu\Programs\Dino.lnk)";
if (!std::filesystem::exists(path)) if (!std::filesystem::exists(path))
{ {
return InstallShortcut(exePath.value(), aumid, path); return SUCCEEDED(InstallShortcut(exePath.value(), waumid, path));
} }
else else
{ {
return ValidateShortcut(path, aumid); return SUCCEEDED(ValidateShortcut(path, waumid));
} }
return S_OK;
} }
return S_FALSE; return false;
} }
extern "C" extern "C"
{ {
gboolean TryCreateShortcut(const gchar* aumid) gboolean TryCreateShortcut(const gchar* aumid)
{ {
auto result = sview_to_wstr(aumid); return g_try_invoke(TryCreateShortcutInternal, aumid);
if (result.empty())
{
return FALSE;
}
return SUCCEEDED(TryCreateShortcutInternal(result));
} }
} }

View file

@ -3,6 +3,7 @@
#include "win32.hpp" #include "win32.hpp"
#include "converter.hpp" #include "converter.hpp"
#include "ginvoke.hpp"
std::optional<std::wstring> GetCurrentModulePath() std::optional<std::wstring> GetCurrentModulePath()
{ {
@ -28,9 +29,14 @@ std::optional<std::wstring> GetShortcutPath()
return std::nullopt; 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" extern "C"
@ -51,12 +57,7 @@ extern "C"
gboolean SetAppModelID(const gchar* aumid) gboolean SetAppModelID(const gchar* aumid)
{ {
auto result = sview_to_wstr(aumid); return g_try_invoke(SetAppModelIDInternal, aumid);
if (result.empty())
{
return FALSE;
}
return SetAppModelIDInternal(result);
} }
} }