using System;
using System.Collections;
+using System.Globalization;
using System.IO;
using System.Text;
public string[] WellKnownProperties = {
"Comments",
"CompanyName",
- "FileDescription",
"FileVersion",
"InternalName",
- "LegalCopyright",
"LegalTrademarks",
"OriginalFilename",
"ProductName",
Hashtable properties;
- public Win32VersionResource (int id, int language) : base (Win32ResourceType.RT_VERSION, id, language) {
+ public Win32VersionResource (int id, int language, bool compilercontext) : base (Win32ResourceType.RT_VERSION, id, language) {
// Initialize non-public members to the usual values used in
// resources
signature = 0xfeef04bd;
file_subtype = 0;
file_date = 0;
- file_lang = 0x7f;
+ file_lang = compilercontext ? 0x00 : 0x7f;
file_codepage = 1200;
properties = new Hashtable ();
+ string defaultvalue = compilercontext ? string.Empty : " ";
+
// Well known properties
foreach (string s in WellKnownProperties)
// The value of properties can't be empty
- properties [s] = " ";
+ properties [s] = defaultvalue;
+
+ LegalCopyright = " ";
+ FileDescription = " ";
}
public string Version {
long[] ver = new long [4] { 0, 0, 0, 0 };
if (value != null) {
string[] parts = value.Split ('.');
-
- for (int i = 0; i < parts.Length; ++i) {
- try {
+
+ try {
+ for (int i = 0; i < parts.Length; ++i) {
if (i < ver.Length)
ver [i] = Int32.Parse (parts [i]);
}
- catch (FormatException) {
- }
+ } catch (FormatException) {
}
}
file_version = (ver [0] << 48) | (ver [1] << 32) | (ver [2] << 16) + ver [3];
+ properties ["FileVersion"] = Version;
}
}
return (string)properties ["ProductVersion"];
}
set {
- properties ["ProductVersion"] = value == String.Empty ? " " : value;
+ if (value == null || value.Length == 0)
+ value = " ";
+
+ long [] ver = new long [4] { 0, 0, 0, 0 };
+
+ string [] parts = value.Split ('.');
+
+ try {
+ for (int i = 0; i < parts.Length; ++i) {
+ if (i < ver.Length)
+ ver [i] = Int32.Parse (parts [i]);
+ }
+ } catch (FormatException) {
+ }
+
+ properties ["ProductVersion"] = value;
+ product_version = (ver [0] << 48) | (ver [1] << 32) | (ver [2] << 16) + ver [3];
}
}
}
public virtual int FileLanguage {
- get {
- return file_lang;
- }
- set {
- file_lang = value;
- }
+ get { return file_lang; }
+ set { file_lang = value; }
}
public virtual string FileVersion {
return (string)properties ["FileVersion"];
}
set {
- properties ["FileVersion"] = value == String.Empty ? " " : value;
+ if (value == null || value.Length == 0)
+ value = " ";
+
+ long[] ver = new long [4] { 0, 0, 0, 0 };
+ string[] parts = value.Split ('.');
+
+ try {
+ for (int i = 0; i < parts.Length; ++i) {
+ if (i < ver.Length)
+ ver [i] = Int32.Parse (parts [i]);
+ }
+ } catch (FormatException) {
+ }
+
+ properties ["FileVersion"] = value;
+ file_version = (ver [0] << 48) | (ver [1] << 32) | (ver [2] << 16) + ver [3];
}
}
int read_int16 () {
int b1 = res_file.ReadByte ();
- int b2 = res_file.ReadByte ();
+ if (b1 == -1)
+ return -1;
- if ((b1 == -1) || (b2 == -1))
+ int b2 = res_file.ReadByte ();
+ if (b2 == -1)
return -1;
- else
- return b1 | (b2 << 8);
+
+ return b1 | (b2 << 8);
}
int read_int32 () {
int w1 = read_int16 ();
+ if (w1 == -1)
+ return -1;
int w2 = read_int16 ();
-
- if ((w1 == -1) || (w2 == -1))
+ if (w2 == -1)
return -1;
+
return w1 | (w2 << 16);
}
- private void read_padding () {
- while ((res_file.Position % 4) != 0)
- read_int16 ();
+ private bool read_padding () {
+ while ((res_file.Position % 4) != 0){
+ if (read_int16 () == -1)
+ return false;
+ }
+ return true;
}
NameOrId read_ordinal () {
while (true) {
- read_padding ();
-
+ if (!read_padding ())
+ break;
+
int data_size = read_int32 ();
if (data_size == -1)
NameOrId type = read_ordinal ();
NameOrId name = read_ordinal ();
- read_padding ();
-
+ if (!read_padding ())
+ break;
+
//int data_version =
read_int32 ();
//int memory_flags =
continue;
byte[] data = new byte [data_size];
- res_file.Read (data, 0, data_size);
+ if (res_file.Read (data, 0, data_size) != data_size)
+ break;
resources.Add (new Win32EncodedResource (type, name, language_id, data));
}
//
internal class ICONDIRENTRY {
+#pragma warning disable 649
public byte bWidth;
public byte bHeight;
public byte bColorCount;
public Int16 wBitCount;
public Int32 dwBytesInRes;
public Int32 dwImageOffset;
-
+#pragma warning restore 649
public byte[] image;
public override string ToString () {