/// <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> /// Removes a version string table for a locale. /// </summary> /// <param name="locale">Locale of the table</param> public void Remove(int locale) { VersionInfo svi = this.rawVersionInfo["StringFileInfo"]; if (svi != null) { foreach (VersionInfo strings in svi) { int stringsLocale = UInt16.Parse(strings.Key.Substring(0, 4), NumberStyles.HexNumber, CultureInfo.InvariantCulture); if (stringsLocale == locale) { svi.Remove(strings); this.dirty = true; break; } } } VersionInfo vvi = this.rawVersionInfo["VarFileInfo"]; if (vvi != null) { VersionInfo tVerInfo = vvi["Translation"]; if (tVerInfo != null) { byte[] newValue = new byte[tVerInfo.Data.Length]; int j = 0; using (BinaryWriter bw = new BinaryWriter(new MemoryStream(newValue, 0, newValue.Length, true))) { using (BinaryReader br = new BinaryReader(new MemoryStream(tVerInfo.Data))) { for (int i = tVerInfo.Data.Length / 4; i > 0; i--) { ushort tLocale = br.ReadUInt16(); ushort cp = br.ReadUInt16(); if (tLocale != locale) { bw.Write((ushort)tLocale); bw.Write((ushort)cp); j++; } } } } tVerInfo.Data = new byte[j * 4]; Array.Copy(newValue, tVerInfo.Data, tVerInfo.Data.Length); } } }