Beispiel #1
0
        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);
                }
            }
        }
Beispiel #2
0
        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);
                    }
                }
            }
        }
Beispiel #3
0
        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);
        }
        public void TestDeepCopyBytes(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));
            VersionResource existingVersionResource = new VersionResource();

            existingVersionResource.Language = ResourceUtil.USENGLISHLANGID;
            Console.WriteLine("Loading {0}", filename);
            existingVersionResource.LoadFrom(filename);
            DumpResource.Dump(existingVersionResource);

            VersionResource versionResource = new VersionResource();

            versionResource.FileVersion    = existingVersionResource.FileVersion;
            versionResource.ProductVersion = existingVersionResource.ProductVersion;

            StringFileInfo existingVersionResourceStringFileInfo = (StringFileInfo)existingVersionResource["StringFileInfo"];
            VarFileInfo    existingVersionResourceVarFileInfo    = (VarFileInfo)existingVersionResource["VarFileInfo"];

            // copy string resources, data only
            StringFileInfo stringFileInfo = new StringFileInfo();

            versionResource["StringFileInfo"] = stringFileInfo;
            {
                Dictionary <string, StringTable> .Enumerator enumerator = existingVersionResourceStringFileInfo.Strings.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    StringTable stringTable = new StringTable(enumerator.Current.Key);
                    stringFileInfo.Strings.Add(enumerator.Current.Key, stringTable);
                    Dictionary <string, StringTableEntry> .Enumerator resourceEnumerator = enumerator.Current.Value.Strings.GetEnumerator();
                    while (resourceEnumerator.MoveNext())
                    {
                        StringTableEntry stringResource = new StringTableEntry(resourceEnumerator.Current.Key);
                        stringResource.Value = resourceEnumerator.Current.Value.Value;
                        stringTable.Strings.Add(resourceEnumerator.Current.Key, stringResource);
                    }
                }
            }

            // copy var resources, data only
            VarFileInfo varFileInfo = new VarFileInfo();

            versionResource["VarFileInfo"] = varFileInfo;
            {
                Dictionary <string, VarTable> .Enumerator enumerator = existingVersionResourceVarFileInfo.Vars.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    VarTable varTable = new VarTable(enumerator.Current.Key);
                    varFileInfo.Vars.Add(enumerator.Current.Key, varTable);
                    Dictionary <UInt16, UInt16> .Enumerator translationEnumerator = enumerator.Current.Value.Languages.GetEnumerator();
                    while (translationEnumerator.MoveNext())
                    {
                        varTable.Languages.Add(translationEnumerator.Current.Key, translationEnumerator.Current.Value);
                    }
                }
            }

            ByteUtils.CompareBytes(existingVersionResource.WriteAndGetBytes(), versionResource.WriteAndGetBytes());
        }