예제 #1
0
        public void InitializeAppInfo(string installedLocation)
        {
            Location = installedLocation;
            var path = Path.Combine(installedLocation, "AppxManifest.xml");

            var namespaces = XmlNamespaces(path);

            InitPackageVersion(namespaces);

            const uint noAttribute   = 0x80;
            const Stgm exclusiveRead = Stgm.Read;
            var        hResult       = NativeMethods.SHCreateStreamOnFileEx(path, exclusiveRead, noAttribute, false, null, out IStream stream);

            if (hResult == Hresult.Ok)
            {
                var apps = new List <UWPApplication>();

                List <IAppxManifestApplication> appsViaManifests = AppxPackageHelper.GetAppsFromManifest(stream);
                foreach (var appInManifest in appsViaManifests)
                {
                    var app = new UWPApplication(appInManifest, this);
                    apps.Add(app);
                }

                Apps = apps.Where(a =>
                {
                    var valid =
                        !string.IsNullOrEmpty(a.UserModelId) &&
                        !string.IsNullOrEmpty(a.DisplayName) &&
                        a.AppListEntry != "none";

                    return(valid);
                }).ToArray();

                if (Marshal.ReleaseComObject(stream) > 0)
                {
                    Log.Error("AppxManifest.xml was leaked", MethodBase.GetCurrentMethod().DeclaringType);
                }
            }
            else
            {
                var e = Marshal.GetExceptionForHR((int)hResult);
                ProgramLogger.Exception("Error caused while trying to get the details of the UWP program", e, GetType(), path);

                Apps = new List <UWPApplication>().ToArray();
            }
        }
예제 #2
0
        public void InitializeAppInfo(string installedLocation)
        {
            Location = installedLocation;
            var path = Path.Combine(installedLocation, "AppxManifest.xml");

            var namespaces = XmlNamespaces(path);

            InitPackageVersion(namespaces);

            IStream    stream;
            const uint noAttribute   = 0x80;
            const Stgm exclusiveRead = Stgm.Read;
            var        hResult       = NativeMethods.SHCreateStreamOnFileEx(path, exclusiveRead, noAttribute, false, null, out stream);

            if (hResult == Hresult.Ok)
            {
                var apps = new List <UWPApplication>();

                List <IAppxManifestApplication> _apps = AppxPackageHelper.getAppsFromManifest(stream);
                foreach (var _app in _apps)
                {
                    var app = new UWPApplication(_app, this);
                    apps.Add(app);
                }

                Apps = apps.Where(a =>
                {
                    var valid =
                        !string.IsNullOrEmpty(a.UserModelId) &&
                        !string.IsNullOrEmpty(a.DisplayName) &&
                        a.AppListEntry != "none";

                    return(valid);
                }).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 <UWPApplication>().ToArray();
            }
        }