diff --git a/.gitignore b/.gitignore index d42e621e..07d6d385 100644 --- a/.gitignore +++ b/.gitignore @@ -336,4 +336,7 @@ ASALocalRun/ launchSettings.json tmp/ -index.js \ No newline at end of file +index.js + +# post build config +ReallifeGamemode.Server/post_build_config.xml \ No newline at end of file diff --git a/ReallifeGamemode.Server/ReallifeGamemode.Server.csproj b/ReallifeGamemode.Server/ReallifeGamemode.Server.csproj index c01cba6b..6dba5b4b 100644 --- a/ReallifeGamemode.Server/ReallifeGamemode.Server.csproj +++ b/ReallifeGamemode.Server/ReallifeGamemode.Server.csproj @@ -19,6 +19,7 @@ + all @@ -41,6 +42,6 @@ - + \ No newline at end of file diff --git a/ReallifeGamemode.Server/Scripts/moveItems.ps1 b/ReallifeGamemode.Server/Scripts/moveItems.ps1 deleted file mode 100644 index 78f828b2..00000000 --- a/ReallifeGamemode.Server/Scripts/moveItems.ps1 +++ /dev/null @@ -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" \ No newline at end of file diff --git a/ReallifeGamemode.Server/post_build.ps1 b/ReallifeGamemode.Server/post_build.ps1 new file mode 100644 index 00000000..8b4ca9d2 --- /dev/null +++ b/ReallifeGamemode.Server/post_build.ps1 @@ -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 +} \ No newline at end of file