I have a simple managed VC ++ project in solution. It has a resource file app.rcthat is used to store assembly information (version, product, copyright, etc.). If I open the file in a text editor , it says that it is Unicode (UTF-16 LE BOM) . And Visual Studio displays it correctly if I select Unicode - Codepage 1200 .
VS_VERSION_INFO VERSIONINFO
FILEVERSION 0,0,0,0
PRODUCTVERSION 0,0,0,0
FILEFLAGSMASK 0x3fL
FILEFLAGS 0x1L
FILEFLAGS 0x0L
FILEOS 0x40004L
FILETYPE 0x2L
FILESUBTYPE 0x0L
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "040904b0"
BEGIN
VALUE "CompanyName", "My Company, LLC"
VALUE "FileVersion", "0.0.0.0"
VALUE "InternalName", "myassembly.dll"
VALUE "LegalCopyright", "Copyright (C) 2011 My Company, LLC"
VALUE "OriginalFilename", "myassembly.dll"
VALUE "ProductName", "The Product"
VALUE "ProductVersion", "0.0.0.0"
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x409, 1200
END
END
I use Ruby / Rake to configure and run local builds. Part of this assembly replaces the version in assembly resources. I read the gsubversion numbers in the file and write the file back. However, when I read in a file, I get garbage
irb(main):001:0> File.open("source\\myproject\\app.rc").read
=> "\xFF\xFE/\x00/\x00 \x00M\x00i\x00c\x00r\x00o\x00s\x00o\x00f\x00t\x00 \x00V\x00i\x00s\x
00u\x00a\x00l\x00 \x00C\x00+\x00+\x00 \x00g\x00e\x00n\x00e\x00r\x00a\x00t\x00e\x00d\x00 \x
00r\x00e\x00s\x00o\x00u\x00r\x00c\x00e\x00 \x00s\x00c\x00r\x00i\x00p\x00t\x00.\x00\n\x00\n
\x00/\x00/\x00\n\x00\n\x00#\x00i\x00n\x00c\x00l\x00u\x00d\x00e\x00 \x00\"\x00r\x00e\x00s\x
Ruby , IBM437.
irb(main):006:0> File.open("source\\myproject\\app.rc").external_encoding
=> #<Encoding:IBM437>
, ( , Unicode (UTF-16 BE BOM)).
䴀椀挀爀漀猀漀昀琀 嘀椀猀甀愀氀 䌀⬀⬀ 最攀渀攀爀愀琀攀搀 爀攀猀漀甀爀挀攀 猀挀爀椀瀀琀⸀ഊ
⼀⼀ഊ
⌀椀渀挀氀甀搀攀 ∀爀攀猀漀甀爀挀攀⸀栀∀ഊ
ഊ
/ ?
, , encodings.
irb(main):003:0> File.open("source\\myproject\\app.rc", "rb:UTF-16LE")
=> #<File:source\myproject\app.rc>
.
irb(main):003:0> c = File.open("source\\myproject\\app.rc", "rb:UTF-16LE").read
irb(main):007:0> c.gsub("0.0.0.0", "0.0.5.0")
Encoding::CompatibilityError: incompatible encoding regexp match (US-ASCII regexp with UTF-16LE string)
gsub. ?