Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Using Immersive Cache instead of manually parsing AppManifests each time
  • Loading branch information
AgentMC committed Mar 21, 2016
1 parent eca172c commit 431ee73
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 161 deletions.
126 changes: 0 additions & 126 deletions DataProviders/AppxUserModelIdProvider.cs

This file was deleted.

1 change: 1 addition & 0 deletions DataProviders/ImmersiveApp.cs
Expand Up @@ -21,6 +21,7 @@ public string DisplayName
public string PackageId { get; set; }
//------
public string ApplicationPath { get; set; }
public string File { get; set; }
//------
public string Logo
{
Expand Down
17 changes: 13 additions & 4 deletions DataProviders/ImmersiveAppsProvider.cs
Expand Up @@ -11,8 +11,15 @@ namespace Power8.DataProviders
{
public static class ImmersiveAppsProvider
{
public const string APPXMANIFEST_XML = "AppxManifest.xml";
//Main entry point
public static IEnumerable<ImmersiveApp> GetApps()
private static List<ImmersiveApp> _cache;
public static List<ImmersiveApp> GetAppsCache()
{
return _cache ?? (_cache = new List<ImmersiveApp>(GetApps()));
}

private static IEnumerable<ImmersiveApp> GetApps()
{
//Step 1. Getting initial package deployment info: package ids and related deployment paths and display names
var pathCache = GetDeploymentPathCache();
Expand All @@ -28,7 +35,7 @@ public static IEnumerable<ImmersiveApp> GetApps()
foreach (var package in serverCache)
{
var pathCacheItem = pathCache[package.Key];
var appxManifestPath = Path.Combine(pathCacheItem.RootPath, "AppxManifest.xml");
var appxManifestPath = Path.Combine(pathCacheItem.RootPath, APPXMANIFEST_XML);
if (!File.Exists(appxManifestPath)) continue;

string company = null, logoTemplate = null;
Expand All @@ -51,6 +58,7 @@ public static IEnumerable<ImmersiveApp> GetApps()
return new
{
Id = e.Attribute("Id").Value,
File = (e.Attribute("Executable") ?? e.Attribute("StartPage")).Value,
Description = visual.GetValueOrNull("Description"),
DisplayName = visual.GetValueOrNull("DisplayName"),
Logos = visual.Attributes()
Expand Down Expand Up @@ -82,6 +90,7 @@ public static IEnumerable<ImmersiveApp> GetApps()
yield return new ImmersiveApp
{
PackageId = package.Key,
File = appDataItem.File,
ApplicationName = Util.ExtractStringIndirect(pathCacheItem.DisplayName),
ApplicationDisplayName = ExtractStringFromPackageOptional(appDataItem.DisplayName, pathCacheItem.DisplayName),
ApplicationCompany = ExtractStringFromPackageOptional(company, pathCacheItem.DisplayName),
Expand Down Expand Up @@ -221,7 +230,7 @@ private static int HexCharToByte(char ch1)
return ch1 > 9 ? (ch1 > 41 ? ch1 - 39 : ch1 - 7) : ch1;
}

internal static string ExtractStringFromPackageOptional(string resourceKey, string uriTemplate)
private static string ExtractStringFromPackageOptional(string resourceKey, string uriTemplate)
{
if (resourceKey == null) return null;
if (resourceKey.StartsWith("ms-resource:"))
Expand All @@ -245,7 +254,7 @@ internal static string ExtractStringFromPackageOptional(string resourceKey, stri
return resourceKey;
}

public static string GetValueOrNull(this XElement xe, string nullForValueOrAttributeName = null)
private static string GetValueOrNull(this XElement xe, string nullForValueOrAttributeName = null)
{
if (xe == null) return null;
if (nullForValueOrAttributeName == null) return xe.Value;
Expand Down
3 changes: 1 addition & 2 deletions DataProviders/PowerItemTree.cs
Expand Up @@ -427,12 +427,11 @@ public static PowerItem ImmersiveRoot
if (Util.OsIs.EightOrMore)
{
//todo:
//fix UI (icons and everything)
//make possible for custom and auto-mfu lists
//add comments to all new methods and properties
//test on W10 and W7
//find out what to do with BrowserChoice background and VS dev apps
foreach (var immersiveApp in ImmersiveAppsProvider.GetApps())
foreach (var immersiveApp in ImmersiveAppsProvider.GetAppsCache())
{
if (immersiveApp.Background == ImmersiveIgnore ||
immersiveApp.ApplicationPath.Contains(VpnPlugins))
Expand Down
40 changes: 12 additions & 28 deletions Helpers/Util.cs
Expand Up @@ -14,7 +14,6 @@
using System.Windows.Interop;
using System.Windows.Media;
using System.Windows.Threading;
using System.Xml.Linq;
using Microsoft.Win32;
using Power8.DataProviders;
using Power8.Helpers;
Expand Down Expand Up @@ -751,12 +750,15 @@ public static bool TryLaunchMetroApp(string targ)
{
// ReSharper disable AssignNullToNotNullAttribute
//First, try locating the manifest that contains identity and ID
const string mxml = ImmersiveAppsProvider.APPXMANIFEST_XML;
const StringComparison caseless = StringComparison.OrdinalIgnoreCase;
Log.Raw("Searching for manifest", targ);
var manifest = Path.Combine(Path.GetDirectoryName(targ), "AppxManifest.xml");
if (!File.Exists(manifest) && targ.EndsWith(".lnk", StringComparison.OrdinalIgnoreCase))
var manifest = Path.Combine(Path.GetDirectoryName(targ), mxml);
if (!File.Exists(manifest) && targ.EndsWith(".lnk", caseless))
{
targ = ResolveLinkSafe(targ);
manifest = Path.Combine(Path.GetDirectoryName(targ), "AppxManifest.xml");
manifest = Path.Combine(Path.GetDirectoryName(targ), mxml);
}
// ReSharper restore AssignNullToNotNullAttribute
if (!File.Exists(manifest))
Expand All @@ -765,43 +767,25 @@ public static bool TryLaunchMetroApp(string targ)
return false;
}
//Load manifest and extract package Identity and all included apps IDs
Log.Raw("Parsing manifest", targ);
var xm = XElement.Load(manifest);
var ns = xm.GetDefaultNamespace();
// ReSharper disable PossibleNullReferenceException
var identity = xm.Element(ns + "Identity")
.Attribute("Name")
.Value;
var apps = xm.Element(ns + "Applications")
.Elements(ns + "Application")
.Select(x => new
{
Id = x.Attribute("Id").Value,
File = (x.Attribute("Executable") ?? x.Attribute("StartPage")).Value
});
// ReSharper restore PossibleNullReferenceException
//The app passed in targ argument should be registered Metro application, otherwise it can't be activated
Log.Raw("Defining target app", targ);
var app = apps.FirstOrDefault(a => targ.EndsWith(a.File, StringComparison.OrdinalIgnoreCase));
var app = ImmersiveAppsProvider.GetAppsCache()
.Where(a => Path.Combine(a.ApplicationPath, mxml).Equals(manifest, caseless))
.SingleOrDefault(a => targ.EndsWith(a.File, caseless));
if (app == null)
{
Log.Raw("Target app wasn't discovered, defaulting to regular shell launch", targ);
return false;
}
//As we know it's ModernUI app, let's try extracting it's AppUMID.
Log.Raw("Getting AppUserModelId", targ);
appUserModelId = AppxUserModelIdProvider.GetAppUserModelId(identity, app.Id);
appUserModelId = app.AppUserModelID;
}
catch (Exception ex)
{
DispatchCaughtException(ex);
return false;
}
if (appUserModelId == null)
{//no Windows registry entries fpund describing the app or it's not activatable
{//no Windows registry entries found describing the app or it's not activatable
Log.Raw("Failed to retrieve AppUserModelId", targ);
return false;
}
Expand Down
1 change: 0 additions & 1 deletion Power8.csproj
Expand Up @@ -106,7 +106,6 @@
<Compile Include="Converters\BoolToGridRowConverter.cs" />
<Compile Include="Converters\Stretch2BoolConverter.cs" />
<Compile Include="Converters\TextToBoolConverter.cs" />
<Compile Include="DataProviders\AppxUserModelIdProvider.cs" />
<Compile Include="DataProviders\ImmersiveApp.cs" />
<Compile Include="DataProviders\ImmersiveAppsProvider.cs" />
<Compile Include="DataProviders\MfuList.cs" />
Expand Down

0 comments on commit 431ee73

Please sign in to comment.