Click here to Skip to main content
12,292,585 members (69,630 online)
Click here to Skip to main content

Stats

83.4K views
2K downloads
111 bookmarked
Posted

File Resource Management Library (.NET)

, 16 Sep 2009 CPOL
A .NET implementation of a file resource management, with complete support for VS_VERSIONINFO version resources.
Vestris.ResourceLib
1.2
ResourceLib.chm
Article
Bin
Release
Vestris.ResourceLib.dll
Source
ResourceLib.proj
Version.proj
Common
ResourceLib
Properties
ResourceLibUnitTests
Properties
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.Runtime.InteropServices;
using System.IO;

namespace Vestris.ResourceLib
{
    /// <summary>
    /// This structure depicts the organization of data in a file-version resource. 
    /// It contains version information not dependent on a particular language and code page combination.
    /// http://msdn.microsoft.com/en-us/library/aa909193.aspx
    /// </summary>
    public class VarFileInfo : ResourceTable
    {
        Dictionary<string, VarTable> _variables;

        public Dictionary<string, VarTable> Vars
        {
            get
            {
                return _variables;
            }
        }

        public VarFileInfo(IntPtr lpRes)
        {
            Read(lpRes);
        }

        public override IntPtr Read(IntPtr lpRes)
        {
            _variables = new Dictionary<string, VarTable>();
            IntPtr pChild = base.Read(lpRes);

            while (pChild.ToInt32() < (lpRes.ToInt32() + _header.wLength))
            {
                VarTable res = new VarTable(pChild);
                _variables.Add(res.Key, res);
                pChild = ResourceUtil.Align(pChild.ToInt32() + res.Header.wLength);
            }

            return new IntPtr(lpRes.ToInt32() + _header.wLength);
        }

        public override void Write(BinaryWriter w)
        {
            long headerPos = w.BaseStream.Position;
            base.Write(w);

            Dictionary<string, VarTable>.Enumerator variablesEnum = _variables.GetEnumerator();
            while (variablesEnum.MoveNext())
            {
                variablesEnum.Current.Value.Write(w);
            }

            ResourceUtil.WriteAt(w, w.BaseStream.Position - headerPos, headerPos);
        }

        public VarTable Default
        {
            get
            {
                Dictionary<string, VarTable>.Enumerator variablesEnum = _variables.GetEnumerator();
                if (variablesEnum.MoveNext()) return variablesEnum.Current.Value;
                return null;
            }
        }

        public UInt16 this[UInt16 language]
        {
            get
            {
                return Default[language];
            }
            set
            {
                Default[language] = value;
            }
        }
    }
}

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.

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.160518.1 | Last Updated 16 Sep 2009
Article Copyright 2008 by dB.
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid