public static StreamResourceInfo GetResourceStream (Uri uriResource)
{
if (uriResource == null)
throw new ArgumentNullException ("uriResource");
if (uriResource.IsAbsoluteUri && uriResource.Scheme != Uri.UriSchemeFile) {
throw new ArgumentException ("Absolute uriResource");
}
// FIXME: URI must point to
// - the application assembly (embedded resources)
// - an assembly part of the application package (embedded resources)
// - something included in the package
Assembly assembly;
string assembly_name;
string resource;
string loc = uriResource.ToString ();
int p = loc.IndexOf (';');
/* We have a resource of the format /assembly;component/resourcename */
/* It looks like the / is optional tho. *SIGH* */
if (p > 0) {
int l = loc [0] == '/' ? 1 : 0;
assembly_name = loc.Substring (l, p - l);
assembly = GetAssembly (assembly_name);
if (assembly == null)
return null;
resource = loc.Substring (p + 11);
} else {
assembly = Deployment.Current.EntryAssembly;
// Deployment.Current.EntryPointAssembly is not usable outside the main thread
assembly_name = assembly.GetName ().Name;
resource = loc;
}
resource = resource [0] == '/' ? resource : string.Format ("/{0}", resource);
resource = Path.GetFullPath (resource);
resource = resource [0] == '/' ? resource.Substring (1) : resource;
try {
var manager = new ResourceManager (assembly_name + ".g", assembly) { IgnoreCase = true };
var stream = manager.GetStream (Uri.EscapeUriString (resource));
if (stream != null)
return new StreamResourceInfo (stream, string.Empty);
} catch {}
return GetXapResource (resource);
}