From 3caaf742fcd19170a8732570654d3b2cbb18830f Mon Sep 17 00:00:00 2001 From: Rob Mensching Date: Tue, 4 May 2021 12:07:04 -0700 Subject: Move Dependency.wixext into ext --- src/ext/Dependency/Dependency.wixext.sln | 61 +++ src/ext/Dependency/Directory.Build.props | 27 ++ src/ext/Dependency/Directory.Build.targets | 51 ++ src/ext/Dependency/Directory.csproj.props | 13 + src/ext/Dependency/Directory.csproj.targets | 26 ++ src/ext/Dependency/Directory.vcxproj.props | 93 ++++ src/ext/Dependency/README.md | 2 + src/ext/Dependency/appveyor.cmd | 19 + src/ext/Dependency/appveyor.yml | 42 ++ src/ext/Dependency/ca/custommsierrors.h | 5 + src/ext/Dependency/ca/dependencyca.vcxproj | 73 +++ src/ext/Dependency/ca/dependencyca.vcxproj.filters | 36 ++ src/ext/Dependency/ca/dllmain.cpp | 27 ++ src/ext/Dependency/ca/precomp.h | 18 + src/ext/Dependency/ca/wixdepca.cpp | 516 +++++++++++++++++++++ src/ext/Dependency/ca/wixdepca.def | 8 + src/ext/Dependency/nuget.config | 18 + .../DependencyExtensionFixture.cs | 38 ++ .../TestData/UsingProvides/Package.en-us.wxl | 11 + .../TestData/UsingProvides/Package.wxs | 21 + .../WixToolsetTest.Dependency.csproj | 39 ++ src/ext/Dependency/wix.snk | Bin 0 -> 596 bytes src/ext/Dependency/wixext/DependencyCompiler.cs | 61 +++ src/ext/Dependency/wixext/DependencyDecompiler.cs | 347 ++++++++++++++ .../Dependency/wixext/DependencyExtensionData.cs | 29 ++ .../wixext/DependencyExtensionFactory.cs | 17 + .../wixext/WixToolset.Dependency.wixext.csproj | 32 ++ .../wixext/WixToolset.Dependency.wixext.nuspec | 25 + .../wixext/WixToolset.Dependency.wixext.targets | 11 + src/ext/Dependency/wixlib/DependencyExtension.wxs | 21 + .../wixlib/DependencyExtension_Platform.wxi | 28 ++ .../wixlib/DependencyExtension_arm64.wxs | 7 + .../Dependency/wixlib/DependencyExtension_x64.wxs | 7 + .../Dependency/wixlib/DependencyExtension_x86.wxs | 7 + src/ext/Dependency/wixlib/caDecor.wxi | 39 ++ src/ext/Dependency/wixlib/caerr.wxi | 96 ++++ src/ext/Dependency/wixlib/dependency.wixproj | 30 ++ src/ext/Dependency/wixlib/en-us.wxl | 7 + src/ext/global.json | 5 + 39 files changed, 1913 insertions(+) create mode 100644 src/ext/Dependency/Dependency.wixext.sln create mode 100644 src/ext/Dependency/Directory.Build.props create mode 100644 src/ext/Dependency/Directory.Build.targets create mode 100644 src/ext/Dependency/Directory.csproj.props create mode 100644 src/ext/Dependency/Directory.csproj.targets create mode 100644 src/ext/Dependency/Directory.vcxproj.props create mode 100644 src/ext/Dependency/README.md create mode 100644 src/ext/Dependency/appveyor.cmd create mode 100644 src/ext/Dependency/appveyor.yml create mode 100644 src/ext/Dependency/ca/custommsierrors.h create mode 100644 src/ext/Dependency/ca/dependencyca.vcxproj create mode 100644 src/ext/Dependency/ca/dependencyca.vcxproj.filters create mode 100644 src/ext/Dependency/ca/dllmain.cpp create mode 100644 src/ext/Dependency/ca/precomp.h create mode 100644 src/ext/Dependency/ca/wixdepca.cpp create mode 100644 src/ext/Dependency/ca/wixdepca.def create mode 100644 src/ext/Dependency/nuget.config create mode 100644 src/ext/Dependency/test/WixToolsetTest.Dependency/DependencyExtensionFixture.cs create mode 100644 src/ext/Dependency/test/WixToolsetTest.Dependency/TestData/UsingProvides/Package.en-us.wxl create mode 100644 src/ext/Dependency/test/WixToolsetTest.Dependency/TestData/UsingProvides/Package.wxs create mode 100644 src/ext/Dependency/test/WixToolsetTest.Dependency/WixToolsetTest.Dependency.csproj create mode 100644 src/ext/Dependency/wix.snk create mode 100644 src/ext/Dependency/wixext/DependencyCompiler.cs create mode 100644 src/ext/Dependency/wixext/DependencyDecompiler.cs create mode 100644 src/ext/Dependency/wixext/DependencyExtensionData.cs create mode 100644 src/ext/Dependency/wixext/DependencyExtensionFactory.cs create mode 100644 src/ext/Dependency/wixext/WixToolset.Dependency.wixext.csproj create mode 100644 src/ext/Dependency/wixext/WixToolset.Dependency.wixext.nuspec create mode 100644 src/ext/Dependency/wixext/WixToolset.Dependency.wixext.targets create mode 100644 src/ext/Dependency/wixlib/DependencyExtension.wxs create mode 100644 src/ext/Dependency/wixlib/DependencyExtension_Platform.wxi create mode 100644 src/ext/Dependency/wixlib/DependencyExtension_arm64.wxs create mode 100644 src/ext/Dependency/wixlib/DependencyExtension_x64.wxs create mode 100644 src/ext/Dependency/wixlib/DependencyExtension_x86.wxs create mode 100644 src/ext/Dependency/wixlib/caDecor.wxi create mode 100644 src/ext/Dependency/wixlib/caerr.wxi create mode 100644 src/ext/Dependency/wixlib/dependency.wixproj create mode 100644 src/ext/Dependency/wixlib/en-us.wxl create mode 100644 src/ext/global.json (limited to 'src/ext') diff --git a/src/ext/Dependency/Dependency.wixext.sln b/src/ext/Dependency/Dependency.wixext.sln new file mode 100644 index 00000000..e771ddf6 --- /dev/null +++ b/src/ext/Dependency/Dependency.wixext.sln @@ -0,0 +1,61 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.30204.135 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "dependencyca", "src\ca\dependencyca.vcxproj", "{B86AF46C-0F90-49CC-923F-A800B088D015}" +EndProject +Project("{930C7802-8A8C-48F9-8165-68863BCCD9DD}") = "dependency", "src\wixlib\dependency.wixproj", "{58ED0EC8-73F8-4EE1-8664-A53486D38EC8}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WixToolset.Dependency.wixext", "src\wixext\WixToolset.Dependency.wixext.csproj", "{A0B6D3F1-AE5E-423B-BA92-60C9926CA498}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WixToolsetTest.Dependency", "src\test\WixToolsetTest.Dependency\WixToolsetTest.Dependency.csproj", "{E2AB6AA2-359D-4305-92B0-D90C8F87AF9B}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Debug|x86 = Debug|x86 + Release|Any CPU = Release|Any CPU + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {B86AF46C-0F90-49CC-923F-A800B088D015}.Debug|Any CPU.ActiveCfg = Debug|Win32 + {B86AF46C-0F90-49CC-923F-A800B088D015}.Debug|Any CPU.Build.0 = Debug|Win32 + {B86AF46C-0F90-49CC-923F-A800B088D015}.Debug|x86.ActiveCfg = Debug|Win32 + {B86AF46C-0F90-49CC-923F-A800B088D015}.Debug|x86.Build.0 = Debug|Win32 + {B86AF46C-0F90-49CC-923F-A800B088D015}.Release|Any CPU.ActiveCfg = Release|Win32 + {B86AF46C-0F90-49CC-923F-A800B088D015}.Release|Any CPU.Build.0 = Release|Win32 + {B86AF46C-0F90-49CC-923F-A800B088D015}.Release|x86.ActiveCfg = Release|Win32 + {B86AF46C-0F90-49CC-923F-A800B088D015}.Release|x86.Build.0 = Release|Win32 + {58ED0EC8-73F8-4EE1-8664-A53486D38EC8}.Debug|Any CPU.ActiveCfg = Debug|x86 + {58ED0EC8-73F8-4EE1-8664-A53486D38EC8}.Debug|Any CPU.Build.0 = Debug|x86 + {58ED0EC8-73F8-4EE1-8664-A53486D38EC8}.Debug|x86.ActiveCfg = Debug|x86 + {58ED0EC8-73F8-4EE1-8664-A53486D38EC8}.Debug|x86.Build.0 = Debug|x86 + {58ED0EC8-73F8-4EE1-8664-A53486D38EC8}.Release|Any CPU.ActiveCfg = Release|x86 + {58ED0EC8-73F8-4EE1-8664-A53486D38EC8}.Release|Any CPU.Build.0 = Release|x86 + {58ED0EC8-73F8-4EE1-8664-A53486D38EC8}.Release|x86.ActiveCfg = Release|x86 + {58ED0EC8-73F8-4EE1-8664-A53486D38EC8}.Release|x86.Build.0 = Release|x86 + {A0B6D3F1-AE5E-423B-BA92-60C9926CA498}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A0B6D3F1-AE5E-423B-BA92-60C9926CA498}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A0B6D3F1-AE5E-423B-BA92-60C9926CA498}.Debug|x86.ActiveCfg = Debug|Any CPU + {A0B6D3F1-AE5E-423B-BA92-60C9926CA498}.Debug|x86.Build.0 = Debug|Any CPU + {A0B6D3F1-AE5E-423B-BA92-60C9926CA498}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A0B6D3F1-AE5E-423B-BA92-60C9926CA498}.Release|Any CPU.Build.0 = Release|Any CPU + {A0B6D3F1-AE5E-423B-BA92-60C9926CA498}.Release|x86.ActiveCfg = Release|Any CPU + {A0B6D3F1-AE5E-423B-BA92-60C9926CA498}.Release|x86.Build.0 = Release|Any CPU + {E2AB6AA2-359D-4305-92B0-D90C8F87AF9B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E2AB6AA2-359D-4305-92B0-D90C8F87AF9B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E2AB6AA2-359D-4305-92B0-D90C8F87AF9B}.Debug|x86.ActiveCfg = Debug|Any CPU + {E2AB6AA2-359D-4305-92B0-D90C8F87AF9B}.Debug|x86.Build.0 = Debug|Any CPU + {E2AB6AA2-359D-4305-92B0-D90C8F87AF9B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E2AB6AA2-359D-4305-92B0-D90C8F87AF9B}.Release|Any CPU.Build.0 = Release|Any CPU + {E2AB6AA2-359D-4305-92B0-D90C8F87AF9B}.Release|x86.ActiveCfg = Release|Any CPU + {E2AB6AA2-359D-4305-92B0-D90C8F87AF9B}.Release|x86.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {77F012B1-8E94-4F85-9450-066C6BD15000} + EndGlobalSection +EndGlobal diff --git a/src/ext/Dependency/Directory.Build.props b/src/ext/Dependency/Directory.Build.props new file mode 100644 index 00000000..b3c6287c --- /dev/null +++ b/src/ext/Dependency/Directory.Build.props @@ -0,0 +1,27 @@ + + + + + + Debug + false + MSB3246 + + $(MSBuildProjectName) + $([System.IO.Path]::GetFullPath($(MSBuildThisFileDirectory)..\build\)) + $(BaseOutputPath)obj\$(ProjectName)\ + $(BaseOutputPath)$(Configuration)\ + + WiX Toolset Team + WiX Toolset + Copyright (c) .NET Foundation and contributors. All rights reserved. + MS-RL + WiX Toolset + + + + + diff --git a/src/ext/Dependency/Directory.Build.targets b/src/ext/Dependency/Directory.Build.targets new file mode 100644 index 00000000..2fcc765a --- /dev/null +++ b/src/ext/Dependency/Directory.Build.targets @@ -0,0 +1,51 @@ + + + + + + + true + $(SolutionPath) + $(NCrunchOriginalSolutionPath) + + + + + + + $([System.IO.File]::ReadAllText($(TheSolutionPath))) + $([System.IO.Path]::GetDirectoryName( $(TheSolutionPath) )) + (?<="[PackageName]", ")(.*)(?=", ") + + + + + + %(Identity) + $(SolutionFileContent.Contains('\%(Identity).csproj')) + + + + + $(RegexPattern.Replace('[PackageName]','%(PackageName)') ) + $([System.Text.RegularExpressions.Regex]::Match('$(SolutionFileContent)', '%(Pattern)')) + + + + + + + + + + + + + + diff --git a/src/ext/Dependency/Directory.csproj.props b/src/ext/Dependency/Directory.csproj.props new file mode 100644 index 00000000..81d24ad1 --- /dev/null +++ b/src/ext/Dependency/Directory.csproj.props @@ -0,0 +1,13 @@ + + + + + true + true + $([System.IO.Path]::GetFullPath($(MSBuildThisFileDirectory)wix.snk)) + false + + diff --git a/src/ext/Dependency/Directory.csproj.targets b/src/ext/Dependency/Directory.csproj.targets new file mode 100644 index 00000000..c3270426 --- /dev/null +++ b/src/ext/Dependency/Directory.csproj.targets @@ -0,0 +1,26 @@ + + + + + false + $(OutputPath)\$(AssemblyName).xml + + + + + $(PrivateRepositoryUrl.Replace('.git','')) + + $(MSBuildProjectName).nuspec + $(OutputPath)..\ + $(NuspecProperties);Id=$(PackageId);Authors=$(Authors);Copyright=$(Copyright);Description=$(Description);Title=$(Title) + $(NuspecProperties);Version=$(PackageVersion);RepositoryCommit=$(SourceRevisionId);RepositoryType=$(RepositoryType);RepositoryUrl=$(PrivateRepositoryUrl);ProjectFolder=$(MSBuildProjectDirectory)\;ProjectUrl=$(ProjectUrl) + true + snupkg + + + + diff --git a/src/ext/Dependency/Directory.vcxproj.props b/src/ext/Dependency/Directory.vcxproj.props new file mode 100644 index 00000000..664bc1d8 --- /dev/null +++ b/src/ext/Dependency/Directory.vcxproj.props @@ -0,0 +1,93 @@ + + + + + + Win32 + $(BaseIntermediateOutputPath)$(Configuration)\$(Platform)\ + $(OutputPath)$(Platform)\ + + + $(Company) + $(Copyright) + + win-x86;win-x64;win-arm64 + native,Version=v0.0 + + + + $([Microsoft.Build.Utilities.ToolLocationHelper]::GetLatestSDKTargetPlatformVersion('Windows', '10.0')) + + + + + $(DisableSpecificCompilerWarnings) + Level4 + $(ProjectDir)inc;$(MSBuildProjectDirectory);$(IntDir);$(SqlCESdkIncludePath);$(ProjectAdditionalIncludeDirectories);%(AdditionalIncludeDirectories) + WIN32;_WINDOWS;_WIN32_MSI=500;_WIN32_WINNT=0x0501;$(ArmPreprocessorDefinitions);$(UnicodePreprocessorDefinitions);_CRT_STDIO_LEGACY_WIDE_SPECIFIERS;_WINSOCK_DEPRECATED_NO_WARNINGS;%(PreprocessorDefinitions) + Use + precomp.h + StdCall + true + false + -YlprecompDefine + /Zc:threadSafeInit- %(AdditionalOptions) + true + + + $(ArmPreprocessorDefinitions);%(PreprocessorDefinitions) + $(ProjectAdditionalResourceIncludeDirectories);%(AdditionalIncludeDirectories) + + + $(OutDir);$(AdditionalMultiTargetLibraryPath);$(ProjectAdditionalLibraryDirectories);%(AdditionalLibraryDirectories) + + + $(ProjectSubSystem) + $(ProjectModuleDefinitionFile) + $(ResourceOnlyDll) + true + $(ProjectAdditionalLinkLibraries);advapi32.lib;comdlg32.lib;user32.lib;oleaut32.lib;gdi32.lib;shell32.lib;ole32.lib;version.lib;%(AdditionalDependencies) + $(OutDir);$(AdditionalMultiTargetLibraryPath);$(ArmLibraryDirectories);$(ProjectAdditionalLinkLibraryDirectories);%(AdditionalLibraryDirectories) + /IGNORE:4099 %(AdditionalOptions) + + + + + + NoExtensions + + + + + CDecl + + + + + OldStyle + true + true + + + + + Disabled + EnableFastChecks + _DEBUG;DEBUG;%(PreprocessorDefinitions) + MultiThreadedDebug + + + + + MinSpace + NDEBUG;%(PreprocessorDefinitions) + true + true + MultiThreaded + + + true + true + + + diff --git a/src/ext/Dependency/README.md b/src/ext/Dependency/README.md new file mode 100644 index 00000000..09feba68 --- /dev/null +++ b/src/ext/Dependency/README.md @@ -0,0 +1,2 @@ +# Dependency.wixext +WixToolset.Dependency.wixext - Dependency WiX Toolset Extension diff --git a/src/ext/Dependency/appveyor.cmd b/src/ext/Dependency/appveyor.cmd new file mode 100644 index 00000000..3450d535 --- /dev/null +++ b/src/ext/Dependency/appveyor.cmd @@ -0,0 +1,19 @@ +@setlocal +@pushd %~dp0 +@set _C=Release +@if /i "%1"=="debug" set _C=Debug + +:: Restore +msbuild -p:Configuration=%_C% -t:Restore || exit /b + +:: Build +msbuild -p:Configuration=%_C% src\test\WixToolsetTest.Dependency\WixToolsetTest.Dependency.csproj || exit /b + +:: Test +dotnet test -c %_C% --no-build src\test\WixToolsetTest.Dependency || exit /b + +:: Pack +msbuild -p:Configuration=%_C% -p:NoBuild=true -t:Pack src\wixext\WixToolset.Dependency.wixext.csproj || exit /b + +@popd +@endlocal diff --git a/src/ext/Dependency/appveyor.yml b/src/ext/Dependency/appveyor.yml new file mode 100644 index 00000000..c53cc9cc --- /dev/null +++ b/src/ext/Dependency/appveyor.yml @@ -0,0 +1,42 @@ +# Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. +# +# Do NOT modify this file. Update the canonical version in Home\repo-template\src\appveyor.yml +# then update all of the repos. + +branches: + only: + - master + - develop + +image: Visual Studio 2019 + +version: 0.0.0.{build} +configuration: Release + +environment: + DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true + DOTNET_CLI_TELEMETRY_OPTOUT: 1 + NUGET_XMLDOC_MODE: skip + +build_script: + - appveyor.cmd + +pull_requests: + do_not_increment_build_number: true + +nuget: + disable_publish_on_pr: true + +skip_branch_with_pr: true +skip_tags: true + +artifacts: +- path: build\Release\**\*.nupkg + name: nuget +- path: build\Release\**\*.snupkg + name: snupkg + +notifications: +- provider: Slack + incoming_webhook: + secure: p5xuu+4x2JHfwGDMDe5KcG1k7gZxqYc4jWVwvyNZv5cvkubPD2waJs5yXMAXZNN7Z63/3PWHb7q4KoY/99AjauYa1nZ4c5qYqRPFRBKTHfA= diff --git a/src/ext/Dependency/ca/custommsierrors.h b/src/ext/Dependency/ca/custommsierrors.h new file mode 100644 index 00000000..26450452 --- /dev/null +++ b/src/ext/Dependency/ca/custommsierrors.h @@ -0,0 +1,5 @@ +#pragma once +// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. + +#define msierrDependencyMissingDependencies 26451 +#define msierrDependencyHasDependents 26452 diff --git a/src/ext/Dependency/ca/dependencyca.vcxproj b/src/ext/Dependency/ca/dependencyca.vcxproj new file mode 100644 index 00000000..2a0760d6 --- /dev/null +++ b/src/ext/Dependency/ca/dependencyca.vcxproj @@ -0,0 +1,73 @@ + + + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + Debug + ARM64 + + + Release + ARM64 + + + + + {B86AF46C-0F90-49CC-923F-A800B088D015} + DynamicLibrary + v142 + Unicode + dependencyca + wixdepca.def + WiX Toolset Dependency CustomAction + 10.0 + + + + + + + msi.lib + + + + + Create + + + + + + + + + + + + + + + + + + + + + diff --git a/src/ext/Dependency/ca/dependencyca.vcxproj.filters b/src/ext/Dependency/ca/dependencyca.vcxproj.filters new file mode 100644 index 00000000..bfe457e2 --- /dev/null +++ b/src/ext/Dependency/ca/dependencyca.vcxproj.filters @@ -0,0 +1,36 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Source Files + + + Source Files + + + + + Header Files + + + + + Source Files + + + + \ No newline at end of file diff --git a/src/ext/Dependency/ca/dllmain.cpp b/src/ext/Dependency/ca/dllmain.cpp new file mode 100644 index 00000000..7d299feb --- /dev/null +++ b/src/ext/Dependency/ca/dllmain.cpp @@ -0,0 +1,27 @@ +// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. + +#include "precomp.h" + +/******************************************************************** +DllMain - standard entry point for all WiX custom actions. + +********************************************************************/ +extern "C" BOOL WINAPI DllMain( + IN HINSTANCE hInstance, + IN ULONG ulReason, + IN LPVOID) +{ + switch(ulReason) + { + case DLL_PROCESS_ATTACH: + WcaGlobalInitialize(hInstance); + ::DisableThreadLibraryCalls(hInstance); + break; + + case DLL_PROCESS_DETACH: + WcaGlobalFinalize(); + break; + } + + return TRUE; +} diff --git a/src/ext/Dependency/ca/precomp.h b/src/ext/Dependency/ca/precomp.h new file mode 100644 index 00000000..5fd06cff --- /dev/null +++ b/src/ext/Dependency/ca/precomp.h @@ -0,0 +1,18 @@ +#pragma once +// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. + + +#include +#include +#include +#include + +#include "wcautil.h" +#include "fileutil.h" +#include "strutil.h" +#include "memutil.h" +#include "regutil.h" +#include "dictutil.h" +#include "deputil.h" + +#include "CustomMsiErrors.h" diff --git a/src/ext/Dependency/ca/wixdepca.cpp b/src/ext/Dependency/ca/wixdepca.cpp new file mode 100644 index 00000000..d6433707 --- /dev/null +++ b/src/ext/Dependency/ca/wixdepca.cpp @@ -0,0 +1,516 @@ +// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. + +#include "precomp.h" + +#define IDNOACTION 0 +#define INITIAL_STRINGDICT_SIZE 4 + +LPCWSTR vcsDependencyProviderQuery = + L"SELECT `WixDependencyProvider`.`WixDependencyProvider`, `WixDependencyProvider`.`Component_`, `WixDependencyProvider`.`ProviderKey`, `WixDependencyProvider`.`Attributes` " + L"FROM `WixDependencyProvider`"; +enum eDependencyProviderQuery { dpqId = 1, dpqComponent, dpqProviderKey, dpqAttributes }; + +LPCWSTR vcsDependencyQuery = + L"SELECT `WixDependency`.`WixDependency`, `WixDependencyProvider`.`Component_`, `WixDependency`.`ProviderKey`, `WixDependency`.`MinVersion`, `WixDependency`.`MaxVersion`, `WixDependency`.`Attributes` " + L"FROM `WixDependencyProvider`, `WixDependency`, `WixDependencyRef` " + L"WHERE `WixDependency`.`WixDependency` = `WixDependencyRef`.`WixDependency_` AND `WixDependencyProvider`.`WixDependencyProvider` = `WixDependencyRef`.`WixDependencyProvider_`"; +enum eDependencyComponentQuery { dqId = 1, dqComponent, dqProviderKey, dqMinVersion, dqMaxVersion, dqAttributes }; + +static HRESULT EnsureRequiredDependencies( + __in MSIHANDLE hInstall, + __in BOOL fMachineContext + ); + +static HRESULT EnsureAbsentDependents( + __in MSIHANDLE hInstall, + __in BOOL fMachineContext + ); + +static HRESULT SplitIgnoredDependents( + __deref_inout STRINGDICT_HANDLE* psdIgnoredDependents + ); + +static HRESULT CreateDependencyRecord( + __in int iMessageId, + __in_ecount(cDependencies) const DEPENDENCY* rgDependencies, + __in UINT cDependencies, + __out MSIHANDLE *phRecord + ); + +static LPCWSTR LogDependencyName( + __in_z LPCWSTR wzName + ); + +/*************************************************************************** + WixDependencyRequire - Checks that all required dependencies are installed. + +***************************************************************************/ +extern "C" UINT __stdcall WixDependencyRequire( + __in MSIHANDLE hInstall + ) +{ + HRESULT hr = S_OK; + UINT er = ERROR_SUCCESS; + BOOL fMachineContext = FALSE; + + hr = WcaInitialize(hInstall, "WixDependencyRequire"); + ExitOnFailure(hr, "Failed to initialize."); + + hr = RegInitialize(); + ExitOnFailure(hr, "Failed to initialize the registry functions."); + + // Determine whether we're installing per-user or per-machine. + fMachineContext = WcaIsPropertySet("ALLUSERS"); + + // Check for any provider components being (re)installed that their requirements are already installed. + hr = EnsureRequiredDependencies(hInstall, fMachineContext); + ExitOnFailure(hr, "Failed to ensure required dependencies for (re)installing components."); + +LExit: + RegUninitialize(); + + er = FAILED(hr) ? ERROR_INSTALL_FAILURE : ERROR_SUCCESS; + return WcaFinalize(er); +} + +/*************************************************************************** + WixDependencyCheck - Check dependencies based on component state. + + Note: may return ERROR_NO_MORE_ITEMS to terminate the session early. +***************************************************************************/ +extern "C" UINT __stdcall WixDependencyCheck( + __in MSIHANDLE hInstall + ) +{ + HRESULT hr = S_OK; + UINT er = ERROR_SUCCESS; + BOOL fMachineContext = FALSE; + + hr = WcaInitialize(hInstall, "WixDependencyCheck"); + ExitOnFailure(hr, "Failed to initialize."); + + hr = RegInitialize(); + ExitOnFailure(hr, "Failed to initialize the registry functions."); + + // Determine whether we're installing per-user or per-machine. + fMachineContext = WcaIsPropertySet("ALLUSERS"); + + // Check for any dependents of provider components being uninstalled. + hr = EnsureAbsentDependents(hInstall, fMachineContext); + ExitOnFailure(hr, "Failed to ensure absent dependents for uninstalling components."); + +LExit: + RegUninitialize(); + + er = FAILED(hr) ? ERROR_INSTALL_FAILURE : ERROR_SUCCESS; + return WcaFinalize(er); +} + +/*************************************************************************** + EnsureRequiredDependencies - Check that dependencies are installed for + any provider component that is being installed or reinstalled. + + Note: Skipped if DISABLEDEPENDENCYCHECK is set. +***************************************************************************/ +static HRESULT EnsureRequiredDependencies( + __in MSIHANDLE /*hInstall*/, + __in BOOL fMachineContext + ) +{ + HRESULT hr = S_OK; + DWORD er = ERROR_SUCCESS; + STRINGDICT_HANDLE sdDependencies = NULL; + HKEY hkHive = NULL; + PMSIHANDLE hView = NULL; + PMSIHANDLE hRec = NULL; + LPWSTR sczId = NULL; + LPWSTR sczComponent = NULL; + LPWSTR sczProviderKey = NULL; + LPWSTR sczMinVersion = NULL; + LPWSTR sczMaxVersion = NULL; + int iAttributes = 0; + WCA_TODO tComponentAction = WCA_TODO_UNKNOWN; + DEPENDENCY* rgDependencies = NULL; + UINT cDependencies = 0; + PMSIHANDLE hDependencyRec = NULL; + + // Skip the dependency check if the WixDependency table is missing (no dependencies to check for). + hr = WcaTableExists(L"WixDependency"); + if (S_FALSE == hr) + { + WcaLog(LOGMSG_STANDARD, "Skipping the dependency check since no dependencies are authored."); + ExitFunction1(hr = S_OK); + } + + // If the table exists but not the others, the database was not authored correctly. + ExitOnFailure(hr, "Failed to check if the WixDependency table exists."); + + // Initialize the dictionary to keep track of unique dependency keys. + hr = DictCreateStringList(&sdDependencies, INITIAL_STRINGDICT_SIZE, DICT_FLAG_CASEINSENSITIVE); + ExitOnFailure(hr, "Failed to initialize the unique dependency string list."); + + // Set the registry hive to use depending on install context. + hkHive = fMachineContext ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; + + // Loop over the provider components. + hr = WcaOpenExecuteView(vcsDependencyQuery, &hView); + ExitOnFailure(hr, "Failed to open the query view for dependencies."); + + while (S_OK == (hr = WcaFetchRecord(hView, &hRec))) + { + hr = WcaGetRecordString(hRec, dqId, &sczId); + ExitOnFailure(hr, "Failed to get WixDependency.WixDependency."); + + hr = WcaGetRecordString(hRec, dqComponent, &sczComponent); + ExitOnFailure(hr, "Failed to get WixDependencyProvider.Component_."); + + // Skip the current component if its not being installed or reinstalled. + tComponentAction = WcaGetComponentToDo(sczComponent); + if (WCA_TODO_INSTALL != tComponentAction && WCA_TODO_REINSTALL != tComponentAction) + { + WcaLog(LOGMSG_STANDARD, "Skipping dependency check for %ls because the component %ls is not being (re)installed.", sczId, sczComponent); + continue; + } + + hr = WcaGetRecordString(hRec, dqProviderKey, &sczProviderKey); + ExitOnFailure(hr, "Failed to get WixDependency.ProviderKey."); + + hr = WcaGetRecordString(hRec, dqMinVersion, &sczMinVersion); + ExitOnFailure(hr, "Failed to get WixDependency.MinVersion."); + + hr = WcaGetRecordString(hRec, dqMaxVersion, &sczMaxVersion); + ExitOnFailure(hr, "Failed to get WixDependency.MaxVersion."); + + hr = WcaGetRecordInteger(hRec, dqAttributes, &iAttributes); + ExitOnFailure(hr, "Failed to get WixDependency.Attributes."); + + // Check the registry to see if the required providers (dependencies) exist. + hr = DepCheckDependency(hkHive, sczProviderKey, sczMinVersion, sczMaxVersion, iAttributes, sdDependencies, &rgDependencies, &cDependencies); + if (E_NOTFOUND != hr) + { + ExitOnFailure(hr, "Failed dependency check for %ls.", sczId); + } + } + + if (E_NOMOREITEMS != hr) + { + ExitOnFailure(hr, "Failed to enumerate all of the rows in the dependency query view."); + } + else + { + hr = S_OK; + } + + // If we collected any dependencies in the previous check, pump a message and prompt the user. + if (0 < cDependencies) + { + hr = CreateDependencyRecord(msierrDependencyMissingDependencies, rgDependencies, cDependencies, &hDependencyRec); + ExitOnFailure(hr, "Failed to create the dependency record for message %d.", msierrDependencyMissingDependencies); + + // Send a yes/no message with a warning icon since continuing could be detrimental. + // This is sent as a USER message to better detect whether a user or dependency-aware bootstrapper is responding + // or if Windows Installer or a dependency-unaware boostrapper is returning a typical default response. + er = WcaProcessMessage(static_cast(INSTALLMESSAGE_USER | MB_ICONWARNING | MB_YESNO | MB_DEFBUTTON2), hDependencyRec); + switch (er) + { + // Only a user or dependency-aware bootstrapper that prompted the user should return IDYES to continue anyway. + case IDYES: + ExitFunction1(hr = S_OK); + + // Only a user or dependency-aware bootstrapper that prompted the user should return IDNO to terminate the operation. + case IDNO: + WcaSetReturnValue(ERROR_INSTALL_USEREXIT); + ExitFunction1(hr = S_OK); + + // A dependency-aware bootstrapper should return IDCANCEL if running silently and the operation should be canceled. + case IDCANCEL: + __fallthrough; + + // Bootstrappers which are not dependency-aware may return IDOK for unhandled messages. + case IDOK: + __fallthrough; + + // Windows Installer returns 0 for USER messages when silent or passive, or when a bootstrapper does not handle the message. + case IDNOACTION: + WcaSetReturnValue(ERROR_INSTALL_FAILURE); + ExitFunction1(hr = S_OK); + + default: + ExitOnFailure(hr = E_UNEXPECTED, "Unexpected message response %d from user or bootstrapper application.", er); + } + } + +LExit: + ReleaseDependencyArray(rgDependencies, cDependencies); + ReleaseStr(sczId); + ReleaseStr(sczComponent); + ReleaseStr(sczProviderKey); + ReleaseStr(sczMinVersion); + ReleaseStr(sczMaxVersion); + ReleaseDict(sdDependencies); + + return hr; +} + +/*************************************************************************** + EnsureAbsentDependents - Checks that there are no dependents + registered for providers that are being uninstalled. + + Note: Skipped if UPGRADINGPRODUCTCODE is set. +***************************************************************************/ +static HRESULT EnsureAbsentDependents( + __in MSIHANDLE /*hInstall*/, + __in BOOL fMachineContext + ) +{ + HRESULT hr = S_OK; + DWORD er = ERROR_SUCCESS; + STRINGDICT_HANDLE sdIgnoredDependents = NULL; + HKEY hkHive = NULL; + PMSIHANDLE hView = NULL; + PMSIHANDLE hRec = NULL; + LPWSTR sczId = NULL; + LPWSTR sczComponent = NULL; + LPWSTR sczProviderKey = NULL; + int iAttributes = 0; + WCA_TODO tComponentAction = WCA_TODO_UNKNOWN; + DEPENDENCY* rgDependents = NULL; + UINT cDependents = 0; + PMSIHANDLE hDependencyRec = NULL; + + // Skip the dependent check if the WixDependencyProvider table is missing (no dependency providers). + hr = WcaTableExists(L"WixDependencyProvider"); + if (S_FALSE == hr) + { + WcaLog(LOGMSG_STANDARD, "Skipping the dependents check since no dependency providers are authored."); + ExitFunction1(hr = S_OK); + } + + ExitOnFailure(hr, "Failed to check if the WixDependencyProvider table exists."); + + // Split the IGNOREDEPENDENCIES property for use below if set. If it is "ALL", then quit now. + hr = SplitIgnoredDependents(&sdIgnoredDependents); + ExitOnFailure(hr, "Failed to get the ignored dependents."); + + hr = DictKeyExists(sdIgnoredDependents, L"ALL"); + if (E_NOTFOUND != hr) + { + ExitOnFailure(hr, "Failed to check if \"ALL\" was set in IGNOREDEPENDENCIES."); + + // Otherwise... + WcaLog(LOGMSG_STANDARD, "Skipping the dependencies check since IGNOREDEPENDENCIES contains \"ALL\"."); + ExitFunction(); + } + else + { + // Key was not found, so proceed. + hr = S_OK; + } + + // Set the registry hive to use depending on install context. + hkHive = fMachineContext ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; + + // Loop over the provider components. + hr = WcaOpenExecuteView(vcsDependencyProviderQuery, &hView); + ExitOnFailure(hr, "Failed to open the query view for dependency providers."); + + while (S_OK == (hr = WcaFetchRecord(hView, &hRec))) + { + hr = WcaGetRecordString(hRec, dpqId, &sczId); + ExitOnFailure(hr, "Failed to get WixDependencyProvider.WixDependencyProvider."); + + hr = WcaGetRecordString(hRec, dpqComponent, &sczComponent); + ExitOnFailure(hr, "Failed to get WixDependencyProvider.Component."); + + // Skip the current component if its not being uninstalled. + tComponentAction = WcaGetComponentToDo(sczComponent); + if (WCA_TODO_UNINSTALL != tComponentAction) + { + WcaLog(LOGMSG_STANDARD, "Skipping dependents check for %ls because the component %ls is not being uninstalled.", sczId, sczComponent); + continue; + } + + hr = WcaGetRecordString(hRec, dpqProviderKey, &sczProviderKey); + ExitOnFailure(hr, "Failed to get WixDependencyProvider.ProviderKey."); + + hr = WcaGetRecordInteger(hRec, dpqAttributes, &iAttributes); + ExitOnFailure(hr, "Failed to get WixDependencyProvider.Attributes."); + + // Check the registry to see if the provider has any dependents registered. + hr = DepCheckDependents(hkHive, sczProviderKey, iAttributes, sdIgnoredDependents, &rgDependents, &cDependents); + ExitOnFailure(hr, "Failed dependents check for %ls.", sczId); + } + + if (E_NOMOREITEMS != hr) + { + ExitOnFailure(hr, "Failed to enumerate all of the rows in the dependency provider query view."); + } + else + { + hr = S_OK; + } + + // If we collected any providers with dependents in the previous check, pump a message and prompt the user. + if (0 < cDependents) + { + hr = CreateDependencyRecord(msierrDependencyHasDependents, rgDependents, cDependents, &hDependencyRec); + ExitOnFailure(hr, "Failed to create the dependency record for message %d.", msierrDependencyHasDependents); + + // Send a yes/no message with a warning icon since continuing could be detrimental. + // This is sent as a USER message to better detect whether a user or dependency-aware bootstrapper is responding + // or if Windows Installer or a dependency-unaware boostrapper is returning a typical default response. + er = WcaProcessMessage(static_cast(INSTALLMESSAGE_USER | MB_ICONWARNING | MB_YESNO | MB_DEFBUTTON2), hDependencyRec); + switch (er) + { + // Only a user or dependency-aware bootstrapper that prompted the user should return IDYES to continue anyway. + case IDYES: + ExitFunction1(hr = S_OK); + + // Only a user or dependency-aware bootstrapper that prompted the user should return IDNO to terminate the operation. + case IDNO: + __fallthrough; + + // Bootstrappers which are not dependency-aware may return IDOK for unhandled messages. + case IDOK: + __fallthrough; + + // Windows Installer returns 0 for USER messages when silent or passive, or when a bootstrapper does not handle the message. + case IDNOACTION: + WcaSetReturnValue(ERROR_NO_MORE_ITEMS); + ExitFunction1(hr = S_OK); + + // A dependency-aware bootstrapper should return IDCANCEL if running silently and the operation should be canceled. + case IDCANCEL: + WcaSetReturnValue(ERROR_INSTALL_FAILURE); + ExitFunction1(hr = S_OK); + + default: + hr = E_UNEXPECTED; + ExitOnFailure(hr, "Unexpected message response %d from user or bootstrapper application.", er); + } + } + +LExit: + ReleaseDependencyArray(rgDependents, cDependents); + ReleaseStr(sczId); + ReleaseStr(sczComponent); + ReleaseStr(sczProviderKey); + + return hr; +} + +/*************************************************************************** + SplitIgnoredDependents - Splits the IGNOREDEPENDENCIES property into a map. + +***************************************************************************/ +static HRESULT SplitIgnoredDependents( + __deref_inout STRINGDICT_HANDLE* psdIgnoredDependents + ) +{ + HRESULT hr = S_OK; + LPWSTR sczIgnoreDependencies = NULL; + LPCWSTR wzDelim = L";"; + LPWSTR wzContext = NULL; + + hr = WcaGetProperty(L"IGNOREDEPENDENCIES", &sczIgnoreDependencies); + ExitOnFailure(hr, "Failed to get the string value of the IGNOREDEPENDENCIES property."); + + hr = DictCreateStringList(psdIgnoredDependents, INITIAL_STRINGDICT_SIZE, DICT_FLAG_CASEINSENSITIVE); + ExitOnFailure(hr, "Failed to create the string dictionary."); + + // Parse through the semicolon-delimited tokens and add to the string dictionary. + for (LPCWSTR wzToken = ::wcstok_s(sczIgnoreDependencies, wzDelim, &wzContext); wzToken; wzToken = ::wcstok_s(NULL, wzDelim, &wzContext)) + { + hr = DictAddKey(*psdIgnoredDependents, wzToken); + ExitOnFailure(hr, "Failed to ignored dependency \"%ls\" to the string dictionary.", wzToken); + } + +LExit: + ReleaseStr(sczIgnoreDependencies); + + return hr; +} + +/*************************************************************************** + CreateDependencyRecord - Creates a record containing the message template + and records to send to the UI handler. + + Notes: Callers should call WcaProcessMessage and handle return codes. +***************************************************************************/ +static HRESULT CreateDependencyRecord( + __in int iMessageId, + __in_ecount(cDependencies) const DEPENDENCY* rgDependencies, + __in UINT cDependencies, + __out MSIHANDLE *phRecord + ) +{ + HRESULT hr = S_OK; + UINT er = ERROR_SUCCESS; + UINT cParams = 0; + UINT iParam = 0; + + // Should not be PMSIHANDLE. + MSIHANDLE hRec = NULL; + + // Calculate the number of parameters based on the format: + // msgId, count, key1, name1, key2, name2, etc. + cParams = 2 + 2 * cDependencies; + + hRec = ::MsiCreateRecord(cParams); + ExitOnNull(hRec, hr, E_OUTOFMEMORY, "Not enough memory to create the message record."); + + er = ::MsiRecordSetInteger(hRec, ++iParam, iMessageId); + ExitOnFailure(hr = HRESULT_FROM_WIN32(er), "Failed to set the message identifier into the message record."); + + er = ::MsiRecordSetInteger(hRec, ++iParam, cDependencies); + ExitOnFailure(hr = HRESULT_FROM_WIN32(er), "Failed to set the number of dependencies into the message record."); + + // Now loop through each dependency and add the key and name to the record. + for (UINT i = 0; i < cDependencies; i++) + { + const DEPENDENCY* pDependency = &rgDependencies[i]; + + // Log message type-specific information. + switch (iMessageId) + { + // Send a user message when installing a component that is missing some dependencies. + case msierrDependencyMissingDependencies: + WcaLog(LOGMSG_VERBOSE, "The dependency \"%ls\" is missing or is not the required version.", pDependency->sczKey); + break; + + // Send a user message when uninstalling a component that still has registered dependents. + case msierrDependencyHasDependents: + WcaLog(LOGMSG_VERBOSE, "Found dependent \"%ls\", name: \"%ls\".", pDependency->sczKey, LogDependencyName(pDependency->sczName)); + break; + } + + er = ::MsiRecordSetStringW(hRec, ++iParam, pDependency->sczKey); + ExitOnFailure(hr = HRESULT_FROM_WIN32(er), "Failed to set the dependency key \"%ls\" into the message record.", pDependency->sczKey); + + er = ::MsiRecordSetStringW(hRec, ++iParam, pDependency->sczName); + ExitOnFailure(hr = HRESULT_FROM_WIN32(er), "Failed to set the dependency name \"%ls\" into the message record.", pDependency->sczName); + } + + // Only assign the out parameter if successful to this point. + *phRecord = hRec; + hRec = NULL; + +LExit: + if (hRec) + { + ::MsiCloseHandle(hRec); + } + + return hr; +} + +/*************************************************************************** + LogDependencyName - Returns the dependency name or "Unknown" if null. + +***************************************************************************/ +static LPCWSTR LogDependencyName( + __in_z LPCWSTR wzName + ) +{ + return wzName ? wzName : L"Unknown"; +} diff --git a/src/ext/Dependency/ca/wixdepca.def b/src/ext/Dependency/ca/wixdepca.def new file mode 100644 index 00000000..651c6373 --- /dev/null +++ b/src/ext/Dependency/ca/wixdepca.def @@ -0,0 +1,8 @@ +; Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. + + +LIBRARY "dependencyca" + +EXPORTS + WixDependencyRequire + WixDependencyCheck diff --git a/src/ext/Dependency/nuget.config b/src/ext/Dependency/nuget.config new file mode 100644 index 00000000..10ef488d --- /dev/null +++ b/src/ext/Dependency/nuget.config @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/ext/Dependency/test/WixToolsetTest.Dependency/DependencyExtensionFixture.cs b/src/ext/Dependency/test/WixToolsetTest.Dependency/DependencyExtensionFixture.cs new file mode 100644 index 00000000..708ae658 --- /dev/null +++ b/src/ext/Dependency/test/WixToolsetTest.Dependency/DependencyExtensionFixture.cs @@ -0,0 +1,38 @@ +// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. + +namespace WixToolsetTest.Dependency +{ + using System.Linq; + using System.Text.RegularExpressions; + using WixBuildTools.TestSupport; + using WixToolset.Core.TestPackage; + using WixToolset.Dependency; + using Xunit; + + public class DependencyExtensionFixture + { + [Fact] + public void CanBuildUsingProvides() + { + var folder = TestData.Get(@"TestData\UsingProvides"); + var build = new Builder(folder, typeof(DependencyExtensionFactory), new[] { folder }); + + var results = build.BuildAndQuery(Build, "CustomAction", "WixDependencyProvider") + .Select(r => Regex.Replace(r, "{[^}]*}", "{*}")) + .ToArray(); + WixAssert.CompareLineByLine(new[] + { + "CustomAction:Wix4DependencyCheck_X86\t1\tDependencyCA_X86\tWixDependencyCheck\t", + "CustomAction:Wix4DependencyRequire_X86\t1\tDependencyCA_X86\tWixDependencyRequire\t", + "WixDependencyProvider:dep74OfIcniaqxA7EprRGBw4Oyy3r8\tfilF5_pLhBuF5b4N9XEo52g_hUM5Lo\tUsingProvides\t\t\t", + "WixDependencyProvider:depTpv28q7slcxvXPWmU4Z0GfbiI.4\tfilF5_pLhBuF5b4N9XEo52g_hUM5Lo\t{*}\t\t\t", + }, results); + } + + private static void Build(string[] args) + { + var result = WixRunner.Execute(args) + .AssertSuccess(); + } + } +} diff --git a/src/ext/Dependency/test/WixToolsetTest.Dependency/TestData/UsingProvides/Package.en-us.wxl b/src/ext/Dependency/test/WixToolsetTest.Dependency/TestData/UsingProvides/Package.en-us.wxl new file mode 100644 index 00000000..38c12ac1 --- /dev/null +++ b/src/ext/Dependency/test/WixToolsetTest.Dependency/TestData/UsingProvides/Package.en-us.wxl @@ -0,0 +1,11 @@ + + + + + + A newer version of [ProductName] is already installed. + MsiPackage + + diff --git a/src/ext/Dependency/test/WixToolsetTest.Dependency/TestData/UsingProvides/Package.wxs b/src/ext/Dependency/test/WixToolsetTest.Dependency/TestData/UsingProvides/Package.wxs new file mode 100644 index 00000000..65984395 --- /dev/null +++ b/src/ext/Dependency/test/WixToolsetTest.Dependency/TestData/UsingProvides/Package.wxs @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/src/ext/Dependency/test/WixToolsetTest.Dependency/WixToolsetTest.Dependency.csproj b/src/ext/Dependency/test/WixToolsetTest.Dependency/WixToolsetTest.Dependency.csproj new file mode 100644 index 00000000..0b80dc83 --- /dev/null +++ b/src/ext/Dependency/test/WixToolsetTest.Dependency/WixToolsetTest.Dependency.csproj @@ -0,0 +1,39 @@ + + + + + + netcoreapp3.1 + embedded + false + + + + NU1701 + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/ext/Dependency/wix.snk b/src/ext/Dependency/wix.snk new file mode 100644 index 00000000..3908a66a Binary files /dev/null and b/src/ext/Dependency/wix.snk differ diff --git a/src/ext/Dependency/wixext/DependencyCompiler.cs b/src/ext/Dependency/wixext/DependencyCompiler.cs new file mode 100644 index 00000000..3d6c84a7 --- /dev/null +++ b/src/ext/Dependency/wixext/DependencyCompiler.cs @@ -0,0 +1,61 @@ +// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. + +namespace WixToolset.Dependency +{ + using System.Collections.Generic; + using System.Xml.Linq; + using WixToolset.Data; + using WixToolset.Extensibility; + using WixToolset.Extensibility.Data; + + /// + /// The compiler for the WiX Toolset Dependency Extension. + /// + public sealed class DependencyCompiler : BaseCompilerExtension + { + public override XNamespace Namespace => "http://wixtoolset.org/schemas/v4/wxs/dependency"; + + /// + /// Processes an attribute for the Compiler. + /// + /// Source line number for the parent element. + /// Parent element of attribute. + /// Attribute to process. + public override void ParseAttribute(Intermediate intermediate, IntermediateSection section, XElement parentElement, XAttribute attribute, IDictionary context) + { + var sourceLineNumbers = this.ParseHelper.GetSourceLineNumbers(parentElement); + var addCheck = YesNoType.NotSet; + var addRequire = YesNoType.NotSet; + + switch (parentElement.Name.LocalName) + { + case "Provides": + if (attribute.Name.LocalName == "Check" && parentElement.Parent?.Name.LocalName == "Component") + { + addCheck = this.ParseHelper.GetAttributeYesNoValue(sourceLineNumbers, attribute); + } + break; + case "Requires": + case "RequiresRef": + if (attribute.Name.LocalName == "Enforce" && parentElement.Parent?.Parent?.Name.LocalName == "Component") + { + addRequire = this.ParseHelper.GetAttributeYesNoValue(sourceLineNumbers, attribute); + } + break; + } + + if (addCheck == YesNoType.NotSet && addRequire == YesNoType.NotSet) + { + this.ParseHelper.UnexpectedAttribute(parentElement, attribute); + } + else if (addCheck == YesNoType.Yes) + { + this.ParseHelper.CreateCustomActionReference(sourceLineNumbers, section, "Wix4DependencyCheck", this.Context.Platform, CustomActionPlatforms.X86 | CustomActionPlatforms.X64 | CustomActionPlatforms.ARM64); + } + else if (addRequire == YesNoType.Yes) + { + this.ParseHelper.CreateCustomActionReference(sourceLineNumbers, section, "Wix4DependencyRequire", this.Context.Platform, CustomActionPlatforms.X86 | CustomActionPlatforms.X64 | CustomActionPlatforms.ARM64); + } + } + } +} diff --git a/src/ext/Dependency/wixext/DependencyDecompiler.cs b/src/ext/Dependency/wixext/DependencyDecompiler.cs new file mode 100644 index 00000000..31de3097 --- /dev/null +++ b/src/ext/Dependency/wixext/DependencyDecompiler.cs @@ -0,0 +1,347 @@ +// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. + +namespace WixToolset.Dependency +{ +#if TODO_CONSIDER_DECOMPILER + using System; + using System.Collections.Generic; + using System.Collections.ObjectModel; + using WixToolset; + using WixToolset.Data; + using WixToolset.Extensibility; + using WixToolset.Extensions.Serialize.Dependency; + using Dependency = WixToolset.Extensions.Serialize.Dependency; + using Wix = WixToolset.Data.Serialize; + + /// + /// The decompiler for the WiX toolset dependency extension. + /// + public sealed class DependencyDecompiler : DecompilerExtension + { + private RegistryKeyValueCollection registryValues; + private Dictionary keyCache; + + /// + /// Creates a new instance of the class. + /// + public DependencyDecompiler() + { + this.registryValues = new RegistryKeyValueCollection(); + this.keyCache = new Dictionary(); + + this.TableDefinitions = DependencyExtensionData.GetExtensionTableDefinitions(); + } + + /// + /// Get the extensions library to be removed. + /// + /// Table definitions for library. + /// Library to remove from decompiled output. + public override Library GetLibraryToRemove(TableDefinitionCollection tableDefinitions) + { + return DependencyExtensionData.GetExtensionLibrary(tableDefinitions); + } + + /// + /// Decompiles an extension table. + /// + /// The table to decompile. + public override void DecompileTable(Table table) + { + switch (table.Name) + { + case "WixDependencyProvider": + this.DecompileWixDependencyProviderTable(table); + break; + + case "WixDependency": + this.DecompileWixDependencyTable(table); + break; + + case "WixDependencyRef": + this.DecompileWixDependencyRefTable(table); + break; + + default: + base.DecompileTable(table); + break; + } + } + + /// + /// Finalize decompilation by removing registry values that the compiler writes. + /// + /// The collection of all tables. + public override void Finish(TableIndexedCollection tables) + { + // Remove generated registry rows. + this.FinalizeRegistryTable(tables); + + // Remove extension properties. + this.FinalizeProperties(); + } + + /// + /// Decompiles the WixDependencyProvider table. + /// + /// The table to decompile. + private void DecompileWixDependencyProviderTable(Table table) + { + foreach (Row row in table.Rows) + { + Provides provides = new Provides(); + + provides.Id = (string)row[0]; + provides.Key = (string)row[2]; + + if (null != row[3]) + { + provides.Version = (string)row[3]; + } + + if (null != row[4]) + { + provides.DisplayName = (string)row[4]; + } + + // Nothing to parse for attributes currently. + + Wix.Component component = (Wix.Component)this.Core.GetIndexedElement("Component", (string)row[1]); + if (null != component) + { + component.AddChild(provides); + } + else + { + this.Core.OnMessage(WixWarnings.ExpectedForeignRow(row.SourceLineNumbers, table.Name, row.GetPrimaryKey(DecompilerConstants.PrimaryKeyDelimiter), "Component_", (string)row[1], "Component")); + } + + // Index the provider to parent the RequiresRef elements. + this.Core.IndexElement(row, provides); + + // Add the provider-specific registry keys to be removed during finalization. + // Only remove specific keys that the compiler writes. + string keyProvides = String.Concat(DependencyCommon.RegistryRoot, provides.Key); + + this.registryValues.Add(keyProvides, null); + this.registryValues.Add(keyProvides, "Version"); + this.registryValues.Add(keyProvides, "DisplayName"); + this.registryValues.Add(keyProvides, "Attributes"); + + // Cache the provider key. + this.keyCache[provides.Id] = provides.Key; + } + } + + /// + /// Decompiles the WixDependency table. + /// + /// The table to decompile. + private void DecompileWixDependencyTable(Table table) + { + foreach (Row row in table.Rows) + { + Requires requires = new Requires(); + + requires.Id = (string)row[0]; + requires.ProviderKey = (string)row[1]; + + if (null != row[2]) + { + requires.Minimum = (string)row[2]; + } + + if (null != row[3]) + { + requires.Maximum = (string)row[3]; + } + + if (null != row[4]) + { + int attributes = (int)row[4]; + + if (0 != (attributes & DependencyCommon.RequiresAttributesMinVersionInclusive)) + { + requires.IncludeMinimum = Dependency.YesNoType.yes; + } + + if (0 != (attributes & DependencyCommon.RequiresAttributesMaxVersionInclusive)) + { + requires.IncludeMaximum = Dependency.YesNoType.yes; + } + } + + this.Core.RootElement.AddChild(requires); + + // Cache the requires key. + this.keyCache[requires.Id] = requires.ProviderKey; + } + } + + /// + /// Decompiles the WixDependencyRef table. + /// + /// The table to decompile. + private void DecompileWixDependencyRefTable(Table table) + { + foreach (Row row in table.Rows) + { + RequiresRef requiresRef = new RequiresRef(); + + requiresRef.Id = (string)row[1]; + + Provides provides = (Provides)this.Core.GetIndexedElement("WixDependencyProvider", (string)row[0]); + if (null != provides) + { + provides.AddChild(requiresRef); + } + else + { + this.Core.OnMessage(WixWarnings.ExpectedForeignRow(row.SourceLineNumbers, table.Name, row.GetPrimaryKey(DecompilerConstants.PrimaryKeyDelimiter), "WixDependencyProvider_", (string)row[0], "WixDependencyProvider")); + } + + // Get the cached keys for the provider and dependency IDs and generate registry rows. + string providesKey = null; + string requiresKey = null; + + if (null != provides && this.keyCache.ContainsKey(provides.Id)) + { + providesKey = this.keyCache[provides.Id]; + } + else + { + this.Core.OnMessage(DependencyWarnings.ProvidesKeyNotFound(row.SourceLineNumbers, provides.Id)); + } + + if (this.keyCache.ContainsKey(requiresRef.Id)) + { + requiresKey = this.keyCache[requiresRef.Id]; + } + else + { + this.Core.OnMessage(DependencyWarnings.RequiresKeyNotFound(row.SourceLineNumbers, requiresRef.Id)); + } + + if (!this.Core.EncounteredError) + { + // Add the dependency-specific registry keys to be removed during finalization. + // Only remove specific keys that the compiler writes. + string keyRequires = String.Format(@"{0}{1}\{2}\{3}", DependencyCommon.RegistryRoot, requiresKey, DependencyCommon.RegistryDependents, providesKey); + + this.registryValues.Add(keyRequires, "*"); + this.registryValues.Add(keyRequires, "MinVersion"); + this.registryValues.Add(keyRequires, "MaxVersion"); + this.registryValues.Add(keyRequires, "Attributes"); + } + } + } + + /// + /// Removes rows from the Registry table that are generated by this extension. + /// + /// The collection of tables. + private void FinalizeRegistryTable(TableIndexedCollection tables) + { + Table registryTable = tables["Registry"]; + if (null != registryTable) + { + foreach (Row registryRow in registryTable.Rows) + { + // Check if the compiler writes this registry value; if so, it should be removed. + if (this.registryValues.Contains(registryRow)) + { + Wix.ISchemaElement elem = this.Core.GetIndexedElement(registryRow); + + // If the registry row was found, remove it from its parent. + if (null != elem && null != elem.ParentElement) + { + Wix.IParentElement elemParent = elem.ParentElement as Wix.IParentElement; + if (null != elemParent) + { + elemParent.RemoveChild(elem); + } + } + } + } + } + } + + /// + /// Removes properties defined by this extension. + /// + /// The collection of tables. + private void FinalizeProperties() + { + string[] properties = new string[] { "DISABLEDEPENDENCYCHECK", "IGNOREDEPENDENCIES" }; + foreach (string property in properties) + { + Wix.Property elem = this.Core.GetIndexedElement("Property", property) as Wix.Property; + if (null != elem) + { + // If a value is defined, log a warning we're removing it. + if (!String.IsNullOrEmpty(elem.Value)) + { + this.Core.OnMessage(DependencyWarnings.PropertyRemoved(elem.Id)); + } + + // If the property row was found, remove it from its parent. + if (null != elem.ParentElement) + { + Wix.IParentElement elemParent = elem.ParentElement as Wix.IParentElement; + if (null != elemParent) + { + elemParent.RemoveChild(elem); + } + } + } + } + } + + /// + /// Provides an O(1) lookup for registry key and value name pairs for use in the decompiler. + /// + private sealed class RegistryKeyValueCollection : KeyedCollection> + { + /// + /// Adds the registry key and value name pair to the collection if it doesn't already exist. + /// + /// The registry key to add. + /// The registry value name to add. + internal void Add(string key, string name) + { + KeyValuePair pair = new KeyValuePair(key, name); + if (!this.Contains(pair)) + { + this.Add(pair); + } + } + + /// + /// Returns whether the collection contains the registry key and value name pair from the . + /// + /// The registry to search for. + /// True if the collection contains the registry key and value name pair from the ; otherwise, false. + internal bool Contains(Row row) + { + if (null == row) + { + return false; + } + + KeyValuePair pair = new KeyValuePair((string)row[2], (string)row[3]); + return this.Contains(pair); + } + + /// + /// Return the hash code of the key and value pair concatenated with a colon as a delimiter. + /// + /// The registry key and value name pair. + /// + protected override int GetKeyForItem(KeyValuePair pair) + { + return String.Concat(pair.Key, ":", pair.Value).GetHashCode(); + } + } + } +#endif +} diff --git a/src/ext/Dependency/wixext/DependencyExtensionData.cs b/src/ext/Dependency/wixext/DependencyExtensionData.cs new file mode 100644 index 00000000..2f30c2bf --- /dev/null +++ b/src/ext/Dependency/wixext/DependencyExtensionData.cs @@ -0,0 +1,29 @@ +// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. + +namespace WixToolset.Dependency +{ + using WixToolset.Data; + using WixToolset.Extensibility; + + /// + /// The WiX Toolset Dependency Extension. + /// + public sealed class DependencyExtensionData : BaseExtensionData + { + /// + /// Gets the default culture. + /// + /// The default culture. + public override string DefaultCulture => "en-US"; + + /// + /// Gets the contained .wixlib content. + /// + /// Strong typed symbold definitions. + /// The .wixlib. + public override Intermediate GetLibrary(ISymbolDefinitionCreator symbolDefinitions) + { + return Intermediate.Load(typeof(DependencyExtensionData).Assembly, "WixToolset.Dependency.dependency.wixlib", symbolDefinitions); + } + } +} diff --git a/src/ext/Dependency/wixext/DependencyExtensionFactory.cs b/src/ext/Dependency/wixext/DependencyExtensionFactory.cs new file mode 100644 index 00000000..413f99ae --- /dev/null +++ b/src/ext/Dependency/wixext/DependencyExtensionFactory.cs @@ -0,0 +1,17 @@ +// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. + +namespace WixToolset.Dependency +{ + using System; + using System.Collections.Generic; + using WixToolset.Extensibility; + + public class DependencyExtensionFactory : BaseExtensionFactory + { + protected override IReadOnlyCollection ExtensionTypes => new[] + { + typeof(DependencyCompiler), + typeof(DependencyExtensionData), + }; + } +} diff --git a/src/ext/Dependency/wixext/WixToolset.Dependency.wixext.csproj b/src/ext/Dependency/wixext/WixToolset.Dependency.wixext.csproj new file mode 100644 index 00000000..b2663231 --- /dev/null +++ b/src/ext/Dependency/wixext/WixToolset.Dependency.wixext.csproj @@ -0,0 +1,32 @@ + + + + + + netstandard2.0 + embedded + WixToolset.Dependency + WiX Toolset Dependency Extension + WiX Toolset Dependency Extension + true + true + + + + + + + + + + + + + + + + + + + + diff --git a/src/ext/Dependency/wixext/WixToolset.Dependency.wixext.nuspec b/src/ext/Dependency/wixext/WixToolset.Dependency.wixext.nuspec new file mode 100644 index 00000000..ba3eaade --- /dev/null +++ b/src/ext/Dependency/wixext/WixToolset.Dependency.wixext.nuspec @@ -0,0 +1,25 @@ + + + + $id$ + $version$ + $title$ + $description$ + $authors$ + MS-RL + false + $copyright$ + $projectUrl$ + + + + + + + + + + + + + diff --git a/src/ext/Dependency/wixext/WixToolset.Dependency.wixext.targets b/src/ext/Dependency/wixext/WixToolset.Dependency.wixext.targets new file mode 100644 index 00000000..2b298736 --- /dev/null +++ b/src/ext/Dependency/wixext/WixToolset.Dependency.wixext.targets @@ -0,0 +1,11 @@ + + + + + + $(MSBuildThisFileDirectory)..\tools\WixToolset.Dependency.wixext.dll + + + + + diff --git a/src/ext/Dependency/wixlib/DependencyExtension.wxs b/src/ext/Dependency/wixlib/DependencyExtension.wxs new file mode 100644 index 00000000..0516b18c --- /dev/null +++ b/src/ext/Dependency/wixlib/DependencyExtension.wxs @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/src/ext/Dependency/wixlib/DependencyExtension_Platform.wxi b/src/ext/Dependency/wixlib/DependencyExtension_Platform.wxi new file mode 100644 index 00000000..9ab28ef3 --- /dev/null +++ b/src/ext/Dependency/wixlib/DependencyExtension_Platform.wxi @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/ext/Dependency/wixlib/DependencyExtension_arm64.wxs b/src/ext/Dependency/wixlib/DependencyExtension_arm64.wxs new file mode 100644 index 00000000..958650e6 --- /dev/null +++ b/src/ext/Dependency/wixlib/DependencyExtension_arm64.wxs @@ -0,0 +1,7 @@ + + + + + + + diff --git a/src/ext/Dependency/wixlib/DependencyExtension_x64.wxs b/src/ext/Dependency/wixlib/DependencyExtension_x64.wxs new file mode 100644 index 00000000..4fe458e8 --- /dev/null +++ b/src/ext/Dependency/wixlib/DependencyExtension_x64.wxs @@ -0,0 +1,7 @@ + + + + + + + diff --git a/src/ext/Dependency/wixlib/DependencyExtension_x86.wxs b/src/ext/Dependency/wixlib/DependencyExtension_x86.wxs new file mode 100644 index 00000000..d8ac6785 --- /dev/null +++ b/src/ext/Dependency/wixlib/DependencyExtension_x86.wxs @@ -0,0 +1,7 @@ + + + + + + + diff --git a/src/ext/Dependency/wixlib/caDecor.wxi b/src/ext/Dependency/wixlib/caDecor.wxi new file mode 100644 index 00000000..b1711518 --- /dev/null +++ b/src/ext/Dependency/wixlib/caDecor.wxi @@ -0,0 +1,39 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/ext/Dependency/wixlib/caerr.wxi b/src/ext/Dependency/wixlib/caerr.wxi new file mode 100644 index 00000000..ff7ec121 --- /dev/null +++ b/src/ext/Dependency/wixlib/caerr.wxi @@ -0,0 +1,96 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/ext/Dependency/wixlib/dependency.wixproj b/src/ext/Dependency/wixlib/dependency.wixproj new file mode 100644 index 00000000..76e3ecd3 --- /dev/null +++ b/src/ext/Dependency/wixlib/dependency.wixproj @@ -0,0 +1,30 @@ + + + + + + + Library + true + + 1086 + en-us + + + + + + + + + + + + + + + + + + + diff --git a/src/ext/Dependency/wixlib/en-us.wxl b/src/ext/Dependency/wixlib/en-us.wxl new file mode 100644 index 00000000..6ad7d63d --- /dev/null +++ b/src/ext/Dependency/wixlib/en-us.wxl @@ -0,0 +1,7 @@ + + + + + If you continue with this install, the product may not work properly because [2] or more dependencies are missing. Do you want to continue with this install anyway? + If you continue with this uninstall, [2] or more products may stop working properly. Do you want to continue with this uninstall anyway? + diff --git a/src/ext/global.json b/src/ext/global.json new file mode 100644 index 00000000..23d7a5bd --- /dev/null +++ b/src/ext/global.json @@ -0,0 +1,5 @@ +{ + "msbuild-sdks": { + "WixToolset.Sdk": "4.0.0-build-0213" + } +} -- cgit v1.2.3-55-g6feb