|
13 | 13 |
|
14 | 14 | #include <wil/resource.h> |
15 | 15 | #include <string> |
16 | | -#include "AppModel.Identity.IsPackagedProcess.h" |
17 | | -#include "WindowsAppRuntime.SelfContained.h" |
| 16 | +#include <appmodel.h> |
18 | 17 | namespace Microsoft::WindowsAppRuntime::Insights |
19 | 18 | { |
20 | 19 | enum class TraceLoggingInformationFlags : std::uint32_t |
|
43 | 42 | return channel; |
44 | 43 | } |
45 | 44 |
|
| 45 | + // Inlined from the canonical implementations (see for reference): |
| 46 | + // IsPackagedProcess: dev/Common/AppModel.Identity.IsPackagedProcess.h |
| 47 | + // IsSelfContained: dev/Common/WindowsAppRuntime.SelfContained.h / .cpp |
| 48 | + // Duplicated here to avoid exposing those headers as public API. |
46 | 49 | static std::uint32_t TraceLoggingInformationFlags() |
47 | 50 | { |
48 | 51 | static std::uint32_t flags{ []() -> std::uint32_t { |
|
53 | 56 | f |= Insights::TraceLoggingInformationFlags::IsDebuggerPresent; |
54 | 57 | } |
55 | 58 |
|
56 | | - bool isPackagedProcess{}; |
57 | | - if (SUCCEEDED_LOG(::AppModel::Identity::IsPackagedProcess_nothrow(isPackagedProcess)) && isPackagedProcess) |
58 | 59 | { |
59 | | - f |= Insights::TraceLoggingInformationFlags::IsPackagedProcess; |
| 60 | + UINT32 n{}; |
| 61 | + const auto rc{ ::GetCurrentPackageFullName(&n, nullptr) }; |
| 62 | + if ((rc != APPMODEL_ERROR_NO_PACKAGE) && (rc != ERROR_INSUFFICIENT_BUFFER)) |
| 63 | + { |
| 64 | + LOG_HR(HRESULT_FROM_WIN32(rc)); |
| 65 | + } |
| 66 | + else if (rc == ERROR_INSUFFICIENT_BUFFER) |
| 67 | + { |
| 68 | + f |= Insights::TraceLoggingInformationFlags::IsPackagedProcess; |
| 69 | + } |
60 | 70 | } |
61 | 71 |
|
62 | | - bool isSelfContained{}; |
63 | | - if (SUCCEEDED_LOG(::WindowsAppRuntime::SelfContained::IsSelfContained_nothrow(isSelfContained)) && isSelfContained) |
64 | 72 | { |
65 | | - f |= Insights::TraceLoggingInformationFlags::IsSelfContained; |
| 73 | + auto module{ ::GetModuleHandleW(L"Microsoft.WindowsAppRuntime.dll") }; |
| 74 | + if (module) |
| 75 | + { |
| 76 | + using IsSelfContainedFn = HRESULT(__stdcall*)(BOOL*); |
| 77 | + auto fn{ reinterpret_cast<IsSelfContainedFn>(::GetProcAddress(module, "WindowsAppRuntime_IsSelfContained")) }; |
| 78 | + if (fn) |
| 79 | + { |
| 80 | + BOOL result{}; |
| 81 | + if (SUCCEEDED_LOG(fn(&result)) && result) |
| 82 | + { |
| 83 | + f |= Insights::TraceLoggingInformationFlags::IsSelfContained; |
| 84 | + } |
| 85 | + } |
| 86 | + } |
66 | 87 | } |
67 | 88 |
|
68 | 89 | return static_cast<std::uint32_t>(f); |
|
0 commit comments