Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move to WinAppSDK-1.1.0 #18603

Merged
merged 4 commits into from
Jun 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/actions/spell-check/expect.txt
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,7 @@ DCOM
dcomp
DComposition
ddf
DDLM
Deact
debian
debugbreak
Expand Down Expand Up @@ -1295,6 +1296,7 @@ MYTZ
NAMECHANGE
nameof
namespace
namespaceanddescendants
Navassa
NCACTIVATE
ncc
Expand Down
21 changes: 11 additions & 10 deletions installer/PowerToysSetup/PowerToys.wxs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
<?define Dotnet6PayloadSize="57791288"?>
<?define Dotnet6PayloadHash="B5B1819CCA753B070181F50411375B80412860A3"?>

<?define WinAppSDKPayloadSize="57090456"?>
<?define WinAppSDKPayloadHash="1269BB136655325EF6D66A018269BDAB3921E56B"?>
<?define WinAppSDKPayloadSize="59625472"?>
<?define WinAppSDKPayloadHash="8696DA7FE75464E8729FFB487A6E3A6247BC53D0"?>

<?define VCRedistDownloadUrl="https://download.visualstudio.microsoft.com/download/pr/6b6923b0-3045-4379-a96f-ef5506a65d5b/426A34C6F10EA8F7DA58A8C976B586AD84DD4BAB42A0CFDBE941F1763B7755E5/VC_redist.x64.exe"?>
<?define VCRedistPayloadSize="25337776"?>
Expand All @@ -27,8 +27,8 @@
<?define Dotnet6PayloadSize="51774400"?>
<?define Dotnet6PayloadHash="62C15858951B123AFD4D3E14F8BE4829A7CAFF18"?>

<?define WinAppSDKPayloadSize="57092528"?>
<?define WinAppSDKPayloadHash="377ACE2157BE077C63C650588A18CBEFD93B5B51"?>
<?define WinAppSDKPayloadSize="59625472"?>
<?define WinAppSDKPayloadHash="29F1CD6782CF840C652343C9C718DFE9D155D2F3"?>

<?define VCRedistDownloadUrl="https://download.visualstudio.microsoft.com/download/pr/6b6923b0-3045-4379-a96f-ef5506a65d5b/6114C0A7A526EA47D9ADD78C718BEA0BA32EEF0826AA5610AF76877CC5FEB7F3/VC_redist.arm64.exe"?>
<?define VCRedistPayloadSize="11596400"?>
Expand Down Expand Up @@ -110,18 +110,19 @@
UninstallCommand="/silent /uninstall">
</ExePackage>
<ExePackage
Name="WindowsAppRuntimeInstall-1.0.3.exe"
Name="WindowsAppRuntimeInstall-1.1.0.exe"
Compressed="no"
Id="WinAppSDK101"
DownloadUrl="https://aka.ms/windowsappsdk/1.0/1.0.3/windowsappruntimeinstall-1.0.3-$(var.PowerToysPlatform).exe"
Id="WinAppSDK110"
DownloadUrl="https://aka.ms/windowsappsdk/1.1/1.1.0/windowsappruntimeinstall-1.1.0-$(var.PowerToysPlatform).exe"
InstallCommand="--force"
RepairCommand=""
Permanent="yes">
<ExitCode Value="-2147009274" Behavior="success"/>
<RemotePayload
Description="Windows App SDK 1.0.3 Runtime Install"
ProductName="Windows App SDK 1.0.3 Runtime Install"
Description="Windows App SDK 1.1.0 Runtime Install"
ProductName="Windows App SDK 1.1.0 Runtime Install"
Size="$(var.WinAppSDKPayloadSize)"
Version="1.0.3.0"
Version="1.1.0.0"
Hash="$(var.WinAppSDKPayloadHash)" />
</ExePackage>
<ExePackage
Expand Down
31 changes: 2 additions & 29 deletions src/common/utils/elevation.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ namespace
inline bool GetDesktopAutomationObject(REFIID riid, void** ppv)
{
CComPtr<IShellView> spsv;

// Desktop may not be available on startup
auto attempts = 5;
for (auto i = 1; i <= attempts; i++)
Expand Down Expand Up @@ -492,31 +492,4 @@ inline bool check_user_is_admin()

freeMemory(pSID, pGroupInfo);
return false;
}

