[Settings] Add Image Resizer Settings hyperlink on feature detection of older OS Versions (#2868)

* Added the settings hyperlink code back

* Moved the os detection code to a different file so that it can be imported by image resizer

* Added code to the Image resizer project to react to import the dll

* Added an empty dll project

* Added a dll which can be imported by image resizer

* ImageResizer binding works

* Added the setDllDirectory to load the os-detection dll

* Removed the OS detection files that has been added to the common project

* Added reference to os-detect and removed reference to common/OS-Detection.h

* Modified project files

* Revert "Modified project files"

This reverts commit 75f9d73f30.

* Removed unnecessary showAdvanced bool variables

* Removed OS Detection code from common project

* Cleaned configuration properties of soln and projects

* runner is dependent on os-detection

* Added the os-detection.dll to wxs file

* nit space formatting

* Added reference to os-detection

* Added os-detection header file

* Add os-detection reference

* Added os-detection.dll

* removed the set dll directory and using relative paths instead

* Add relative path
This commit is contained in:
Alekhya 2020-05-12 09:58:29 -07:00 committed by GitHub
parent 0f8fbf6a1e
commit 62d9735a7e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
20 changed files with 275 additions and 44 deletions

View File

@ -29,6 +29,7 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "runner", "src\runner\runner
{F9C68EDF-AC74-4B77-9AF1-005D9C9F6A99} = {F9C68EDF-AC74-4B77-9AF1-005D9C9F6A99}
{07C389E3-6BC8-41CF-923E-307B1265FA2D} = {07C389E3-6BC8-41CF-923E-307B1265FA2D}
{89F34AF7-1C34-4A72-AA6E-534BCF972BD9} = {89F34AF7-1C34-4A72-AA6E-534BCF972BD9}
{E6410BFC-B341-498C-8C67-312C20CDD8D5} = {E6410BFC-B341-498C-8C67-312C20CDD8D5}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "common", "src\common\common.vcxproj", "{74485049-C722-400F-ABE5-86AC52D929B3}"
@ -255,6 +256,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PowerLauncher.Telemetry", "
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Telemetry", "src\common\ManagedTelemetry\Telemetry\Telemetry.csproj", "{5D00D290-4016-4CFE-9E41-1E7C724509BA}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "os-detection", "src\common\os-detection\os-detection.vcxproj", "{E6410BFC-B341-498C-8C67-312C20CDD8D5}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
@ -497,6 +500,10 @@ Global
{5D00D290-4016-4CFE-9E41-1E7C724509BA}.Debug|x64.Build.0 = Debug|x64
{5D00D290-4016-4CFE-9E41-1E7C724509BA}.Release|x64.ActiveCfg = Release|x64
{5D00D290-4016-4CFE-9E41-1E7C724509BA}.Release|x64.Build.0 = Release|x64
{E6410BFC-B341-498C-8C67-312C20CDD8D5}.Debug|x64.ActiveCfg = Debug|x64
{E6410BFC-B341-498C-8C67-312C20CDD8D5}.Debug|x64.Build.0 = Debug|x64
{E6410BFC-B341-498C-8C67-312C20CDD8D5}.Release|x64.ActiveCfg = Release|x64
{E6410BFC-B341-498C-8C67-312C20CDD8D5}.Release|x64.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@ -566,6 +573,7 @@ Global
{787B8AA6-CA93-4C84-96FE-DF31110AD1C4} = {4AFC9975-2456-4C70-94A4-84073C1CED93}
{08C8C05F-0362-41BC-818C-724572DF8B06} = {C140A3EF-6DBF-4084-9D4C-4EB5A99FEE68}
{5D00D290-4016-4CFE-9E41-1E7C724509BA} = {1AFB6476-670D-4E80-A464-657E01DFF482}
{E6410BFC-B341-498C-8C67-312C20CDD8D5} = {1AFB6476-670D-4E80-A464-657E01DFF482}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {C3A2F9D1-7930-4EF4-A6FC-7EE0A99821D0}

View File

@ -347,6 +347,9 @@
<Component Id="powertoysinterop_dll" Guid="B7DD2DF4-C8F2-46FA-9571-D6EF1588ADF3" Win64="yes">
<File Id="PowerToysInterop.dll" KeyPath="yes" Checksum="yes" />
</Component>
<Component Id="osDetection_dll" Guid="AA370C25-4AC8-447B-A2FF-C99365C6BE67" Win64="yes">
<File Source="$(var.BinX64Dir)os-detection.dll" KeyPath="yes" Checksum="yes" />
</Component>
</DirectoryRef>
<DirectoryRef Id="SvgsInstallFolder" FileSource="$(var.BinX64Dir)svgs\">
<Component Id="PowerToysSvgs" Guid="7C4D4EED-9338-423D-992C-DCE02F3E2D35" Win64="yes">
@ -693,6 +696,7 @@
<ComponentRef Id="powertoys_toast_clsid" />
<ComponentRef Id="License_rtf" />
<ComponentRef Id="powertoysinterop_dll" />
<ComponentRef Id="osDetection_dll" />
<ComponentRef Id="PowerToysSvgs" />
<ComponentRef Id="Module_ShortcutGuide" />
<ComponentRef Id="Module_FancyZones" />

View File

@ -0,0 +1,19 @@
// dllmain.cpp : Defines the entry point for the DLL application.
#include "pch.h"
BOOL APIENTRY DllMain( HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}

View File

@ -0,0 +1,5 @@
#pragma once
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
// Windows Header Files
#include <windows.h>

View File

@ -0,0 +1,38 @@
#include "pch.h"
#include "os-detect.h"
#include <winrt/Windows.Foundation.Metadata.h>
// The following three helper functions determine if the user has a build version higher than or equal to 19h1, as that is a requirement for xaml islands
// Source : Microsoft-ui-xaml github
// Link: https://github.com/microsoft/microsoft-ui-xaml/blob/c045cde57c5c754683d674634a0baccda34d58c4/dev/dll/SharedHelpers.cpp
template<uint16_t APIVersion>
bool IsAPIContractVxAvailable()
{
static bool isAPIContractVxAvailableInitialized = false;
static bool isAPIContractVxAvailable = false;
if (!isAPIContractVxAvailableInitialized)
{
isAPIContractVxAvailableInitialized = true;
isAPIContractVxAvailable = winrt::Windows::Foundation::Metadata::ApiInformation::IsApiContractPresent(L"Windows.Foundation.UniversalApiContract", APIVersion);
}
return isAPIContractVxAvailable;
}
bool IsAPIContractV8Available()
{
return IsAPIContractVxAvailable<8>();
}
bool Is19H1OrHigher()
{
return IsAPIContractV8Available();
}
// This function returns true if the build is 19h1 or higher, so that we deploy the new settings.
// It returns false otherwise.
bool UseNewSettings()
{
return Is19H1OrHigher();
}

View File

@ -0,0 +1,3 @@
#pragma once
extern "C" __declspec(dllexport) bool UseNewSettings();

View File

@ -0,0 +1,100 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>16.0</VCProjectVersion>
<ProjectGuid>{E6410BFC-B341-498C-8C67-312C20CDD8D5}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>osdetection</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<PrecompiledHeader>Use</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_DEBUG;OSDETECTION_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableUAC>false</EnableUAC>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<PrecompiledHeader>Use</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>NDEBUG;OSDETECTION_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableUAC>false</EnableUAC>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="framework.h" />
<ClInclude Include="os-detect.h" />
<ClInclude Include="pch.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="dllmain.cpp" />
<ClCompile Include="os-detect.cpp" />
<ClCompile Include="pch.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader>
</ClCompile>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@ -0,0 +1,39 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;c++;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>
</Filter>
<Filter Include="Resource Files">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="framework.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="pch.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="os-detect.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="dllmain.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="pch.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="os-detect.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
</Project>

View File

@ -0,0 +1,6 @@
// pch.cpp: source file corresponding to the pre-compiled header
#include "pch.h"
#pragma comment(lib, "windowsapp")
// When you are using pre-compiled headers, this source file is necessary for compilation to succeed.

View File

@ -0,0 +1,13 @@
// pch.h: This is a precompiled header file.
// Files listed below are compiled only once, improving build performance for future builds.
// This also affects IntelliSense performance, including code completion and many code browsing features.
// However, files listed here are ALL re-compiled if any one of them is updated between builds.
// Do not add files here that you will be updating frequently as this negates the performance advantage.
#ifndef PCH_H
#define PCH_H
// add headers that you want to pre-compile here
#include "framework.h"
#endif //PCH_H

View File

@ -98,6 +98,7 @@
<Compile Include="Extensions\BitmapEncoderExtensions.cs" />
<Compile Include="Extensions\ICollectionExtensions.cs" />
<Compile Include="Extensions\TimeSpanExtensions.cs" />
<Compile Include="Models\AdvancedSettings.cs" />
<Compile Include="Models\ResizeError.cs" />
<Compile Include="Properties\Settings.cs" />
<Compile Include="Models\CustomSize.cs" />

View File

@ -0,0 +1,13 @@
// This class sets the visibility property of Advanced settings based on the OS Version
using System;
using System.Runtime.InteropServices;
namespace ImageResizer.Models
{
public class AdvancedSettings
{
[DllImport("../os-detection.dll", EntryPoint = "UseNewSettings", ExactSpelling = false)]
public static extern bool UseNewSettings();
}
}

View File

@ -33,8 +33,13 @@ namespace ImageResizer.ViewModels
ResizeCommand = new RelayCommand(Resize);
CancelCommand = new RelayCommand(Cancel);
ShowAdvancedCommand = new RelayCommand(ShowAdvanced);
ShowAdvancedSettings = !AdvancedSettings.UseNewSettings();
}
public bool ShowAdvancedSettings { get; }
public Settings Settings { get; }
public ICommand ResizeCommand { get; }
@ -51,5 +56,8 @@ namespace ImageResizer.ViewModels
public void Cancel()
=> _mainView.Close();
public void ShowAdvanced()
=> _mainView.ShowAdvanced(new AdvancedViewModel(Settings));
}
}

