public string GetString(ushort id)
 {
     StringResource sr = new StringResource();
     sr.Name = new ResourceId(StringResource.GetBlockId(id));
     sr.LoadFrom(file);
     return sr[id];
 }
Exemplo n.º 2
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]);
        }
Exemplo n.º 3
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]);
        }