|
| 1 | +[CmdletBinding()] |
| 2 | +param( |
| 3 | + [string]$RepoRoot = ( Resolve-Path ( Join-Path $PSScriptRoot ".." ) ).Path, |
| 4 | + [string]$GameRootPath, |
| 5 | + [string]$Version, |
| 6 | + [string]$Tag, |
| 7 | + [string]$OutputRoot, |
| 8 | + [switch]$SkipBuild |
| 9 | +) |
| 10 | + |
| 11 | +$ErrorActionPreference = "Stop" |
| 12 | +Set-StrictMode -Version Latest |
| 13 | + |
| 14 | +function Get-ProjectPropertyValue { |
| 15 | + param( |
| 16 | + [Parameter( Mandatory = $true )] |
| 17 | + [string]$ProjectFilePath, |
| 18 | + [Parameter( Mandatory = $true )] |
| 19 | + [string]$PropertyName |
| 20 | + ) |
| 21 | + |
| 22 | + [xml]$projectXml = Get-Content -LiteralPath $ProjectFilePath -Raw |
| 23 | + foreach( $propertyGroup in $projectXml.Project.PropertyGroup ) { |
| 24 | + $propertyElement = $propertyGroup.SelectSingleNode( $PropertyName ) |
| 25 | + if( $null -eq $propertyElement ) { |
| 26 | + continue |
| 27 | + } |
| 28 | + |
| 29 | + $propertyValue = $propertyElement.InnerText |
| 30 | + if( -not [string]::IsNullOrWhiteSpace( $propertyValue ) ) { |
| 31 | + return $propertyValue.Trim() |
| 32 | + } |
| 33 | + } |
| 34 | + |
| 35 | + throw "Property '$PropertyName' was not found in '$ProjectFilePath'." |
| 36 | +} |
| 37 | + |
| 38 | +function Copy-DirectoryContents { |
| 39 | + param( |
| 40 | + [Parameter( Mandatory = $true )] |
| 41 | + [string]$SourcePath, |
| 42 | + [Parameter( Mandatory = $true )] |
| 43 | + [string]$DestinationPath, |
| 44 | + [string[]]$ExcludeNames = @() |
| 45 | + ) |
| 46 | + |
| 47 | + New-Item -ItemType Directory -Path $DestinationPath -Force | Out-Null |
| 48 | + Get-ChildItem -LiteralPath $SourcePath -Force | Where-Object { |
| 49 | + $ExcludeNames -notcontains $_.Name |
| 50 | + } | ForEach-Object { |
| 51 | + Copy-Item -LiteralPath $_.FullName -Destination ( Join-Path $DestinationPath $_.Name ) -Recurse -Force |
| 52 | + } |
| 53 | +} |
| 54 | + |
| 55 | +$repoRootPath = ( Resolve-Path -LiteralPath $RepoRoot ).Path |
| 56 | +$propsPath = Join-Path $repoRootPath "Directory.Build.props" |
| 57 | + |
| 58 | +if( -not ( Test-Path -LiteralPath $propsPath ) ) { |
| 59 | + throw "Directory.Build.props was not found at '$propsPath'." |
| 60 | +} |
| 61 | + |
| 62 | +if( [string]::IsNullOrWhiteSpace( $Version ) ) { |
| 63 | + $Version = Get-ProjectPropertyValue -ProjectFilePath $propsPath -PropertyName "Version" |
| 64 | +} |
| 65 | + |
| 66 | +if( [string]::IsNullOrWhiteSpace( $GameRootPath ) ) { |
| 67 | + $GameRootPath = Get-ProjectPropertyValue -ProjectFilePath $propsPath -PropertyName "GameRootPath" |
| 68 | +} |
| 69 | + |
| 70 | +$gameRootResolvedPath = ( Resolve-Path -LiteralPath $GameRootPath ).Path |
| 71 | + |
| 72 | +if( [string]::IsNullOrWhiteSpace( $Tag ) ) { |
| 73 | + $Tag = "v$Version" |
| 74 | +} |
| 75 | + |
| 76 | +if( [string]::IsNullOrWhiteSpace( $OutputRoot ) ) { |
| 77 | + $OutputRoot = Join-Path $repoRootPath ( Join-Path "artifacts/release" $Tag ) |
| 78 | +} |
| 79 | + |
| 80 | +$outputRootPath = [System.IO.Path]::GetFullPath( $OutputRoot ) |
| 81 | +$stageRootPath = Join-Path $outputRootPath "package" |
| 82 | +$zipFileName = "OstranautsTranslator-$Tag.zip" |
| 83 | +$zipPath = Join-Path $outputRootPath $zipFileName |
| 84 | +$releaseNotesPath = Join-Path $outputRootPath "release-notes.md" |
| 85 | + |
| 86 | +if( -not $SkipBuild ) { |
| 87 | + $vsDevShellPath = "D:/Program Files/Microsoft Visual Studio/18/BuildTools/Common7/Tools/Launch-VsDevShell.ps1" |
| 88 | + if( -not ( Test-Path -LiteralPath $vsDevShellPath ) ) { |
| 89 | + throw "Visual Studio developer shell script was not found at '$vsDevShellPath'." |
| 90 | + } |
| 91 | + |
| 92 | + & $vsDevShellPath -Arch amd64 -HostArch amd64 |
| 93 | + |
| 94 | + Push-Location $repoRootPath |
| 95 | + try { |
| 96 | + msbuild .\OstranautsTranslator.sln /p:Configuration=Release /nologo /verbosity:quiet /clp:Summary |
| 97 | + } |
| 98 | + finally { |
| 99 | + Pop-Location |
| 100 | + } |
| 101 | +} |
| 102 | + |
| 103 | +$pluginSourcePath = Join-Path $gameRootResolvedPath "BepInEx/plugins/OstranautsTranslator" |
| 104 | +$toolSourcePath = Join-Path $gameRootResolvedPath "OstranautsTranslator" |
| 105 | +$modsRootPath = Join-Path $gameRootResolvedPath "Ostranauts_Data/Mods" |
| 106 | +$loadingOrderSourcePath = Join-Path $modsRootPath "loading_order.json" |
| 107 | +$modSourcePath = Join-Path $modsRootPath "OstranautsTranslate" |
| 108 | +$modInfoPath = Join-Path $modSourcePath "mod_info.json" |
| 109 | + |
| 110 | +foreach( $requiredPath in @( $pluginSourcePath, $toolSourcePath, $loadingOrderSourcePath, $modSourcePath, $modInfoPath ) ) { |
| 111 | + if( -not ( Test-Path -LiteralPath $requiredPath ) ) { |
| 112 | + throw "Required release input was not found: '$requiredPath'." |
| 113 | + } |
| 114 | +} |
| 115 | + |
| 116 | +if( Test-Path -LiteralPath $outputRootPath ) { |
| 117 | + Remove-Item -LiteralPath $outputRootPath -Recurse -Force |
| 118 | +} |
| 119 | + |
| 120 | +New-Item -ItemType Directory -Path $outputRootPath -Force | Out-Null |
| 121 | + |
| 122 | +Copy-DirectoryContents -SourcePath $pluginSourcePath -DestinationPath ( Join-Path $stageRootPath "BepInEx/plugins/OstranautsTranslator" ) |
| 123 | +Copy-DirectoryContents -SourcePath $toolSourcePath -DestinationPath ( Join-Path $stageRootPath "OstranautsTranslator" ) -ExcludeNames @( "config.ini", "workspace", "workspace-validation", "XUnity.AutoTranslator.Workspace" ) |
| 124 | +New-Item -ItemType Directory -Path ( Join-Path $stageRootPath "Ostranauts_Data/Mods" ) -Force | Out-Null |
| 125 | +Copy-Item -LiteralPath $loadingOrderSourcePath -Destination ( Join-Path $stageRootPath "Ostranauts_Data/Mods/loading_order.json" ) -Force |
| 126 | +Copy-Item -LiteralPath $modSourcePath -Destination ( Join-Path $stageRootPath "Ostranauts_Data/Mods/OstranautsTranslate" ) -Recurse -Force |
| 127 | + |
| 128 | +$modInfo = Get-Content -LiteralPath $modInfoPath -Raw | ConvertFrom-Json |
| 129 | +$gameVersion = if( $modInfo.Count -gt 0 -and -not [string]::IsNullOrWhiteSpace( $modInfo[0].strGameVersion ) ) { |
| 130 | + $modInfo[0].strGameVersion |
| 131 | +} |
| 132 | +else { |
| 133 | + "Unknown" |
| 134 | +} |
| 135 | + |
| 136 | +@" |
| 137 | +# OstranautsTranslator $Tag |
| 138 | +
|
| 139 | +Compatible game version: $gameVersion |
| 140 | +
|
| 141 | +## Installation |
| 142 | +
|
| 143 | +1. Close the game. |
| 144 | +2. Download $zipFileName. |
| 145 | +3. Extract the archive directly into the game root, the folder that contains Ostranauts.exe. |
| 146 | +4. Overwrite existing files when prompted. |
| 147 | +5. Launch the game. Press F6 to open the status window. |
| 148 | +
|
| 149 | +## Included content |
| 150 | +
|
| 151 | +- BepInEx/plugins/OstranautsTranslator |
| 152 | +- OstranautsTranslator |
| 153 | +- Ostranauts_Data/Mods/loading_order.json |
| 154 | +- Ostranauts_Data/Mods/OstranautsTranslate |
| 155 | +
|
| 156 | +## Notes |
| 157 | +
|
| 158 | +- This package targets Simplified Chinese. |
| 159 | +- config.ini and workspace data are intentionally excluded from the release package. |
| 160 | +- If the game updates, rerun OstranautsTranslator.exe or install a newer release package. |
| 161 | +"@ | Set-Content -LiteralPath $releaseNotesPath -Encoding UTF8 |
| 162 | + |
| 163 | +Compress-Archive -Path ( Join-Path $stageRootPath "*" ) -DestinationPath $zipPath -CompressionLevel Optimal |
| 164 | + |
| 165 | +Write-Host "Release package created: $zipPath" |
| 166 | +Write-Host "Release notes created: $releaseNotesPath" |
0 commit comments