Skip to content

Commit

Permalink
DeferredExePackage
Browse files Browse the repository at this point in the history
  • Loading branch information
nirbar committed Oct 2, 2023
1 parent c427b04 commit 427158c
Show file tree
Hide file tree
Showing 11 changed files with 213 additions and 4 deletions.
92 changes: 92 additions & 0 deletions DeferredExePackage/DeferredExePackage.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
#include <Windows.h>
#include <tchar.h>

#define SKIP_UNTIL_HERE TEXT("--skip-until-here")
#define IGNORE_ME TEXT("--ignore-me")

int _tmain()
{
DWORD dwExitCode = ERROR_SUCCESS;
STARTUPINFO startupInfo;
PROCESS_INFORMATION processInfo;
_TCHAR* szCmdLine = nullptr;
_TCHAR* szSkipArg = nullptr;
_TCHAR* szIgnoreArg = nullptr;
BOOL bRes = TRUE;

::memset(&processInfo, 0, sizeof(processInfo));
::memset(&startupInfo, 0, sizeof(startupInfo));
startupInfo.cb = sizeof(startupInfo);

szCmdLine = ::GetCommandLine();
if ((szCmdLine == nullptr) || (szCmdLine[0] == NULL))
{
goto LExit;
}
_tprintf(TEXT("\nParsing command line '%s'\n"), szCmdLine); //TODO Does that reveal passwords? It isn't logged by burn anyway

// Search for first arg in full command line
szSkipArg = _tcsstr(szCmdLine, SKIP_UNTIL_HERE);
szIgnoreArg = _tcsstr(szCmdLine, IGNORE_ME);
if (szIgnoreArg && (!szSkipArg || (szIgnoreArg < szSkipArg)))
{
_tprintf(TEXT("Empty run requested: %s\n"), ::GetCommandLine());
goto LExit;
}
if (!szSkipArg)
{
_tprintf(TEXT("Unidentified command line: '%s'\n"), szCmdLine);
dwExitCode = ERROR_BAD_ARGUMENTS;
goto LExit;
}

szCmdLine = szSkipArg + ::_tcsclen(SKIP_UNTIL_HERE);
while ((szCmdLine[0] != NULL) && ::_istspace(szCmdLine[0]))
{
++szCmdLine;
}
if (szCmdLine[0] == NULL)
{
_tprintf(TEXT("Command line after skip is empty: %s\n"), ::GetCommandLine());
dwExitCode = ERROR_BAD_ARGUMENTS;
goto LExit;
}

bRes = ::CreateProcess(nullptr, szCmdLine, nullptr, nullptr, FALSE, CREATE_NEW_PROCESS_GROUP, nullptr, nullptr, &startupInfo, &processInfo);
if (!bRes)
{
dwExitCode = ::GetLastError();
_tprintf(TEXT("Failed to launch process with command line '%s'. Exit code is %u\n"), szCmdLine, dwExitCode);
goto LExit;
}

dwExitCode = ::WaitForSingleObject(processInfo.hProcess, INFINITE);
if (dwExitCode != WAIT_OBJECT_0)
{
_tprintf(TEXT("Failed to wait on process with command line '%s'. Wait error code is %u\n"), szCmdLine, dwExitCode);
goto LExit;
}

bRes = ::GetExitCodeProcess(processInfo.hProcess, &dwExitCode);
if (!bRes)
{
dwExitCode = ::GetLastError();
_tprintf(TEXT("Failed to get exit code of process with command line '%s'. Error code is %u\n"), szCmdLine, dwExitCode);
goto LExit;
}

_tprintf(TEXT("Process exit code is %u\n"), dwExitCode);

LExit:
if (processInfo.hThread != NULL)
{
::CloseHandle(processInfo.hThread);
}
if (processInfo.hProcess != NULL)
{
::CloseHandle(processInfo.hProcess);
}

return dwExitCode;
}
57 changes: 57 additions & 0 deletions DeferredExePackage/DeferredExePackage.vcxproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="16.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectCapability Include="PackageReferences" />
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<NuGetTargetMoniker Condition="'$(NuGetTargetMoniker)' == ''">native,Version=v0.0</NuGetTargetMoniker>
<ProjectGuid>{b729fb3c-25cf-4216-940d-69ea78779cd7}</ProjectGuid>
<RootNamespace>DeferredExePackage</RootNamespace>
<TargetName>DeferredExePackage</TargetName>
<Keyword>Win32Proj</Keyword>
<ConfigurationType>Application</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
<LinkIncremental Condition="'$(Configuration)'=='Release'">false</LinkIncremental>
<ResolveNuGetPackages>false</ResolveNuGetPackages>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)'=='Release'" Label="Configuration">
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ItemDefinitionGroup>
<ClCompile>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<ConformanceMode>true</ConformanceMode>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="DeferredExePackage.cpp" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="TidyBuild" />
</ItemGroup> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
</Project>
27 changes: 27 additions & 0 deletions DeferredExePackage/DeferredExePackage.vcxproj.filters
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?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++;cppm;ixx;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>
<ClCompile Include="DeferredExePackage.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="$(IntDir)\Version.rc">
<Filter>Resource Files</Filter>
</ResourceCompile>
</ItemGroup>
</Project>
14 changes: 14 additions & 0 deletions PanelSwWixExtension.sln
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ Project("{B7DD6F7E-DEF8-4E67-B5B7-07EF123DB6F0}") = "PromptFileDowngrades", "Uni
EndProject
Project("{B7DD6F7E-DEF8-4E67-B5B7-07EF123DB6F0}") = "HeatExtUT", "UnitTests\HeatExtUT\HeatExtUT.wixproj", "{EBB376C5-D953-405D-BFA5-1E50FD10F419}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DeferredExePackage", "DeferredExePackage\DeferredExePackage.vcxproj", "{B729FB3C-25CF-4216-940D-69EA78779CD7}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|ARM64 = Debug|ARM64
Expand Down Expand Up @@ -563,6 +565,18 @@ Global
{EBB376C5-D953-405D-BFA5-1E50FD10F419}.Release|x64.Build.0 = Release|x64
{EBB376C5-D953-405D-BFA5-1E50FD10F419}.Release|x86.ActiveCfg = Release|x86
{EBB376C5-D953-405D-BFA5-1E50FD10F419}.Release|x86.Build.0 = Release|x86
{B729FB3C-25CF-4216-940D-69EA78779CD7}.Debug|ARM64.ActiveCfg = Release|ARM64
{B729FB3C-25CF-4216-940D-69EA78779CD7}.Debug|ARM64.Build.0 = Release|ARM64
{B729FB3C-25CF-4216-940D-69EA78779CD7}.Debug|x64.ActiveCfg = Release|x64
{B729FB3C-25CF-4216-940D-69EA78779CD7}.Debug|x64.Build.0 = Release|x64
{B729FB3C-25CF-4216-940D-69EA78779CD7}.Debug|x86.ActiveCfg = Release|Win32
{B729FB3C-25CF-4216-940D-69EA78779CD7}.Debug|x86.Build.0 = Release|Win32
{B729FB3C-25CF-4216-940D-69EA78779CD7}.Release|ARM64.ActiveCfg = Release|ARM64
{B729FB3C-25CF-4216-940D-69EA78779CD7}.Release|ARM64.Build.0 = Release|ARM64
{B729FB3C-25CF-4216-940D-69EA78779CD7}.Release|x64.ActiveCfg = Release|x64
{B729FB3C-25CF-4216-940D-69EA78779CD7}.Release|x64.Build.0 = Release|x64
{B729FB3C-25CF-4216-940D-69EA78779CD7}.Release|x86.ActiveCfg = Release|Win32
{B729FB3C-25CF-4216-940D-69EA78779CD7}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
5 changes: 4 additions & 1 deletion PanelSwWixExtension/PanelSwWixExtension.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
Expand Down Expand Up @@ -37,6 +37,8 @@
<None Include="..\Nuget\*" Visible="false" Pack="true" PackagePath="build\" />
<None Include="$(TargetPath)" Visible="false" Pack="true" PackagePath="tools\lib\"/>
<None Include="$(TargetDir)\..\PanelSwWixHarvestExtension\PanelSwWixHarvestExtension.dll" Visible="false" Pack="true" PackagePath="tools\lib\"/>
<None Include="..\build\x86\bin\$(Configuration)\DeferredExePackage\DeferredExePackage.exe" Visible="false" Pack="true" PackagePath="tools\lib\x86\"/>
<None Include="..\build\x64\bin\$(Configuration)\DeferredExePackage\DeferredExePackage.exe" Visible="false" Pack="true" PackagePath="tools\lib\x64\"/>
<None Include=".\Xsd\PanelSwWixExtension.xsd" Visible="false" Pack="true" PackagePath="content"/>
<!-- lib -->
<None Include="..\build\x86\bin\$(Configuration)\CaCommon\CaCommon.lib" Visible="false" Pack="true" PackagePath="tools\lib\v142\x86\"/>
Expand All @@ -53,6 +55,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\DeferredExePackage\DeferredExePackage.vcxproj" ReferenceOutputAssembly="false" SkipGetTargetFrameworkProperties="true" />
<ProjectReference Include="..\PanelSwWixHarvestExtension\PanelSwWixHarvestExtension.csproj" />
<ProjectReference Include="..\wixlib\PanelSwWixLib.wixproj" ReferenceOutputAssembly="false" SkipGetTargetFrameworkProperties="true" />
</ItemGroup>
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ I would like to thank JetBrains for their [support](https://www.jetbrains.com/co

- Bundle elements:
- *ContainerTemplate*: A container template to which bundle payloads can be assigned
- *!(bindpath.PanelSwWixExtension)\x86\DeferredExePackage.exe* An executable that can execute arbitrary commands during chain execution
- Use InstallArguments='--skip-until-here "[SomeExecutable]" "arg1" "arg2"': Create a process with any arguments after the `--skip-until-here` part
- Use InstallArguments='--ignore-me': Ignore anything after the `--ignore-me` part
- Heat extension command line arguments:
- *-inc*: Semicolon seperated list of filename to include. Wildcards are accepted. If specified, any file not matching the pattern will be excluded
- *-exc*: Semicolon seperated list of filename to exclude. Wildcards are accepted. If specified, any file matching the pattern will be excluded
Expand Down
2 changes: 1 addition & 1 deletion TidyBuild.custom.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Project ToolsVersion="16.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildThisFileDirectory)TidyBuild.user.props" Condition="Exists('$(MSBuildThisFileDirectory)TidyBuild.user.props')"/>
<PropertyGroup>
<FullVersion>3.9.0</FullVersion>
<FullVersion>3.10.0</FullVersion>
<FullVersion Condition=" '$(APPVEYOR_BUILD_VERSION)'!='' ">$(APPVEYOR_BUILD_VERSION)</FullVersion>
<FullVersion Condition=" '$(GITHUB_RUN_NUMBER)'!='' ">$(FullVersion).$(GITHUB_RUN_NUMBER)</FullVersion>
<ProductName>PanelSwWixExtension</ProductName>
Expand Down
5 changes: 5 additions & 0 deletions UnitTests/HeatExtUT/HeatExtUT.wixproj
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,9 @@
<PreprocessorVariable>var.THISDIR</PreprocessorVariable>
</HarvestDirectory>
</ItemGroup>
<ItemGroup>
<BindInputPaths Include="$(BuildFolder)\..\$(Platform)\bin\$(Configuration)\DeferredExePackage\">
<BindName>DeferredExePackage</BindName>
</BindInputPaths>
</ItemGroup>
</Project>
7 changes: 6 additions & 1 deletion UnitTests/HeatExtUT/HeatExtUT.wxs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@
<PayloadGroupRef Id="HeatExtUT"/>
</BootstrapperApplication>

<Variable Name="SOME_EXECUTABLE" Value="" Type="string" bal:Overridable="yes"/>

<Chain ParallelCache="yes" DisableSystemRestore="yes">
<PackageGroupRef Id="NetFx462RedistAsPrereq"/>
<ExePackage SourceFile="!(bindpath.DeferredExePackage)DeferredExePackage.exe" Id="DeferredExePackage.exe"
DetectCondition="SOME_EXECUTABLE"
InstallArguments='--skip-until-here "[SOME_EXECUTABLE]"'
UninstallArguments='--ignore-me'/>
</Chain>
</Bundle>
</Wix>
2 changes: 2 additions & 0 deletions dirs.proj
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@
<ProjectReference Include="Dism\Dism.vcxproj" Properties="Platform=Win32" Targets="Restore;Build" BuildInParallel="false"/>
<ProjectReference Include="PanelSwCustomActions\PanelSwCustomActions.vcxproj" Properties="Platform=Win32" Targets="Restore;Build" BuildInParallel="false"/>
<ProjectReference Include="PswManagedCA\PswManagedCA.csproj" Properties="Platform=x86" Targets="Restore;Build" BuildInParallel="false"/>
<ProjectReference Include="DeferredExePackage\DeferredExePackage.vcxproj" Properties="Platform=Win32" Targets="Restore;Build" BuildInParallel="false"/>

<!-- x64 -->
<ProjectReference Include="Dism\Dism.vcxproj" Properties="Platform=x64" Targets="Restore;Build" BuildInParallel="false"/>
<ProjectReference Include="DeferredExePackage\DeferredExePackage.vcxproj" Properties="Platform=x64" Targets="Restore;Build" BuildInParallel="false"/>
<ProjectReference Include="PswManagedCA\PswManagedCA.csproj" Properties="Platform=x64" Targets="Restore;Build" BuildInParallel="false"/>

<!-- WiX -->
Expand Down
3 changes: 2 additions & 1 deletion wixlib/PanelSwWixLib.wixproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\PswManagedCA\PswManagedCA.csproj" Platforms="x86;x64" />
<ProjectReference Include="..\PanelSwCustomActions\PanelSwCustomActions.vcxproj" Platforms="$(CaPlatform)"/>
<ProjectReference Include="..\PanelSwCustomActions\PanelSwCustomActions.vcxproj" Platforms="$(CaPlatform)" />
<ProjectReference Include="..\Dism\Dism.vcxproj" Platforms="Win32;x64" Condition="'$(CaPlatform)' == 'Win32'" />
<ProjectReference Include="..\DeferredExePackage\DeferredExePackage.vcxproj" Platforms="Win32;x64" Condition="'$(CaPlatform)' == 'Win32'" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="WixToolset.Util.wixext" />
Expand Down

0 comments on commit 427158c

Please sign in to comment.