예제 #1
0
        public override ResourceData GetResourceData(ResourceLang lang)
        {
            if (lang.Name.Type.Source != this)
            {
                throw new ArgumentException("The specified ResourceLang does not exist in this ResourceSource");
            }

            // TODO: Check that ResourceLang refers to a Resource that actually does exist in this resource and is not a pending add operation

            // use FindResourceEx and LoadResource to get a handle to the resource
            // use SizeOfResource to get the length of the byte array
            // then LockResource to get a pointer to it. Use Marshal to get a byte array and take it from there

            IntPtr resInfo = NativeMethods.FindResourceEx(_moduleHandle, lang.Name.Type.Identifier.NativeId, lang.Name.Identifier.NativeId, lang.LanguageId);
            IntPtr resData = NativeMethods.LoadResource(_moduleHandle, resInfo);
            Int32  size    = NativeMethods.SizeOfResource(_moduleHandle, resInfo);

            if (resData == IntPtr.Zero)
            {
                return(null);
            }

            IntPtr resPtr = NativeMethods.LockResource(resData);                // there is no method to unlock resources, but they should be freed anyway

            Byte[] data = new Byte[size];

            Marshal.Copy(resPtr, data, 0, size);

            NativeMethods.FreeResource(resData);

            ResourceData retval = ResourceData.FromResource(lang, data);

            return(retval);
        }
예제 #2
0
        public override ResourceData GetResourceData(ResourceLang lang)
        {
            if (lang.Name.Type.Source != this)
            {
                throw new ArgumentException("The specified ResourceLang does not exist in this ResourceSource");
            }

            if (lang.Action == ResourceDataAction.Add)
            {
                throw new ArgumentException("The specified ResourceLang's data does not exist in this ResourceSource");
            }

            // use FindResourceEx and LoadResource to get a handle to the resource
            // use SizeOfResource to get the length of the byte array
            // then LockResource to get a pointer to it. Use Marshal to get a byte array and take it from there

            var resInfo = NativeMethods.FindResourceEx(
                _moduleHandle,
                lang.Name.Type.Identifier.NativeId,
                lang.Name.Identifier.NativeId,
                lang.LanguageId
                );
            var resData = NativeMethods.LoadResource(_moduleHandle, resInfo);
            var size    = NativeMethods.SizeOfResource(_moduleHandle, resInfo);

            if (resData == IntPtr.Zero)
            {
                return(null);
            }

            var resPtr =
                NativeMethods.LockResource(
                    resData
                    ); // there is no method to unlock resources, but they should be freed anyway

            var data = new byte[size];

            Marshal.Copy(resPtr, data, 0, size);

            NativeMethods.FreeResource(resData);

            var retval = ResourceData.FromResource(lang, data);

            return(retval);
        }
예제 #3
0
        public override ResourceData GetResourceData(ResourceLang lang)
        {
            ResResource res = _resources.Find(r => r.Lang == lang);

            if (res == null)
            {
                throw new ArgumentException("ResourceLang not found");
            }

            _stream.Seek(res.DataOffset, SeekOrigin.Begin);

            Byte[] data = new Byte[res.DataLength];
            if (_stream.Read(data, 0, res.DataLength) != res.DataLength)
            {
                throw new AnolisException("Couldn't read all Resource Data");
            }

            return(ResourceData.FromResource(lang, data));
        }