View File

@ -12,6 +12,8 @@ namespace ImageResizer.Views
{
void Close();
void ShowAdvanced(AdvancedViewModel viewModel);
IEnumerable<string> OpenPictureFiles();
}
}

View File

@ -130,13 +130,14 @@
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<!--
<TextBlock VerticalAlignment="Center">
<TextBlock VerticalAlignment="Center"
Visibility="{Binding ShowAdvancedSettings, Converter={StaticResource BoolValueConverter}}">
<Hyperlink Command="{Binding ShowAdvancedCommand}">
<Run Text="{x:Static p:Resources.Input_ShowAdvanced}"/>
</Hyperlink>
</TextBlock>
-->
<Button Grid.Column="1"
Height="23"
MinWidth="75"

View File

@ -39,10 +39,9 @@ namespace ImageResizer.Views
return openFileDialog.FileNames;
}
/*
public void ShowAdvanced(AdvancedViewModel viewModel)
=> viewModel.Close(new AdvancedWindow(viewModel).ShowDialog() == true);
*/
void IMainView.Close()
=> Dispatcher.Invoke((Action)Close);
}

View File

@ -29,5 +29,4 @@
#include <winrt/Windows.ApplicationModel.h>
#include <winrt/Windows.Storage.h>
#include <winrt/Windows.Foundation.Metadata.h>
#include <wil/resource.h>

