MCPcopy Create free account
hub / github.com/TranslucentTB/TranslucentTB / DynamicDependency

Method DynamicDependency

TranslucentTB/uwp/dynamicdependency.cpp:10–48  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

8#include "../windows/window.hpp"
9
10DynamicDependency::DynamicDependency(HMODULE hModule, Util::null_terminated_wstring_view packageFamilyName, const PACKAGE_VERSION &minVersion, bool hasPackageIdentity) :
11 m_Context(nullptr)
12{
13 if (!hasPackageIdentity)
14 {
15 if (!IsApiSetImplemented("api-ms-win-appmodel-runtime-l1-1-5"))
16 {
17 Localization::ShowLocalizedMessageBox(IDS_PORTABLE_UNSUPPORTED, MB_OK | MB_ICONWARNING | MB_SETFOREGROUND, hModule).join();
18 ExitProcess(1);
19 }
20
21 static constexpr PackageDependencyProcessorArchitectures arch =
22#if defined(_M_AMD64)
23 PackageDependencyProcessorArchitectures_X64;
24#elif defined(_M_ARM64)
25 PackageDependencyProcessorArchitectures_Arm64;
26#endif
27
28 // we are using process dependency lifetime because we want the app to be portable, so we cannot be sure if a dependency ID created by a
29 // previous instance is valid anymore - the app might have been launched on another computer. Plus I'm too lazy to implement proper storage.
30 HRESULT hr = TryCreatePackageDependency(nullptr, packageFamilyName.c_str(), minVersion, arch, PackageDependencyLifetimeKind_Process, nullptr, CreatePackageDependencyOptions_None, m_dependencyId.put());
31 if (FAILED(hr)) [[unlikely]]
32 {
33 if (hr == STATEREPOSITORY_E_DEPENDENCY_NOT_RESOLVED)
34 {
35 Localization::ShowLocalizedMessageBoxWithFormat(IDS_MISSING_DEPENDENCIES, MB_OK | MB_ICONWARNING | MB_SETFOREGROUND, hModule, packageFamilyName, Version::FromPackageVersion(minVersion)).join();
36 ExitProcess(1);
37 }
38 else
39 {
40 HresultHandle(hr, spdlog::level::critical, L"Failed to create a dynamic dependency");
41 }
42 }
43
44 wil::unique_process_heap_string packageFullName;
45 hr = AddPackageDependency(m_dependencyId.get(), 0, AddPackageDependencyOptions_None, &m_Context, packageFullName.put());
46 HresultVerify(hr, spdlog::level::critical, L"Failed to add a runtime dependency");
47 }
48}
49
50DynamicDependency::~DynamicDependency() noexcept(false)
51{

Callers

nothing calls this directly

Calls 4

c_strMethod · 0.80
putMethod · 0.80
getMethod · 0.80

Tested by

no test coverage detected