inline bool is_process_of_window_elevated(HWND window)
{
DWORD pid = 0;
GetWindowThreadProcessId(window, &pid);
if (!pid)
{
return false;
}

wil::unique_handle hProcess{ OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION,
FALSE,
pid) };

wil::unique_handle token;

if (OpenProcessToken(hProcess.get(), TOKEN_QUERY, &token))
{
TOKEN_ELEVATION elevation;
DWORD size;
if (GetTokenInformation(token.get(), TokenElevation, &elevation, sizeof(elevation), &size))
{
return elevation.TokenIsElevated != 0;
}
}
return false;
}
}
28 changes: 25 additions & 3 deletions src/modules/fancyzones/FancyZonesLib/WindowUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@

#include <common/display/dpi_aware.h>
#include <common/logger/logger.h>
#include <common/utils/elevation.h>
#include <common/utils/excluded_apps.h>
#include <common/utils/process_path.h>
#include <common/utils/winapi_error.h>
#include <common/utils/window.h>
#include <common/utils/excluded_apps.h>

#include <FancyZonesLib/FancyZonesWindowProperties.h>
#include <FancyZonesLib/Settings.h>
Expand Down Expand Up @@ -246,7 +245,30 @@ bool FancyZonesWindowUtils::IsCandidateForZoning(HWND window)

bool FancyZonesWindowUtils::IsProcessOfWindowElevated(HWND window)
{
return is_process_of_window_elevated(window);
DWORD pid = 0;
GetWindowThreadProcessId(window, &pid);
if (!pid)
{
return false;
}

wil::unique_handle hProcess{ OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION,
FALSE,
pid) };

wil::unique_handle token;
bool elevated = false;

if (OpenProcessToken(hProcess.get(), TOKEN_QUERY, &token))
{
TOKEN_ELEVATION elevation;
DWORD size;
if (GetTokenInformation(token.get(), TokenElevation, &elevation, sizeof(elevation), &size))
{
return elevation.TokenIsElevated != 0;
}
}
return false;
}

