Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 51 additions & 28 deletions package/Update-InstallerLocalization.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -43,40 +43,63 @@ $projects = switch ($Product) {
default { @('AgentWindowsManaged', 'WindowsManaged') }
}

foreach ($project in $projects) {
$resources = Join-Path $PSScriptRoot "$project\Resources"
$template = Join-Path $resources 'Strings.g.tt'
$newtonsoft = Join-Path $resources 'Newtonsoft.Json.dll'

# TextTransform.exe does not expand the `$(SolutionDir)` macro that Visual Studio resolves.
# Use a temporary copy of the template (it must live next to the original: outputs are written beside the template).
$temporaryTemplate = Join-Path $resources "_Strings.$([guid]::NewGuid().ToString('N')).tt"
$text = [IO.File]::ReadAllText($template).Replace('$(SolutionDir)Resources\Newtonsoft.Json.dll', $newtonsoft)
[IO.File]::WriteAllText($temporaryTemplate, $text)

# T4 drops the byte order mark that some existing files carry; keep each file as it was.
$hadBom = @{}
Get-ChildItem $resources -Include '*.wxl', 'Strings.g.cs' -File -Recurse | ForEach-Object {
$bytes = [IO.File]::ReadAllBytes($_.FullName)
$hadBom[$_.FullName] = $bytes.Length -ge 3 -and $bytes[0] -eq 0xEF -and $bytes[1] -eq 0xBB -and $bytes[2] -eq 0xBF
function Get-GeneratedFiles {
$projects | ForEach-Object {
Get-ChildItem (Join-Path $PSScriptRoot "$_\Resources") -Include '*.wxl', 'Strings.g.cs' -File -Recurse
}
}

try {
& $TextTransformPath $temporaryTemplate -out (Join-Path $resources 'Strings.g.cs')
# T4 drops the byte order mark that some existing files carry; keep each file as it was.
# On failure T4 still overwrites its output with `ErrorGeneratingOutput`, so keep the original bytes of every selected project to restore them.
$original = @{}
$hadBom = @{}
Get-GeneratedFiles | ForEach-Object {
$bytes = [IO.File]::ReadAllBytes($_.FullName)
$original[$_.FullName] = $bytes
$hadBom[$_.FullName] = $bytes.Length -ge 3 -and $bytes[0] -eq 0xEF -and $bytes[1] -eq 0xBB -and $bytes[2] -eq 0xBF
}

if ($LASTEXITCODE -ne 0) {
throw "TextTransform failed for $project"
try {
foreach ($project in $projects) {
$resources = Join-Path $PSScriptRoot "$project\Resources"
$template = Join-Path $resources 'Strings.g.tt'
$newtonsoft = Join-Path $resources 'Newtonsoft.Json.dll'

# TextTransform.exe does not expand the `$(SolutionDir)` macro that Visual Studio resolves.
# Use a temporary copy of the template (it must live next to the original: outputs are written beside the template).
$temporaryTemplate = Join-Path $resources "_Strings.$([guid]::NewGuid().ToString('N')).tt"
$text = [IO.File]::ReadAllText($template).Replace('$(SolutionDir)Resources\Newtonsoft.Json.dll', $newtonsoft)
# TextTransform.exe fails to compile a template with LF line endings (CS1519), so use CRLF whatever the checkout has.
$text = $text -replace '\r?\n', "`r`n"
[IO.File]::WriteAllText($temporaryTemplate, $text)

try {
& $TextTransformPath $temporaryTemplate -out (Join-Path $resources 'Strings.g.cs')

if ($LASTEXITCODE -ne 0) {
throw "TextTransform failed for $project"
}
}
finally {
Remove-Item $temporaryTemplate -ErrorAction SilentlyContinue
}

# The repository stores these files with LF line endings, while T4 emits mixed endings.
Get-ChildItem $resources -Include '*.wxl', 'Strings.g.cs' -File -Recurse | ForEach-Object {
$content = [IO.File]::ReadAllText($_.FullName).Replace("`r`n", "`n")
[IO.File]::WriteAllText($_.FullName, $content, (New-Object Text.UTF8Encoding($hadBom[$_.FullName] -eq $true)))
}

Write-Output "Regenerated localization files for $project"
}
finally {
Remove-Item $temporaryTemplate -ErrorAction SilentlyContinue
}
}
catch {
# Leave every selected project as it was: drop outputs this run created, then restore the rest.
Get-GeneratedFiles | Where-Object { -not $original.ContainsKey($_.FullName) } | Remove-Item

# The repository stores these files with LF line endings, while T4 emits mixed endings.
Get-ChildItem $resources -Include '*.wxl', 'Strings.g.cs' -File -Recurse | ForEach-Object {
$content = [IO.File]::ReadAllText($_.FullName).Replace("`r`n", "`n")
[IO.File]::WriteAllText($_.FullName, $content, (New-Object Text.UTF8Encoding($hadBom[$_.FullName] -eq $true)))
foreach ($path in $original.Keys) {
[IO.File]::WriteAllBytes($path, $original[$path])
}

Write-Output "Regenerated localization files for $project"
throw "$_; generated files were left unchanged"
}
10 changes: 5 additions & 5 deletions package/WindowsManaged/Resources/Strings.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ public static string I18n(this MsiRuntime runtime, string res)
/// <summary>
/// Agent Tunnel
/// </summary>
public const string Group_AgentTunnel = "Group_AgentTunnel";
public const string Group_AgentTunnel = "Group_AgentTunnel";
/// <summary>
/// External Access
/// </summary>
Expand Down Expand Up @@ -419,11 +419,11 @@ public static string I18n(this MsiRuntime runtime, string res)
/// <summary>
/// Enabled
/// </summary>
public const string Property_EnableAgentTunnel = "Property_EnableAgentTunnel";
public const string Property_EnableAgentTunnel = "Property_EnableAgentTunnel";
/// <summary>
/// UDP Port
/// </summary>
public const string Property_AgentTunnelPort = "Property_AgentTunnelPort";
public const string Property_AgentTunnelPort = "Property_AgentTunnelPort";
/// <summary>
/// Directory
/// </summary>
Expand Down Expand Up @@ -587,11 +587,11 @@ public static string I18n(this MsiRuntime runtime, string res)
/// <summary>
/// Enable Agent Tunnel
/// </summary>
public const string EnableAgentTunnel = "EnableAgentTunnel";
public const string EnableAgentTunnel = "EnableAgentTunnel";
/// <summary>
/// UDP port
/// </summary>
public const string AgentTunnelUdpPort = "AgentTunnelUdpPort";
public const string AgentTunnelUdpPort = "AgentTunnelUdpPort";
/// <summary>
/// Enable the Gateway web interface
/// </summary>
Expand Down
Loading