diff --git a/src/Svrooij.WinTuner.CmdLets/Commands/DeployWtWin32App.cs b/src/Svrooij.WinTuner.CmdLets/Commands/DeployWtWin32App.cs index 3e9eb8a..360fc4f 100644 --- a/src/Svrooij.WinTuner.CmdLets/Commands/DeployWtWin32App.cs +++ b/src/Svrooij.WinTuner.CmdLets/Commands/DeployWtWin32App.cs @@ -12,6 +12,8 @@ using WingetIntune.Intune; using GraphModels = Microsoft.Graph.Beta.Models; using System.Linq; +using Microsoft.Kiota.Abstractions.Serialization; +using Microsoft.Kiota.Abstractions.Extensions; namespace Svrooij.WinTuner.CmdLets.Commands; /// @@ -175,6 +177,12 @@ public class DeployWtWin32App : BaseIntuneCmdlet HelpMessage = "Groups that the app should be uninstalled for, Group Object ID or `AllUsers` / `AllDevices`")] public string[]? UninstallFor { get; set; } + /// + /// The role scope tags for this app + /// + [Parameter(Mandatory = false, Position = 15, HelpMessage = "The role scope tags for this app")] + public string[]? RoleScopeTags { get; set; } + [ServiceDependency] private ILogger? logger; @@ -196,16 +204,28 @@ protected override async Task ProcessAuthenticatedAsync(IAuthenticationProvider { logger?.LogDebug("Loading package details from RootPackageFolder {RootPackageFolder}, PackageId {PackageId}, Version {Version}", RootPackageFolder, PackageId, Version); PackageFolder = Path.Combine(RootPackageFolder!, PackageId!, Version!); - logger?.LogDebug("Loading package details from folder {packageFolder}", PackageFolder); + logger?.LogDebug("Loading package details from folder {PackageFolder}", PackageFolder); } if (PackageFolder is not null) { - logger?.LogInformation("Loading package details from folder {packageFolder}", PackageFolder); - var packageInfo = await metadataManager!.LoadPackageInfoFromFolderAsync(PackageFolder, cancellationToken); - App = metadataManager.ConvertPackageInfoToWin32App(packageInfo); - LogoPath = Path.Combine(PackageFolder, "..", "logo.png"); - IntuneWinFile = metadataManager.GetIntuneWinFileName(PackageFolder, packageInfo); + logger?.LogInformation("Loading package details from folder {PackageFolder}", PackageFolder); + var win32LobAppFile = Path.Combine(PackageFolder, "win32LobApp.json"); + if (File.Exists(win32LobAppFile)) + { + logger?.LogDebug("Loading Win32LobApp from file {Win32LobAppFile}", win32LobAppFile); + var json = await File.ReadAllTextAsync(win32LobAppFile, cancellationToken); + App = await KiotaSerializer.DeserializeAsync("application/json", json, cancellationToken); + IntuneWinFile = Path.Combine(PackageFolder, App!.FileName!); + } + else + { + logger?.LogDebug("Loading package info from folder {PackageFolder}", PackageFolder); + var packageInfo = await metadataManager!.LoadPackageInfoFromFolderAsync(PackageFolder, cancellationToken); + App = metadataManager.ConvertPackageInfoToWin32App(packageInfo); + LogoPath = Path.Combine(PackageFolder, "..", "logo.png"); + IntuneWinFile = metadataManager.GetIntuneWinFileName(PackageFolder, packageInfo); + } } else { @@ -215,6 +235,12 @@ protected override async Task ProcessAuthenticatedAsync(IAuthenticationProvider } } + if (RoleScopeTags is not null && RoleScopeTags.Any()) + { + logger?.LogInformation("Adding role scope tags to app"); + App.RoleScopeTagIds = RoleScopeTags.AsList(); + } + if (!string.IsNullOrEmpty(OverrideAppName)) { App.DisplayName = OverrideAppName; diff --git a/src/Svrooij.WinTuner.CmdLets/Svrooij.WinTuner.CmdLets.dll-Help.xml b/src/Svrooij.WinTuner.CmdLets/Svrooij.WinTuner.CmdLets.dll-Help.xml index bd855c1..d01f046 100644 --- a/src/Svrooij.WinTuner.CmdLets/Svrooij.WinTuner.CmdLets.dll-Help.xml +++ b/src/Svrooij.WinTuner.CmdLets/Svrooij.WinTuner.CmdLets.dll-Help.xml @@ -690,6 +690,17 @@ Connect-WtWinTuner -UseDefaultCredentials None + + RoleScopeTags + + The role scope tags for this app + + String[] + + String[] + + None + GraphId @@ -792,6 +803,17 @@ Connect-WtWinTuner -UseDefaultCredentials None + + RoleScopeTags + + The role scope tags for this app + + String[] + + String[] + + None + GraphId @@ -872,6 +894,17 @@ Connect-WtWinTuner -UseDefaultCredentials None + + RoleScopeTags + + The role scope tags for this app + + String[] + + String[] + + None + GraphId @@ -1040,6 +1073,17 @@ Connect-WtWinTuner -UseDefaultCredentials None + + RoleScopeTags + + The role scope tags for this app + + String[] + + String[] + + None + diff --git a/src/WingetIntune/Intune/IntuneManager.cs b/src/WingetIntune/Intune/IntuneManager.cs index 6944df2..364ce7a 100644 --- a/src/WingetIntune/Intune/IntuneManager.cs +++ b/src/WingetIntune/Intune/IntuneManager.cs @@ -4,6 +4,7 @@ using Microsoft.Graph.Beta.Models; using Microsoft.Graph.Beta.Models.ODataErrors; using Microsoft.Kiota.Abstractions.Authentication; +using Microsoft.Kiota.Abstractions.Serialization; using System.Text; using System.Text.Json; using WingetIntune.Graph; @@ -677,6 +678,27 @@ private async Task WritePackageInfo(string packageFolder, PackageInfo packageInf var json = JsonSerializer.SerializeToUtf8Bytes(packageInfo, MyJsonContext.Default.PackageInfo); var jsonFile = Path.Combine(packageFolder, "app.json"); await fileManager.WriteAllBytesAsync(jsonFile, json, cancellationToken); + + var win32File = Path.Combine(packageFolder, "win32LobApp.json"); + + var win32App = mapper.ToWin32LobApp(packageInfo); + var logoPath = Path.Combine(packageFolder, "..", "logo.png"); + var logoBytes = await fileManager.ReadAllBytesAsync(logoPath, cancellationToken); + if (logoBytes.Length > 0) + { + win32App.LargeIcon = new MimeContent + { + Type = "image/png", + Value = logoBytes + }; + } + + using var stream = new MemoryStream(); + using var jsonStream = KiotaSerializer.SerializeAsStream("application/json", win32App, false); + await jsonStream.CopyToAsync(stream, cancellationToken); + await stream.FlushAsync(cancellationToken); + stream.Seek(0, SeekOrigin.Begin); + await fileManager.WriteAllBytesAsync(win32File, stream.ToArray(), cancellationToken); } private GraphServiceClient CreateGraphClientFromOptions(IntunePublishOptions options)