Add dynamic post build powershell script with config file

This commit is contained in:
Codename
2019-09-07 03:59:30 +02:00
parent 05607f8ee2
commit 4eceb6b6df
4 changed files with 115 additions and 40 deletions

3
.gitignore vendored
View File

@@ -337,3 +337,6 @@ launchSettings.json
tmp/ tmp/
index.js index.js
# post build config
ReallifeGamemode.Server/post_build_config.xml

View File

@@ -19,6 +19,7 @@
</Content> </Content>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="gtanetwork.api" Version="0.3.6" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.2.0" /> <PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.2.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.2.0"> <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.2.0">
<PrivateAssets>all</PrivateAssets> <PrivateAssets>all</PrivateAssets>
@@ -41,6 +42,6 @@
</Reference> </Reference>
</ItemGroup> </ItemGroup>
<Target Name="PostBuild" AfterTargets="PostBuildEvent" Condition="'$(ConfigurationName)' != 'ServerBuild'"> <Target Name="PostBuild" AfterTargets="PostBuildEvent" Condition="'$(ConfigurationName)' != 'ServerBuild'">
<Exec Command="powershell.exe -executionpolicy bypass .\Scripts\moveItems.ps1 -outDir $(OutDir) -outFile $(TargetFileName)" /> <Exec Command="powershell -ExecutionPolicy ByPass -File .\post_build.ps1 -buildDirectory $(OutDir) -buildFilename $(TargetFileName)" />
</Target> </Target>
</Project> </Project>

View File

@@ -1,38 +0,0 @@
# Verschiebt die Dateien aus dem Output-Verzeichnis in den resources Ordner
param (
[string]$outDir,
[string]$outFile
)
$rootPath = "$PSScriptRoot\.."
$outputPath = "$rootPath\$outDir"
$bridgePath = "$rootPath\..\..\bridge\"
$resourcePath = "$bridgePath\resources\reallife-gamemode"
$runtimePath = "$bridgePath\runtime"
# Pruefen, ob Output-Pfad existiert
if(!(Test-Path $outputPath))
{
$absoluteOutputPath = Resolve-Path $outputPath
Write-Host "Output Folder ($absoluteOutputPath) does not exist."
Exit 0
}
# Pruefen, ob resources-Pfad existiert
# Wenn NEIN => erstellen
if(!(Test-Path $resourcePath))
{
Write-Host "Creating 'reallife-gamemode' resources directory"
New-Item -ItemType Directory -Path $resourcePath | Out-Null
}
# Gamemode und Meta-Datei verschieben
Copy-Item "$outputPath\$outFile" "$resourcePath\" -Force
Copy-Item "$outputPath\meta.xml" "$resourcePath\" -Force
# Abhaengige DLLs in runtime Ordner verschieben
Copy-Item "$outputPath\*.dll" "$runtimePath\" -Exclude "ReallifeGamemode.Server.dll"

View File

@@ -0,0 +1,109 @@
# set parameters
param (
[string]$buildDirectory,
[string]$buildFilename
)
# set constant paths
Set-Variable configPath -option Constant -value "$PSScriptRoot\post_build_config.xml"
# set constant dirs
Set-Variable serverRuntimeDir -option Constant -value "bridge\runtime"
Set-Variable serverResourcesDir -option Constant -value "bridge\resources"
Set-Variable serverGamemodeDir -option Constant -value "reallife-gamemode"
# create default config if not exist
if (![System.IO.File]::Exists($configPath)) {
# create xml config object
[xml]$xmlConfig = New-Object System.Xml.XmlDocument
if (!$xmlConfig) {
Write-Error "XML config creation failed"
exit 1
}
# declare xml config object
$declaration = $xmlConfig.CreateXmlDeclaration("1.0", "UTF-8", $null)
if (!$declaration) {
Write-Error "XML config declaration failed"
exit 1
}
$xmlConfig.AppendChild($declaration)
# resolve default server path (default: .\..\..)
$defaultServerPath = (Resolve-Path -Path "$PSScriptRoot\..\..")
if (!$defaultServerPath) {
Write-Error "resolving server path failed"
exit 1
}
# create 'root' node
$rootNode = $xmlConfig.CreateNode("element", "config", $null)
$xmlConfig.AppendChild($rootNode)
# create 'rageMpServerPath' node and set default value
$serverPathNode = $xmlConfig.CreateNode("element", "rageMpServerPath", $null)
$serverPathNode.InnerText = $defaultServerPath
$rootNode.AppendChild($serverPathNode)
# create 'updateMetaEverytime' node and set default value
$metaNode = $xmlConfig.CreateNode("element", "updateMetaEverytime", $null)
$metaNode.InnerText = "true"
$rootNode.AppendChild($metaNode)
# create 'updateAllDependenciesEverytime' node and set default value
$dependenciesNode = $xmlConfig.CreateNode("element", "updateAllDependenciesEverytime", $null)
$dependenciesNode.InnerText = "true"
$rootNode.AppendChild($dependenciesNode)
# save xml object to file
$xmlConfig.save($configPath)
}
# load existing xml config file
[xml]$xmlConfig = Get-Content -Path $configPath
if (!$xmlConfig) {
Write-Error "opening XML config failed"
exit 1
}
# get server path from xml config file
Set-Variable serverPath -option Constant -value $xmlConfig.config.rageMpServerPath
if (!$serverPath) {
Write-Error "empty rage mp server path"
exit 1
}
# check if server resources path exists
Set-Variable serverResourcesPath -option Constant -value "$serverPath\$serverResourcesDir"
if (!(Test-Path $serverResourcesPath)) {
Write-Error "server resources path ($serverResourcesPath) not found. Please set up C# Bridge first,
see https://wiki.gtanet.work/index.php?title=Setting_up_the_Bridge_on_Linux/Windows"
exit 1
}
# create gamemode dir if not exist
Set-Variable serverGamemodePath -option Constant -value "$serverResourcesPath\$serverGamemodeDir"
if (!(Test-Path $serverGamemodePath)) {
New-Item -ItemType Directory -Force -Path $serverGamemodePath
}
# copy compiled gamemode to server gamemode path
Copy-Item "$buildDirectory\$buildFilename" $serverGamemodePath -Force
# copy meta.xml to server gamemode path if 'updateMetaEverytime' is set to 'true' in config file
if ($xmlConfig.config.updateMetaEverytime -eq "true") {
Copy-Item "$buildDirectory\meta.xml" $serverGamemodePath -Force
}
# check if server runtime path exists
Set-Variable serverRuntimePath -option Constant -value "$serverPath\$serverRuntimeDir"
if (!(Test-Path $serverRuntimePath)) {
Write-Error "server runtime path ($serverRuntimePath) not found. Please set up C# Bridge first,
see https://wiki.gtanet.work/index.php?title=Setting_up_the_Bridge_on_Linux/Windows"
exit 1
}
# copy dependencies to server runtime path if 'updateAllDependenciesEverytime' is set to 'true' in config file
if ($xmlConfig.config.updateAllDependenciesEverytime -eq "true") {
Copy-Item "$buildDirectory\*.dll" $serverRuntimePath -Exclude "*$buildFilename*" -Force
}