public ResolvedPackageDependency(AppxPackage package, Version minVersion) : base(package.Name, package.Publisher, minVersion) { this.InstalledVersion = System.Version.Parse(package.Version); this.DisplayName = package.DisplayName; this.PublisherDisplayName = package.PublisherDisplayName; this.Package = package; }
// ReSharper disable once MemberCanBeMadeStatic.Local private async Task <PsfContentViewModel> LoadPsf(IAppxFileReader source, AppxPackage manifest) { var paths = manifest.Applications.Where(a => PackageTypeConverter.GetPackageTypeFrom(a.EntryPoint, a.Executable, a.StartPage, manifest.IsFramework) == MsixPackageType.BridgePsf).Select(a => a.Executable).Where(a => a != null).Select(Path.GetDirectoryName).Where(a => !string.IsNullOrEmpty(a)).Distinct().ToList(); paths.Add(string.Empty); foreach (var items in paths) { var configJsonPath = string.IsNullOrWhiteSpace(items) ? "config.json" : Path.Combine(items, "config.json"); if (!source.FileExists(configJsonPath)) { continue; } using (var s = source.GetFile(configJsonPath)) { using var stringReader = new StreamReader(s); var all = await stringReader.ReadToEndAsync().ConfigureAwait(false); var psfSerializer = new PsfConfigSerializer(); var configJson = psfSerializer.Deserialize(all); return(new PsfContentViewModel(configJson)); } } return(null); }
private static void Show(int indent, AppxPackage package) { string sindent = new string(' ', indent); Console.WriteLine(sindent + "FullName : " + package.FullName); Console.WriteLine(sindent + "FamilyName : " + package.FamilyName); Console.WriteLine(sindent + "IsFramework : " + package.IsFramework); Console.WriteLine(sindent + "ApplicationUserModelId : " + package.ApplicationUserModelId); Console.WriteLine(sindent + "Path : " + package.Path); Console.WriteLine(sindent + "Publisher : " + package.Publisher); Console.WriteLine(sindent + "PublisherId : " + package.PublisherId); Console.WriteLine(sindent + "Logo : " + package.Logo); Console.WriteLine(sindent + "Best Logo Path : " + package.FindHighestScaleQualifiedImagePath(package.Logo)); Console.WriteLine(sindent + "ProcessorArchitecture : " + package.ProcessorArchitecture); Console.WriteLine(sindent + "Version : " + package.Version); Console.WriteLine(sindent + "PublisherDisplayName : " + package.PublisherDisplayName); Console.WriteLine(sindent + " Localized : " + package.LoadResourceString(package.PublisherDisplayName)); Console.WriteLine(sindent + "DisplayName : " + package.DisplayName); Console.WriteLine(sindent + " Localized : " + package.LoadResourceString(package.DisplayName)); Console.WriteLine(sindent + "Description : " + package.Description); Console.WriteLine(sindent + " Localized : " + package.LoadResourceString(package.Description)); Console.WriteLine(sindent + "Apps :"); int i = 0; foreach (var app in package.Apps) { Console.WriteLine(sindent + " App [" + i + "] Description : " + app.Description); Console.WriteLine(sindent + " Localized : " + package.LoadResourceString(app.Description)); Console.WriteLine(sindent + " App [" + i + "] DisplayName : " + app.DisplayName); Console.WriteLine(sindent + " Localized : " + package.LoadResourceString(app.DisplayName)); Console.WriteLine(sindent + " App [" + i + "] ShortName : " + app.ShortName); Console.WriteLine(sindent + " Localized : " + package.LoadResourceString(app.ShortName)); Console.WriteLine(sindent + " App [" + i + "] EntryPoint : " + app.EntryPoint); Console.WriteLine(sindent + " App [" + i + "] Executable : " + app.Executable); Console.WriteLine(sindent + " App [" + i + "] Id : " + app.Id); Console.WriteLine(sindent + " App [" + i + "] Logo : " + app.Logo); Console.WriteLine(sindent + " App [" + i + "] SmallLogo : " + app.SmallLogo); Console.WriteLine(sindent + " App [" + i + "] StartPage : " + app.StartPage); Console.WriteLine(sindent + " App [" + i + "] Square150x150Logo : " + app.Square150x150Logo); Console.WriteLine(sindent + " App [" + i + "] Square30x30Logo : " + app.Square30x30Logo); Console.WriteLine(sindent + " App [" + i + "] BackgroundColor : " + app.BackgroundColor); Console.WriteLine(sindent + " App [" + i + "] ForegroundText : " + app.ForegroundText); Console.WriteLine(sindent + " App [" + i + "] WideLogo : " + app.WideLogo); Console.WriteLine(sindent + " App [" + i + "] Wide310x310Logo : " + app.Wide310x310Logo); Console.WriteLine(sindent + " App [" + i + "] Square310x310Logo : " + app.Square310x310Logo); Console.WriteLine(sindent + " App [" + i + "] Square70x70Logo : " + app.Square70x70Logo); Console.WriteLine(sindent + " App [" + i + "] MinWidth : " + app.MinWidth); Console.WriteLine(sindent + " App [" + i + "] Square71x71Logo : " + app.GetStringValue("Square71x71Logzo")); i++; } Console.WriteLine(sindent + "Deps :"); foreach (var dep in package.DependencyGraph) { Show(indent + 1, dep); } Console.WriteLine("\n\n"); }
private async Task <FoundUsersViewModel> GetUsers( AppxPackage package, bool forceElevation, CancellationToken cancellationToken = default, IProgress <ProgressData> progress = null) { if (!forceElevation) { if (!await UserHelper.IsAdministratorAsync(cancellationToken)) { return(new FoundUsersViewModel(new List <User>(), ElevationStatus.ElevationRequired)); } } try { var manager = await this.appxPackageManagerProvider.GetProxyFor(forceElevation?SelfElevationLevel.AsAdministrator : SelfElevationLevel.HighestAvailable, cancellationToken); var stateDetails = await manager.GetUsersForPackage(package.FullName, cancellationToken, progress).ConfigureAwait(false); if (stateDetails == null) { return(new FoundUsersViewModel(new List <User>(), ElevationStatus.ElevationRequired)); } return(new FoundUsersViewModel(stateDetails, ElevationStatus.OK)); } catch (Exception) { return(new FoundUsersViewModel(new List <User>(), ElevationStatus.ElevationRequired)); } }
public ResolvedMainPackageDependency(AppxPackage package) : base(package.Name) { this.InstalledVersion = System.Version.Parse(package.Version); this.Publisher = package.Publisher; this.DisplayName = package.DisplayName; this.PublisherDisplayName = package.PublisherDisplayName; this.Package = package; }
public string GetStringValue(string name) { if (name == null) { throw new ArgumentNullException("name"); } return(AppxPackage.GetStringValue(_app, name)); }
public AppxApplicationViewModel(AppxApplication model, AppxPackage package) { this.model = model; this.package = package; this.Psf = model.Psf == null ? null : new AppxPsfViewModel(package.RootFolder, model.Psf); this.Services = model.Extensions == null ? null : new AppxServicesViewModel(model.Extensions); this.Type = PackageTypeConverter.GetPackageTypeFrom(this.model.EntryPoint, this.model.Executable, this.model.StartPage, this.package.IsFramework); this.Alias = this.model.ExecutionAlias?.Any() == true ? string.Join(", ", this.model.ExecutionAlias.Distinct(StringComparer.OrdinalIgnoreCase)) : null; }
static void Main(string[] args) { foreach (var p in Process.GetProcesses()) { var package = AppxPackage.FromProcess(p); if (package != null) { Show(0, package); Console.WriteLine(); Console.WriteLine(); } } }
public void RemoveAppxPackageFromTargetTest_Existing() { MsIotApiWrapper msIotApiWrapper = new MsIotApiWrapper("127.0.0.1", "user", "password", new MockHttpMessageHandler()); AppxPackage removablePackage = new AppxPackage { CanUninstall = true, PackageFullName = "Exists", PackageName = "AppName", PackageRelativeId = "PackageRelativeId" }; Assert.DoesNotThrow(() => msIotApiWrapper.RemoveAppxPackageFromTarget(removablePackage)); }
public void SetDefaultStartupAppTest_Existing() { MsIotApiWrapper msIotApiWrapper = new MsIotApiWrapper("127.0.0.1", "user", "password", new MockHttpMessageHandler()); AppxPackage existingApp = new AppxPackage { CanUninstall = true, PackageFullName = "ExistingPackageFullName", PackageName = "ExistingAppName", PackageRelativeId = "ExistingPackageRelativeId" }; Assert.DoesNotThrow(() => msIotApiWrapper.SetDefaultStartupApp(existingApp)); }
public Task MovePackageToVolume(AppxVolume volume, AppxPackage package, CancellationToken cancellationToken = default, IProgress <ProgressData> progress = default) { if (volume == null) { throw new ArgumentNullException(nameof(volume)); } if (package == null) { throw new ArgumentNullException(nameof(package)); } return(this.MovePackageToVolume(volume.Name, package.FullName, cancellationToken, progress)); }
public void SetDefaultStartupAppTest_NotExisting() { MsIotApiWrapper msIotApiWrapper = new MsIotApiWrapper("127.0.0.1", "user", "password", new MockHttpMessageHandler()); AppxPackage existingApp = new AppxPackage { CanUninstall = true, PackageFullName = "NotExistingPackageFullName", PackageName = "NotExistingAppName", PackageRelativeId = "NotExistingPackageRelativeId" }; AggregateException exception = Assert.Throws <AggregateException>(() => msIotApiWrapper.SetDefaultStartupApp(existingApp)); Assert.That(exception.InnerException.Message.Contains("500")); }
/// <summary> /// Removes an app from the device /// </summary> /// <remarks>An according package will be searched on the device. With the package identified the uninstall process will be triggered.</remarks> /// <param name="appName">The app's name which shall be removed.</param> static void RemoveAppIfExists(string appName) { // first, get the package via the app's name AppxPackage installedPackage = installedAppsOnTarget .Where(app => app.PackageName.Contains(appName)) .FirstOrDefault(); if (installedPackage != null) { // invoke uninstall Console.Write("A previous version of " + appName + " was found on the target. Removing " + installedPackage.PackageFullName + "..."); msIotApiWrapper.RemoveAppxPackageFromTarget(installedPackage); Console.WriteLine(" Done."); } }
private async Task <List <InstalledPackageViewModel> > GetAddOns(AppxPackage package, CancellationToken cancellationToken = default, IProgress <ProgressData> progress = null) { var manager = await this.appxPackageManagerProvider.GetProxyFor(SelfElevationLevel.HighestAvailable, cancellationToken); var results = await manager.GetModificationPackages(package.FullName, PackageFindMode.Auto, cancellationToken, progress).ConfigureAwait(false); var list = new List <InstalledPackageViewModel>(); foreach (var item in results) { list.Add(new InstalledPackageViewModel(item)); } return(list); }
public void RemoveAppxPackageFromTargetTest_NotExisting() { MsIotApiWrapper msIotApiWrapper = new MsIotApiWrapper("127.0.0.1", "user", "password", new MockHttpMessageHandler()); AppxPackage notRemovablePackage = new AppxPackage { CanUninstall = true, PackageFullName = "DoesNotExist", PackageName = "AppName", PackageRelativeId = "PackageRelativeId" }; AggregateException exception = Assert.Throws <AggregateException>(() => msIotApiWrapper.RemoveAppxPackageFromTarget(notRemovablePackage)); Assert.That(exception.InnerException.Message.Contains("500")); }
public MovePackageToVolumeDto(AppxPackage package, AppxVolume volume) { if (package == null) { throw new ArgumentNullException(nameof(package)); } if (volume == null) { throw new ArgumentNullException(nameof(volume)); } this.PackageFullName = package.FullName; this.VolumePackagePath = volume.PackageStorePath; }
/// <summary> /// Sets the app specified by its name as startup app. /// </summary> /// <remarks>An according package will be searched on the device. With the package identified the startup setup will be triggered.</remarks> /// <param name="appName">The app's name which shall be set as startup app.</param> static void SetDefaultStartupApp(string appName) { Console.Write("Default startup app specified: " + appName); installedAppsOnTarget = msIotApiWrapper.GetInstalledApps(); AppxPackage StartupAppPackage = installedAppsOnTarget.Where(app => app.PackageName.Contains(appName)).FirstOrDefault(); if (StartupAppPackage != null) { Console.Write(" having the ID " + StartupAppPackage.PackageRelativeId + ". Trying to register as default startup app... "); msIotApiWrapper.SetDefaultStartupApp(StartupAppPackage); Console.WriteLine(" Done."); } else { Console.WriteLine(". This app could not be found on the target."); } }
private async void execute_RefreshCommand(object obj) { borderLoading.Visibility = Visibility.Visible; ViewModel.AppxPackageCollection.Clear(); string[] dirs = null; try { dirs = AppxPackage.GetDirs(); } catch (Exception ex) { borderLoading.Visibility = Visibility.Collapsed; MessageBox.Show(ex.Message, nameof(WindowsAppsRegister), MessageBoxButton.OK, MessageBoxImage.Warning); return; } ViewModel.ProgressMaximum = dirs.Length; ViewModel.ProgressValue = 0; foreach (var dir in dirs) { ViewModel.ProgressValue++; AppxPackage package = new AppxPackage(); await Task.Run(() => package.Load(dir)); if ( package.InstallLocation == null || package.IsFramework || package.IsResourcePackage) { continue; } await package.RefreshRegisterStatusAsync(); ViewModel.AppxPackageCollection.Add(package); } borderLoading.Visibility = Visibility.Collapsed; }
public PackageGraphElement(int id, AppxPackage package) : base(id) { this.Package = package; this.PackageName = package.DisplayName; }
private static async Task <AppxPackage> Translate(IAppxFileReader fileReader, AppxPackage package, CancellationToken cancellationToken) { var translationRequired = package.DisplayName?.StartsWith("ms-resource:") == true || package.PublisherDisplayName?.StartsWith("ms-resource:") == true || package.Description?.StartsWith("ms-resource:") == true || package.Applications.Any(a => a.DisplayName?.StartsWith("ms-resource:") == true) || package.Applications.Any(a => a.Description?.StartsWith("ms-resource:") == true); if (!translationRequired) { return(package); } string priFullPath = null; var cleanup = false; try { if (fileReader.FileExists("resources.pri")) { using (var stream = fileReader.GetFile("resources.pri")) { if (stream is FileStream fileStream) { priFullPath = fileStream.Name; } else { priFullPath = Path.GetTempFileName(); cleanup = true; using (var fs = File.OpenWrite(priFullPath)) { await stream.CopyToAsync(fs, cancellationToken).ConfigureAwait(false); await fs.FlushAsync(cancellationToken).ConfigureAwait(false); } } } package.DisplayName = StringLocalizer.Localize(priFullPath, package.Name, package.FullName, package.DisplayName); package.Description = StringLocalizer.Localize(priFullPath, package.Name, package.FullName, package.Description); package.PublisherDisplayName = StringLocalizer.Localize(priFullPath, package.Name, package.FullName, package.PublisherDisplayName); if (string.IsNullOrEmpty(package.DisplayName)) { package.DisplayName = package.Name; } if (string.IsNullOrEmpty(package.PublisherDisplayName)) { package.PublisherDisplayName = package.Publisher; } foreach (var app in package.Applications ?? Enumerable.Empty <AppxApplication>()) { app.DisplayName = StringLocalizer.Localize(priFullPath, app.Id, package.FullName, app.DisplayName); if (string.IsNullOrEmpty(app.DisplayName)) { app.DisplayName = app.Id; } app.Description = StringLocalizer.Localize(priFullPath, app.Id, package.FullName, app.Description); } } return(package); } finally { if (cleanup && File.Exists(priFullPath)) { File.Delete(priFullPath); } } }
private async Task <AppxPackage> ReadMsix(IAppxFileReader fileReader, string manifestFileName, CancellationToken cancellationToken = default) { using (var file = fileReader.GetFile(manifestFileName)) { var document = await XDocument.LoadAsync(file, LoadOptions.None, cancellationToken).ConfigureAwait(false); if (document.Root == null) { throw new FormatException("The manifest is malformed. There is no root element."); } var ns = XNamespace.Get("http://schemas.microsoft.com/appx/manifest/foundation/windows10"); var ns2 = XNamespace.Get("http://schemas.microsoft.com/appx/2010/manifest"); var uap = XNamespace.Get("http://schemas.microsoft.com/appx/manifest/uap/windows10"); var uap10 = XNamespace.Get("http://schemas.microsoft.com/appx/manifest/uap/windows10/10"); var uap5 = XNamespace.Get("http://schemas.microsoft.com/appx/manifest/uap/windows10/5"); var uap3 = XNamespace.Get("http://schemas.microsoft.com/appx/manifest/uap/windows10/3"); var desktop10 = XNamespace.Get("http://schemas.microsoft.com/appx/manifest/desktop/windows10"); var desktop6 = XNamespace.Get("http://schemas.microsoft.com/appx/manifest/desktop/windows10/6"); var desktop2 = XNamespace.Get("http://schemas.microsoft.com/appx/manifest/desktop/windows10/2"); var build = XNamespace.Get("http://schemas.microsoft.com/developer/appx/2015/build"); if (document.Root == null) { throw new FormatException("The manifest is malformed. The document root must be <Package /> element."); } if (document.Root.Name.LocalName != "Package") { throw new FormatException("The manifest is malformed. The document root must be <Package /> element."); } if (document.Root.Name.Namespace != ns && document.Root.Name.Namespace != ns2) { throw new FormatException("The manifest is malformed. The document root must be <Package /> element, belonging to a supported namespace."); } var nodePackage = document.Root; cancellationToken.ThrowIfCancellationRequested(); var nodeIdentity = nodePackage.Element(ns + "Identity") ?? nodePackage.Element(ns2 + "Identity"); cancellationToken.ThrowIfCancellationRequested(); var nodeProperties = nodePackage.Element(ns + "Properties") ?? nodePackage.Element(ns2 + "Properties"); cancellationToken.ThrowIfCancellationRequested(); var nodeApplicationsRoot = nodePackage.Element(ns + "Applications") ?? nodePackage.Element(ns2 + "Applications"); cancellationToken.ThrowIfCancellationRequested(); var nodeCapabilitiesRoot = nodePackage.Element(ns + "Capabilities") ?? nodePackage.Element(ns2 + "Capabilities"); cancellationToken.ThrowIfCancellationRequested(); var nodeDependenciesRoot = nodePackage.Element(ns + "Dependencies") ?? nodePackage.Element(ns2 + "Dependencies"); cancellationToken.ThrowIfCancellationRequested(); var nodePrerequisitesRoot = nodePackage.Element(ns + "Prerequisites") ?? nodePackage.Element(ns2 + "Prerequisites"); cancellationToken.ThrowIfCancellationRequested(); var nodeBuild = nodePackage.Element(build + "Metadata"); var appxPackage = new AppxPackage(); if (fileReader is IAppxDiskFileReader diskReader) { appxPackage.RootFolder = diskReader.RootDirectory; } else if (fileReader is ZipArchiveFileReaderAdapter zipArchiveReader) { appxPackage.RootFolder = Path.GetDirectoryName(zipArchiveReader.PackagePath); } cancellationToken.ThrowIfCancellationRequested(); if (nodeIdentity != null) { appxPackage.Name = nodeIdentity.Attribute("Name")?.Value; var procArch = nodeIdentity.Attribute("ProcessorArchitecture")?.Value; if (Enum.TryParse(typeof(AppxPackageArchitecture), procArch ?? string.Empty, true, out object parsedArchitecture) && parsedArchitecture != null) { appxPackage.ProcessorArchitecture = (AppxPackageArchitecture)parsedArchitecture; } else { appxPackage.ProcessorArchitecture = AppxPackageArchitecture.Neutral; } appxPackage.Publisher = nodeIdentity.Attribute("Publisher")?.Value; appxPackage.Version = nodeIdentity.Attribute("Version")?.Value; } cancellationToken.ThrowIfCancellationRequested(); if (nodeProperties != null) { foreach (var node in nodeProperties.Elements()) { switch (node.Name.LocalName) { case "Logo": var logo = node.Value; if (!string.IsNullOrEmpty(logo)) { using (var resourceStream = fileReader.GetResource(logo)) { if (resourceStream != null) { using (var memoryStream = new MemoryStream()) { await resourceStream.CopyToAsync(memoryStream, cancellationToken).ConfigureAwait(false); await memoryStream.FlushAsync(cancellationToken).ConfigureAwait(false); appxPackage.Logo = memoryStream.ToArray(); } } } } break; case "DisplayName": appxPackage.DisplayName = node.Value; break; case "PublisherDisplayName": appxPackage.PublisherDisplayName = node.Value; break; case "PackageIntegrity": var packageIntegrityContent = nodeProperties.Element(uap10 + "Content"); if (packageIntegrityContent != null) { appxPackage.PackageIntegrity = packageIntegrityContent.Attribute("Enforcement")?.Value == "on"; } break; case "Framework": appxPackage.IsFramework = string.Equals(node.Value ?? "false", "true", StringComparison.OrdinalIgnoreCase); break; case "Description": appxPackage.Description = node.Value; break; } } } cancellationToken.ThrowIfCancellationRequested(); appxPackage.PackageDependencies = new List <AppxPackageDependency>(); appxPackage.OperatingSystemDependencies = new List <AppxOperatingSystemDependency>(); appxPackage.MainPackages = new List <AppxMainPackageDependency>(); appxPackage.Applications = new List <AppxApplication>(); if (nodeApplicationsRoot != null) { foreach (var node in nodeApplicationsRoot.Elements().Where(x => x.Name.LocalName == "Application" && (x.Name.Namespace == ns || x.Name.Namespace == ns2))) { cancellationToken.ThrowIfCancellationRequested(); /* * <Application EntryPoint="SparklerApp.App" Executable="XD.exe" Id="App"> * <uap:VisualElements BackgroundColor="#2D001E" Description="Adobe XD" DisplayName="Adobe XD" Square150x150Logo="Assets\xd_med_tile.png" Square44x44Logo="Assets\xd_app_list_icon.png"> * <uap:DefaultTile Square310x310Logo="Assets\xd_large_tile.png" Square71x71Logo="Assets\xd_small_tile.png" Wide310x150Logo="Assets\xd_wide_tile.png"> * <uap:ShowNameOnTiles> * <uap:ShowOn Tile="square150x150Logo" /> * <uap:ShowOn Tile="wide310x150Logo" /> * <uap:ShowOn Tile="square310x310Logo" /> * </uap:ShowNameOnTiles> * </uap:DefaultTile> * <uap:SplashScreen BackgroundColor="#FFFFFF" Image="Assets\xd_splash.png" /> * </uap:VisualElements> * * <Application Id="RayEval" Executable="PsfLauncher32.exe" EntryPoint="Windows.FullTrustApplication"> * <uap:VisualElements DisplayName="RayEval" Description="RayEval Raynet GmbH" BackgroundColor="transparent" * Square150x150Logo="Assets\Square150x150Logo.scale-100.png" Square44x44Logo="Assets\Square44x44Logo.scale-100.png"> * <uap:DefaultTile Wide310x150Logo="Assets\Square310x150Logo.scale-100.png" Square310x310Logo="Assets\Square310x310Logo.scale-100.png" Square71x71Logo="Assets\Square71x71Logo.scale-100.png" /> * </uap:VisualElements> * <Extensions /> * </Application> */ var appxApplication = new AppxApplication { EntryPoint = node.Attribute("EntryPoint")?.Value, StartPage = node.Attribute("StartPage")?.Value, Executable = node.Attribute("Executable")?.Value, Id = node.Attribute("Id")?.Value, Extensions = new List <AppxExtension>() }; /* * <Extensions><desktop6:Extension Category="windows.service" Executable="VFS\ProgramFilesX86\RayPackStudio\FloatingLicenseServer\FloatingLicenseServer.exe" EntryPoint="Windows.FullTrustApplication"><desktop6:Service Name="PkgSuiteFloatingLicenseServer" StartupType="auto" StartAccount="networkService" /></desktop6:Extension></Extensions> */ var nodeExtensions = node.Elements().FirstOrDefault(e => e.Name.LocalName == "Extensions"); if (nodeExtensions != null) { foreach (var extension in nodeExtensions.Elements().Where(e => e.Name.LocalName == "Extension" && (e.Name.Namespace == ns || e.Name.Namespace == ns2 || e.Name.Namespace == desktop6 || e.Name.Namespace == desktop2 || e.Name.Namespace == uap5 || e.Name.Namespace == uap3))) { cancellationToken.ThrowIfCancellationRequested(); var category = extension.Attribute("Category")?.Value; switch (category) { case "windows.appExecutionAlias": var aliasNode = extension.Element(uap3 + "AppExecutionAlias") ?? extension.Element(uap5 + "AppExecutionAlias"); if (aliasNode != null) { var desktopExecAliases = aliasNode.Elements(desktop10 + "ExecutionAlias").Concat(aliasNode.Elements(uap5 + "ExecutionAlias")); foreach (var desktopExecAlias in desktopExecAliases) { if (appxApplication.ExecutionAlias == null) { appxApplication.ExecutionAlias = new List <string>(); } appxApplication.ExecutionAlias.Add(desktopExecAlias.Attribute("Alias")?.Value); } } break; case "windows.service": var serviceNode = extension.Element(desktop6 + "Service"); if (serviceNode == null) { continue; } var service = new AppxService { Category = "windows.service" }; service.EntryPoint = extension.Attribute("EntryPoint")?.Value; service.Executable = extension.Attribute("Executable")?.Value; service.Name = extension.Attribute("Name")?.Value; service.StartAccount = extension.Attribute("StartAccount")?.Value; service.StartupType = extension.Attribute("StartupType")?.Value; appxApplication.Extensions.Add(service); break; } } } var visualElements = node.Elements().FirstOrDefault(e => e.Name.LocalName == "VisualElements"); if (visualElements != null) { cancellationToken.ThrowIfCancellationRequested(); appxApplication.Description = visualElements.Attribute("Description")?.Value; appxApplication.DisplayName = visualElements.Attribute("DisplayName")?.Value; appxApplication.BackgroundColor = visualElements.Attribute("BackgroundColor")?.Value; appxApplication.Square150x150Logo = visualElements.Attribute("Square150x150Logo")?.Value; appxApplication.Square44x44Logo = visualElements.Attribute("Square44x44Logo")?.Value; appxApplication.Visible = visualElements.Attribute("AppListEntry")?.Value != "none"; var defaultTile = visualElements.Element(uap + "DefaultTile"); if (defaultTile != null) { appxApplication.Wide310x150Logo = defaultTile.Attribute("Wide310x150Logo")?.Value; appxApplication.Square310x310Logo = defaultTile.Attribute("Square310x310Logo")?.Value; appxApplication.Square71x71Logo = defaultTile.Attribute("Square71x71Logo")?.Value; appxApplication.ShortName = defaultTile.Attribute("ShortName")?.Value; } var logo = appxApplication.Square44x44Logo ?? appxApplication.Square30x30Logo ?? appxApplication.Square71x71Logo ?? appxApplication.Square150x150Logo; if (logo == null) { appxApplication.Logo = appxPackage.Logo; } else { using (var stream = fileReader.GetResource(appxApplication.Square44x44Logo) ?? fileReader.GetResource(appxApplication.Square30x30Logo) ?? fileReader.GetResource(appxApplication.Square71x71Logo) ?? fileReader.GetResource(appxApplication.Square150x150Logo)) { if (stream != null) { var bytes = new byte[stream.Length]; await stream.ReadAsync(bytes, 0, bytes.Length, cancellationToken).ConfigureAwait(false); appxApplication.Logo = bytes; } else { appxApplication.Logo = appxPackage.Logo; } } } } appxPackage.Applications.Add(appxApplication); } var psfApps = appxPackage.Applications.Where(a => PackageTypeConverter.GetPackageTypeFrom(a.EntryPoint, a.Executable, a.StartPage, appxPackage.IsFramework) == MsixPackageType.BridgePsf).ToArray(); if (psfApps.Any()) { foreach (var psfApp in psfApps) { cancellationToken.ThrowIfCancellationRequested(); psfApp.Psf = this.PsfReader.Read(psfApp.Id, psfApp.Executable, fileReader); } } } if (nodeDependenciesRoot != null) { var dependencies = nodeDependenciesRoot.Elements(); if (dependencies != null) { foreach (var node in dependencies) { switch (node.Name.LocalName) { case "MainPackageDependency": var modName = node.Attribute("Name")?.Value; var appxModPackDependency = new AppxMainPackageDependency { Name = modName, }; appxPackage.MainPackages.Add(appxModPackDependency); break; case "TargetDeviceFamily": { /* * <TargetDeviceFamily MaxVersionTested="10.0.15063.0" MinVersion="10.0.15063.0" Name="Windows.Universal" /> */ var minVersion = node.Attribute("MinVersion")?.Value; var maxVersion = node.Attribute("MaxVersionTested")?.Value; var name = node.Attribute("Name")?.Value; appxPackage.OperatingSystemDependencies.Add(new AppxOperatingSystemDependency { Minimum = WindowsNames.GetOperatingSystemFromNameAndVersion(name, minVersion), Tested = WindowsNames.GetOperatingSystemFromNameAndVersion(name, maxVersion), }); break; } case "PackageDependency": { /* * <PackageDependency MinVersion="1.4.24201.0" Name="Microsoft.NET.Native.Runtime.1.4" Publisher="CN=Microsoft Corporation, O=Microsoft Corporation, L=Redmond, S=Washington, C=US" /> */ var minVersion = node.Attribute("MinVersion")?.Value; var name = node.Attribute("Name")?.Value; var publisher = node.Attribute("Publisher")?.Value; var appxDependency = new AppxPackageDependency { Publisher = publisher, Name = name, Version = minVersion }; appxPackage.PackageDependencies.Add(appxDependency); break; } } } } } if (nodePrerequisitesRoot != null) { var min = nodePrerequisitesRoot.Element(ns2 + "OSMinVersion")?.Value; var max = nodePrerequisitesRoot.Element(ns2 + "OSMaxVersionTested")?.Value; appxPackage.OperatingSystemDependencies.Add(new AppxOperatingSystemDependency { Minimum = min == null ? null : WindowsNames.GetOperatingSystemFromNameAndVersion("Windows.Desktop", min), Tested = max == null ? null : WindowsNames.GetOperatingSystemFromNameAndVersion("Windows.Desktop", max), }); } if (nodeBuild != null) { var buildKeyValues = new Dictionary <string, string>(); foreach (var buildNode in nodeBuild.Elements(build + "Item")) { var attrName = buildNode.Attribute("Name")?.Value; if (attrName == null) { continue; } var attrVersion = buildNode.Attribute("Version")?.Value; if (attrVersion == null) { attrVersion = buildNode.Attribute("Value")?.Value; if (attrVersion == null) { continue; } } buildKeyValues[attrName] = attrVersion; } var appDetector = new AuthoringAppDetector(fileReader); if (appDetector.TryDetectAny(buildKeyValues, out var buildInfo)) { appxPackage.BuildInfo = buildInfo; } } appxPackage.FamilyName = AppxPackaging.GetPackageFamilyName(appxPackage.Name, appxPackage.Publisher); appxPackage.FullName = AppxPackaging.GetPackageFullName(appxPackage.Name, appxPackage.Publisher, appxPackage.ProcessorArchitecture, appxPackage.Version, appxPackage.ResourceId); appxPackage.Capabilities = this.GetCapabilities(nodeCapabilitiesRoot); var pkgManager = new PackageManager(); var pkg = pkgManager.FindPackageForUser(string.Empty, appxPackage.FullName); if (pkg == null && appxPackage.ResourceId == null) { appxPackage.FullName = AppxPackaging.GetPackageFullName(appxPackage.Name, appxPackage.Publisher, appxPackage.ProcessorArchitecture, appxPackage.Version, "neutral"); pkg = pkgManager.FindPackageForUser(string.Empty, appxPackage.FullName); } string manifestFilePath; if (pkg?.InstalledLocation != null) { manifestFilePath = Path.Combine(pkg.InstalledLocation.Path, FileConstants.AppxManifestFile); } else if (fileReader is IAppxDiskFileReader appxDiskReader) { manifestFilePath = Path.Combine(appxDiskReader.RootDirectory, manifestFileName); } else { manifestFilePath = manifestFileName; } if (pkg == null) { appxPackage.Source = new NotInstalledSource(); } else if (pkg.SignatureKind == PackageSignatureKind.System) { appxPackage.Source = new SystemSource(manifestFilePath); } else if (pkg.SignatureKind == PackageSignatureKind.None || pkg.IsDevelopmentMode) { appxPackage.Source = new DeveloperSource(Path.Combine(appxPackage.RootFolder, manifestFileName)); } else if (pkg.SignatureKind == PackageSignatureKind.Store) { appxPackage.Source = new StorePackageSource(appxPackage.FamilyName, Path.GetDirectoryName(manifestFilePath)); } else { var appInstaller = pkg.GetAppInstallerInfo(); if (appInstaller != null) { appxPackage.Source = new AppInstallerPackageSource(appInstaller.Uri, Path.GetDirectoryName(manifestFilePath)); } } if (appxPackage.Source == null) { appxPackage.Source = new StandardSource(manifestFilePath); } return(await Translate(fileReader, appxPackage, cancellationToken).ConfigureAwait(false)); } }
public RootGraphElement(AppxPackage package) : base(0, package) { }
public RootDependencyVertex(AppxPackage packageDependency) { this.packageDependency = packageDependency; }
public PackageContentDetailsViewModel(AppxPackage model, string filePath = null) { this.Model = model; this.DisplayName = model.DisplayName; this.Description = model.Description; this.Publisher = model.Publisher; this.FamilyName = model.FamilyName; this.Architecture = model.ProcessorArchitecture.ToString(); this.PackageFullName = model.FullName; this.PublisherDisplayName = model.PublisherDisplayName; this.Version = model.Version; this.Logo = model.Logo; this.OperatingSystemDependencies = new ObservableCollection <OperatingSystemDependencyViewModel>(); this.Applications = new ObservableCollection <AppxApplicationViewModel>(); this.PackageDependencies = new ObservableCollection <PackageDependencyViewModel>(); if (model.OperatingSystemDependencies != null) { foreach (var item in model.OperatingSystemDependencies) { this.OperatingSystemDependencies.Add(new OperatingSystemDependencyViewModel(item)); } } if (model.PackageDependencies != null) { foreach (var item in model.PackageDependencies) { this.PackageDependencies.Add(new PackageDependencyViewModel(item)); } } this.HasOperatingSystemDependencies = this.OperatingSystemDependencies.Any(); this.HasPackageDependencies = this.PackageDependencies.Any(); this.ScriptsCount = 0; if (model.Applications != null) { foreach (var item in model.Applications) { if (string.IsNullOrEmpty(this.TileColor)) { this.TileColor = item.BackgroundColor; } this.Applications.Add(new AppxApplicationViewModel(item, model)); this.ScriptsCount += item.Psf?.Scripts?.Count ?? 0; } } this.Fixups = new ObservableCollection <AppxApplicationViewModel>(this.Applications.Where(a => a.HasPsf && a.Psf != null && (a.Psf.HasFileRedirections || a.Psf.HasTracing || a.Psf.HasOtherFixups))); this.selectedFixup = this.Fixups.FirstOrDefault(); // 1) fixup count is the sum of all individual file redirections... this.FixupsCount = this.Fixups.SelectMany(s => s.Psf.FileRedirections).Select(s => s.Exclusions.Count + s.Inclusions.Count).Sum(); // 2) plus additionally number of apps that have tracing this.FixupsCount += this.Applications.Count(a => a.HasPsf && a.Psf.HasTracing); this.BuildInfo = model.BuildInfo; if (string.IsNullOrEmpty(this.TileColor)) { this.TileColor = "#666666"; } this.Capabilities = new CapabilitiesViewModel(model.Capabilities); this.PackageIntegrity = model.PackageIntegrity; this.RootDirectory = filePath; }
public InstalledDependencyVertex(AppxPackage packageDependency) { this.packageDependency = packageDependency; }
public static async void DeployAppAsync(HttpClient client, string addr, AppxPackage app) { throw new NotImplementedException(); }
private static IEnumerable <AppxPackage> QueryPackageInfo(string fullName, PackageConstants flags) { IntPtr infoRef; OpenPackageInfoByFullName(fullName, 0, out infoRef); if (infoRef != IntPtr.Zero) { IntPtr infoBuffer = IntPtr.Zero; try { int len = 0; int count; GetPackageInfo(infoRef, flags, ref len, IntPtr.Zero, out count); if (len > 0) { var factory = (IAppxFactory) new AppxFactory(); infoBuffer = Marshal.AllocHGlobal(len); int res = GetPackageInfo(infoRef, flags, ref len, infoBuffer, out count); for (int i = 0; i < count; i++) { var info = (PACKAGE_INFO)Marshal.PtrToStructure(infoBuffer + i * Marshal.SizeOf(typeof(PACKAGE_INFO)), typeof(PACKAGE_INFO)); var package = new AppxPackage(); package.FamilyName = Marshal.PtrToStringUni(info.packageFamilyName); package.FullName = Marshal.PtrToStringUni(info.packageFullName); package.Path = Marshal.PtrToStringUni(info.path); package.Publisher = Marshal.PtrToStringUni(info.packageId.publisher); package.PublisherId = Marshal.PtrToStringUni(info.packageId.publisherId); package.ResourceId = Marshal.PtrToStringUni(info.packageId.resourceId); package.ProcessorArchitecture = info.packageId.processorArchitecture; package.Version = new Version(info.packageId.VersionMajor, info.packageId.VersionMinor, info.packageId.VersionBuild, info.packageId.VersionRevision); // read manifest string manifestPath = System.IO.Path.Combine(package.Path, "AppXManifest.xml"); const int STGM_SHARE_DENY_NONE = 0x40; IStream strm; SHCreateStreamOnFileEx(manifestPath, STGM_SHARE_DENY_NONE, 0, false, IntPtr.Zero, out strm); if (strm != null) { var reader = factory.CreateManifestReader(strm); package._properties = reader.GetProperties(); package.Description = package.GetPropertyStringValue("Description"); package.DisplayName = package.GetPropertyStringValue("DisplayName"); package.Logo = package.GetPropertyStringValue("Logo"); package.PublisherDisplayName = package.GetPropertyStringValue("PublisherDisplayName"); package.IsFramework = package.GetPropertyBoolValue("Framework"); var apps = reader.GetApplications(); while (apps.GetHasCurrent()) { var app = apps.GetCurrent(); var appx = new AppxApp(app); appx.Description = GetStringValue(app, "Description"); appx.DisplayName = GetStringValue(app, "DisplayName"); appx.EntryPoint = GetStringValue(app, "EntryPoint"); appx.Executable = GetStringValue(app, "Executable"); appx.Id = GetStringValue(app, "Id"); appx.Logo = GetStringValue(app, "Logo"); appx.SmallLogo = GetStringValue(app, "SmallLogo"); appx.StartPage = GetStringValue(app, "StartPage"); appx.Square150x150Logo = GetStringValue(app, "Square150x150Logo"); appx.Square30x30Logo = GetStringValue(app, "Square30x30Logo"); appx.BackgroundColor = GetStringValue(app, "BackgroundColor"); appx.ForegroundText = GetStringValue(app, "ForegroundText"); appx.WideLogo = GetStringValue(app, "WideLogo"); appx.Wide310x310Logo = GetStringValue(app, "Wide310x310Logo"); appx.ShortName = GetStringValue(app, "ShortName"); appx.Square310x310Logo = GetStringValue(app, "Square310x310Logo"); appx.Square70x70Logo = GetStringValue(app, "Square70x70Logo"); appx.MinWidth = GetStringValue(app, "MinWidth"); package._apps.Add(appx); apps.MoveNext(); } Marshal.ReleaseComObject(strm); } yield return(package); } Marshal.ReleaseComObject(factory); } } finally { if (infoBuffer != IntPtr.Zero) { Marshal.FreeHGlobal(infoBuffer); } ClosePackageInfo(infoRef); } } }
private async Task <IList <AppxPackage> > GetConsideredPackages(AppxPackage startPackage, CancellationToken cancellationToken = default, IProgress <ProgressData> progress = default) { var progressForGettingPackages = new RangeProgress(progress, 0, 70); var progressForGettingAddOns = new RangeProgress(progress, 70, 90); var progressForCalculation = new RangeProgress(progress, 90, 100); var manager = await this.packageManager.GetProxyFor(SelfElevationLevel.HighestAvailable, cancellationToken).ConfigureAwait(false); var allPackages = await manager.GetInstalledPackages(PackageFindMode.Auto, cancellationToken, progressForGettingPackages).ConfigureAwait(false); var consideredPackages = new List <AppxPackage> { startPackage }; var addOnPackages = new List <AppxPackage>(); var manifestReader = new AppxManifestReader(); progressForGettingAddOns.Report(new ProgressData(0, "Reading optional packages...")); foreach (var addOnPackage in allPackages.Where(installedPackage => installedPackage.IsOptional)) { using var fileReader = FileReaderFactory.CreateFileReader(addOnPackage.ManifestLocation); addOnPackages.Add(await manifestReader.Read(fileReader, false, cancellationToken).ConfigureAwait(false)); } progressForCalculation.Report(new ProgressData(0, "Reading relations...")); for (var i = 0; i < consideredPackages.Count; i++) { var currentPkg = consideredPackages[i]; var matchingAddOns = addOnPackages.Where(addOnPackage => addOnPackage.MainPackages.Any(dep => dep.Name == currentPkg.Name)); foreach (var matchingAddOn in matchingAddOns) { if (consideredPackages.Any(existing => existing.Publisher == matchingAddOn.Publisher && existing.Name == matchingAddOn.Name)) { // we have already processes this package continue; } consideredPackages.Add(matchingAddOn); } foreach (var dependency in currentPkg.PackageDependencies) { if (consideredPackages.Any(existing => existing.Publisher == dependency.Publisher && existing.Name == dependency.Name)) { // we have already processes this package continue; } var candidate = allPackages.FirstOrDefault(installedPackage => installedPackage.Name == dependency.Name && installedPackage.Publisher == dependency.Publisher && installedPackage.Version >= Version.Parse(dependency.Version)); if (candidate != null) { using var fileReader = FileReaderFactory.CreateFileReader(candidate.ManifestLocation); consideredPackages.Add(await manifestReader.Read(fileReader, false, cancellationToken).ConfigureAwait(false)); } } foreach (var dependency in currentPkg.MainPackages) { if (consideredPackages.Any(existing => existing.Name == dependency.Name)) { // we have already processes this package continue; } var candidate = allPackages.FirstOrDefault(installedPackage => installedPackage.Name == dependency.Name); if (candidate != null) { using var fileReader = FileReaderFactory.CreateFileReader(candidate.ManifestLocation); consideredPackages.Add(await manifestReader.Read(fileReader, false, cancellationToken).ConfigureAwait(false)); } } } return(consideredPackages); }
public PackageExpertPropertiesViewModel(AppxPackage model, string filePath = null) { this.Model = model; this.DisplayName = model.DisplayName; this.Description = model.Description; this.Publisher = model.Publisher; this.FamilyName = model.FamilyName; this.Architecture = model.ProcessorArchitecture.ToString(); this.PackageFullName = model.FullName; this.PublisherDisplayName = model.PublisherDisplayName; this.Version = model.Version; this.Logo = model.Logo; this.OperatingSystemDependencies = new ObservableCollection <OperatingSystemDependencyViewModel>(); this.Applications = new ObservableCollection <AppxApplicationViewModel>(); this.PackageDependencies = new ObservableCollection <PackageDependencyViewModel>(); if (model.OperatingSystemDependencies != null) { foreach (var item in model.OperatingSystemDependencies) { this.OperatingSystemDependencies.Add(new OperatingSystemDependencyViewModel(item)); } } if (model.PackageDependencies != null) { foreach (var item in model.PackageDependencies) { this.PackageDependencies.Add(new PackageDependencyViewModel(item)); } } this.HasOperatingSystemDependencies = this.OperatingSystemDependencies.Any(); this.HasPackageDependencies = this.PackageDependencies.Any(); this.ScriptsCount = 0; if (model.Applications != null) { foreach (var item in model.Applications) { if (string.IsNullOrEmpty(this.TileColor)) { this.TileColor = item.BackgroundColor; } this.Applications.Add(new AppxApplicationViewModel(item, model)); this.ScriptsCount += item.Psf?.Scripts?.Count ?? 0; } } this.Fixups = new ObservableCollection <AppxApplicationViewModel>(this.Applications.Where(a => a.HasPsf && a.Psf != null && (a.Psf.HasFileRedirections || a.Psf.HasTracing || a.Psf.HasOtherFixups))); // 1) fixup count is the sum of all individual file redirections... this.FixupsCount = this.Fixups.SelectMany(s => s.Psf.FileRedirections).Select(s => s.Exclusions.Count + s.Inclusions.Count).Sum(); // 2) plus additionally number of apps that have tracing this.FixupsCount += this.Applications.Count(a => a.HasPsf && a.Psf.HasTracing); this.BuildInfo = model.BuildInfo; if (string.IsNullOrEmpty(this.TileColor)) { this.TileColor = "#666666"; } if (filePath != null) { this.RootDirectory = filePath.Replace(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles).TrimEnd('\\'), "%programfiles%"); } this.Capabilities = new CapabilitiesViewModel(model.Capabilities); this.PackageIntegrity = model.PackageIntegrity; this.UserDirectory = Path.Combine("%localappdata%", "Packages", this.FamilyName, "LocalCache"); this.PsfFilePath = Path.Combine(filePath, "config.json"); this.ManifestFilePath = Path.Combine(filePath, FileConstants.AppxManifestFile); if (!File.Exists(this.PsfFilePath)) { this.PsfFilePath = null; } if (!File.Exists(this.ManifestFilePath)) { this.ManifestFilePath = null; } }
public async Task <DependencyGraph> GetGraph(AppxPackage package, CancellationToken cancellationToken = default, IProgress <ProgressData> progress = null) { var dependencyGraph = new DependencyGraph(); var list = await this.GetConsideredPackages(package, cancellationToken, progress).ConfigureAwait(false); var packages = this.GetPackageDependencies(0, list).ToList(); var operatingSystems = this.GetOperatingSystemDependencies(packages.Count, list).ToList(); var unresolvedDependencies = new List <MissingPackageGraphElement>(); var id = packages.Count + operatingSystems.Count; foreach (var pkg in packages) { foreach (var packageDependency in pkg.Package.PackageDependencies) { var findDependency = packages.FirstOrDefault(depPkg => depPkg.Package.Name == packageDependency.Name && depPkg.Package.Publisher == packageDependency.Publisher); if (findDependency != null) { dependencyGraph.Relations.Add(new Relation(findDependency, packageDependency.Version + "˄", pkg)); } else { var findUnresolved = unresolvedDependencies.FirstOrDefault(unresolved => unresolved.PackageName == packageDependency.Name); if (findUnresolved == null) { id++; findUnresolved = new MissingPackageGraphElement(id, packageDependency.Name); unresolvedDependencies.Add(findUnresolved); dependencyGraph.Elements.Add(findUnresolved); } dependencyGraph.Relations.Add(new Relation(findUnresolved, packageDependency.Version + "˄", pkg)); } } foreach (var systemDependency in pkg.Package.OperatingSystemDependencies) { var findSystem = operatingSystems.First(os => os.OperatingSystem == GetOsFamily(systemDependency)); dependencyGraph.Relations.Add(new Relation(findSystem, findSystem.MaxRequiredVersion + "˄", pkg)); } foreach (var mainPackage in pkg.Package.MainPackages) { var findParent = packages.FirstOrDefault(depPkg => depPkg.Package.Name == mainPackage.Name); if (findParent != null) { dependencyGraph.Relations.Add(new Relation(findParent, "main package", pkg)); } else { var findUnresolved = unresolvedDependencies.FirstOrDefault(unresolved => unresolved.PackageName == mainPackage.Name); if (findUnresolved == null) { id++; findUnresolved = new MissingPackageGraphElement(id, mainPackage.Name); unresolvedDependencies.Add(findUnresolved); dependencyGraph.Elements.Add(findUnresolved); } dependencyGraph.Relations.Add(new Relation(findUnresolved, "main package", pkg)); } } } foreach (var pkg in packages) { dependencyGraph.Elements.Add(pkg); } foreach (var os in operatingSystems) { dependencyGraph.Elements.Add(os); } return(dependencyGraph); }