From 825fa209634e1f67e1f5eb48574dd34843a56171 Mon Sep 17 00:00:00 2001 From: "Steve Lee (POWERSHELL HE/HIM) (from Dev Box)" Date: Tue, 2 Jul 2024 14:22:24 -0700 Subject: [PATCH 1/2] Add prompt when `dsc` is run from MS Store and ability to build private msix for testing --- build.ps1 | 23 ++++++++++++++++++----- dsc/src/main.rs | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 5 deletions(-) diff --git a/build.ps1 b/build.ps1 index a69cb635..0917ddb0 100644 --- a/build.ps1 +++ b/build.ps1 @@ -7,7 +7,7 @@ param( $architecture = 'current', [switch]$Clippy, [switch]$SkipBuild, - [ValidateSet('msix','msixbundle','tgz','zip')] + [ValidateSet('msix','msix-private','msixbundle','tgz','zip')] $packageType, [switch]$Test, [switch]$GetPackageVersion, @@ -422,7 +422,7 @@ if ($packageType -eq 'msixbundle') { $msixPath = Join-Path $PSScriptRoot 'bin' 'msix' & $makeappx bundle /d $msixPath /p "$PSScriptRoot\bin\$packageName.msixbundle" return -} elseif ($packageType -eq 'msix') { +} elseif ($packageType -eq 'msix' -or $packageType -eq 'msix-private') { if (!$IsWindows) { throw "MSIX is only supported on Windows" } @@ -431,6 +431,8 @@ if ($packageType -eq 'msixbundle') { throw 'MSIX requires a specific architecture' } + $isPrivate = $packageType -eq 'msix-private' + $makeappx = Find-MakeAppx $makepri = Get-Item (Join-Path $makeappx.Directory "makepri.exe") -ErrorAction Stop $displayName = "DesiredStateConfiguration" @@ -438,14 +440,25 @@ if ($packageType -eq 'msixbundle') { $productName = "DesiredStateConfiguration" if ($isPreview) { Write-Verbose -Verbose "Preview version detected" - $productName += "-Preview" + if ($isPrivate) { + $productName += "-Private" + } + else { + $productName += "-Preview" + } # save preview number $previewNumber = $productVersion -replace '.*?-[a-z]+\.([0-9]+)', '$1' # remove label from version $productVersion = $productVersion.Split('-')[0] # replace revision number with preview number $productVersion = $productVersion -replace '(\d+)$', "$previewNumber.0" - $displayName += "-Preview" + + if ($isPrivate) { + $displayName += "-Private" + } + else { + $displayName += "-Preview" + } } Write-Verbose -Verbose "Product version is $productVersion" $arch = if ($architecture -eq 'aarch64-pc-windows-msvc') { 'arm64' } else { 'x64' } @@ -517,7 +530,7 @@ if ($packageType -eq 'msixbundle') { throw "Failed to create msix package" } - Write-Host -ForegroundColor Green "`nMSIX package is created at $packageName.msix" + Write-Host -ForegroundColor Green "`nMSIX package is created at $packageName" } elseif ($packageType -eq 'zip') { $zipTarget = Join-Path $PSScriptRoot 'bin' $architecture 'zip' if (Test-Path $zipTarget) { diff --git a/dsc/src/main.rs b/dsc/src/main.rs index 655c952c..d9b10656 100644 --- a/dsc/src/main.rs +++ b/dsc/src/main.rs @@ -26,6 +26,9 @@ fn main() { #[cfg(debug_assertions)] check_debug(); + #[cfg(windows)] + check_store(); + if ctrlc::set_handler(ctrlc_handler).is_err() { error!("Error: Failed to set Ctrl-C handler"); } @@ -156,3 +159,37 @@ fn check_debug() { } } } + +// Check if the dsc binary parent process is WinStore.App or Exploerer.exe +#[cfg(windows)] +fn check_store() { + let message = r" +DSC.exe is a command-line tool and cannot be run directly from the Windows Store or Explorer. +Visit https://aka.ms/dscv3-docs for more information on how to use DSC.exe. + +Press any key to close this window +"; + let sys = System::new_with_specifics(RefreshKind::new().with_processes(ProcessRefreshKind::new())); + // get current process + let Ok(current_pid) = get_current_pid() else { + return; + }; + + // get parent process + let Some(current_process) = sys.process(current_pid) else { + return; + }; + let Some(parent_process_pid) = current_process.parent() else { + return; + }; + let Some(parent_process) = sys.process(parent_process_pid) else { + return; + }; + + if parent_process.name().to_lowercase() == "winstore.app.exe" || parent_process.name().to_lowercase() == "explorer.exe"{ + eprintln!("{message}"); + // wait for keypress + let _ = io::stdin().read(&mut [0u8]).unwrap(); + exit(util::EXIT_INVALID_ARGS); + } +} From a9639019efcd0e6bfca524eb712554806284aa64 Mon Sep 17 00:00:00 2001 From: "Steve Lee (POWERSHELL HE/HIM) (from Dev Box)" Date: Tue, 2 Jul 2024 17:34:27 -0700 Subject: [PATCH 2/2] update name of store host --- dsc/src/main.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/dsc/src/main.rs b/dsc/src/main.rs index d9b10656..d516c727 100644 --- a/dsc/src/main.rs +++ b/dsc/src/main.rs @@ -186,7 +186,8 @@ Press any key to close this window return; }; - if parent_process.name().to_lowercase() == "winstore.app.exe" || parent_process.name().to_lowercase() == "explorer.exe"{ + // MS Store runs app using `sihost.exe` + if parent_process.name().to_lowercase() == "sihost.exe" || parent_process.name().to_lowercase() == "explorer.exe"{ eprintln!("{message}"); // wait for keypress let _ = io::stdin().read(&mut [0u8]).unwrap();