Beispiel #1
0
        private IAppxFile GetManifestInfoFromPackage(IAppxFactory appxFactory, IAppxPackageReader packageReader)
        {
            var appxFile = packageReader.GetFootprintFile(APPX_FOOTPRINT_FILE_TYPE.MANIFEST);
            IAppxManifestReader manifestReader;

            appxFactory.CreateManifestReader(appxFile.GetStream(), out manifestReader);
            GetManifestInfo(manifestReader);
            return(appxFile);
        }
Beispiel #2
0
 private void GetManifestInfoFromFile(IAppxFactory appxFactory, string manifestPath)
 {
     Console.WriteLine("Reading manifest info from: " + manifestPath);
     using (var stream = new StreamWrapper(File.OpenRead(manifestPath)))
     {
         IAppxManifestReader manifestReader;
         appxFactory.CreateManifestReader(stream, out manifestReader);
         GetManifestInfo(manifestReader);
     }
 }
Beispiel #3
0
        // This function returns a list of attributes of applications
        public static IEnumerable <IAppxManifestApplication> GetAppsFromManifest(IStream stream)
        {
            var reader       = AppxFactory.CreateManifestReader(stream);
            var manifestApps = reader.GetApplications();

            while (manifestApps.GetHasCurrent())
            {
                var manifestApp = manifestApps.GetCurrent();
                var hr          = manifestApp.GetStringValue("AppListEntry", out var appListEntry);
                _ = CheckHRAndReturnOrThrow(hr, appListEntry);
                if (appListEntry != "none")
                {
                    yield return(manifestApp);
                }

                manifestApps.MoveNext();
            }
        }
Beispiel #4
0
 private void GetManifestInfoFromFile(IAppxFactory appxFactory, string manifestPath)
 {
     Console.WriteLine("Reading manifest info from: " + manifestPath);
     using (var stream = new StreamWrapper(File.OpenRead(manifestPath)))
     {
         IAppxManifestReader manifestReader;
         appxFactory.CreateManifestReader(stream, out manifestReader);
         GetManifestInfo(manifestReader);
     }
 }