bool FancyZonesWindowUtils::IsExcludedByUser(const std::wstring& processPath) noexcept
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\..\..\..\packages\Microsoft.WindowsAppSDK.1.1.0\build\native\Microsoft.WindowsAppSDK.props" Condition="Exists('..\..\..\..\packages\Microsoft.WindowsAppSDK.1.1.0\build\native\Microsoft.WindowsAppSDK.props')" />
<Import Project="..\..\..\..\packages\Microsoft.Windows.CppWinRT.2.0.220418.1\build\native\Microsoft.Windows.CppWinRT.props" Condition="Exists('..\..\..\..\packages\Microsoft.Windows.CppWinRT.2.0.220418.1\build\native\Microsoft.Windows.CppWinRT.props')" />
<Import Project="..\..\..\..\packages\Microsoft.WindowsAppSDK.1.0.3\build\native\Microsoft.WindowsAppSDK.props" Condition="Exists('..\..\..\..\packages\Microsoft.WindowsAppSDK.1.0.3\build\native\Microsoft.WindowsAppSDK.props')" />
<Import Project="..\..\..\..\packages\Microsoft.Windows.SDK.BuildTools.10.0.22000.197\build\Microsoft.Windows.SDK.BuildTools.props" Condition="Exists('..\..\..\..\packages\Microsoft.Windows.SDK.BuildTools.10.0.22000.197\build\Microsoft.Windows.SDK.BuildTools.props')" />
<PropertyGroup Label="Globals">
<CppWinRTOptimized>true</CppWinRTOptimized>
Expand Down Expand Up @@ -171,10 +171,10 @@
<ImportGroup Label="ExtensionTargets">
<Import Project="..\..\..\..\packages\Microsoft.Windows.ImplementationLibrary.1.0.220201.1\build\native\Microsoft.Windows.ImplementationLibrary.targets" Condition="Exists('..\..\..\..\packages\Microsoft.Windows.ImplementationLibrary.1.0.220201.1\build\native\Microsoft.Windows.ImplementationLibrary.targets')" />
<Import Project="..\..\..\..\packages\Microsoft.Windows.SDK.BuildTools.10.0.22000.197\build\Microsoft.Windows.SDK.BuildTools.targets" Condition="Exists('..\..\..\..\packages\Microsoft.Windows.SDK.BuildTools.10.0.22000.197\build\Microsoft.Windows.SDK.BuildTools.targets')" />
<Import Project="..\..\..\..\packages\Microsoft.WindowsAppSDK.1.0.3\build\native\Microsoft.WindowsAppSDK.targets" Condition="Exists('..\..\..\..\packages\Microsoft.WindowsAppSDK.1.0.3\build\native\Microsoft.WindowsAppSDK.targets')" />
<Import Project="..\..\..\..\packages\boost.1.79.0\build\boost.targets" Condition="Exists('..\..\..\..\packages\boost.1.79.0\build\boost.targets')" />
<Import Project="..\..\..\..\packages\boost_regex-vc143.1.79.0\build\boost_regex-vc143.targets" Condition="Exists('..\..\..\..\packages\boost_regex-vc143.1.79.0\build\boost_regex-vc143.targets')" />
<Import Project="..\..\..\..\packages\Microsoft.Windows.CppWinRT.2.0.220418.1\build\native\Microsoft.Windows.CppWinRT.targets" Condition="Exists('..\..\..\..\packages\Microsoft.Windows.CppWinRT.2.0.220418.1\build\native\Microsoft.Windows.CppWinRT.targets')" />
<Import Project="..\..\..\..\packages\Microsoft.WindowsAppSDK.1.1.0\build\native\Microsoft.WindowsAppSDK.targets" Condition="Exists('..\..\..\..\packages\Microsoft.WindowsAppSDK.1.1.0\build\native\Microsoft.WindowsAppSDK.targets')" />
</ImportGroup>
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
Expand All @@ -183,12 +183,12 @@
<Error Condition="!Exists('..\..\..\..\packages\Microsoft.Windows.ImplementationLibrary.1.0.220201.1\build\native\Microsoft.Windows.ImplementationLibrary.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\..\packages\Microsoft.Windows.ImplementationLibrary.1.0.220201.1\build\native\Microsoft.Windows.ImplementationLibrary.targets'))" />
<Error Condition="!Exists('..\..\..\..\packages\Microsoft.Windows.SDK.BuildTools.10.0.22000.197\build\Microsoft.Windows.SDK.BuildTools.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\..\packages\Microsoft.Windows.SDK.BuildTools.10.0.22000.197\build\Microsoft.Windows.SDK.BuildTools.props'))" />
<Error Condition="!Exists('..\..\..\..\packages\Microsoft.Windows.SDK.BuildTools.10.0.22000.197\build\Microsoft.Windows.SDK.BuildTools.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\..\packages\Microsoft.Windows.SDK.BuildTools.10.0.22000.197\build\Microsoft.Windows.SDK.BuildTools.targets'))" />
<Error Condition="!Exists('..\..\..\..\packages\Microsoft.WindowsAppSDK.1.0.3\build\native\Microsoft.WindowsAppSDK.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\..\packages\Microsoft.WindowsAppSDK.1.0.3\build\native\Microsoft.WindowsAppSDK.props'))" />
<Error Condition="!Exists('..\..\..\..\packages\Microsoft.WindowsAppSDK.1.0.3\build\native\Microsoft.WindowsAppSDK.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\..\packages\Microsoft.WindowsAppSDK.1.0.3\build\native\Microsoft.WindowsAppSDK.targets'))" />
<Error Condition="!Exists('..\..\..\..\packages\boost.1.79.0\build\boost.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\..\packages\boost.1.79.0\build\boost.targets'))" />
<Error Condition="!Exists('..\..\..\..\packages\boost_regex-vc143.1.79.0\build\boost_regex-vc143.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\..\packages\boost_regex-vc143.1.79.0\build\boost_regex-vc143.targets'))" />
<Error Condition="!Exists('..\..\..\..\packages\Microsoft.Windows.CppWinRT.2.0.220418.1\build\native\Microsoft.Windows.CppWinRT.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\..\packages\Microsoft.Windows.CppWinRT.2.0.220418.1\build\native\Microsoft.Windows.CppWinRT.props'))" />
<Error Condition="!Exists('..\..\..\..\packages\Microsoft.Windows.CppWinRT.2.0.220418.1\build\native\Microsoft.Windows.CppWinRT.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\..\packages\Microsoft.Windows.CppWinRT.2.0.220418.1\build\native\Microsoft.Windows.CppWinRT.targets'))" />
<Error Condition="!Exists('..\..\..\..\packages\Microsoft.WindowsAppSDK.1.1.0\build\native\Microsoft.WindowsAppSDK.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\..\packages\Microsoft.WindowsAppSDK.1.1.0\build\native\Microsoft.WindowsAppSDK.props'))" />
<Error Condition="!Exists('..\..\..\..\packages\Microsoft.WindowsAppSDK.1.1.0\build\native\Microsoft.WindowsAppSDK.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\..\packages\Microsoft.WindowsAppSDK.1.1.0\build\native\Microsoft.WindowsAppSDK.targets'))" />
</Target>
<Target Name="AddWildCardItems" AfterTargets="BuildGenerateSources">
<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/modules/powerrename/PowerRenameUILib/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
<package id="Microsoft.Windows.CppWinRT" version="2.0.220418.1" targetFramework="native" />
<package id="Microsoft.Windows.ImplementationLibrary" version="1.0.220201.1" targetFramework="native" />
<package id="Microsoft.Windows.SDK.BuildTools" version="10.0.22000.197" targetFramework="native" />
<package id="Microsoft.WindowsAppSDK" version="1.0.3" targetFramework="native" />
<package id="Microsoft.WindowsAppSDK" version="1.1.0" targetFramework="native" />
</packages>
1 change: 0 additions & 1 deletion src/modules/powerrename/lib/PowerRenameInterfaces.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ interface __declspec(uuid("C7F59201-4DE1-4855-A3A2-26FC3279C8A5")) IPowerRenameI
IFACEMETHOD(GetSelected)(_Out_ bool* selected) = 0;
IFACEMETHOD(PutSelected)(_In_ bool selected) = 0;
IFACEMETHOD(GetId)(_Out_ int *id) = 0;
IFACEMETHOD(GetIconIndex)(_Out_ int* iconIndex) = 0;
IFACEMETHOD(GetDepth)(_Out_ UINT* depth) = 0;
IFACEMETHOD(PutDepth)(_In_ int depth) = 0;
IFACEMETHOD(ShouldRenameItem)(_In_ DWORD flags, _Out_ bool* shouldRename) = 0;
Expand Down
11 changes: 0 additions & 11 deletions src/modules/powerrename/lib/PowerRenameItem.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include "pch.h"
#include "PowerRenameItem.h"
#include <common/themes/icon_helpers.h>

