Example #1
0
File: UWP.cs Project: ncheng8/Wox
        private void InitializeAppInfo()
        {
            var path = Path.Combine(Location, "AppxManifest.xml");

            try
            {
                var namespaces = XmlNamespaces(path);
                InitPackageVersion(namespaces);
            }
            catch (ArgumentException e)
            {
                Logger.WoxError(e.Message);
                Apps = Apps = new List <Application>().ToArray();
                return;
            }


            var        appxFactory = new AppxFactory();
            IStream    stream;
            const uint noAttribute = 0x80;
            // shared read will slow speed https://docs.microsoft.com/en-us/windows/win32/stg/stgm-constants
            // but cannot find a way to release stearm, so use shared read
            // exclusive read will cause exception during reinexing
            // System.IO.FileLoadException: The process cannot access the file because it is being used by another process
            const Stgm sharedRead = Stgm.Read | Stgm.ShareDenyNone;
            var        hResult    = SHCreateStreamOnFileEx(path, sharedRead, noAttribute, false, null, out stream);

            if (hResult == Hresult.Ok)
            {
                var reader       = appxFactory.CreateManifestReader(stream);
                var manifestApps = reader.GetApplications();
                var apps         = new List <Application>();
                while (manifestApps.GetHasCurrent() != 0)
                {
                    var manifestApp  = manifestApps.GetCurrent();
                    var appListEntry = manifestApp.GetStringValue("AppListEntry");
                    if (appListEntry != "none")
                    {
                        var app = new Application(manifestApp, this);
                        apps.Add(app);
                    }
                    manifestApps.MoveNext();
                }
                Apps = apps.Where(a => a.AppListEntry != "none").ToArray();
                return;
            }
            else
            {
                var e = Marshal.GetExceptionForHR((int)hResult);
                e.Data.Add(nameof(path), path);
                Logger.WoxError($"Cannot not get UWP details {path}", e);
                Apps = new List <Application>().ToArray();
                return;
            }
        }
Example #2
0
        private Application[] AppInfos()
        {
            var        path = Path.Combine(Location, "AppxManifest.xml");
            var        appx = new AppxFactory();
            IStream    stream;
            const uint noAttribute   = 0x80;
            const Stgm exclusiveRead = Stgm.Read | Stgm.ShareExclusive;
            var        result        = SHCreateStreamOnFileEx(path, exclusiveRead, noAttribute, false, null, out stream);

            if (result == Hresult.Ok)
            {
                var reader = appx.CreateManifestReader(stream);

                var properties = reader.GetProperties();
                PublisherDisplayName = properties.GetStringValue("PublisherDisplayName");
                DisplayName          = properties.GetStringValue("DisplayName");
                Description          = properties.GetStringValue("Description");

                var apps       = reader.GetApplications();
                var parsedApps = new List <Application>();
                while (apps.GetHasCurrent() != 0)
                {
                    var current      = apps.GetCurrent();
                    var appListEntry = current.GetStringValue("AppListEntry");
                    if (appListEntry != "none")
                    {
                        var app = new Application
                        {
                            UserModelId     = current.GetAppUserModelId(),
                            BackgroundColor = current.GetStringValue("BackgroundColor") ?? string.Empty,
                            Location        = Location,
                            LogoPath        = Application.LogoFromManifest(current, Location),
                            Valid           = true // useless for now
                        };

                        if (!string.IsNullOrEmpty(app.UserModelId))
                        {
                            parsedApps.Add(app);
                        }
                    }
                    apps.MoveNext();
                }

                return(parsedApps.ToArray());
            }
            else
            {
                return(new Application[] { });
            }
        }
