コード例 #1
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);
 }
コード例 #2
0
 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);
 }
コード例 #3
0
        public static void injectResources()
        {
            if(isCreateBackup)
                File.Copy(dll, dll + ".bak", false);    // Don't overwrite

            DirectoryInfo d = new DirectoryInfo(workingDir);
            foreach (var file in d.GetFiles())
            {
                try
                {
                    // The resource ID MUST be parsed as a uint to replace the current resource, otherwise
                    // it will be added as a new resource which will be ignored by iTunes.
                    var res = new GenericResource
                        (RT_RCDATA, new ResourceId(uint.Parse(Path.GetFileNameWithoutExtension(file.Name))), LANG_ENGLISH);

                    res.Data = File.ReadAllBytes(file.FullName);
                    res.SaveTo(dll);

                    Console.WriteLine("Injection Successful: " + file.Name);
                }
                catch
                {
                    Console.WriteLine("Injection Failed: " + file.Name);
                }
            }
        }