int CPowerRenameItem::s_id = 0;

Expand Down Expand Up @@ -180,16 +179,6 @@ IFACEMETHODIMP CPowerRenameItem::GetId(_Out_ int* id)
return S_OK;
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this removed? Wouldn’t expect it in a rev for 1.1

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the PR description. Looks like it isn't used and breaks the build.

Removed PowerRename method was breaking the build because of the unresolved reference. Method is not needed, therefore deleted.

IFACEMETHODIMP CPowerRenameItem::GetIconIndex(_Out_ int* iconIndex)
{
if (m_iconIndex == -1)
{
GetIconIndexFromPath((PCWSTR)m_path, &m_iconIndex);
}
*iconIndex = m_iconIndex;
return S_OK;
}

IFACEMETHODIMP CPowerRenameItem::GetDepth(_Out_ UINT* depth)
{
*depth = m_depth;
Expand Down
1 change: 0 additions & 1 deletion src/modules/powerrename/lib/PowerRenameItem.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ class CPowerRenameItem :
IFACEMETHODIMP GetSelected(_Out_ bool* selected);
IFACEMETHODIMP PutSelected(_In_ bool selected);
IFACEMETHODIMP GetId(_Out_ int* id);
IFACEMETHODIMP GetIconIndex(_Out_ int* iconIndex);
IFACEMETHODIMP GetDepth(_Out_ UINT* depth);
IFACEMETHODIMP PutDepth(_In_ int depth);
IFACEMETHODIMP Reset();
Expand Down
3 changes: 0 additions & 3 deletions src/runner/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,4 @@
<data name="BUGREPORT_SUCCESS" xml:space="preserve">
<value>Bug report .zip file has been created on your Desktop.</value>
</data>
<data name="CANNOT_LAUNCH_SETTINGS_NONELEVATED" xml:space="preserve">
<value>Cannot start PowerToys.Settings process non-elevated, because explorer.exe process is elevated. Consider enabling UAC.</value>
</data>
</root>
86 changes: 67 additions & 19 deletions src/runner/settings_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#include "restart_elevated.h"
#include "UpdateUtils.h"
#include "centralized_kb_hook.h"
#include "Generated Files/resource.h"

#include <common/utils/json.h>
#include <common/SettingsAPI/settings_helpers.cpp>
Expand All @@ -21,7 +20,6 @@
#include <common/utils/elevation.h>
#include <common/utils/process_path.h>
#include <common/utils/timeutil.h>
#include <common/utils/resources.h>
#include <common/utils/winapi_error.h>
#include <common/updating/updateState.h>
#include <common/themes/windows_colors.h>
Expand Down Expand Up @@ -199,6 +197,67 @@ void receive_json_send_to_main_thread(const std::wstring& msg)
dispatch_run_on_main_ui_thread(dispatch_received_json_callback, copy);
}

