-
Notifications
You must be signed in to change notification settings - Fork 24
/
Generate-Resources.ps1
143 lines (121 loc) · 4.58 KB
/
Generate-Resources.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
[CmdletBinding()]
param()
function Get-StronglyTypeCsFileForResx
{
param($xml, $ClassName, $moduleName)
# Example
#
# $ClassName = Full.Name.Of.The.ClassFoo
# $shortClassName = ClassFoo
# $namespaceName = Full.Name.Of.The
$shortClassName = $ClassName
$namespaceName = $null
$lastIndexOfDot = $className.LastIndexOf(".")
if ($lastIndexOfDot -ne -1)
{
$namespaceName = $className.Substring(0, $lastIndexOfDot)
$shortClassName = $className.Substring($lastIndexOfDot + 1)
}
$banner = @'
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a New-StronglyTypedCsFileForResx funciton.
// To add or remove a member, edit your .ResX file then rerun buildCoreClr.ps1
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
{0}
'@
$namespace = @'
namespace {0} {{
{1}
}}
'@
$body = @'
using System;
using System.Reflection;
/// <summary>
/// A strongly-typed resource class, for looking up localized strings, etc.
/// </summary>
[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}() {{
}}
/// <summary>
/// Returns the cached ResourceManager instance used by this class.
/// </summary>
[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("{3}.resources.{2}", typeof({0}).GetTypeInfo().Assembly);
resourceMan = temp;
}}
return resourceMan;
}}
}}
/// <summary>
/// Overrides the current thread's CurrentUICulture property for all
/// resource lookups using this strongly typed resource class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture {{
get {{
return resourceCulture;
}}
set {{
resourceCulture = value;
}}
}}
{1}
}}
'@
$entry = @'
/// <summary>
/// Looks up a localized string similar to {1}
/// </summary>
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
$bodyCode = $body -f $shortClassName,$entries,$ClassName,$moduleName
if ($NamespaceName)
{
$bodyCode = $namespace -f $NamespaceName, $bodyCode
}
$resultCode = $banner -f $bodyCode
return $resultCode -replace "`r`n?|`n","`r`n"
}
$className = "Microsoft.PackageManagement.NuGetProvider.Resources.Messages"
$moduleName = "NuGetProvider"
$xmlFilePath = Join-Path -Path $PSScriptRoot -ChildPath resources | Join-Path -ChildPath Messages.resx
$newResxFile = Join-Path $PSScriptRoot -ChildPath resources | Join-Path -ChildPath "$className.resx"
Copy-Item $xmlFilePath $newResxFile -Force
$outputFilePath = Join-Path -Path $PSScriptRoot -ChildPath gen | Join-Path -ChildPath "$className.cs"
$xml = [xml](Get-Content -raw $xmlFilePath)
$genSource = Get-StronglyTypeCsFileForResx -xml $xml -ClassName $className -moduleName $moduleName
$outputDir = Split-Path $outputFilePath -Parent
if (-not (Test-Path -Path $outputDir)) {
$null = New-Item $outputDir -ItemType Directory
}
if (-not (Test-Path -Path $outputFilePath)) {
$null = New-Item $outputFilePath
}
Set-Content -Encoding Ascii -Path $outputFilePath -Value $genSource
Write-Verbose "Generated '$outputFilePath' from '$xmlFilePath'"