Example #3
0
File: UWP.cs Project: alexmg/Wox
        private void InitializeAppInfo()
        {
            var        path = Path.Combine(Location, "AppxManifest.xml");
            var        appx = new AppxFactory();
            IStream    stream;
            const uint noAttribute   = 0x80;
            const Stgm exclusiveRead = Stgm.Read | Stgm.ShareExclusive;
            var        result        = SHCreateStreamOnFileEx(path, exclusiveRead, noAttribute, false, null, out stream);

            if (result == Hresult.Ok)
            {
                var reader = appx.CreateManifestReader(stream);

                var properties = reader.GetProperties();
                PublisherDisplayName = properties.GetStringValue("PublisherDisplayName");
                DisplayName          = properties.GetStringValue("DisplayName");
                Description          = properties.GetStringValue("Description");

                var apps = reader.GetApplications();
                int i    = 0;
                while (apps.GetHasCurrent() != 0 && i <= Apps.Length)
                {
                    var currentApp   = apps.GetCurrent();
                    var appListEntry = currentApp.GetStringValue("AppListEntry");
                    if (appListEntry != "nonoe")
                    {
                        Apps[i].UserModelId     = currentApp.GetAppUserModelId();
                        Apps[i].Executable      = currentApp.GetStringValue("Executable") ?? string.Empty;
                        Apps[i].BackgroundColor = currentApp.GetStringValue("BackgroundColor") ?? string.Empty;
                        Apps[i].LogoPath        = Path.Combine(Location, currentApp.GetStringValue("Square44x44Logo"));
                        Apps[i].Location        = Location;
                    }
                    apps.MoveNext();
                    i++;
                }
                if (i != Apps.Length)
                {
                    var message = $"Wrong application number - {Name}: {i}";
                    Console.WriteLine(message);
                }
            }
        }
Example #4
0
        // This function returns a list of attributes of applications
        public static List <IAppxManifestApplication> getAppsFromManifest(IStream stream)
        {
            List <IAppxManifestApplication> apps = new List <IAppxManifestApplication>();
            var appxFactory  = new AppxFactory();
            var reader       = ((IAppxFactory)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")
                {
                    apps.Add(manifestApp);
                }
                manifestApps.MoveNext();
            }
            return(apps);
        }
Example #5
0
File: UWP.cs Project: yzx2001/Wox
        private void InitializeAppInfo()
        {
            var path = Path.Combine(Location, "AppxManifest.xml");

            var namespaces = XmlNamespaces(path);

            InitPackageVersion(namespaces);

            var        appxFactory = new AppxFactory();
            IStream    stream;
            const uint noAttribute   = 0x80;
            const Stgm exclusiveRead = Stgm.Read | Stgm.ShareExclusive;
            var        hResult       = SHCreateStreamOnFileEx(path, exclusiveRead, noAttribute, false, null, out stream);

            if (hResult == Hresult.Ok)
            {
                var reader       = appxFactory.CreateManifestReader(stream);
                var manifestApps = reader.GetApplications();
                var apps         = new List <Application>();
                while (manifestApps.GetHasCurrent() != 0)
                {
                    var manifestApp  = manifestApps.GetCurrent();
                    var appListEntry = manifestApp.GetStringValue("AppListEntry");
                    if (appListEntry != "none")
                    {
                        var app = new Application(manifestApp, this);
                        apps.Add(app);
                    }
                    manifestApps.MoveNext();
                }
                Apps = apps.Where(a => a.AppListEntry != "none").ToArray();
            }
            else
            {
                var e = Marshal.GetExceptionForHR((int)hResult);
                ProgramLogger.LogException($"|UWP|InitializeAppInfo|{path}" +
                                           "|Error caused while trying to get the details of the UWP program", e);

                Apps = new List <Application>().ToArray();
            }
        }
