terminal/src/propslib/ShortcutSerialization.hpp
Malcolm Smith 601286ac69
Find icon from shortcut target if shortcut doesn't specify it (#6277)
Implements what I was suggesting in #6266 where if a shortcut doesn't
specify an icon, the shortcut target full path is used before searching
for a matching executable in the path.

## References

Found due to not getting the right icon in conhost from the Yori
installer.  It's fixed in the installer from
5af366b6a5
for all current users of conhost though, so this PR is just trying to
minimize surprises for the next guy.

## Detailed Description of the Pull Request / Additional comments

I know conhost and shortcut settings aren't really the team's focus
which is why I'm doing this.  I understand though if there's a better
way or there are factors that I hadn't considered.  Note that the path
searching code is used when programs are launched without using a
shortcut, and it will match if the working directory of the shortcut is
the directory containing the executable.

## Validation Steps Performed

Created a shortcut that didn't specify an icon to a binary that wasn't
in the path, and verified that the icon in the upper left of the console
window could resolve correctly when opening the shortcut.  I'm not aware
of a way to get into this path (of launching via a shortcut to a command
line process) without replacing the system conhost, which is what I did
to verify it.  In order to diagnose it, I used hardcoded DebugBreak()
since even ImageFileExecutionOptions didn't like running against conhost-
is there are better way to debug and test these cases without being so
invasive on the system?

Closes #6266
2020-06-01 17:19:05 +00:00

69 lines
4 KiB
C++

/*++
Copyright (c) Microsoft Corporation
Licensed under the MIT license.
Module Name:
- ShortcutSerialization.hpp
Abstract:
- This module is used for writing console properties to the link associated
with a particular console title.
Author(s):
- Michael Niksa (MiNiksa) 23-Jul-2014
- Paul Campbell (PaulCam) 23-Jul-2014
- Mike Griese (MiGrie) 04-Aug-2015
Revision History:
- From components of srvinit.c
- From miniksa, paulcam's Registry.cpp
--*/
#pragma once
class ShortcutSerialization
{
public:
[[nodiscard]] static NTSTATUS s_SetLinkValues(_In_ PCONSOLE_STATE_INFO pStateInfo, const BOOL fEastAsianSystem, const BOOL fForceV2, const bool writeTerminalSettings);
[[nodiscard]] static NTSTATUS s_GetLinkConsoleProperties(_Inout_ PCONSOLE_STATE_INFO pStateInfo);
[[nodiscard]] static NTSTATUS s_GetLinkValues(_Inout_ PCONSOLE_STATE_INFO pStateInfo,
_Out_ BOOL* const pfReadConsoleProperties,
_Out_writes_opt_(cchShortcutTitle) PWSTR pwszShortcutTitle,
const size_t cchShortcutTitle,
_Out_writes_opt_(cchLinkTarget) PWSTR pwszLinkTarget,
const size_t cchLinkTarget,
_Out_writes_opt_(cchIconLocation) PWSTR pwszIconLocation,
const size_t cchIconLocation,
_Out_opt_ int* const piIcon,
_Out_opt_ int* const piShowCmd,
_Out_opt_ WORD* const pwHotKey);
private:
static void s_InitPropVarFromBool(_In_ BOOL fVal, _Out_ PROPVARIANT* ppropvar);
static void s_InitPropVarFromByte(_In_ BYTE bVal, _Out_ PROPVARIANT* ppropvar);
static void s_InitPropVarFromDword(_In_ DWORD dwVal, _Out_ PROPVARIANT* ppropvar);
static void s_SetLinkPropertyBoolValue(_In_ IPropertyStore* pps, _In_ REFPROPERTYKEY refPropKey, const BOOL fVal);
static void s_SetLinkPropertyByteValue(_In_ IPropertyStore* pps, _In_ REFPROPERTYKEY refPropKey, const BYTE bVal);
static void s_SetLinkPropertyDwordValue(_In_ IPropertyStore* pps, _In_ REFPROPERTYKEY refPropKey, const DWORD dwVal);
[[nodiscard]] static HRESULT s_GetPropertyBoolValue(_In_ IPropertyStore* const pPropStore,
_In_ REFPROPERTYKEY refPropKey,
_Out_ BOOL* const pfValue);
[[nodiscard]] static HRESULT s_GetPropertyByteValue(_In_ IPropertyStore* const pPropStore,
_In_ REFPROPERTYKEY refPropKey,
_Out_ BYTE* const pbValue);
[[nodiscard]] static HRESULT s_GetPropertyDwordValue(_In_ IPropertyStore* const pPropStore,
_In_ REFPROPERTYKEY refPropKey,
_Out_ DWORD* const pdwValue);
[[nodiscard]] static HRESULT s_PopulateV1Properties(_In_ IShellLink* const pslConsole, _In_ PCONSOLE_STATE_INFO pStateInfo);
[[nodiscard]] static HRESULT s_PopulateV2Properties(_In_ IShellLink* const pslConsole, _In_ PCONSOLE_STATE_INFO pStateInfo);
static void s_GetLinkTitle(_In_ PCWSTR pwszShortcutFilename, _Out_writes_(cchShortcutTitle) PWSTR pwszShortcutTitle, const size_t cchShortcutTitle);
[[nodiscard]] static HRESULT s_GetLoadedShellLinkForShortcut(_In_ PCWSTR pwszShortcutFileName,
const DWORD dwMode,
_COM_Outptr_ IShellLink** ppsl,
_COM_Outptr_ IPersistFile** ppPf);
};