public string GetAppResourceStr(string resourcePath) { string resourceStr = null; AppResourceStrLock.EnterReadLock(); AppResourceStrCache.TryGetValue(resourcePath, out resourceStr); AppResourceStrLock.ExitReadLock(); if (resourceStr != null) { return(resourceStr); } var AppResource = TextHelpers.Split2(resourcePath.Substring(2, resourcePath.Length - 3), "?"); Windows.ApplicationModel.Package package = packageManager.FindPackage(AppResource.Item1); if (package != null) { string pathToPri = Path.Combine(package.InstalledLocation.Path, "resources.pri"); resourceStr = MiscFunc.GetResourceStr(pathToPri, AppResource.Item2); } if (resourceStr != null) { AppResourceStrLock.EnterWriteLock(); if (!AppResourceStrCache.ContainsKey(resourcePath)) { AppResourceStrCache.Add(resourcePath, resourceStr); } AppResourceStrLock.ExitWriteLock(); } return(resourceStr == null ? resourcePath : resourceStr); }
public UWP(Package package) { Package = package; Name = Package.Id.Name; FullName = Package.Id.FullName; FamilyName = Package.Id.FamilyName; Location = Package.InstalledLocation.Path; Apps = MergedApps(); }
private static XDocument LoadDocument(Package package) { if (package == null) { throw new ArgumentNullException(nameof(package)); } string manifestPath = Path.Combine(package.InstalledLocation.Path, "AppxManifest.xml"); XDocument document = XDocument.Load(manifestPath); return document; }
private static void DisplayPackageInfo(Windows.ApplicationModel.Package package) { Console.WriteLine("Name: {0}", package.Id.Name); Console.WriteLine("FullName: {0}", package.Id.FullName); Console.WriteLine("Version: {0}.{1}.{2}.{3}", package.Id.Version.Major, package.Id.Version.Minor, package.Id.Version.Build, package.Id.Version.Revision); Console.WriteLine("Publisher: {0}", package.Id.Publisher); Console.WriteLine("PublisherId: {0}", package.Id.PublisherId); }
public Adapter(string DCGWURLParam, string userName, string userPassword) { //setting IP of gateway from UI DCGWUrl = "http://" + DCGWURLParam + ":8080/"; user = userPassword; password = userPassword; Windows.ApplicationModel.Package package = Windows.ApplicationModel.Package.Current; Windows.ApplicationModel.PackageId packageId = package.Id; Windows.ApplicationModel.PackageVersion versionFromPkg = packageId.Version; this.Vendor = "EnOcean"; this.AdapterName = "Bridge"; // the adapter prefix must be something like "com.mycompany" (only alpha num and dots) // it is used by the Device System Bridge as root string for all services and interfaces it exposes this.ExposedAdapterPrefix = "com." + this.Vendor.ToLower(); this.ExposedApplicationGuid = Guid.Parse("{0x0b2b3b87,0xc1fc,0x4282,{0x96,0xad,0x88,0xc7,0x90,0xaf,0x15,0xe3}}"); if (null != package && null != packageId) { this.ExposedApplicationName = packageId.Name; this.Version = versionFromPkg.Major.ToString() + "." + versionFromPkg.Minor.ToString() + "." + versionFromPkg.Revision.ToString() + "." + versionFromPkg.Build.ToString(); } else { this.ExposedApplicationName = "EnOcean Alljoyn DSB"; this.Version = "0.0.0.0"; } try { this.Signals = new List <IAdapterSignal>(); this.devices = new List <IAdapterDevice>(); this.devicesDict = new Dictionary <string, IAdapterDevice>(); this.deviceSignals = new Dictionary <string, IAdapterSignal>(); this.signalListeners = new Dictionary <int, IList <SIGNAL_LISTENER_ENTRY> >(); //Create Adapter Signals this.createSignals(); } catch (OutOfMemoryException ex) { throw; } }
public UWP(Package package) { Location = package.InstalledLocation.Path; Name = package.Id.Name; FullName = package.Id.FullName; FamilyName = package.Id.FamilyName; InitializeAppInfo(); Apps = Apps.Where(a => { var valid = !string.IsNullOrEmpty(a.UserModelId) && !string.IsNullOrEmpty(a.DisplayName); return valid; }).ToArray(); }
private static async Task<string> TryGetPublisherName_Modern(Windows.ApplicationModel.Package item) { var appxManifest = await item.InstalledLocation.TryGetItemAsync("AppxManifest.xml"); if ((appxManifest != null) && (appxManifest is StorageFile)) { string appxManifestData = await FileIO.ReadTextAsync((StorageFile)appxManifest); string publisher = appxManifestData.Substring(appxManifestData.IndexOf("<PublisherDisplayName>") + "<PublisherDisplayName>".Length); publisher = publisher.Substring(0, publisher.IndexOf("</PublisherDisplayName>")); if ((publisher.Length > "ms-resource:".Length) && (publisher.Substring(0, "ms-resource:".Length) == "ms-resource:")) publisher = ""; return publisher; } return ""; }
private static void DisplayPackageInfo(Windows.ApplicationModel.Package package) { Console.WriteLine("Name: {0}", package.Id.Name); Console.WriteLine("FullName: {0}", package.Id.FullName); Console.WriteLine("Version: {0}.{1}.{2}.{3}", package.Id.Version.Major, package.Id.Version.Minor, package.Id.Version.Build, package.Id.Version.Revision); Console.WriteLine("Publisher: {0}", package.Id.Publisher); Console.WriteLine("PublisherId: {0}", package.Id.PublisherId); Console.WriteLine("Installed Location: {0}", package.InstalledLocation.Path); // Console.WriteLine("Architecture: {0}", // Enum.GetName(typeof(Windows.Management.Deployment.PackageArchitecture), package.Id.Architecture)); Console.WriteLine("IsFramework: {0}", package.IsFramework); }
/// <summary> /// Parses the package. /// </summary> /// <param name="manifestPath">The manifest path.</param> private void ParsePackage(Package package) { var manifestPath = Path.Combine( package.InstalledLocation.Path, "AppxManifest.xml"); var xManifest = XDocument.Load( manifestPath, LoadOptions.None); var xDefaultNamespace = xManifest.Root.GetDefaultNamespace(); // Find all of the namespaces that we can ignore. var ignorableNamespaces = new List<string>(); var xIgnoredNamespaces = xManifest.Root.Attribute("IgnorableNamespaces"); if (xIgnoredNamespaces != null) { ignorableNamespaces = xIgnoredNamespaces.Value.Split(' ').ToList(); } // Find useable namespaces for this manifest var manifestNamespaces = xManifest.Root .Attributes() .Where( attr => attr.IsNamespaceDeclaration && !ignorableNamespaces.Contains(attr.Value)) .Select(ns => XNamespace.Get(ns.Value)) .OrderBy(ns => ns == xDefaultNamespace ? 0 : 1); var xApplications = xManifest.Root.Element(xDefaultNamespace + "Applications"); if (xApplications != null) { foreach (var xApplication in xApplications.Elements(xDefaultNamespace + "Application")) { var applicationId = xApplication.Attribute("Id").Value; foreach (var xNamespace in manifestNamespaces) { var xVisualElements = xApplication.Element(xNamespace + "VisualElements"); if (xVisualElements != null) { // Name var displayNameAttribute = xVisualElements.Attribute("DisplayName"); var displayName = displayNameAttribute != null ? displayNameAttribute.Value : null; // Description var descriptionAttribute = xVisualElements.Attribute("Description"); var description = descriptionAttribute != null ? descriptionAttribute.Value : null; // Icon var smallIconPathAttribute = xVisualElements.Attribute("Square30x30Logo"); if (smallIconPathAttribute == null) { smallIconPathAttribute = xVisualElements.Attribute("SmallLogo"); } var smallIconPath = smallIconPathAttribute != null ? smallIconPathAttribute.Value : null; var application = new MetroApplication() { ApplicationId = applicationId, AppUserModelId = ResolveAppUserModelId(package.Id.FullName, applicationId), Name = ResolveManifestString(displayName, package.Id.Name, package.InstalledLocation.Path), Description = ResolveManifestString(description, package.Id.Name, package.InstalledLocation.Path), Icon = ResolveIcon(smallIconPath, package.InstalledLocation.Path) }; this.Applications.Add(application); break; } } } } }
private async Task<AppData> LoadModernAndLegacyAppData(Windows.ApplicationModel.Package item, StorageFolder saveLogoLocation) { AppData data = new AppData(); try { data.FamilyName = item.Id.FamilyName; if (familyNameAppData.ContainsKey(data.FamilyName)) { familyNameAppData[data.FamilyName].PackageId = item.Id.FullName; //Refresh package id. data.PackageId = ""; return data; } IReadOnlyList<Windows.ApplicationModel.Core.AppListEntry> x = await item.GetAppListEntriesAsync(); if ((x == null) || (x.Count == 0)) return null; data.DisplayName = (x.First().DisplayInfo.DisplayName); data.PackageId = item.Id.FullName; data.PackageRootFolder = item.InstalledLocation.Path; data.IsLegacyApp = data.PackageRootFolder[data.PackageRootFolder.Length - 1] == '}'; data.PackageDataFolder = await GetDataFolder(data); if ((await saveLogoLocation.TryGetItemAsync(data.FamilyName + ".png")) == null) { WriteableBitmap bmp = null; try { var stream = await x.First().DisplayInfo.GetLogo(new Size(50, 50)).OpenReadAsync(); BitmapDecoder decoder = await BitmapDecoder.CreateAsync(stream); bmp = new WriteableBitmap((int)decoder.PixelWidth, (int)decoder.PixelHeight); bmp.SetSource(stream); await bmp.SaveAsync(saveLogoLocation, data.FamilyName + ".png"); } catch { } } data.LogoPath = System.IO.Path.Combine(saveLogoLocation.Path, data.FamilyName + ".png"); try { if (data.IsLegacyApp) data.Publisher = await TryGetPublisherName_Legacy(item); else data.Publisher = await TryGetPublisherName_Modern(item); } catch { } return data; } catch { } return null; }
// unloads all extensions associated with a package - used for updating and when package status goes away public async Task UnloadUWPExtensions(Package package) { await _dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { _extensions.Where(ext => ext.AppExtension.Package.Id.FamilyName == package.Id.FamilyName).ToList().ForEach(e => { e.UnloadUWPExtension(); }); }); }
private AppInfo?GetInfo(Windows.ApplicationModel.Package package, string sid) { string path; try { path = package.InstalledLocation.Path; } catch { return(null); } string manifest = Path.Combine(path, "AppxManifest.xml"); if (!File.Exists(manifest)) { return(null); } XElement xelement; try { string manifestXML = File.ReadAllText(manifest); int startIndex = manifestXML.IndexOf("<Properties>", StringComparison.Ordinal); int num = manifestXML.IndexOf("</Properties>", StringComparison.Ordinal); xelement = XElement.Parse(manifestXML.Substring(startIndex, num - startIndex + 13).Replace("uap:", string.Empty)); } catch (Exception err) { AppLog.Exception(err); return(null); } string displayName = null; string logoPath = null; try { displayName = xelement.Element((XName)"DisplayName")?.Value; logoPath = xelement.Element((XName)"Logo")?.Value; } catch (Exception err) { AppLog.Exception(err); } if (displayName == null) { return(null); } try { Uri result; if (Uri.TryCreate(displayName, UriKind.Absolute, out result)) { string pathToPri = Path.Combine(package.InstalledLocation.Path, "resources.pri"); string resourceKey1 = "ms-resource://" + package.Id.Name + "/resources/" + ((IEnumerable <string>)result.Segments).Last <string>(); string stringFromPriFile = MiscFunc.GetResourceStr(pathToPri, resourceKey1); if (!string.IsNullOrEmpty(stringFromPriFile.Trim())) { displayName = stringFromPriFile; } else { string str = string.Concat(((IEnumerable <string>)result.Segments).Skip <string>(1)); string resourceKey2 = "ms-resource://" + package.Id.Name + "/" + str; stringFromPriFile = MiscFunc.GetResourceStr(pathToPri, resourceKey2); if (!string.IsNullOrEmpty(stringFromPriFile.Trim())) { displayName = stringFromPriFile; } } } if (logoPath != null) { string path1 = Path.Combine(package.InstalledLocation.Path, logoPath); if (File.Exists(path1)) { logoPath = path1; } else { string path2 = Path.Combine(package.InstalledLocation.Path, Path.ChangeExtension(path1, "scale-100.png")); if (File.Exists(path2)) { logoPath = path2; } else { string path3 = Path.Combine(Path.Combine(package.InstalledLocation.Path, "en-us"), logoPath); string path4 = Path.Combine(package.InstalledLocation.Path, Path.ChangeExtension(path3, "scale-100.png")); if (File.Exists(path4)) { logoPath = path4; } else { logoPath = null; } } } } } catch (Exception err) { AppLog.Exception(err); } return(new AppInfo() { Name = displayName, Logo = logoPath, ID = package.Id.FamilyName, SID = sid }); }
private async Task <AppData> LoadModernAndLegacyAppData(Windows.ApplicationModel.Package item, StorageFolder saveLogoLocation) { AppData data = new AppData(); try { data.FamilyName = item.Id.FamilyName; if (familyNameAppData.ContainsKey(data.FamilyName)) { familyNameAppData[data.FamilyName].PackageId = item.Id.FullName; //Refresh package id. data.PackageId = ""; return(data); } // // Сводка: // Перечисляет упакованные приложения на устройстве. Возвращаются только упакованные // приложения, зарегистрированные для текущего пользователя. // // Возврат: // Список упакованных приложений вместе с их отображаемым именем, описанием и логотипом. IReadOnlyList <Windows.ApplicationModel.Core.AppListEntry> x = await item.GetAppListEntriesAsync(); if ((x == null) || (x.Count == 0)) { return(null); } data.DisplayName = (x.First().DisplayInfo.DisplayName); data.PackageId = item.Id.FullName; data.PackageRootFolder = item.InstalledLocation.Path; data.IsLegacyApp = data.PackageRootFolder[data.PackageRootFolder.Length - 1] == '}'; data.PackageDataFolder = await GetDataFolder(data); if ((await saveLogoLocation.TryGetItemAsync(data.FamilyName + ".png")) == null) { WriteableBitmap bmp = null; try { var stream = await x.First().DisplayInfo.GetLogo(new Size(50, 50)).OpenReadAsync(); BitmapDecoder decoder = await BitmapDecoder.CreateAsync(stream); bmp = new WriteableBitmap((int)decoder.PixelWidth, (int)decoder.PixelHeight); bmp.SetSource(stream); //await bmp.SaveAsync(saveLogoLocation, data.FamilyName + ".png"); } catch { } } data.LogoPath = System.IO.Path.Combine(saveLogoLocation.Path, data.FamilyName + ".png"); try { if (data.IsLegacyApp) { data.Publisher = await TryGetPublisherName_Legacy(item); } else { data.Publisher = await TryGetPublisherName_Modern(item); } } catch { } return(data); } catch { } return(null); }
private static void DisplayPackageUsers(Windows.Management.Deployment.PackageManager packageManager, Windows.ApplicationModel.Package package) { IEnumerable <Windows.Management.Deployment.PackageUserInformation> packageUsers = packageManager.FindUsers(package.Id.FullName); Console.Write("Users: "); foreach (var packageUser in packageUsers) { Console.Write("{0} ", SidToAccountName(packageUser.UserSecurityId)); } Console.WriteLine(); }
/// <summary> /// Initializes a new instance of the <see cref="MetroPackage"/> class. /// </summary> /// <param name="package">The package.</param> public MetroPackage(Package package) { this.ParsePackage(package); }
public PackageManifest(Package package) : base(LoadDocument(package).Root) { }
public PackageViewModel(Package pPackage) { _package = pPackage; }