예제 #1
0
        public UWPApplication(IAppxManifestApplication manifestApp, UWP package)
        {
            if (manifestApp == null)
            {
                throw new ArgumentNullException(nameof(manifestApp));
            }

            var hr = manifestApp.GetAppUserModelId(out var tmpUserModelId);

            UserModelId = AppxPackageHelper.CheckHRAndReturnOrThrow(hr, tmpUserModelId);

            hr = manifestApp.GetAppUserModelId(out var tmpUniqueIdentifier);
            UniqueIdentifier = AppxPackageHelper.CheckHRAndReturnOrThrow(hr, tmpUniqueIdentifier);

            hr          = manifestApp.GetStringValue("DisplayName", out var tmpDisplayName);
            DisplayName = AppxPackageHelper.CheckHRAndReturnOrThrow(hr, tmpDisplayName);

            hr          = manifestApp.GetStringValue("Description", out var tmpDescription);
            Description = AppxPackageHelper.CheckHRAndReturnOrThrow(hr, tmpDescription);

            hr = manifestApp.GetStringValue("BackgroundColor", out var tmpBackgroundColor);
            BackgroundColor = AppxPackageHelper.CheckHRAndReturnOrThrow(hr, tmpBackgroundColor);

            hr         = manifestApp.GetStringValue("EntryPoint", out var tmpEntryPoint);
            EntryPoint = AppxPackageHelper.CheckHRAndReturnOrThrow(hr, tmpEntryPoint);

            Package = package ?? throw new ArgumentNullException(nameof(package));

            DisplayName = ResourceFromPri(package.FullName, DisplayName);
            Description = ResourceFromPri(package.FullName, Description);
            logoUri     = LogoUriFromManifest(manifestApp);

            Enabled        = true;
            CanRunElevated = IfApplicationcanRunElevated();
        }
    internal static string GetStringValue(IAppxManifestApplication app, string name)
    {
        string value;

        app.GetStringValue(name, out value);
        return(value);
    }
예제 #3
0
            public Application(IAppxManifestApplication manifestApp, UWP package)
            {
                UserModelId     = manifestApp.GetAppUserModelId();
                DisplayName     = manifestApp.GetStringValue("DisplayName");
                Description     = manifestApp.GetStringValue("Description");
                BackgroundColor = manifestApp.GetStringValue("BackgroundColor");
                Package         = package;

                DisplayName = ResourceFromPri(package.FullName, DisplayName);
                Description = ResourceFromPri(package.FullName, Description);
                LogoUri     = LogoUriFromManifest(manifestApp);
                LogoPath    = LogoPathFromUri(LogoUri);
            }
예제 #4
0
 internal string LogoUriFromManifest(IAppxManifestApplication app)
 {
     if (_logoKeyFromVersion.TryGetValue(Package.Version, out var key))
     {
         var hr = app.GetStringValue(key, out var logoUriFromApp);
         _ = AppxPackageHelper.CheckHRAndReturnOrThrow(hr, logoUriFromApp);
         return(logoUriFromApp);
     }
     else
     {
         return(string.Empty);
     }
 }
예제 #5
0
파일: UWP.cs 프로젝트: JackeydoubleX/Wox
            public Application(IAppxManifestApplication manifestApp, UWP package)
            {
                UserModelId      = manifestApp.GetAppUserModelId();
                UniqueIdentifier = manifestApp.GetAppUserModelId();
                DisplayName      = manifestApp.GetStringValue("DisplayName");
                Description      = manifestApp.GetStringValue("Description");
                BackgroundColor  = manifestApp.GetStringValue("BackgroundColor");
                Package          = package;
                DisplayName      = ResourcesFromPri(package.FullName, package.Name, DisplayName);
                Description      = ResourcesFromPri(package.FullName, package.Name, Description);
                LogoUri          = LogoUriFromManifest(manifestApp);
                LogoPath         = FilesFromPri(package.FullName, package.Name, LogoUri);

                Enabled = true;
            }
예제 #6
0
            internal string LogoUriFromManifest(IAppxManifestApplication app)
            {
                var logoKeyFromVersion = new Dictionary <PackageVersion, string>
                {
                    { PackageVersion.Windows10, "Square44x44Logo" },
                    { PackageVersion.Windows81, "Square30x30Logo" },
                    { PackageVersion.Windows8, "SmallLogo" }
                };

                if (logoKeyFromVersion.ContainsKey(Package.Version))
                {
                    var key     = logoKeyFromVersion[Package.Version];
                    var logoUri = app.GetStringValue(key);
                    return(logoUri);
                }

                return(string.Empty);
            }