Example #6
0
File: UWP.cs Project: xueyawei/Wox
        private void InitializeAppInfo()
        {
            var path = Path.Combine(Location, "AppxManifest.xml");

            var namespaces = XmlNamespaces(path);

            InitPackageVersion(namespaces);

            var        appxFactory = new AppxFactory();
            IStream    stream;
            const uint noAttribute   = 0x80;
            const Stgm exclusiveRead = Stgm.Read | Stgm.ShareExclusive;
            var        hResult       = SHCreateStreamOnFileEx(path, exclusiveRead, noAttribute, false, null, out stream);

            if (hResult == Hresult.Ok)
            {
                var reader       = appxFactory.CreateManifestReader(stream);
                var manifestApps = reader.GetApplications();
                var apps         = new List <Application>();
                while (manifestApps.GetHasCurrent() != 0)
                {
                    var manifestApp  = manifestApps.GetCurrent();
                    var appListEntry = manifestApp.GetStringValue("AppListEntry");
                    if (appListEntry != "none")
                    {
                        var app = new Application(manifestApp, this);
                        apps.Add(app);
                    }
                    manifestApps.MoveNext();
                }
                Apps = apps.Where(a => a.AppListEntry != "none").ToArray();
            }
            else
            {
                Log.Error($"SHCreateStreamOnFileEx on path: <{path}> failed, HResult error code: {hResult}. Package location: <{Location}>.");
                var exception = Marshal.GetExceptionForHR((int)hResult);
                Log.Exception(exception);
            }
        }
Example #7
0
        private void InitializeAppInfo()
        {
            var path = Path.Combine(Location, "AppxManifest.xml");

            var namespaces = XmlNamespaces(path);
            InitPackageVersion(namespaces);

            var appxFactory = new AppxFactory();
            IStream stream;
            const uint noAttribute = 0x80;
            const Stgm exclusiveRead = Stgm.Read | Stgm.ShareExclusive;
            var hResult = SHCreateStreamOnFileEx(path, exclusiveRead, noAttribute, false, null, out stream);

            if (hResult == Hresult.Ok)
            {
                var reader = appxFactory.CreateManifestReader(stream);
                var manifestApps = reader.GetApplications();
                var apps = new List<Application>();
                while (manifestApps.GetHasCurrent() != 0)
                {
                    var manifestApp = manifestApps.GetCurrent();
                    var appListEntry = manifestApp.GetStringValue("AppListEntry");
                    if (appListEntry != "none")
                    {
                        var app = new Application(manifestApp, this);
                        apps.Add(app);
                    }
                    manifestApps.MoveNext();
                }
                Apps = apps.Where(a => a.AppListEntry != "none").ToArray();
            }
            else
            {
                Log.Error($"SHCreateStreamOnFileEx on path: <{path}> failed, HResult error code: {hResult}. Package location: <{Location}>.");
                var exception = Marshal.GetExceptionForHR((int)hResult);
                Log.Exception(exception);
            }
        }
Example #8
0
        private Application[] AppInfos()
        {
            var path = Path.Combine(Location, "AppxManifest.xml");
            var appx = new AppxFactory();
            IStream stream;
            const uint noAttribute = 0x80;
            const Stgm exclusiveRead = Stgm.Read | Stgm.ShareExclusive;
            var result = SHCreateStreamOnFileEx(path, exclusiveRead, noAttribute, false, null, out stream);

            if (result == Hresult.Ok)
            {
                var reader = appx.CreateManifestReader(stream);

                var properties = reader.GetProperties();
                PublisherDisplayName = properties.GetStringValue("PublisherDisplayName");
                DisplayName = properties.GetStringValue("DisplayName");
                Description = properties.GetStringValue("Description");

                var apps = reader.GetApplications();
                var parsedApps = new List<Application>();
                while (apps.GetHasCurrent() != 0)
                {
                    var current = apps.GetCurrent();
                    var appListEntry = current.GetStringValue("AppListEntry");
                    if (appListEntry != "none")
                    {
                        var app = new Application
                        {
                            UserModelId = current.GetAppUserModelId(),
                            BackgroundColor = current.GetStringValue("BackgroundColor") ?? string.Empty,
                            Location = Location,
                            LogoPath = Application.LogoFromManifest(current, Location),
                            Valid = true // useless for now
                        };

                        if (!string.IsNullOrEmpty(app.UserModelId))
                        {
                            parsedApps.Add(app);
                        }
                    }
                    apps.MoveNext();
                }

                return parsedApps.ToArray();
            }
            else
            {
                return new Application[] { };
            }
        }