diff --git a/src/SubtitleEdit.sln b/src/SubtitleEdit.sln index 62c30e510..62852e4c9 100644 --- a/src/SubtitleEdit.sln +++ b/src/SubtitleEdit.sln @@ -20,6 +20,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UpdateAssemblyInfo", "Updat EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UpdateLanguageFiles", "UpdateLanguageFiles\UpdateLanguageFiles.csproj", "{36BCA2A7-EE6B-45FD-AF90-D3F76A84DA76}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UpdateResourceScript", "UpdateResourceScript\UpdateResourceScript.csproj", "{2CB9698C-F0A8-42FF-8938-DE047292D5FE}" +EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{E5F70420-EF49-403E-851F-700953769937}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LibSE", "..\libse\LibSE.csproj", "{3E3CB28F-3A7B-430F-9EB3-0D6C1E53B753}" @@ -50,6 +52,9 @@ Global {36BCA2A7-EE6B-45FD-AF90-D3F76A84DA76}.Debug|Any CPU.Build.0 = Debug|Any CPU {36BCA2A7-EE6B-45FD-AF90-D3F76A84DA76}.Release|Any CPU.ActiveCfg = Release|Any CPU {36BCA2A7-EE6B-45FD-AF90-D3F76A84DA76}.Release|Any CPU.Build.0 = Release|Any CPU + {2CB9698C-F0A8-42FF-8938-DE047292D5FE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2CB9698C-F0A8-42FF-8938-DE047292D5FE}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2CB9698C-F0A8-42FF-8938-DE047292D5FE}.Release|Any CPU.Build.0 = Release|Any CPU {3E3CB28F-3A7B-430F-9EB3-0D6C1E53B753}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {3E3CB28F-3A7B-430F-9EB3-0D6C1E53B753}.Debug|Any CPU.Build.0 = Debug|Any CPU {3E3CB28F-3A7B-430F-9EB3-0D6C1E53B753}.Release|Any CPU.ActiveCfg = Release|Any CPU diff --git a/src/UpdateResourceScript/App.config b/src/UpdateResourceScript/App.config new file mode 100644 index 000000000..b2750aa5d --- /dev/null +++ b/src/UpdateResourceScript/App.config @@ -0,0 +1,6 @@ + + + + + + diff --git a/src/UpdateResourceScript/Program.cs b/src/UpdateResourceScript/Program.cs new file mode 100644 index 000000000..0d75d0ce3 --- /dev/null +++ b/src/UpdateResourceScript/Program.cs @@ -0,0 +1,124 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Globalization; +using System.IO; +using System.Text; + +namespace UpdateResourceScript +{ + internal static class ExtensionMethods + { + public static string Escape(this string s) + { + return s.Replace("\\", "\\\\").Replace("\"", "\\\""); + } + + public static StringBuilder Append(this StringBuilder sb, string name, string value) + { + return sb.AppendFormat("\nVALUE \"{0}\", \"{1}\"", name, value.Escape()); + } + } + + internal class Program + { + private class VersionInfoResource + { + public string StringFileInfo { get; private set; } + public string ProductVersion { get; private set; } + public string FileVersion { get; private set; } + public string FileFlags { get; private set; } + + public VersionInfoResource(string assemblyFileName) + { + var fileInfo = FileVersionInfo.GetVersionInfo(assemblyFileName); + if (fileInfo.OriginalFilename == null) + throw new Exception("File '" + assemblyFileName + "' is not an assembly file"); + + // Fixed-info properties + FileVersion = string.Format(CultureInfo.InvariantCulture, "{0:D}, {1:D}, {2:D}, {3:D}", fileInfo.FileMajorPart, fileInfo.FileMinorPart, fileInfo.FileBuildPart, fileInfo.FilePrivatePart); + ProductVersion = string.Format(CultureInfo.InvariantCulture, "{0:D}, {1:D}, {2:D}, {3:D}", fileInfo.ProductMajorPart, fileInfo.ProductMinorPart, fileInfo.ProductBuildPart, fileInfo.ProductPrivatePart); + + var flags = new HashSet(); + var block = new StringBuilder(); + // Required string-information-block values + block.Append("VALUE \"FileDescription\", TargetAssemblyDescription"); // TargetAssemblyDescription is a resource-script macro + block.Append("\nVALUE \"OriginalFilename\", TargetAssemblyFileName"); // TargetAssemblyFileName is a resource-script macro + block.Append("FileVersion", fileInfo.FileVersion); + block.Append("ProductVersion", fileInfo.ProductVersion); + block.Append("ProductName", fileInfo.ProductName); + block.Append("CompanyName", fileInfo.CompanyName); + // Optional string-information-block values + block.Append("\nVALUE \"InternalName\", TargetAssemblyFileName"); // Consistent with VS behaviour (differs from MSDN) + if (fileInfo.LegalTrademarks != null) + block.Append("LegalTrademarks", fileInfo.LegalTrademarks); + if (fileInfo.LegalCopyright != null) + block.Append("LegalCopyright", fileInfo.LegalCopyright); + if (fileInfo.Comments != null) + block.Append("Comments", fileInfo.Comments); + // Flagged string-information-block values + if (fileInfo.IsSpecialBuild && fileInfo.SpecialBuild != null) + { + block.Append("SpecialBuild", fileInfo.SpecialBuild); + flags.Add("VS_FF_SPECIALBUILD"); + } + if (fileInfo.IsPrivateBuild && fileInfo.PrivateBuild != null) + { + block.Append("PrivateBuild", fileInfo.PrivateBuild); + flags.Add("VS_FF_PRIVATEBUILD"); + } + StringFileInfo = block.Replace("\n", Environment.NewLine + new String(' ', 3 * 4 /* Indentation */)).ToString(); + + if (fileInfo.IsPreRelease) + flags.Add("VS_FF_PRERELEASE"); + FileFlags = (flags.Count > 0) ? "(" + string.Join("|", flags) + ")" : "0L"; + } + } + + private const string WorkInProgress = "Updating win32 resource script..."; + + private static void WriteWarning(string message) + { + Console.WriteLine(); + Console.WriteLine("WARNING: " + message); + Console.Write(WorkInProgress); + } + + private static int Main(string[] args) + { + var myName = Environment.GetCommandLineArgs()[0]; + myName = Path.GetFileNameWithoutExtension(string.IsNullOrWhiteSpace(myName) ? System.Reflection.Assembly.GetEntryAssembly().Location : myName); + if (args.Length != 2) + { + Console.WriteLine("Usage: " + myName + " "); + return 1; + } + + Console.Write(WorkInProgress); + + try + { + var resourceScriptTemplateFileName = Environment.GetCommandLineArgs()[1]; + var resourceScriptFileName = resourceScriptTemplateFileName.Replace(".template", string.Empty); + var assemblyFileName = Environment.GetCommandLineArgs()[2]; + + var info = new VersionInfoResource(assemblyFileName); + var text = File.ReadAllText(resourceScriptTemplateFileName). + Replace("[vi:FileFlags]", info.FileFlags). + Replace("[vi:FileVersion]", info.FileVersion). + Replace("[vi:ProductVersion]", info.ProductVersion). + Replace("[vi:StringFileInfo]", info.StringFileInfo); + File.WriteAllText(resourceScriptFileName, text, Encoding.Unicode); + Console.WriteLine(" done"); + return 0; + } + catch (Exception exception) + { + Console.WriteLine(); + Console.WriteLine("ERROR: " + myName + ": " + exception.Message + Environment.NewLine + exception.StackTrace); + return 2; + } + } + + } +} diff --git a/src/UpdateResourceScript/Properties/AssemblyInfo.cs b/src/UpdateResourceScript/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..2c5abb54d --- /dev/null +++ b/src/UpdateResourceScript/Properties/AssemblyInfo.cs @@ -0,0 +1,35 @@ +using System.Reflection; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("UpdateResourceScript")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("UpdateResourceScript")] +[assembly: AssemblyCopyright("Copyright © 2015")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("d4b8a5cb-cde5-449e-a963-41ea0eef3af5")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/src/UpdateResourceScript/UpdateResourceScript.csproj b/src/UpdateResourceScript/UpdateResourceScript.csproj new file mode 100644 index 000000000..47553cb31 --- /dev/null +++ b/src/UpdateResourceScript/UpdateResourceScript.csproj @@ -0,0 +1,55 @@ + + + + + Properties + UpdateResourceScript + Debug + 512 + Exe + AnyCPU + {2CB9698C-F0A8-42FF-8938-DE047292D5FE} + UpdateResourceScript + Client + v4.0 + + + AllRules.ruleset + true + full + DEBUG;TRACE + prompt + false + bin\Debug\ + AnyCPU + 4 + + + AllRules.ruleset + pdbonly + TRACE + prompt + true + bin\Release\ + AnyCPU + 4 + + + + + + + + + + + + + + \ No newline at end of file