109 lines
3.9 KiB
PowerShell
109 lines
3.9 KiB
PowerShell
# 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
|
|
} |