Beispiel #5
0
 private IAppxFile GetManifestInfoFromPackage(IAppxFactory appxFactory, IAppxPackageReader packageReader)
 {
     var appxFile = packageReader.GetFootprintFile(APPX_FOOTPRINT_FILE_TYPE.MANIFEST);
     IAppxManifestReader manifestReader;
     appxFactory.CreateManifestReader(appxFile.GetStream(), out manifestReader);
     GetManifestInfo(manifestReader);
     return appxFile;
 }
        static public void GetPackagesForCurrentUser(ref List <PackageInfo> packageInfos)
        {
            string currentUserSID = WindowsIdentity.GetCurrent().User.ToString();

            //---------------------------------------------------------------------------------------
            // Get iterator over all packages installed for this user

            // First, we need the PackageManager

            IAppxFactory appxFactory = (IAppxFactory) new AppxFactory();

            PackageManager packageManager = new PackageManager();

            IEnumerable <Package> packages = packageManager.FindPackagesForUser(currentUserSID);
            int cPackages = packages.Count();

            if (cPackages == 0)
            {
                return;
            }

            packageInfos = new List <PackageInfo>(cPackages);
            foreach (Package package in packages)
            {
                try
                {
                    // Find and load manifest
                    string manifestPath = package.InstalledLocation.Path + "\\AppxManifest.xml";

                    AppxPackaging.IStream manifestStream;
                    if (SHCreateStreamOnFileEx(
                            manifestPath,
                            0x00000040, // STGM_READ | STGM_SHARE_DENY_NONE
                            0,          // file creation attributes
                            false,      // fCreate
                            null,       // reserved
                            out manifestStream) < 0)
                    {
                        // If we can't open the manifest for this package, skip it
                        continue;
                    }

                    IAppxManifestReader manifestReader;
                    manifestReader = appxFactory.CreateManifestReader(manifestStream);

                    IAppxManifestApplicationsEnumerator appsEnum = manifestReader.GetApplications();
                    if (appsEnum.GetHasCurrent() == 0)
                    {
                        // Packages with no apps exist, and are uninteresting.  Skip.
                        continue;
                    }

                    // Grab info from Package
                    PackageInfo packageInfo = new PackageInfo();
                    packageInfo.installedLocation = package.InstalledLocation.Path;

                    // Grab info from PackageID
                    PackageId packageId = package.Id;
                    packageInfo.architecture = packageId.Architecture.ToString();
                    packageInfo.fullName     = packageId.FullName;
                    packageInfo.name         = packageId.Name;
                    packageInfo.version      = String.Format(
                        "{0}.{1}.{2}.{3}",
                        packageId.Version.Major,
                        packageId.Version.Minor,
                        packageId.Version.Build,
                        packageId.Version.Revision);

                    IAppxManifestProperties props = manifestReader.GetProperties();
                    packageInfo.publisher = props.GetStringValue("PublisherDisplayName");

                    // Figure out temp folder path

                    if (!GetACInfo(packageId.FamilyName, out packageInfo.acSid, out packageInfo.tempDir))
                    {
                        continue;
                    }

                    // Check to see if CLRHost.dll is listed as an InProcessServer extension.  If so,
                    // it may be a JS/CLR hybrid package, in which case we'll include all the
                    // AppUserModelIds we find later on.
                    bool usesClrHostExtension = false;
                    try
                    {
                        XmlDocument xmlDoc = new XmlDocument();
                        xmlDoc.Load(manifestPath);
                        XPathNavigator      docNavigator = xmlDoc.CreateNavigator();
                        XmlNamespaceManager mgr          = new XmlNamespaceManager(docNavigator.NameTable);
                        mgr.AddNamespace("pm", "http://schemas.microsoft.com/appx/2010/manifest");
                        XPathNodeIterator iterator = docNavigator.Select("/pm:Package/pm:Extensions/pm:Extension/pm:InProcessServer/pm:Path", mgr);
                        foreach (XPathNavigator selectedNodeNavigator in iterator)
                        {
                            if (selectedNodeNavigator.Value.IndexOf("clrhost.dll", StringComparison.CurrentCultureIgnoreCase) != -1)
                            {
                                usesClrHostExtension = true;
                                break;
                            }
                        }
                    }
                    catch (Exception)
                    {
                        // Intentionally fall through. Any error encountered determining
                        // whether this is a hybrid package should just result in us
                        // assuming it isn't one.
                        Debug.Assert(!usesClrHostExtension);
                    }

                    // For each app in the package, get its App User Model ID
                    packageInfo.appInfoList = new List <AppInfo>(5);
                    while (appsEnum.GetHasCurrent() != 0)
                    {
                        IAppxManifestApplication app = appsEnum.GetCurrent();
                        AppInfo appInfo = new AppInfo();
                        appInfo.userModelId = app.GetAppUserModelId();
                        appInfo.exeName     = app.GetStringValue("Executable");
                        IAppxManifestResourcesEnumerator resourcesEnum = manifestReader.GetResources();
                        if ((appInfo.userModelId != null) &&
                            ((appInfo.exeName != null) || usesClrHostExtension))
                        {
                            // Only care about apps with an app user model ID
                            // (which we need for activation) and either an exe name (to display to user) or
                            // evidence that a CLR extension is used
                            if (appInfo.exeName == null)
                            {
                                appInfo.exeName = "(no executable)";
                            }
                            packageInfo.appInfoList.Add(appInfo);
                        }
                        appsEnum.MoveNext();
                    }

                    if (packageInfo.appInfoList.Count > 0)
                    {
                        // Only care about packages that contain apps we care about
                        packageInfos.Add(packageInfo);
                    }
                }
                catch (Exception)
                {
                    // If there are any problems with the package we're currently
                    // iterating over, just skip it and continue with the next package
                    // in the enumeration. For example, can't open the manifest
                    // or can't find installed location for the package (b/c the
                    // developer manually moved files around), skip it
                }
            }
        }
        //Get uwp application details from package
        public static AppxDetails UwpGetAppxDetailsFromAppPackage(Package appPackage)
        {
            IStream      inputStream = null;
            IAppxFactory appxFactory = (IAppxFactory) new AppxFactory();
            AppxDetails  appxDetails = new AppxDetails();

            try
            {
                //Get detailed information from app package
                string appFamilyName = appPackage.Id.FamilyName;
                appxDetails.FullPackageName = appPackage.Id.FullName;
                appxDetails.InstallPath     = appPackage.InstalledLocation.Path;
                string manifestPath = appxDetails.InstallPath + "/AppXManifest.xml";
                //Debug.WriteLine("Reading uwp app manifest file: " + manifestPath);

                //Open the uwp application manifest file
                SHCreateStreamOnFileEx(manifestPath, STGM_MODES.STGM_SHARE_DENY_NONE, 0, false, IntPtr.Zero, out inputStream);
                if (inputStream != null)
                {
                    IAppxManifestReader      appxManifestReader      = appxFactory.CreateManifestReader(inputStream);
                    IAppxManifestApplication appxManifestApplication = appxManifestReader.GetApplications().GetCurrent();

                    //Get and set the application executable name
                    appxManifestApplication.GetStringValue("Executable", out string executableName);
                    appxDetails.ExecutableName = Path.GetFileName(executableName);

                    //Get and set the family name identifier
                    appxManifestApplication.GetStringValue("Id", out string appIdentifier);
                    appxDetails.FamilyNameId = appFamilyName + "!" + appIdentifier;

                    //Get and set the application display name
                    appxManifestApplication.GetStringValue("DisplayName", out string displayName);
                    appxDetails.DisplayName = UwpGetMsResourceString(appIdentifier, appxDetails.FullPackageName, displayName);

                    //Get all the available application logo images
                    appxManifestApplication.GetStringValue("Square30x30Logo", out appxDetails.Square30x30Logo);
                    appxManifestApplication.GetStringValue("Square70x70Logo", out appxDetails.Square70x70Logo);
                    appxManifestApplication.GetStringValue("Square150x150Logo", out appxDetails.Square150x150Logo);
                    appxManifestApplication.GetStringValue("Square310x310Logo", out appxDetails.Square310x310Logo);
                    appxManifestApplication.GetStringValue("Wide310x150Logo", out appxDetails.Wide310x150Logo);

                    //Check the largest available square logo
                    if (!string.IsNullOrWhiteSpace(appxDetails.Square310x310Logo))
                    {
                        appxDetails.SquareLargestLogoPath = Path.Combine(appxDetails.InstallPath, appxDetails.Square310x310Logo);
                    }
                    else if (!string.IsNullOrWhiteSpace(appxDetails.Square150x150Logo))
                    {
                        appxDetails.SquareLargestLogoPath = Path.Combine(appxDetails.InstallPath, appxDetails.Square150x150Logo);
                    }
                    else if (!string.IsNullOrWhiteSpace(appxDetails.Square70x70Logo))
                    {
                        appxDetails.SquareLargestLogoPath = Path.Combine(appxDetails.InstallPath, appxDetails.Square70x70Logo);
                    }
                    else if (!string.IsNullOrWhiteSpace(appxDetails.Square30x30Logo))
                    {
                        appxDetails.SquareLargestLogoPath = Path.Combine(appxDetails.InstallPath, appxDetails.Square30x30Logo);
                    }
                    string originalSquareLargestLogoPath = appxDetails.SquareLargestLogoPath;
                    appxDetails.SquareLargestLogoPath = UwpGetImageSizePath(appxDetails.SquareLargestLogoPath);

                    //Check if the file can be accessed
                    try
                    {
                        if (!string.IsNullOrWhiteSpace(appxDetails.SquareLargestLogoPath))
                        {
                            FileStream fileStream = File.OpenRead(appxDetails.SquareLargestLogoPath);
                            fileStream.Dispose();
                        }
                        else
                        {
                            appxDetails.SquareLargestLogoPath = originalSquareLargestLogoPath;
                        }
                    }
                    catch
                    {
                        //Debug.WriteLine("No permission to open: " + appxDetails.SquareLargestLogoPath);
                        appxDetails.SquareLargestLogoPath = originalSquareLargestLogoPath;
                    }

                    //Check the largest available wide logo
                    if (!string.IsNullOrWhiteSpace(appxDetails.Wide310x150Logo))
                    {
                        appxDetails.WideLargestLogoPath = Path.Combine(appxDetails.InstallPath, appxDetails.Wide310x150Logo);
                    }
                    string originalWideLargestLogoPath = appxDetails.WideLargestLogoPath;
                    appxDetails.WideLargestLogoPath = UwpGetImageSizePath(appxDetails.WideLargestLogoPath);

                    //Check if the file can be accessed
                    try
                    {
                        if (!string.IsNullOrWhiteSpace(appxDetails.WideLargestLogoPath))
                        {
                            FileStream fileStream = File.OpenRead(appxDetails.WideLargestLogoPath);
                            fileStream.Dispose();
                        }
                        else
                        {
                            appxDetails.WideLargestLogoPath = originalWideLargestLogoPath;
                        }
                    }
                    catch
                    {
                        //Debug.WriteLine("No permission to open: " + appxDetails.WideLargestLogoPath);
                        appxDetails.WideLargestLogoPath = originalWideLargestLogoPath;
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Failed reading details from uwp manifest: " + appPackage.Id.FamilyName + "/" + ex.Message);
            }

            Marshal.ReleaseComObject(inputStream);
            Marshal.ReleaseComObject(appxFactory);
            return(appxDetails);
        }