////////////////////////////////////////////////////////////////////////////////////////////// // App resource handling public string GetAppResourceStr(string resourcePath) { // Note: PackageManager requirers admin privilegs var AppResource = TextHelpers.Split2(resourcePath.Substring(2, resourcePath.Length - 3), "?"); var package = packageManager.FindPackage(AppResource.Item1); if (package != null) { string pathToPri = Path.Combine(package.InstalledLocation.Path, "resources.pri"); return(MiscFunc.GetResourceStr(pathToPri, AppResource.Item2)); } return(resourcePath); }
private UwpFunc.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 UwpFunc.AppInfo() { Name = displayName, Logo = logoPath, ID = package.Id.FamilyName, SID = sid }); }
private UwpFunc.AppInfo GetInfo(Windows.ApplicationModel.Package package) { string path; string manifest; try { path = package.InstalledLocation.Path; // that call takes a long time manifest = Path.Combine(path, !package.IsBundle ? @"AppxManifest.xml" : @"AppxMetadata\AppxBundleManifest.xml"); if (!File.Exists(manifest)) { return(null); } } catch { 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(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) { List <string> extensions = new List <string> { "", "scale-100.png", "scale-125.png", "scale-150.png", "scale-200.png", "scale-400.png" }; List <string> sub_dirs = new List <string> { "", "en-us" }; string foundPath = null; foreach (string extension in extensions) { foreach (string sub_dir in sub_dirs) { string testPath = path; if (sub_dir.Length > 0) { testPath = Path.Combine(testPath, sub_dir); } string testName = logoPath; if (extension.Length > 0) { testName = Path.ChangeExtension(testName, extension); } testPath = Path.Combine(testPath, testName); if (File.Exists(testPath)) { foundPath = testPath; goto done; } } } done: logoPath = foundPath; } } catch (Exception err) { AppLog.Exception(err); } return(new UwpFunc.AppInfo() { Name = displayName, Logo = logoPath, ID = package.Id.FamilyName, Path = path }); }