Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public class TestWtIntuneWin : DependencyCmdlet<Startup>
[Parameter(
Mandatory = false,
ParameterSetName = nameof(PackageFolder),
Position = 3,
Position = 4,
HelpMessage = "Clean the test files after run")]
[Parameter(
Mandatory = false,
Expand All @@ -143,7 +143,7 @@ public class TestWtIntuneWin : DependencyCmdlet<Startup>
[Parameter(
Mandatory = false,
ParameterSetName = nameof(PackageFolder),
Position = 4,
Position = 5,
HelpMessage = "Sleep for x seconds before auto shutdown")]
[Parameter(
Mandatory = false,
Expand Down Expand Up @@ -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);
Expand All @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
10 changes: 9 additions & 1 deletion src/WingetIntune/Intune/IntuneManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
}

/// <summary>
Expand Down
9 changes: 6 additions & 3 deletions src/WingetIntune/Testing/WindowsSandbox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ public async Task<string> 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");
Expand Down Expand Up @@ -310,7 +311,7 @@ private async Task PrepareSandboxDependencies(bool fetchWinget = true, Cancellat
/// <param name="cleanup">Should we try to cleanup the folder containing the sandbox file?</param>
/// <param name="cancellationToken">In case you want to cancel the process.</param>
/// <returns></returns>
public async Task<SandboxResult?> RunSandbox(string sandboxFile, bool cleanup, CancellationToken cancellationToken)
public async Task<SandboxResult?> RunSandbox(string sandboxFile, bool cleanup, Action waitForConfirm, CancellationToken cancellationToken)
{
logger.LogInformation("Running sandbox {SsandboxFile}", sandboxFile);
var processResult = await processManager.RunProcessAsync("WindowsSandbox.exe", sandboxFile, cancellationToken);
Expand All @@ -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);
Expand Down