public static string GetImageResourceName(int value, string location = "%system%") { var path = PathEx.Combine(location); if (!string.IsNullOrWhiteSpace(path) && PathEx.IsDir(path)) { path = Path.Combine(path, "imageres.dll"); } if (!path.EndsWithEx("imageres.dll") || !File.Exists(path)) { path = PathEx.Combine("%system%\\imageres.dll"); } var version = FileEx.GetFileVersion(path); // Windows 10 if (version.Major >= 10) { return(Enum.GetName(typeof(ImageResourceSymbol), value)); } // Windows 7 + 8 if (value < 187) { return(Enum.GetName(typeof(ImageResourceSymbol), value)); } if (value.IsBetween(186, 214)) { return(Enum.GetName(typeof(ImageResourceSymbol), ++value)); } if (value.IsBetween(216, version.Minor < 2 ? 218 : 306)) { return(Enum.GetName(typeof(ImageResourceSymbol), value + (value < 240 ? 17 : 16))); } return(null); }
private static void Main() { InitializeConsole(); foreach (var arg in EnvironmentEx.CommandLineArgs(true, 1, false)) { if (_active) { Console.WriteLine(); Console.WriteLine(); } var file = PathEx.Combine(arg); if (!File.Exists(file)) { WriteInnerLine($"Cannot find \'{file}\'", "Error", ErrorCaptionFgColor); continue; } try { var name = Path.GetFileName(file); if (!string.IsNullOrWhiteSpace(name)) { WriteInnerLine(name, "File", !name.EndsWithEx(".exe", ".dll") ? WarnCaptionFgColor : DefaultCaptionFgColor); } var version = FileEx.GetFileVersion(file)?.ToString(); if (!string.IsNullOrWhiteSpace(version) && !version.Equals("0.0.0.0")) { WriteInnerLine(version, "Version", DefaultCaptionFgColor); } var subject = FileEx.GetSignatureSubject(file); if (!string.IsNullOrWhiteSpace(subject)) { WriteInnerLine(subject, "Subject", DefaultCaptionFgColor); } var status = FileEx.GetSignatureStatus(file); if (!string.IsNullOrWhiteSpace(status)) { WriteInnerLine(status, "Status", status.ContainsEx("Unknown", "Error") ? ErrorCaptionFgColor : status.ContainsEx("NotSigned") ? WarnCaptionFgColor : DefaultCaptionFgColor); } } catch (Exception ex) when(ex.IsCaught()) { WriteInnerLine(ex.Message, "Error", ErrorCaptionFgColor); } } ExitConsole(); }
/// <summary> /// Retrieves a backward-compatible integer value of the specified /// <see cref="ImageResourceSymbol"/> value, which depends on the file version /// of the 'imageres.dll' file under the specified location. /// </summary> /// <param name="value"> /// The <see cref="ImageResourceSymbol"/> value. /// </param> /// <param name="location"> /// The directory where the 'imageres.dll' file is located. /// </param> public static int GetImageResourceValue(ImageResourceSymbol value, string location = "%system%") { var path = PathEx.Combine(location); if (!string.IsNullOrWhiteSpace(path) && PathEx.IsDir(path)) { path = Path.Combine(path, "imageres.dll"); } if (!path.EndsWithEx("imageres.dll") || !File.Exists(path)) { path = PathEx.Combine("%system%\\imageres.dll"); } var version = FileEx.GetFileVersion(path); // Windows 10 if (version.Major >= 10) { return((int)value); } // Windows 7 + 8 var index = (int)value; if (index < 187) { return(index); } if (index.IsBetween(187, 215)) { return(--index); } if (index.IsBetween(233, version.Minor < 2 ? 235 : 322)) { return(index - (index < 257 ? 17 : 16)); } return(-1); }