예제 #1
0
 public void TestSaveStringResource()
 {
     Uri uri = new Uri(Assembly.GetExecutingAssembly().CodeBase);
     string uriPath = Path.GetDirectoryName(HttpUtility.UrlDecode(uri.AbsolutePath));
     string sourceFilename = Path.Combine(uriPath, @"Binaries\gutils.dll");
     string targetFilename = Path.Combine(Path.GetTempPath(), "testSaveStringResource.dll");
     File.Copy(sourceFilename, targetFilename, true);
     // a new resource
     StringResource sr = new StringResource();
     sr.Name = new ResourceId(StringResource.GetBlockId(1256));
     sr[1256] = Guid.NewGuid().ToString();
     sr.SaveTo(targetFilename);
     using (ResourceInfo ri = new ResourceInfo())
     {
         ri.Load(targetFilename);
         Assert.AreEqual(2, ri[Kernel32.ResourceTypes.RT_STRING].Count);
         Assert.AreEqual(StringResource.GetBlockId(1256), ri[Kernel32.ResourceTypes.RT_STRING][1].Name.Id.ToInt32());
         Assert.AreEqual(sr[1256], ((StringResource) ri[Kernel32.ResourceTypes.RT_STRING][1])[1256]);
         foreach (StringResource rc in ri[Kernel32.ResourceTypes.RT_STRING])
         {
             Console.WriteLine("StringResource: {0}, {1}", rc.Name, rc.TypeName);
             DumpResource.Dump(rc);
         }
     }
 }
예제 #2
0
        public void TestBatchUpdate()
        {
            Uri uri = new Uri(Assembly.GetExecutingAssembly().CodeBase);
            string originalFilename = Path.Combine(Path.GetDirectoryName(HttpUtility.UrlDecode(uri.AbsolutePath)), "Binaries\\gutils.dll");
            string filename = Path.Combine(Path.GetDirectoryName(HttpUtility.UrlDecode(uri.AbsolutePath)), "Binaries\\gutils_changed.dll");
            if (File.Exists(filename)) File.Delete(filename);
            File.Copy(originalFilename, filename);
            Assert.IsTrue(File.Exists(filename));
            Console.WriteLine("Filename: {0}", filename);

            // read existing string table
            var sr = new StringResource();
            sr.Name = new ResourceId(StringResource.GetBlockId(402));
            sr.Language = 1033;
            sr.LoadFrom(filename);
            Console.WriteLine("StringResource before patching: {0}, {1}, {2}", sr.Name, sr.TypeName, sr.Language);
            DumpResource.Dump(sr);
            Assert.IsNotNull(sr);
            Assert.AreEqual("Out Of Memory", sr[402]);

            // change string and save it
            sr[402] = "OOM";
            Resource.Save(filename, new[] { sr });

            // re-read string table and verify the changed string table entry
            sr = new StringResource();
            sr.Name = new ResourceId(StringResource.GetBlockId(402));
            sr.Language = 1033;
            sr.LoadFrom(filename);
            Console.WriteLine("StringResource after patching: {0}, {1}, {2}", sr.Name, sr.TypeName, sr.Language);
            DumpResource.Dump(sr);
            Assert.AreEqual("OOM", sr[402]);
        }
예제 #3
0
 public void TestLoadStringResource()
 {
     Uri uri = new Uri(Assembly.GetExecutingAssembly().CodeBase);
     string uriPath = Path.GetDirectoryName(HttpUtility.UrlDecode(uri.AbsolutePath));
     string filename = Path.Combine(uriPath, @"Binaries\gutils.dll");
     StringResource sr = new StringResource();
     sr.Name = new ResourceId(StringResource.GetBlockId(402));
     sr.LoadFrom(filename);
     Assert.AreEqual("Out Of Memory", sr[402]);
 }
예제 #4
0
 public static void Dump(StringResource rc)
 {
     Console.WriteLine(rc.ToString());
 }