From cefc16da4f7e9b93a6741b5320cff6e022314925 Mon Sep 17 00:00:00 2001 From: Sergei Vorobev Date: Mon, 4 Apr 2016 14:20:34 -0700 Subject: [PATCH] Add Start-ResGen to PowerShellGitHubDev.psm1 Now everybody can just run resgen, instead of kicking in Jenkins job --- PowerShellGitHubDev.psm1 | 108 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 108 insertions(+) diff --git a/PowerShellGitHubDev.psm1 b/PowerShellGitHubDev.psm1 index 1b6605fcd1..02fbfb3e5c 100644 --- a/PowerShellGitHubDev.psm1 +++ b/PowerShellGitHubDev.psm1 @@ -506,6 +506,26 @@ function Send-GitDiffToSd { } } +function Start-ResGen +{ + @("Microsoft.PowerShell.Commands.Management", +"Microsoft.PowerShell.Commands.Utility", +"Microsoft.PowerShell.ConsoleHost", +"Microsoft.PowerShell.CoreCLR.Eventing", +"Microsoft.PowerShell.Security", +"System.Management.Automation") | % { + $module = $_ + ls "$PSScriptRoot/src/$module/resources" | % { + $className = $_.Name.Replace('.resx', '') + $xml = [xml](cat -raw $_.FullName) + $genSource = Get-StronglyTypeCsFileForResx -xml $xml -ModuleName $module -ClassName $className + $outPath = "$PSScriptRoot/src/windows-build/gen/$module/$className.cs" + log "ResGen for $outPath" + Set-Content -Encoding Ascii -Path "$PSScriptRoot/src/windows-build/gen/$module/$className.cs" -Value $genSource + } + } +} + function script:log([string]$message) { Write-Host -Foreground Green $message @@ -570,3 +590,91 @@ function script:Convert-PSObjectToHashtable { } } } + + +function script:Get-StronglyTypeCsFileForResx +{ + param($xml, $ModuleName, $ClassName) +$body = @' +//------------------------------------------------------------------------------ +// +// This code was generated by a Start-ResGen funciton from PowerShellGitHubDev.psm1. +// To add or remove a member, edit your .ResX file then rerun Start-ResGen. +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +using System; +using System.Reflection; + +/// +/// A strongly-typed resource class, for looking up localized strings, etc. +/// +[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] +[global::System.Diagnostics.DebuggerNonUserCodeAttribute()] +[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + +internal class {0} {{ + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal {0}() {{ + }} + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager {{ + get {{ + if (object.ReferenceEquals(resourceMan, null)) {{ + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("{1}.resources.{0}", typeof({0}).GetTypeInfo().Assembly); + resourceMan = temp; + }} + return resourceMan; + }} + }} + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture {{ + get {{ + return resourceCulture; + }} + set {{ + resourceCulture = value; + }} + }} + {2} +}} +'@ + + $entry = @' + + /// + /// Looks up a localized string similar to {1} + /// + internal static string {0} {{ + get {{ + return ResourceManager.GetString("{0}", resourceCulture); + }} + }} +'@ + $entries = $xml.root.data | % { + if ($_) { + $val = $_.value.Replace("`n", "`n ///") + $name = $_.name.Replace(' ', '_') + $entry -f $name,$val + } + } | Out-String + $body -f $ClassName,$ModuleName,$entries +} +