Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

File Resource Management Library (.NET)

, 16 Sep 2009
A .NET implementation of a file resource management, with complete support for VS_VERSIONINFO version resources.
vestris.resourcelib.1.2.zip
Vestris.ResourceLib
1.2
ResourceLib.chm
Article
Bin
Release
Vestris.ResourceLib.dll
Source
ResourceLib.proj
Version.proj
Common
ResourceLib
Properties
ResourceLibUnitTests
Properties
Vestris.ResourceLib.zip
1.0
Article
Bin
nunit.framework.dll
Vestris.ResourceLib.dll
Vestris.ResourceLibUnitTests.dll
Source
Common
ResourceLib.proj
ResourceLib
Properties
ResourceLibUnitTests
Properties
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using NUnit.Framework;
using Vestris.ResourceLib;
using System.Reflection;
using System.Web;
using System.Runtime.InteropServices;

namespace Vestris.ResourceLibUnitTests
{
    [TestFixture]
    public class ResourceTests
    {
        [Test]
        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);
                    }
                }
            }
        }

        [Test]
        public void TestCustom()
        {
            Uri uri = new Uri(Assembly.GetExecutingAssembly().CodeBase);
            string filename = Path.Combine(Path.GetDirectoryName(HttpUtility.UrlDecode(uri.AbsolutePath)), "Binaries\\custom.exe");
            Assert.IsTrue(File.Exists(filename));
            using (ResourceInfo vi = new ResourceInfo())
            {
                vi.Load(filename);
                // version resources (well-known)
                List<Resource> versionResources = vi[Kernel32.ResourceTypes.RT_VERSION]; // RT_VERSION
                Assert.IsNotNull(versionResources);
                Assert.AreEqual(1, versionResources.Count);
                Resource versionResource = versionResources[0];
                Assert.AreEqual(versionResource.Name.ToString(), "1");
                Assert.AreEqual(versionResource.Type.ToString(), "16");
                // custom resources
                List<Resource> customResources = vi["CUSTOM"];
                Assert.IsNotNull(customResources);
                Assert.AreEqual(1, customResources.Count);
                Resource customResource = customResources[0];
                // check whether the properties are string representations
                Assert.AreEqual(customResource.Name.ToString(), "RES_CONFIGURATION");
                Assert.AreEqual(customResource.Type.ToString(), "CUSTOM");
            }
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

dB.
Team Leader Application Security Inc., www.appsecinc.com
United States United States
Daniel Doubrovkine has been in software engineering for twelve years and is currently development manager at Application Security Inc. in New York City. He has been involved in many software ventures, including Xo3 and Vestris Inc, was a development lead at Microsoft Corp. in Redmond, and director of Engineering at Visible Path Corp. in New York City. Daniel also builds and runs a foodie website, http://www.foodcandy.com.

| Advertise | Privacy | Mobile
Web01 | 2.8.140826.1 | Last Updated 16 Sep 2009
Article Copyright 2008 by dB.
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid