Ejemplo n.º 1
0
 public static Stream GetResourceStream(string resName)
 {
     var assembly = Assembly.GetExecutingAssembly();
     var strResources = assembly.GetName().Name + ".g.resources";
     var rStream = assembly.GetManifestResourceStream(strResources);
     var resourceReader = new ResourceReader(rStream);
     var items = resourceReader.OfType<DictionaryEntry>();
     var stream = items.First(x => (x.Key as string) == resName.ToLower()).Value;
     return (UnmanagedMemoryStream)stream;
 }
Ejemplo n.º 2
0
 void AnalyzeResource(ModuleDefinition mod, int resId)
 {
     EmbeddedResource res = mod.Resources[resId] as EmbeddedResource;
     ResourceReader resRdr = new ResourceReader(res.GetResourceStream());
     Dictionary<string, object> ress;
     Dictionary<string, BamlDocument> bamls;
     (res as IAnnotationProvider).Annotations["Gresources"] = ress = new Dictionary<string, object>();
     (res as IAnnotationProvider).Annotations["Gbamls"] = bamls = new Dictionary<string, BamlDocument>();
     int cc = 0;
     int n = 0;
     var reses = resRdr.OfType<DictionaryEntry>().ToArray();
     foreach (DictionaryEntry entry in reses)
     {
         Stream stream = null;
         if (entry.Value is Stream)
         {
             byte[] buff = new byte[(entry.Value as Stream).Length];
             (entry.Value as Stream).Position = 0;
             (entry.Value as Stream).Read(buff, 0, buff.Length);
             ress.Add(entry.Key as string, stream = new MemoryStream(buff));
         }
         else
             ress.Add(entry.Key as string, entry.Value);
         if (stream != null)
         {
             if ((entry.Key as string).EndsWith(".baml"))
             {
                 ProcessBaml(mod, bamls, ref cc, entry, stream);
             }
             else if ((entry.Key as string).EndsWith(".xaml"))
             {
                 ProcessXaml(mod, ref cc, entry, stream);
             }
         }
         n++;
         Logger._Progress(n, reses.Length);
     }
     if (cc != 0)
         ((res as IAnnotationProvider).Annotations[RenRef] as List<IReference>).Add(new SaveWpfResReference(mod, resId));
 }
Ejemplo n.º 3
0
        private void UpdareResource(HashSet<IAssemblyInfo> modified, string token, IAssemblyInfo assemblyInfo, ModuleDefinition module)
        {
            var resArray = module.Resources.ToArray();
            for (var resIndex = 0; resIndex < resArray.Length; resIndex++)
            {
                var resource = resArray[resIndex];
                if (resource.ResourceType == ResourceType.Embedded)
                {
                    if(!resource.Name.EndsWith(".g.resources"))
                    {
                        continue;
                    }

                    var embededResource = (EmbeddedResource)resource;
                    var modResource = false;

                    var memoryStream = new MemoryStream();
                    var rw = new ResourceWriter(memoryStream);

                    var stream = embededResource.GetResourceStream();
                    var reader = new ResourceReader(stream);
                    foreach (var entry in reader.OfType<DictionaryEntry>().ToArray())
                    {
                        var resourceName = entry.Key.ToString();
                        var resourceStream = entry.Value as Stream;

                        if (resourceStream != null && resourceName.EndsWith(".baml", StringComparison.InvariantCulture))
                        {
                            modResource = this.CheckBaml(modified, token, assemblyInfo, modResource, rw, resourceName, resourceStream);
                        }
                        else
                        {
                            rw.AddResource(resourceName, entry.Value);
                        }
                    }

                    if (modResource)
                    {
                        ReplaceResource(module, resIndex, resource, memoryStream, rw);
                    }
                }
            }
        }
        private static string[] GetResourcesUnder(string folder)
        {
            folder = folder.ToLower() + "/";

            var assembly       = Assembly.GetCallingAssembly();
            var resourcesName  = assembly.GetName().Name + ".g.resources";
            var stream         = assembly.GetManifestResourceStream(resourcesName);
            var resourceReader = new ResourceReader(stream);

            var resources = resourceReader.OfType<DictionaryEntry>()
                .Select(p => p.Key.ToString())
                .Where(theme => theme.StartsWith(folder));

            return resources.ToArray();
        }
		public static int GetResourcesCount(Dictionary<ModuleDefinition, Collection<Resource>> resources)
		{
			int result = 0;

			foreach (Collection<Resource> moduleResources in resources.Values)
			{
				foreach (Resource resource in moduleResources)
				{
					if (resource.ResourceType != ResourceType.Embedded)
					{
						continue;
					}

					EmbeddedResource embeddedResource = (EmbeddedResource)resource;
					if (resource.Name.EndsWith(".g.resources", StringComparison.OrdinalIgnoreCase))
					{
						using (ResourceReader resourceReader = new ResourceReader(embeddedResource.GetResourceStream()))
						{
                            result += resourceReader.OfType<System.Collections.DictionaryEntry>().Count();
						}
					}
					else
					{
						result++;
					}
				}
			}

			return result;
		}