mirror of
https://github.com/SubtitleEdit/subtitleedit.git
synced 2024-11-25 04:33:04 +01:00
Added UpdateResourceScript build helper tool
This commit is contained in:
parent
ed6b4fcc92
commit
18f313c37b
@ -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
|
||||
|
6
src/UpdateResourceScript/App.config
Normal file
6
src/UpdateResourceScript/App.config
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<startup>
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0,Profile=Client" />
|
||||
</startup>
|
||||
</configuration>
|
124
src/UpdateResourceScript/Program.cs
Normal file
124
src/UpdateResourceScript/Program.cs
Normal file
@ -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<string>();
|
||||
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 + " <resource-script-template> <assembly-file>");
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
35
src/UpdateResourceScript/Properties/AssemblyInfo.cs
Normal file
35
src/UpdateResourceScript/Properties/AssemblyInfo.cs
Normal file
@ -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")]
|
55
src/UpdateResourceScript/UpdateResourceScript.csproj
Normal file
55
src/UpdateResourceScript/UpdateResourceScript.csproj
Normal file
@ -0,0 +1,55 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<AssemblyName>UpdateResourceScript</AssemblyName>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<OutputType>Exe</OutputType>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{2CB9698C-F0A8-42FF-8938-DE047292D5FE}</ProjectGuid>
|
||||
<RootNamespace>UpdateResourceScript</RootNamespace>
|
||||
<TargetFrameworkProfile>Client</TargetFrameworkProfile>
|
||||
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="App.config" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
Loading…
Reference in New Issue
Block a user