From 427158cb2136989e51f1acfd7b40860a60615a33 Mon Sep 17 00:00:00 2001 From: Nir Bar Date: Mon, 2 Oct 2023 16:24:53 +0300 Subject: [PATCH] DeferredExePackage --- DeferredExePackage/DeferredExePackage.cpp | 92 +++++++++++++++++++ DeferredExePackage/DeferredExePackage.vcxproj | 57 ++++++++++++ .../DeferredExePackage.vcxproj.filters | 27 ++++++ PanelSwWixExtension.sln | 14 +++ .../PanelSwWixExtension.csproj | 5 +- README.md | 3 + TidyBuild.custom.props | 2 +- UnitTests/HeatExtUT/HeatExtUT.wixproj | 5 + UnitTests/HeatExtUT/HeatExtUT.wxs | 7 +- dirs.proj | 2 + wixlib/PanelSwWixLib.wixproj | 3 +- 11 files changed, 213 insertions(+), 4 deletions(-) create mode 100644 DeferredExePackage/DeferredExePackage.cpp create mode 100644 DeferredExePackage/DeferredExePackage.vcxproj create mode 100644 DeferredExePackage/DeferredExePackage.vcxproj.filters diff --git a/DeferredExePackage/DeferredExePackage.cpp b/DeferredExePackage/DeferredExePackage.cpp new file mode 100644 index 00000000..93b9c251 --- /dev/null +++ b/DeferredExePackage/DeferredExePackage.cpp @@ -0,0 +1,92 @@ +#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers +#include +#include + +#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; +} \ No newline at end of file diff --git a/DeferredExePackage/DeferredExePackage.vcxproj b/DeferredExePackage/DeferredExePackage.vcxproj new file mode 100644 index 00000000..cea839c8 --- /dev/null +++ b/DeferredExePackage/DeferredExePackage.vcxproj @@ -0,0 +1,57 @@ + + + + + + Release + x64 + + + Release + Win32 + + + + native,Version=v0.0 + {b729fb3c-25cf-4216-940d-69ea78779cd7} + DeferredExePackage + DeferredExePackage + Win32Proj + Application + Unicode + false + false + + + + false + true + + + + + + + + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + Level3 + true + true + true + true + MultiThreaded + + + Console + true + true + true + + + + + + + + + diff --git a/DeferredExePackage/DeferredExePackage.vcxproj.filters b/DeferredExePackage/DeferredExePackage.vcxproj.filters new file mode 100644 index 00000000..fe7ae7b6 --- /dev/null +++ b/DeferredExePackage/DeferredExePackage.vcxproj.filters @@ -0,0 +1,27 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;h++;hm;inl;inc;ipp;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 + + + + + Resource Files + + + \ No newline at end of file diff --git a/PanelSwWixExtension.sln b/PanelSwWixExtension.sln index 7d50e17e..0eedb5df 100755 --- a/PanelSwWixExtension.sln +++ b/PanelSwWixExtension.sln @@ -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 @@ -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 diff --git a/PanelSwWixExtension/PanelSwWixExtension.csproj b/PanelSwWixExtension/PanelSwWixExtension.csproj index dab8d491..c5dab4df 100644 --- a/PanelSwWixExtension/PanelSwWixExtension.csproj +++ b/PanelSwWixExtension/PanelSwWixExtension.csproj @@ -1,4 +1,4 @@ - + netstandard2.0 @@ -37,6 +37,8 @@ + + @@ -53,6 +55,7 @@ + diff --git a/README.md b/README.md index 67678ef3..18e4fe9e 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/TidyBuild.custom.props b/TidyBuild.custom.props index b9dc6802..1cb79f29 100644 --- a/TidyBuild.custom.props +++ b/TidyBuild.custom.props @@ -2,7 +2,7 @@ - 3.9.0 + 3.10.0 $(APPVEYOR_BUILD_VERSION) $(FullVersion).$(GITHUB_RUN_NUMBER) PanelSwWixExtension diff --git a/UnitTests/HeatExtUT/HeatExtUT.wixproj b/UnitTests/HeatExtUT/HeatExtUT.wixproj index fc1b381a..ce6d5668 100644 --- a/UnitTests/HeatExtUT/HeatExtUT.wixproj +++ b/UnitTests/HeatExtUT/HeatExtUT.wixproj @@ -28,4 +28,9 @@ var.THISDIR + + + DeferredExePackage + + diff --git a/UnitTests/HeatExtUT/HeatExtUT.wxs b/UnitTests/HeatExtUT/HeatExtUT.wxs index 7fa4a934..d756604e 100644 --- a/UnitTests/HeatExtUT/HeatExtUT.wxs +++ b/UnitTests/HeatExtUT/HeatExtUT.wxs @@ -5,8 +5,13 @@ + + - + diff --git a/dirs.proj b/dirs.proj index 086359f1..c4cbb73f 100644 --- a/dirs.proj +++ b/dirs.proj @@ -10,9 +10,11 @@ + + diff --git a/wixlib/PanelSwWixLib.wixproj b/wixlib/PanelSwWixLib.wixproj index 07b67c1b..579fa9cb 100755 --- a/wixlib/PanelSwWixLib.wixproj +++ b/wixlib/PanelSwWixLib.wixproj @@ -16,8 +16,9 @@ - + +