public void TestReadWriteResourceBytes(string path) { var filename = Path.GetFileName(path); var isDotNet = filename.StartsWith("ClassLibrary_NET") || filename == "idea64.exe"; if (filename == "idea64.exe") { Assert.Ignore("idea64.exe doesn't consider null byte for StringTableEntry length"); } using (ResourceInfo ri = new ResourceInfo()) { ri.Load(path); foreach (Resource rc in ri) { Console.WriteLine("Resource: {0} - {1}", rc.TypeName, rc.Name); GenericResource genericResource = new GenericResource(rc.Type, rc.Name, rc.Language); genericResource.LoadFrom(path); try { StringTableEntry.ConsiderPaddingForLength = isDotNet; byte[] data = rc.WriteAndGetBytes(); ByteUtils.CompareBytes(genericResource.Data, data); } finally { StringTableEntry.ConsiderPaddingForLength = false; } } } }
public void TestReadWriteResourceBytes(string filename) { if (Path.GetFileName(filename).StartsWith("ClassLibrary_NET")) { Assert.Ignore(".NET assemblies will fail because they use a padding different from the specification"); } using (ResourceInfo ri = new ResourceInfo()) { ri.Load(filename); foreach (Resource rc in ri) { Console.WriteLine("Resource: {0} - {1}", rc.TypeName, rc.Name); GenericResource genericResource = new GenericResource(rc.Type, rc.Name, rc.Language); genericResource.LoadFrom(filename); byte[] data = rc.WriteAndGetBytes(); ByteUtils.CompareBytes(genericResource.Data, data); } } }
public void TestReadWriteResourceBytes() { Uri uri = new Uri(Assembly.GetExecutingAssembly().CodeBase); string uriPath = Path.GetDirectoryName(HttpUtility.UrlDecode(uri.AbsolutePath)); foreach (string filename in Directory.GetFiles(Path.Combine(uriPath, "Binaries"))) { Console.WriteLine(filename); using (ResourceInfo ri = new ResourceInfo()) { ri.Load(filename); foreach (Resource rc in ri) { Console.WriteLine("Resource: {0} - {1}", rc.TypeName, rc.Name); GenericResource genericResource = new GenericResource(rc.Type, rc.Name, rc.Language); genericResource.LoadFrom(filename); byte[] data = rc.WriteAndGetBytes(); ByteUtils.CompareBytes(genericResource.Data, data); } } } }
public void TestLoadSave() { string atldll = Path.Combine(Environment.SystemDirectory, "atl.dll"); Assert.IsTrue(File.Exists(atldll)); string targetFilename = Path.Combine(Path.GetTempPath(), "genericResourceTestLoadSave.dll"); Console.WriteLine(targetFilename); File.Copy(atldll, targetFilename, true); // write the resource to a binary GenericResource genericResource = new GenericResource( new ResourceId("TESTTYPE"), new ResourceId("TESTNAME"), ResourceUtil.USENGLISHLANGID); genericResource.Data = Guid.NewGuid().ToByteArray(); genericResource.SaveTo(targetFilename); // reload and compare GenericResource newGenericResource = new GenericResource( new ResourceId("TESTTYPE"), new ResourceId("TESTNAME"), ResourceUtil.USENGLISHLANGID); newGenericResource.LoadFrom(targetFilename); ByteUtils.CompareBytes(newGenericResource.Data, genericResource.Data); }
public void TestReadWriteMenuMixedResourceBytes() { Uri uri = new Uri(Assembly.GetExecutingAssembly().CodeBase); string uriPath = Path.GetDirectoryName(HttpUtility.UrlDecode(uri.AbsolutePath)); string filename = Path.Combine(uriPath, @"Binaries\custom.exe"); using (ResourceInfo ri = new ResourceInfo()) { ri.Load(filename); foreach (MenuResource rc in ri[Kernel32.ResourceTypes.RT_MENU]) { Console.WriteLine(rc.Name); GenericResource genericResource = new GenericResource( rc.Type, rc.Name, rc.Language); genericResource.LoadFrom(filename); byte[] data = rc.WriteAndGetBytes(); ByteUtils.CompareBytes(genericResource.Data, data); } } }
public void TestLoadSave(string binaryName) { Uri uri = new Uri(Assembly.GetExecutingAssembly().CodeBase); string filename = Path.Combine(Path.GetDirectoryName(HttpUtility.UrlDecode(uri.AbsolutePath)), "Binaries\\" + binaryName); Assert.IsTrue(File.Exists(filename)); string targetFilename = Path.Combine(Path.GetTempPath(), "genericResourceTestLoadSave.dll"); Console.WriteLine(targetFilename); File.Copy(filename, targetFilename, true); // write the resource to a binary GenericResource genericResource = new GenericResource( new ResourceId("TESTTYPE"), new ResourceId("TESTNAME"), ResourceUtil.USENGLISHLANGID); genericResource.Data = Guid.NewGuid().ToByteArray(); genericResource.SaveTo(targetFilename); // reload and compare GenericResource newGenericResource = new GenericResource( new ResourceId("TESTTYPE"), new ResourceId("TESTNAME"), ResourceUtil.USENGLISHLANGID); newGenericResource.LoadFrom(targetFilename); ByteUtils.CompareBytes(newGenericResource.Data, genericResource.Data); }