View File

@ -62,7 +62,7 @@
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<PrecompiledHeader>Use</PrecompiledHeader>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<AdditionalIncludeDirectories>..\common\inc;..\common\Telemetry;..;..\modules;..\..\deps\cpprestsdk\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>..\common\inc;..\common\os-detection;..\common\Telemetry;..;..\modules;..\..\deps\cpprestsdk\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>_UNICODE;UNICODE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalOptions>/await %(AdditionalOptions)</AdditionalOptions>
</ClCompile>
@ -86,7 +86,7 @@
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<PrecompiledHeader>Use</PrecompiledHeader>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<AdditionalIncludeDirectories>..\common\inc;..\common\Telemetry;..;..\modules;..\..\deps\cpprestsdk\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>..\common\inc;..\common\os-detection;..\common\Telemetry;..;..\modules;..\..\deps\cpprestsdk\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>_UNICODE;UNICODE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalOptions>/await %(AdditionalOptions)</AdditionalOptions>
</ClCompile>
@ -235,6 +235,9 @@
<ProjectReference Include="..\common\common.vcxproj">
<Project>{74485049-c722-400f-abe5-86ac52d929b3}</Project>
</ProjectReference>
<ProjectReference Include="..\common\os-detection\os-detection.vcxproj">
<Project>{e6410bfc-b341-498c-8c67-312c20cdd8d5}</Project>
</ProjectReference>
<ProjectReference Include="..\common\updating\updating.vcxproj">
<Project>{17da04df-e393-4397-9cf0-84dabe11032e}</Project>
</ProjectReference>
@ -242,7 +245,7 @@
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ItemGroup>
<Manifest Include="PowerToys.exe.manifest" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />

View File

@ -157,4 +157,7 @@
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<Manifest Include="PowerToys.exe.manifest" />
</ItemGroup>
</Project>

View File

@ -14,6 +14,7 @@
#include <common/json.h>
#include <common\settings_helpers.cpp>
#include <os-detect.h>
#define BUFSIZE 1024
@ -206,40 +207,6 @@ BOOL run_settings_non_elevated(LPCWSTR executable_path, LPWSTR executable_args,
return process_created;
}
// The following three helper functions determine if the user has a build version higher than or equal to 19h1, as that is a requirement for xaml islands
// Source : Microsoft-ui-xaml github
// Link: https://github.com/microsoft/microsoft-ui-xaml/blob/c045cde57c5c754683d674634a0baccda34d58c4/dev/dll/SharedHelpers.cpp
template<uint16_t APIVersion> bool IsAPIContractVxAvailable()
{
static bool isAPIContractVxAvailableInitialized = false;
static bool isAPIContractVxAvailable = false;
if (!isAPIContractVxAvailableInitialized)
{
isAPIContractVxAvailableInitialized = true;
isAPIContractVxAvailable = winrt::Windows::Foundation::Metadata::ApiInformation::IsApiContractPresent(L"Windows.Foundation.UniversalApiContract", APIVersion);
}
return isAPIContractVxAvailable;
}
bool IsAPIContractV8Available()
{
return IsAPIContractVxAvailable<8>();
}
bool Is19H1OrHigher()
{
return IsAPIContractV8Available();
}
// This function returns true if the build is 19h1 or higher, so that we deploy the new settings.
// It returns false otherwise.
bool use_new_settings()
{
return Is19H1OrHigher();
}
DWORD g_settings_process_id = 0;
@ -258,7 +225,7 @@ void run_settings_window()
// Arg 1: executable path.
std::wstring executable_path = get_module_folderpath();
if (use_new_settings())
if (UseNewSettings())
{
executable_path.append(L"\\SettingsUIRunner\\Microsoft.PowerToys.Settings.UI.Runner.exe");
}