Cleanup Code and check if windows developer

This commit is contained in:
Codename
2019-09-07 15:08:04 +02:00
parent 4eceb6b6df
commit ab49cd8ec2
2 changed files with 88 additions and 79 deletions

View File

@@ -41,7 +41,7 @@
<HintPath>..\..\bridge\runtime\Bootstrapper.dll</HintPath> <HintPath>..\..\bridge\runtime\Bootstrapper.dll</HintPath>
</Reference> </Reference>
</ItemGroup> </ItemGroup>
<Target Name="PostBuild" AfterTargets="PostBuildEvent" Condition="'$(ConfigurationName)' != 'ServerBuild'"> <Target Name="PostBuild" AfterTargets="PostBuildEvent" Condition="'$(ConfigurationName)' != 'ServerBuild' AND '$(OS)' == 'Windows_NT'">
<Exec Command="powershell -ExecutionPolicy ByPass -File .\post_build.ps1 -buildDirectory $(OutDir) -buildFilename $(TargetFileName)" /> <Exec Command="powershell -ExecutionPolicy ByPass -File .\post_build.ps1 -buildDirectory $(OutDir) -buildFilename $(TargetFileName)" />
</Target> </Target>
</Project> </Project>

View File

@@ -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 ( param (
[string]$buildDirectory, [string]$buildDirectory,
[string]$buildFilename [string]$buildFilename
) )
# set constant paths # set config path
Set-Variable configPath -option Constant -value "$PSScriptRoot\post_build_config.xml" Set-Variable configPath -option Constant -value "$PSScriptRoot\post_build_config.xml"
# set constant dirs # 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 serverResourcesDir -option Constant -value "bridge\resources"
Set-Variable serverGamemodeDir -option Constant -value "reallife-gamemode" 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)) { 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: .\..\..) # resolve default server path (default: .\..\..)
$defaultServerPath = (Resolve-Path -Path "$PSScriptRoot\..\..") $defaultServerPath = (Resolve-Path -Path "$PSScriptRoot\..\..")
if (!$defaultServerPath) { if (!$defaultServerPath) {
Write-Error "resolving server path failed" Write-Error "resolving local server path failed"
exit 1 exit 1
} }
# create 'root' node $defaultXmlContent = "<?xml version=`"1.0`" encoding=`"UTF-8`"?>
$rootNode = $xmlConfig.CreateNode("element", "config", $null) <update>
$xmlConfig.AppendChild($rootNode) <local>
<enabled>true</enabled>
<rageMpServerPath>$defaultServerPath</rageMpServerPath>
<updateMetaXml>true</updateMetaXml>
<updateAllDependencies>true</updateAllDependencies>
</local>
<remote>
<enabled>false</enabled>
<ftpServerAddress>127.0.0.1</ftpServerAddress>
<ftpServerPort>21</ftpServerPort>
<ftpServerUsername>USERNAME</ftpServerUsername>
<ftpServerPassword>PASSWORD</ftpServerPassword>
<rageMpServerPath>.</rageMpServerPath>
<updateMetaXml>false</updateMetaXml>
<updateAllDependencies>false</updateAllDependencies>
</remote>
</update>"
# create 'rageMpServerPath' node and set default value # create default content
$serverPathNode = $xmlConfig.CreateNode("element", "rageMpServerPath", $null) New-Item $configPath
$serverPathNode.InnerText = $defaultServerPath Set-Content $configPath $defaultXmlContent
$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 # load existing xml config file
[xml]$xmlConfig = Get-Content -Path $configPath [xml]$xmlConfig = Get-Content -Path $configPath
if (!$xmlConfig) { if (!$xmlConfig) {
Write-Error "opening XML config failed" Write-Error "opening XML config file failed"
exit 1 exit 1
} }
# get server path from xml config file # update local files if enabled in config file
Set-Variable serverPath -option Constant -value $xmlConfig.config.rageMpServerPath if ($xmlConfig.update.local.enabled -eq "true") {
if (!$serverPath) { # get local server path from xml config file
Write-Error "empty rage mp server path" Set-Variable serverPath -option Constant -value $xmlConfig.update.local.rageMpServerPath
exit 1 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 # update remote files if enabled in config file
Set-Variable serverResourcesPath -option Constant -value "$serverPath\$serverResourcesDir" if ($xmlConfig.update.remote.enabled -eq "true") {
if (!(Test-Path $serverResourcesPath)) { # TODO: connect to remote ftp server and update files
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 exit 0
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
}