From ab49cd8ec241c842a0ebe2b1043f459075e4acef Mon Sep 17 00:00:00 2001 From: Codename Date: Sat, 7 Sep 2019 15:08:04 +0200 Subject: [PATCH] Cleanup Code and check if windows developer --- .../ReallifeGamemode.Server.csproj | 2 +- ReallifeGamemode.Server/post_build.ps1 | 165 +++++++++--------- 2 files changed, 88 insertions(+), 79 deletions(-) diff --git a/ReallifeGamemode.Server/ReallifeGamemode.Server.csproj b/ReallifeGamemode.Server/ReallifeGamemode.Server.csproj index 6dba5b4b..5f1d94e9 100644 --- a/ReallifeGamemode.Server/ReallifeGamemode.Server.csproj +++ b/ReallifeGamemode.Server/ReallifeGamemode.Server.csproj @@ -41,7 +41,7 @@ ..\..\bridge\runtime\Bootstrapper.dll - + \ No newline at end of file diff --git a/ReallifeGamemode.Server/post_build.ps1 b/ReallifeGamemode.Server/post_build.ps1 index 8b4ca9d2..ae5d20a2 100644 --- a/ReallifeGamemode.Server/post_build.ps1 +++ b/ReallifeGamemode.Server/post_build.ps1 @@ -1,10 +1,16 @@ -# set parameters +# +# @description This powershell script for windows developer copies compiled files to (local/remote) server dir +# @author Codename +# @copyright (c) 2008 - 2019 Life of German +# + +# set parameters param ( [string]$buildDirectory, [string]$buildFilename ) -# set constant paths +# set config path Set-Variable configPath -option Constant -value "$PSScriptRoot\post_build_config.xml" # set constant dirs @@ -12,98 +18,101 @@ 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 +# create default config file 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" + Write-Error "resolving local server path failed" exit 1 } + + $defaultXmlContent = " + + + true + $defaultServerPath + true + true + + + false + 127.0.0.1 + 21 + USERNAME + PASSWORD + . + false + false + +" - # 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) + # create default content + New-Item $configPath + Set-Content $configPath $defaultXmlContent } # load existing xml config file [xml]$xmlConfig = Get-Content -Path $configPath if (!$xmlConfig) { - Write-Error "opening XML config failed" + Write-Error "opening XML config file 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 +# update local files if enabled in config file +if ($xmlConfig.update.local.enabled -eq "true") { + # get local server path from xml config file + Set-Variable serverPath -option Constant -value $xmlConfig.update.local.rageMpServerPath + if (!$serverPath) { + Write-Error "empty local rage mp server path in config file" + exit 1 + } + + # check if local server path exists + if (!(Test-Path $serverPath)) { + Write-Error "local rage mp server path ($serverPath) not found. Have you moved your local rage mp directory?" + exit 1 + } + + # check if local server resources path exists + Set-Variable serverResourcesPath -option Constant -value "$serverPath\$serverResourcesDir" + if (!(Test-Path $serverResourcesPath)) { + Write-Error "local server resources path ($serverResourcesPath) not found. Please set up C# Bridge locally first, + see https://wiki.gtanet.work/index.php?title=Setting_up_the_Bridge_on_Linux/Windows" + exit 1 + } + + # create local 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 local server gamemode path + Copy-Item "$buildDirectory\$buildFilename" $serverGamemodePath -Force + + # copy meta.xml to local server gamemode path if 'updateMetaXml' is set to 'true' in config file + if ($xmlConfig.update.local.updateMetaXml -eq "true") { + Copy-Item "$buildDirectory\meta.xml" $serverGamemodePath -Force + } + + # check if local server runtime path exists + Set-Variable serverRuntimePath -option Constant -value "$serverPath\$serverRuntimeDir" + if (!(Test-Path $serverRuntimePath)) { + Write-Error "local server runtime path ($serverRuntimePath) not found. Please set up C# Bridge locally first, + see https://wiki.gtanet.work/index.php?title=Setting_up_the_Bridge_on_Linux/Windows" + exit 1 + } + + # copy dependencies to local server runtime path if 'updateAllDependencies' is set to 'true' in config file + if ($xmlConfig.update.local.updateAllDependencies -eq "true") { + Copy-Item "$buildDirectory\*.dll" $serverRuntimePath -Exclude "*$buildFilename*" -Force + } } -# 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 +# update remote files if enabled in config file +if ($xmlConfig.update.remote.enabled -eq "true") { + # TODO: connect to remote ftp server and update files } -# 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 +exit 0 \ No newline at end of file