From af61bd4134bfd0b483f1bb8ce8a00e73253fc1ae Mon Sep 17 00:00:00 2001 From: henrypp Date: Thu, 21 Jul 2022 11:34:39 +0600 Subject: [PATCH] add uwp.cpp --- src/uwp.cpp | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++ src/uwp.h | 19 +++++++++++++++++ 2 files changed, 79 insertions(+) create mode 100644 src/uwp.cpp create mode 100644 src/uwp.h diff --git a/src/uwp.cpp b/src/uwp.cpp new file mode 100644 index 00000000..79d25de1 --- /dev/null +++ b/src/uwp.cpp @@ -0,0 +1,60 @@ +// simplewall +// Copyright (c) 2022 Henry++ + +#include "routine.h" + +#include +#include +#include +#include +#include +#include + +#include "uwp.h" + +BOOLEAN _app_package_getpackage_info ( + _In_ PR_STRING package_name, + _Out_ PR_STRING_PTR name_ptr, + _Out_ PR_STRING_PTR path_ptr +) +{ + winrt::Windows::ApplicationModel::Package package = NULL; + winrt::hstring display_name; + winrt::hstring path; + + *name_ptr = NULL; + *path_ptr = NULL; + + package = winrt::Windows::Management::Deployment::PackageManager{}.FindPackage (package_name->buffer); + + if (!package) + return FALSE; + + display_name = package.DisplayName (); + path = package.InstalledLocation ().Path (); + + if (display_name.empty ()) + display_name = package.Id ().Name (); + + if (display_name.empty ()) + { + *name_ptr = _r_obj_createstring2 (package_name); + } + else + { + *name_ptr = _r_obj_createstring_ex ( + display_name.c_str (), + display_name.size () * sizeof (WCHAR) + ); + } + + if (!path.empty ()) + { + *path_ptr = _r_obj_createstring_ex ( + path.c_str (), + path.size () * sizeof (WCHAR) + ); + } + + return TRUE; +} diff --git a/src/uwp.h b/src/uwp.h new file mode 100644 index 00000000..6893981c --- /dev/null +++ b/src/uwp.h @@ -0,0 +1,19 @@ +// simplewall +// Copyright (c) 2022 Henry++ + +#pragma once + +#ifdef __cplusplus +extern "C" +{ +#endif + +BOOLEAN _app_package_getpackage_info ( + _In_ PR_STRING package_name, + _Out_ PR_STRING_PTR name_ptr, + _Out_ PR_STRING_PTR path_ptr +); + +#ifdef __cplusplus +} +#endif