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; } }
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[] { }); } }
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(); } }
public void InitializeAppInfo(string installedLocation) { Location = installedLocation; AppxPackageHelper _helper = new AppxPackageHelper(); var path = Path.Combine(installedLocation, "AppxManifest.xml"); var namespaces = XmlNamespaces(path); InitPackageVersion(namespaces); IStream stream; const uint noAttribute = 0x80; const Stgm exclusiveRead = Stgm.Read | Stgm.DenyWrite; var hResult = SHCreateStreamOnFileEx(path, exclusiveRead, noAttribute, false, null, out stream); if (hResult == Hresult.Ok) { var apps = new List <Application>(); List <AppxPackageHelper.IAppxManifestApplication> _apps = _helper.getAppsFromManifest(stream); foreach (var _app in _apps) { var app = new Application(_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 <Application>().ToArray(); } }
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); } } }
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(); } }
private void InitializeAppInfo() { AppxPackageHelper _helper = new AppxPackageHelper(); var path = Path.Combine(Location, "AppxManifest.xml"); var namespaces = XmlNamespaces(path); InitPackageVersion(namespaces); const uint noAttribute = 0x80; const Stgm exclusiveRead = Stgm.Read | Stgm.ShareExclusive; var hResult = SHCreateStreamOnFileEx(path, exclusiveRead, noAttribute, false, null, out IStream stream); if (hResult == Hresult.Ok) { var apps = new List <Application>(); List <AppxPackageHelper.IAppxManifestApplication> _apps = _helper.getAppsFromManifest(stream); foreach (var _app in _apps) { var app = new Application(_app, this); apps.Add(app); } 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(); } if (Marshal.ReleaseComObject(stream) > 0) { Log.Error("Flow.Launcher.Plugin.Program.Programs.UWP", "AppxManifest.xml was leaked"); } }
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); } }
private static extern Hresult SHCreateStreamOnFileEx(string fileName, Stgm grfMode, uint attributes, bool create, IStream reserved, out IStream stream);
public static extern void SHCreateStreamOnFile(string file, Stgm dwMode, [MarshalAs(UnmanagedType.Interface)] out IStream openedStream);
// Only in version 6 and later public static extern void SHCreateStreamOnFileEx([MarshalAs(UnmanagedType.LPWStr)] string file, Stgm dwMode, Int32 dwAttributes, // Used if a file is created. Identical to dwFlagsAndAttributes param of CreateFile. bool create, IntPtr pTemplate, // Reserved, always pass null. [MarshalAs(UnmanagedType.Interface)] out IStream openedStream);
internal static extern int StgOpenStorage([MarshalAs(UnmanagedType.LPWStr)] string wcsName, IStorage pstgPriority, Stgm grfMode, IntPtr snbExclude, int reserved, out IStorage ppstgOpen);
// Only in version 6 and later public static extern void SHCreateStreamOnFileEx([MarshalAs(UnmanagedType.LPWStr)]string file, Stgm dwMode, Int32 dwAttributes, // Used if a file is created. Identical to dwFlagsAndAttributes param of CreateFile. bool create, IntPtr pTemplate, // Reserved, always pass null. [MarshalAs(UnmanagedType.Interface)]out IStream openedStream);
public static extern Hresult SHCreateStreamOnFileEx(string pszFile, Stgm grfMode, uint dwAttributes, bool fCreate, IStream pstmTemplate, out IStream ppstm);
public static extern void SHCreateStreamOnFileEx(string fileName, Stgm grfmode, uint dwAttributes, bool fCreate, System.Runtime.InteropServices.ComTypes.IStream streamNull, ref System.Runtime.InteropServices.ComTypes.IStream stream);
internal static extern void StgOpenStorageOnILockBytes(ILockBytes plkbyt, IStorage pstgPriority, Stgm grfMode, IntPtr snbExclude, uint reserved, out IStorage ppstgOpen);
private static extern void StgOpenStorage([MarshalAs(UnmanagedType.LPWStr)] string pwcsName, IStorage pstgPriority, Stgm grfMode, IntPtr snbExclude, uint reserved, out IStorage ppstgOpen);
public static extern void SHCreateStreamOnFile(string file, Stgm dwMode, [MarshalAs(UnmanagedType.Interface)]out IStream openedStream);
internal static extern int StgCreateDocfileOnILockBytes(ILockBytes plkbyt, Stgm grfMode, uint reserved, out IStorage ppstgOpen);