// // PanelWin16Version.xeto.cs // // Author: // Natalia Portillo // // Copyright (c) 2017-2018 Copyright © Claunia.com // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Globalization; using System.Text; using Eto.Forms; using Eto.Serialization.Xaml; using libexeinfo.Windows; using Version = libexeinfo.Windows.Version; namespace exeinfogui.Win16 { public class PanelWin16Version : Panel { ObservableCollection stringsByLanguage; GridView treeLanguages; GridView treeStrings; TextBox txtFileDate; TextBox txtFileFlags; TextBox txtFileOs; TextBox txtFileSubtype; TextBox txtFileType; TextBox txtFileVersion; TextBox txtProductVersion; public PanelWin16Version() { XamlReader.Load(this); treeLanguages.Columns.Add(new GridColumn { DataCell = new TextBoxCell {Binding = Binding.Property(r => r.Name)}, HeaderText = "Language (codepage)" }); treeStrings.Columns.Add(new GridColumn { DataCell = new TextBoxCell {Binding = Binding.Property(r => r.Key)}, HeaderText = "Key" }); treeStrings.Columns.Add(new GridColumn { DataCell = new TextBoxCell {Binding = Binding.Property(r => r.Value)}, HeaderText = "Value" }); stringsByLanguage = new ObservableCollection(); treeLanguages.SelectionChanged += TreeLanguagesOnSelectionChanged; treeLanguages.AllowMultipleSelection = false; } void TreeLanguagesOnSelectionChanged(object sender, EventArgs eventArgs) { treeStrings.DataStore = null; if(!(treeLanguages.SelectedItem is StrByLang strs)) return; List strings = new List(); foreach(KeyValuePair kvp in strs.Strings) strings.Add(new Strings {Key = kvp.Key, Value = kvp.Value}); treeStrings.DataStore = strings; } public void Update(byte[] data) { Update(new libexeinfo.NE.Version(data)); } public void Update(libexeinfo.NE.Version version) { txtFileDate.Text = version.FileDate != new DateTime(1601, 1, 1) ? $"{version.FileDate}" : "Not set"; txtFileFlags.Text = version.FileFlags == 0 ? "Normal" : $"{version.FileFlags}"; txtFileOs.Text = Version.OsToString(version.FileOs); if(version.FileType == VersionFileType.VFT_DRV) txtFileSubtype.Text = $"{Version.DriverToString(version.FileSubtype)} driver"; else if(version.FileType == VersionFileType.VFT_DRV) txtFileSubtype.Text = $"{Version.FontToString(version.FileSubtype)} font"; else if(version.FileSubtype > 0) txtFileSubtype.Text = $"{(uint)version.FileSubtype}"; else txtFileSubtype.Text = "None"; txtFileType.Text = Version.TypeToString(version.FileType); txtFileVersion.Text = $"{version.FileVersion}"; txtProductVersion.Text = $"{version.ProductVersion}"; stringsByLanguage.Clear(); foreach(KeyValuePair> strByLang in version.StringsByLanguage) { string cultureName; string encodingName; try { cultureName = new CultureInfo(Convert.ToInt32(strByLang.Key.Substring(0, 4), 16)).DisplayName; } catch { cultureName = $"0x{Convert.ToInt32(strByLang.Key.Substring(0, 4), 16):X4}"; } try { encodingName = Encoding.GetEncoding(Convert.ToInt32(strByLang.Key.Substring(4), 16)).EncodingName; } catch { encodingName = $"0x{Convert.ToInt32(strByLang.Key.Substring(4), 16):X4}"; } stringsByLanguage.Add(new StrByLang { Name = $"{cultureName} ({encodingName})", Strings = strByLang.Value }); } treeLanguages.DataStore = stringsByLanguage; } class StrByLang { public Dictionary Strings; public string Name { get; set; } } class Strings { public string Key { get; set; } public string Value { get; set; } } } }