Skip to content

Commit

Permalink
Cleanup, comments, etc.
Browse files Browse the repository at this point in the history
  • Loading branch information
zadjii-msft committed Jul 19, 2022
1 parent dc78b32 commit 9a2ee6a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
16 changes: 16 additions & 0 deletions src/host/srvinit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,22 @@ static bool s_IsOnDesktop()
// strong nudge in that direction. If an application _doesn't_ want VT
// processing, it's free to disable this setting, even in conpty mode.
settings.SetVirtTermLevel(1);

// GH#9458 - In the case of a DefTerm handoff, the OriginalTitle might
// be stashed in the lnk. We want to crack that lnk open, so we can get
// that title from it, but we want to discard everything else. So build
// a dummy Settings object here, and read the link settings into it.
// `Title` will get filled with the title from the lnk, which we'll use
// below.

Settings temp;
// We're not gonna copy over StartupFlags to the main gci settings,
// because we generally don't think those are valuable in ConPTY mode.
// However, we do need to apply them to the temp we've created, so that
// GetSettingsFromLink will actually look for the link settings (it will
// skip that if STARTF_TITLEISLINKNAME is not set).
temp.SetStartupFlags(pStartupSettings->GetStartupFlags());
ServiceLocator::LocateSystemConfigurationProvider()->GetSettingsFromLink(&temp, Title, &TitleLength, CurDir, AppName, nullptr);
}

// 1. The settings we were passed contains STARTUPINFO structure settings to be applied last.
Expand Down
20 changes: 14 additions & 6 deletions src/interactivity/win32/SystemConfigurationProvider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,21 @@ void SystemConfigurationProvider::GetSettingsFromLink(
// Did we get started from a link?
if (pLinkSettings->GetStartupFlags() & STARTF_TITLEISLINKNAME)
{
auto initializeCom = CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED);
// If it's RPC_E_CHANGED_MODE, that's okay, we're doing a defterm and already started COM
if (SUCCEEDED(initializeCom) || initializeCom == RPC_E_CHANGED_MODE)
auto initializedCom = CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED);

// GH#9458: If it's RPC_E_CHANGED_MODE, that's okay, we're doing a
// defterm and have already started COM. We can continue on here.
if (SUCCEEDED(initializedCom) || initializedCom == RPC_E_CHANGED_MODE)
{

// Don't CoUninitialize if we still need COM for defterm.
auto unInitCom = wil::scope_exit[initializedCom]()
{
if (SUCCEEDED(initializedCom))
{
CoUninitialize();
}
};

const auto cch = *pdwTitleLength / sizeof(wchar_t);

gci.SetLinkTitle(std::wstring(pwszTitle, cch));
Expand Down Expand Up @@ -160,8 +170,6 @@ void SystemConfigurationProvider::GetSettingsFromLink(
// settings based on title.
pLinkSettings->UnsetStartupFlag(STARTF_TITLEISLINKNAME);
}
if (SUCCEEDED(initializeCom)) {
CoUninitialize(); }
}
}

Expand Down

1 comment on commit 9a2ee6a

@github-actions

This comment was marked as outdated.

Please sign in to comment.