private static void ExtractResource(IEmbeddedResource res, string outputPath) { var currentAssembly = typeof(ResourceExtractor).Assembly; var arrResources = currentAssembly.GetManifestResourceNames(); var destinationPath = res.RelativePath.Equals("") ? outputPath : Path.Combine(outputPath, res.RelativePath); destinationPath.Create(); var destinationFullPath = res.RelativePath.Equals("") ? Path.Combine(outputPath, res.FileName) : Path.Combine(outputPath, res.RelativePath, res.FileName); if (File.Exists(destinationFullPath) && !res.AlwaysReplaceExisting) { return; } foreach ( var resourceName in arrResources.Where(resourceName => resourceName.ToUpper().Contains(res.SearchQuery.ToUpper()))) { using (var resourceToSave = currentAssembly.GetManifestResourceStream(resourceName)) { using (var output = File.Create(destinationFullPath)) { resourceToSave?.CopyTo(output); } resourceToSave?.Close(); } } }
public static void CopyPhysicalAssets(IEmbeddedResource embeddedResource) { var list = GetListOfEmbeddedResources(embeddedResource, ResourceType.All); var assembly = Assembly.GetExecutingAssembly(); if (list?.Count > 0) { //Copy physical files to destination assembly.ExtractEmbeddedResource(list); } }
private static List<EmbeddedResource> GetListOfEmbeddedResources(IEmbeddedResource embeddedResource, ResourceType resourceType) { List<EmbeddedResource> list = new List<EmbeddedResource>(); foreach (var resource in embeddedResource.Resources) { if (resource.ResourceType == resourceType || resourceType == ResourceType.All) list.Add(resource); } return list; }
private int WriteOtherResource(IResource resource) { byte[] buffer = null; IEmbeddedResource embeddedResource = resource as IEmbeddedResource; if (embeddedResource != null) { buffer = embeddedResource.Value; } IFileResource fileResource = resource as IFileResource; if (fileResource != null) { string location = Path.Combine(Path.GetDirectoryName(fileResource.Module.Location), fileResource.Location); location = Environment.ExpandEnvironmentVariables(location); if (File.Exists(location)) { using (Stream stream = new FileStream(location, FileMode.Open, FileAccess.Read)) { if (fileResource.Offset == 0) { buffer = new byte[stream.Length]; stream.Read(buffer, 0, buffer.Length); } else { BinaryReader reader = new BinaryReader(stream); int size = reader.ReadInt32(); buffer = new byte[size]; stream.Read(buffer, 0, size); } } } } if (buffer != null) { string fileName = Path.Combine(_outputDirectory, GetResourceFileName(resource)); using (Stream stream = File.Create(fileName)) { stream.Write(buffer, 0, buffer.Length); } WriteLine(fileName); } return(0); }
private int WriteResource(IResource resource) { IEmbeddedResource embeddedResource = resource as IEmbeddedResource; if (embeddedResource != null) { try { byte[] buffer = embeddedResource.Value; string fileName = Path.Combine(_outputDirectory, resource.Name); if (resource.Name.EndsWith(".resources")) { fileName = Path.ChangeExtension(fileName, ".resx"); using (MemoryStream ms = new MemoryStream(embeddedResource.Value)) { ResXResourceWriter resxw = new ResXResourceWriter(fileName); IResourceReader reader = new ResourceReader(ms); IDictionaryEnumerator en = reader.GetEnumerator(); while (en.MoveNext()) { resxw.AddResource(en.Key.ToString(), en.Value); } reader.Close(); resxw.Close(); } } else // other embedded resource { if (buffer != null) { using (Stream stream = File.Create(fileName)) { stream.Write(buffer, 0, buffer.Length); } } } AddToProjectFiles(fileName); return(0); } catch (Exception ex) { WriteLine("Error in " + resource.Name + " : " + ex.Message); } } return(WriteOtherResource(resource)); }
private static void ExtractResource(IEmbeddedResource res, string outputPath) { var currentAssembly = typeof(ResourceExtractor).Assembly; var arrResources = currentAssembly.GetManifestResourceNames(); var destinationPath = res.RelativePath.Equals("") ? outputPath : Path.Combine(outputPath, res.RelativePath); destinationPath.Create(); foreach ( var resourceName in arrResources.Where(resourceName => resourceName.ToUpper().Contains(res.SearchQuery.ToUpper()))) { var resInfo = currentAssembly.GetManifestResourceInfo(resourceName); var resSplit = resourceName.Split('.'); var extraFileName = string.Join(".", resSplit.Skip(Math.Max(0, resSplit.Length - 2))); if (resInfo != null) { var fileName = res.FileName.Equals("") ? resInfo.FileName ?? extraFileName : res.FileName; var destinationFullPath = res.RelativePath.Equals("") ? Path.Combine(outputPath, fileName) : Path.Combine(outputPath, res.RelativePath, fileName); if (File.Exists(destinationFullPath) && !res.AlwaysReplaceExisting) { return; } using (var resourceToSave = currentAssembly.GetManifestResourceStream(resourceName)) { using (var output = File.Create(destinationFullPath)) { resourceToSave?.CopyTo(output); } resourceToSave?.Close(); } } } }
private int WriteResource(IResource resource) { IEmbeddedResource embeddedResource = resource as IEmbeddedResource; if (embeddedResource != null) { try { byte[] buffer = embeddedResource.Value; string fileName = Path.Combine(_outputDirectory, GetResourceFileName(resource)); if (resource.Name.EndsWith(".resources")) { fileName = Path.ChangeExtension(fileName, ".resx"); using (MemoryStream ms = new MemoryStream(embeddedResource.Value)) { ResXResourceWriter resxw = new ResXResourceWriter(fileName); IResourceReader reader = new ResourceReader(ms); IDictionaryEnumerator en = reader.GetEnumerator(); while (en.MoveNext()) { bool handled = false; if (en.Value != null) { Type type = en.Value.GetType(); if (type.FullName.EndsWith("Stream")) { Stream s = en.Value as Stream; if (s != null) { byte[] bytes = new byte[s.Length]; if (s.CanSeek) { s.Seek(0, SeekOrigin.Begin); } s.Read(bytes, 0, bytes.Length); resxw.AddResource(en.Key.ToString(), new MemoryStream(bytes)); handled = true; } } } if (handled) { continue; } resxw.AddResource(en.Key.ToString(), en.Value); } reader.Close(); resxw.Close(); } } else // other embedded resource { if (buffer != null) { using (Stream stream = File.Create(fileName)) { stream.Write(buffer, 0, buffer.Length); } } } AddToProjectFiles(fileName); return(0); } catch (Exception ex) { WriteLine("Error in " + resource.Name + " : " + ex.Message); } } return(WriteOtherResource(resource)); }
public virtual void VisitEmbeddedResource(IEmbeddedResource value) { }
protected internal virtual void ValidateEmbeddedResource(string assemblyFullName, string cultureName, string name, IEmbeddedResource embeddedResource) { Assert.IsNotNull(embeddedResource); Assert.AreEqual(assemblyFullName, embeddedResource.Assembly.FullName); Assert.AreEqual(cultureName, embeddedResource.Assembly.Culture.Name); Assert.AreEqual(name, embeddedResource.Name); }
public EmailOps(IConfigManager config, IEmbeddedResource resource) { _config = config; _resource = resource; }
internal static EmbeddedResource FindMatchingResource(AssemblyDefinition adef, IEmbeddedResource eres) { return((from resource in adef.MainModule.Resources where resource is EmbeddedResource && resource.Name.Equals(eres.Name) select resource as EmbeddedResource).FirstOrDefault()); }
public virtual void VisitEmbeddedResource(IEmbeddedResource value) { }
public virtual IResource TransformEmbeddedResource(IEmbeddedResource value) { return value; }