예제 #7
0
            public Application(IAppxManifestApplication manifestApp, UWP package)
            {
                UserModelId      = manifestApp.GetAppUserModelId();
                UniqueIdentifier = manifestApp.GetAppUserModelId();
                DisplayName      = manifestApp.GetStringValue("DisplayName");
                Description      = manifestApp.GetStringValue("Description");
                BackgroundColor  = manifestApp.GetStringValue("BackgroundColor");
                Package          = package;
                EntryPoint       = manifestApp.GetStringValue("EntryPoint");

                DisplayName = ResourceFromPri(package.FullName, DisplayName);
                Description = ResourceFromPri(package.FullName, Description);
                LogoUri     = LogoUriFromManifest(manifestApp);
                LogoPath    = LogoPathFromUri(LogoUri);

                Enabled        = true;
                CanRunElevated = IfApplicationcanRunElevated();
            }
예제 #8
0
        internal string LogoUriFromManifest(IAppxManifestApplication app)
        {
            var logoKeyFromVersion = new Dictionary <PackageVersion, string>
            {
                { PackageVersion.Windows10, "Square44x44Logo" },
                { PackageVersion.Windows81, "Square30x30Logo" },
                { PackageVersion.Windows8, "SmallLogo" },
            };

            if (logoKeyFromVersion.ContainsKey(Package.Version))
            {
                var key = logoKeyFromVersion[Package.Version];
                var hr  = app.GetStringValue(key, out var logoUri);
                _ = AppxPackageHelper.CheckHRAndReturnOrThrow(hr, logoUri);
                return(logoUri);
            }
            else
            {
                return(string.Empty);
            }
        }
예제 #9
0
파일: UWP.cs 프로젝트: zhudaoruyi/Wox
            internal static string LogoFromManifest(IAppxManifestApplication application, string location)
            {
                // todo use hidpi logo when use hidpi screen
                var path1 = Path.Combine(location, application.GetStringValue("Square44x44Logo"));

                path1 = LogoFromPath(path1);
                if (!string.IsNullOrEmpty(path1))
                {
                    return(path1);
                }
                else
                {
                    var path2 = Path.Combine(location, application.GetStringValue("Square150x150Logo"));
                    path2 = LogoFromPath(path2);
                    if (!string.IsNullOrEmpty(path2))
                    {
                        return(path2);
                    }
                    else
                    {
                        return(Constant.ErrorIcon);
                    }
                }
            }
예제 #10
0
파일: UWP.cs 프로젝트: Wox-launcher/Wox
 internal string LogoUriFromManifest(IAppxManifestApplication app)
 {
     var logoKeyFromVersion = new Dictionary<PackageVersion, string>
 {
     {PackageVersion.Windows10, "Square44x44Logo"},
     {PackageVersion.Windows81, "Square30x30Logo"},
     {PackageVersion.Windows8, "SmallLogo"},
 };
     if (logoKeyFromVersion.ContainsKey(Package.Version))
     {
         var key = logoKeyFromVersion[Package.Version];
         var logoUri = app.GetStringValue(key);
         return logoUri;
     }
     else
     {
         return string.Empty;
     }
 }
예제 #11
0
파일: UWP.cs 프로젝트: Wox-launcher/Wox
            public Application(IAppxManifestApplication manifestApp, UWP package)
            {
                UserModelId = manifestApp.GetAppUserModelId();
                DisplayName = manifestApp.GetStringValue("DisplayName");
                Description = manifestApp.GetStringValue("Description");
                BackgroundColor = manifestApp.GetStringValue("BackgroundColor");
                Package = package;

                DisplayName = ResourceFromPri(package.FullName, DisplayName);
                Description = ResourceFromPri(package.FullName, Description);
                LogoUri = LogoUriFromManifest(manifestApp);
                LogoPath = LogoPathFromUri(LogoUri);
            }
예제 #12
0
파일: UWP.cs 프로젝트: JohnTheGr8/Wox
 internal static string LogoFromManifest(IAppxManifestApplication application, string location)
 {
     // todo use hidpi logo when use hidpi screen
     var path1 = Path.Combine(location, application.GetStringValue("Square44x44Logo"));
     path1 = LogoFromPath(path1);
     if (!string.IsNullOrEmpty(path1))
     {
         return path1;
     }
     else
     {
         var path2 = Path.Combine(location, application.GetStringValue("Square150x150Logo"));
         path2 = LogoFromPath(path2);
         if (!string.IsNullOrEmpty(path2))
         {
             return path2;
         }
         else
         {
             return Constant.ErrorIcon;
         }
     }
 }
        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
                }
            }
        }
예제 #14
0
        //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);
        }