Skip to content

Commit

Permalink
Fix an exception on startup (#17960)
Browse files Browse the repository at this point in the history
It bothered me. :)

## Validation Steps Performed
* Launch packaged WT. `IsPackaged() == true` ✅
* Launch unpackaged WT. `IsPackaged() == false` ✅
  • Loading branch information
lhecker authored Sep 25, 2024
1 parent 37aba31 commit a8e0b9c
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions src/cascadia/WinRTUtils/inc/WtExeUtils.h
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

#pragma once

constexpr std::wstring_view WtExe{ L"wt.exe" };
constexpr std::wstring_view WtdExe{ L"wtd.exe" };
constexpr std::wstring_view WindowsTerminalExe{ L"WindowsTerminal.exe" };
constexpr std::wstring_view LocalAppDataAppsPath{ L"%LOCALAPPDATA%\\Microsoft\\WindowsApps\\" };
constexpr std::wstring_view ElevateShimExe{ L"elevate-shim.exe" };

// Forward declared from appmodel.h so that we don't need to pull in that header everywhere.
extern "C" {
WINBASEAPI LONG WINAPI GetCurrentPackageId(UINT32* bufferLength, BYTE* buffer);
}

#ifdef WINRT_Windows_ApplicationModel_H
_TIL_INLINEPREFIX bool IsPackaged()
{
static const auto isPackaged = []() -> bool {
try
{
const auto package = winrt::Windows::ApplicationModel::Package::Current();
return true;
}
catch (...)
{
return false;
}
static const auto isPackaged = []() {
UINT32 bufferLength = 0;
const auto hr = GetCurrentPackageId(&bufferLength, nullptr);
return hr != APPMODEL_ERROR_NO_PACKAGE;
}();
return isPackaged;
}
Expand Down

0 comments on commit a8e0b9c

Please sign in to comment.