// Try to run the Settings process with non-elevated privileges.
BOOL run_settings_non_elevated(LPCWSTR executable_path, LPWSTR executable_args, PROCESS_INFORMATION* process_info)
{
HWND hwnd = GetShellWindow();
if (!hwnd)
{
return false;
}

DWORD pid;
GetWindowThreadProcessId(hwnd, &pid);

winrt::handle process{ OpenProcess(PROCESS_CREATE_PROCESS, FALSE, pid) };
if (!process)
{
return false;
}

SIZE_T size = 0;
InitializeProcThreadAttributeList(nullptr, 1, 0, &size);
auto pproc_buffer = std::unique_ptr<char[]>{ new (std::nothrow) char[size] };
auto pptal = reinterpret_cast<PPROC_THREAD_ATTRIBUTE_LIST>(pproc_buffer.get());
if (!pptal)
{
return false;
}

if (!InitializeProcThreadAttributeList(pptal, 1, 0, &size))
{
return false;
}

if (!UpdateProcThreadAttribute(pptal,
0,
PROC_THREAD_ATTRIBUTE_PARENT_PROCESS,
&process,
sizeof(process),
nullptr,
nullptr))
{
return false;
}

STARTUPINFOEX siex = { 0 };
siex.lpAttributeList = pptal;
siex.StartupInfo.cb = sizeof(siex);

BOOL process_created = CreateProcessW(executable_path,
executable_args,
nullptr,
nullptr,
FALSE,
EXTENDED_STARTUPINFO_PRESENT,
nullptr,
nullptr,
&siex.StartupInfo,
process_info);
g_isLaunchInProgress = false;
return process_created;
}

DWORD g_settings_process_id = 0;

void run_settings_window(bool show_oobe_window, bool show_scoobe_window, std::optional<std::wstring> settings_window)
Expand Down Expand Up @@ -296,24 +355,13 @@ void run_settings_window(bool show_oobe_window, bool show_scoobe_window, std::op

if (is_process_elevated())
{
const bool explorer_is_elevated = is_process_of_window_elevated(GetShellWindow());
if (explorer_is_elevated)
auto res = RunNonElevatedFailsafe(executable_path, executable_args, get_module_folderpath());
process_created = res.has_value();
if (process_created)
{
MessageBoxW(nullptr,
GET_RESOURCE_STRING(IDS_CANNOT_LAUNCH_SETTINGS_NONELEVATED).c_str(),
L"PowerToys",
MB_OK | MB_ICONERROR);
}
else
{
auto res = RunNonElevatedFailsafe(executable_path, executable_args, get_module_folderpath());
process_created = res.has_value();
if (process_created)
{
process_info.dwProcessId = res->processID;
process_info.hProcess = res->processHandle.release();
g_isLaunchInProgress = false;
}
process_info.dwProcessId = res->processID;
process_info.hProcess = res->processHandle.release();
g_isLaunchInProgress = false;
}
}

Expand Down
Loading