diff --git a/src/Svrooij.WinTuner.CmdLets/Commands/Testing/TestWtIntuneWin.cs b/src/Svrooij.WinTuner.CmdLets/Commands/Testing/TestWtIntuneWin.cs index 5eefeb5..42476b8 100644 --- a/src/Svrooij.WinTuner.CmdLets/Commands/Testing/TestWtIntuneWin.cs +++ b/src/Svrooij.WinTuner.CmdLets/Commands/Testing/TestWtIntuneWin.cs @@ -123,7 +123,7 @@ public class TestWtIntuneWin : DependencyCmdlet [Parameter( Mandatory = false, ParameterSetName = nameof(PackageFolder), - Position = 3, + Position = 4, HelpMessage = "Clean the test files after run")] [Parameter( Mandatory = false, @@ -143,7 +143,7 @@ public class TestWtIntuneWin : DependencyCmdlet [Parameter( Mandatory = false, ParameterSetName = nameof(PackageFolder), - Position = 4, + Position = 5, HelpMessage = "Sleep for x seconds before auto shutdown")] [Parameter( Mandatory = false, @@ -180,7 +180,7 @@ public override async Task ProcessRecordAsync(CancellationToken cancellationToke { logger?.LogInformation("Loading package details from folder {PackageFolder}", PackageFolder); var packageInfo = await metadataManager!.LoadPackageInfoFromFolderAsync(PackageFolder, cancellationToken); - InstallerFilename = packageInfo.InstallerFilename; + InstallerFilename ??= packageInfo.InstallerFilename; // If the installer arguments are not set, use the ones from the package info. InstallerArguments ??= packageInfo.InstallCommandLine?.Replace($"\"{packageInfo.InstallerFilename!}\" ", ""); IntuneWinFile = metadataManager.GetIntuneWinFileName(PackageFolder, packageInfo); @@ -195,7 +195,7 @@ public override async Task ProcessRecordAsync(CancellationToken cancellationToke var sandboxFile = await sandbox!.PrepareSandboxFileForPackage(IntuneWinFile!, InstallerFilename, InstallerArguments, timeout: Sleep, cancellationToken: cancellationToken); logger?.LogDebug("Sandbox file created at {SandboxFile}", sandboxFile); - var result = await sandbox.RunSandbox(sandboxFile, Clean, cancellationToken); + var result = await sandbox.RunSandbox(sandboxFile, Clean, () => { this.Host.UI.ReadLine(); }, cancellationToken); if (result is null) { logger?.LogError("Sandbox exited with null result"); diff --git a/src/Svrooij.WinTuner.CmdLets/Commands/Testing/TestWtSetupFile.cs b/src/Svrooij.WinTuner.CmdLets/Commands/Testing/TestWtSetupFile.cs index c67eee3..0b33df3 100644 --- a/src/Svrooij.WinTuner.CmdLets/Commands/Testing/TestWtSetupFile.cs +++ b/src/Svrooij.WinTuner.CmdLets/Commands/Testing/TestWtSetupFile.cs @@ -60,7 +60,7 @@ public override async Task ProcessRecordAsync(CancellationToken cancellationToke { var sandboxFile = await sandbox!.PrepareSandboxForInstaller(SetupFile!, InstallerArguments, Sleep, cancellationToken); logger?.LogDebug("Sandbox file created at {SandboxFile}", sandboxFile); - var result = await sandbox.RunSandbox(sandboxFile, true, cancellationToken); + var result = await sandbox.RunSandbox(sandboxFile, true, () => { this.Host.UI.ReadLine(); }, cancellationToken); if (result is null) { logger?.LogError("Sandbox exited with null result"); diff --git a/src/WingetIntune/Commands/ComputeBestInstallerForPackageCommand.cs b/src/WingetIntune/Commands/ComputeBestInstallerForPackageCommand.cs index b8cc4aa..cd05309 100644 --- a/src/WingetIntune/Commands/ComputeBestInstallerForPackageCommand.cs +++ b/src/WingetIntune/Commands/ComputeBestInstallerForPackageCommand.cs @@ -26,9 +26,10 @@ public void Execute(ref PackageInfo package, PackageOptions? packageOptions = nu package.InstallerUrl = new Uri(installer.InstallerUrl!); package.InstallerFilename = Path.GetFileName(package.InstallerUrl.LocalPath.Replace(" ", "")); - if (string.IsNullOrEmpty(package.InstallerFilename)) + // Maybe just never trust the installer filename and always generate? + if (string.IsNullOrEmpty(package.InstallerFilename) || package.InstallerFilename.IndexOf('.') == -1) { - package.InstallerFilename = $"{package.PackageIdentifier}_{package.Version}.{GuessInstallerExtension(installer.ParseInstallerType())}"; + package.InstallerFilename = $"{package.PackageIdentifier}-{package.Version}.{GuessInstallerExtension(installer.ParseInstallerType())}"; } // Maybe this should be done for other installers as well? diff --git a/src/WingetIntune/Intune/IntuneManager.cs b/src/WingetIntune/Intune/IntuneManager.cs index de0203e..49ac945 100644 --- a/src/WingetIntune/Intune/IntuneManager.cs +++ b/src/WingetIntune/Intune/IntuneManager.cs @@ -76,7 +76,15 @@ public IntuneManager(ILoggerFactory? loggerFactory, IFileManager fileManager, IP await WriteReadmeAsync(packageFolder, packageInfo, cancellationToken); await WritePackageInfo(packageFolder, packageInfo, cancellationToken); - return new Models.WingetPackage(packageInfo, packageFolder, intunePackage!) { InstallerArguments = packageInfo.InstallCommandLine?.Substring(packageInfo.InstallerFilename?.Length + 3 ?? 0), InstallerFile = packageInfo.InstallerFilename }; + var command = packageInfo.InstallCommandLine!.Replace("msiexec /i ", ""); + + + return new Models.WingetPackage(packageInfo, packageFolder, intunePackage!) + { + InstallerArguments = command.Substring(command.IndexOf(packageInfo.InstallerFilename!) + packageInfo.InstallerFilename!.Length).Trim(), + InstallerFile = packageInfo.InstallerFilename, + InstallCommand = packageInfo.InstallCommandLine + }; } /// diff --git a/src/WingetIntune/Testing/WindowsSandbox.cs b/src/WingetIntune/Testing/WindowsSandbox.cs index 9f99933..f4324e2 100644 --- a/src/WingetIntune/Testing/WindowsSandbox.cs +++ b/src/WingetIntune/Testing/WindowsSandbox.cs @@ -63,7 +63,8 @@ public async Task PrepareSandboxFileForPackage(string intuneWinFile, str installerFilename ??= info!.SetupFile!; if (!File.Exists(Path.Combine(installerFolder, installerFilename))) { - throw new FileNotFoundException("Installer in the unpacked folder", installerFilename!); + var ex = new FileNotFoundException("Installer not in the unpacked folder", installerFilename!); + logger.LogCritical(ex, "Installer {InstallerFile} not found in package", installerFilename); } await PrepareSandboxDependencies(cancellationToken: cancellationToken); var sandboxFile = Path.Combine(outputFolder, "sandbox.wsb"); @@ -310,7 +311,7 @@ private async Task PrepareSandboxDependencies(bool fetchWinget = true, Cancellat /// Should we try to cleanup the folder containing the sandbox file? /// In case you want to cancel the process. /// - public async Task RunSandbox(string sandboxFile, bool cleanup, CancellationToken cancellationToken) + public async Task RunSandbox(string sandboxFile, bool cleanup, Action waitForConfirm, CancellationToken cancellationToken) { logger.LogInformation("Running sandbox {SsandboxFile}", sandboxFile); var processResult = await processManager.RunProcessAsync("WindowsSandbox.exe", sandboxFile, cancellationToken); @@ -324,7 +325,9 @@ private async Task PrepareSandboxDependencies(bool fetchWinget = true, Cancellat } logger.LogInformation("Press enter when you closed the sandbox"); - Console.ReadLine(); + + waitForConfirm(); + //Console.ReadLine(); //try //{ // await Task.Delay(600_000, cancellationToken);