/// <summary> /// Gets or sets a string value. /// </summary> /// <param name="key">Name of the string.</param> public string this[string key] { get { VersionInfo verValue = this.rawStringVersionInfo[key]; if (verValue == null) { return(null); } else { return(Encoding.Unicode.GetString(verValue.Data, 0, verValue.Data.Length - 2)); } } set { if (value == null) { rawStringVersionInfo.Remove(key); } else { VersionInfo verValue = rawStringVersionInfo[key]; if (verValue == null) { verValue = new VersionInfo(key); verValue.IsString = true; rawStringVersionInfo.Add(verValue); } verValue.Data = new byte[Encoding.Unicode.GetByteCount(value) + 2]; Encoding.Unicode.GetBytes(value, 0, value.Length, verValue.Data, 0); } this.parent.dirty = true; } }
/// <summary> /// Adds a new version string table for a locale. /// </summary> /// <param name="locale">Locale of the table</param> /// <returns>The new string table, or the existing table if the locale already existed.</returns> public VersionStringTable Add(int locale) { VersionInfo svi = this.rawVersionInfo["StringFileInfo"]; if (svi == null) { svi = new VersionInfo("StringFileInfo"); this.rawVersionInfo.Add(svi); } foreach (VersionInfo strings in svi) { int stringsLocale = UInt16.Parse(strings.Key.Substring(0, 4), NumberStyles.HexNumber, CultureInfo.InvariantCulture); if (stringsLocale == locale) { return(new VersionStringTable(this, strings)); } } VersionInfo newStrings = new VersionInfo( ((ushort)locale).ToString("x4", CultureInfo.InvariantCulture) + ((ushort)1200).ToString("x4", CultureInfo.InvariantCulture)); svi.Add(newStrings); this.dirty = true; VersionInfo vvi = this.rawVersionInfo["VarFileInfo"]; if (vvi == null) { vvi = new VersionInfo("VarFileInfo"); vvi.Add(new VersionInfo("Translation")); this.rawVersionInfo.Add(vvi); } VersionInfo tVerInfo = vvi["Translation"]; if (tVerInfo != null) { byte[] oldValue = tVerInfo.Data; if (oldValue == null) { oldValue = new byte[0]; } tVerInfo.Data = new byte[oldValue.Length + 4]; Array.Copy(oldValue, tVerInfo.Data, oldValue.Length); using (BinaryWriter bw = new BinaryWriter(new MemoryStream(tVerInfo.Data, oldValue.Length, 4, true))) { bw.Write((ushort)locale); bw.Write((ushort)1200); } } return(new VersionStringTable(this, newStrings)); }