From 4eceb6b6dfe1e747ea8fe436e2d89b0afc5f0910 Mon Sep 17 00:00:00 2001 From: Codename Date: Sat, 7 Sep 2019 03:59:30 +0200 Subject: [PATCH 1/3] Add dynamic post build powershell script with config file --- .gitignore | 5 +- .../ReallifeGamemode.Server.csproj | 3 +- ReallifeGamemode.Server/Scripts/moveItems.ps1 | 38 ------ ReallifeGamemode.Server/post_build.ps1 | 109 ++++++++++++++++++ 4 files changed, 115 insertions(+), 40 deletions(-) delete mode 100644 ReallifeGamemode.Server/Scripts/moveItems.ps1 create mode 100644 ReallifeGamemode.Server/post_build.ps1 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 From ab49cd8ec241c842a0ebe2b1043f459075e4acef Mon Sep 17 00:00:00 2001 From: Codename Date: Sat, 7 Sep 2019 15:08:04 +0200 Subject: [PATCH 2/3] 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 From df858c66293c0eb54b8dde288566e3f17d53c30d Mon Sep 17 00:00:00 2001 From: Codename Date: Sat, 7 Sep 2019 20:14:03 +0200 Subject: [PATCH 3/3] Add client files, see postbuild.config.xml to enable updating --- .gitignore | 2 +- .../ReallifeGamemode.Server.csproj | 2 +- ReallifeGamemode.Server/post_build.ps1 | 118 ----------- ReallifeGamemode.sln | 2 + postbuild.ps1 | 183 ++++++++++++++++++ 5 files changed, 187 insertions(+), 120 deletions(-) delete mode 100644 ReallifeGamemode.Server/post_build.ps1 create mode 100644 postbuild.ps1 diff --git a/.gitignore b/.gitignore index 07d6d385..3e4b5a55 100644 --- a/.gitignore +++ b/.gitignore @@ -339,4 +339,4 @@ tmp/ index.js # post build config -ReallifeGamemode.Server/post_build_config.xml \ No newline at end of file +postbuild.config.xml \ No newline at end of file diff --git a/ReallifeGamemode.Server/ReallifeGamemode.Server.csproj b/ReallifeGamemode.Server/ReallifeGamemode.Server.csproj index 5f1d94e9..5bec592a 100644 --- a/ReallifeGamemode.Server/ReallifeGamemode.Server.csproj +++ b/ReallifeGamemode.Server/ReallifeGamemode.Server.csproj @@ -42,6 +42,6 @@ - + \ No newline at end of file diff --git a/ReallifeGamemode.Server/post_build.ps1 b/ReallifeGamemode.Server/post_build.ps1 deleted file mode 100644 index ae5d20a2..00000000 --- a/ReallifeGamemode.Server/post_build.ps1 +++ /dev/null @@ -1,118 +0,0 @@ -# -# @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 config path -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 file if not exist -if (![System.IO.File]::Exists($configPath)) { - # resolve default server path (default: .\..\..) - $defaultServerPath = (Resolve-Path -Path "$PSScriptRoot\..\..") - if (!$defaultServerPath) { - 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 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 file failed" - 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 - } -} - -# update remote files if enabled in config file -if ($xmlConfig.update.remote.enabled -eq "true") { - # TODO: connect to remote ftp server and update files -} - -exit 0 \ No newline at end of file diff --git a/ReallifeGamemode.sln b/ReallifeGamemode.sln index 8c3f7e5e..7dc75b14 100644 --- a/ReallifeGamemode.sln +++ b/ReallifeGamemode.sln @@ -13,6 +13,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution .gitignore = .gitignore .gitlab-ci.yml = .gitlab-ci.yml readme.md = readme.md + postbuild.ps1 = postbuild.ps1 + postbuild.config.xml = postbuild.config.xml EndProjectSection EndProject Global diff --git a/postbuild.ps1 b/postbuild.ps1 new file mode 100644 index 00000000..cca2e937 --- /dev/null +++ b/postbuild.ps1 @@ -0,0 +1,183 @@ +# +# @author Codename +# @copyright (c) 2008 - 2019 Life of German +# @warning Start this script only once, after building server dll +# @description This powershell script copies necessary files to (local/remote) server dir for windows developers +# + +# set parameters +param ( + [string]$buildDirectory, + [string]$buildFilename +) + +# set constant path +Set-Variable configPath -option Constant -value "$PSScriptRoot\postbuild.config.xml" +Set-Variable serverProjectPath -option Constant -value "$PSScriptRoot\ReallifeGamemode.Server" +Set-Variable clientProjectPath -option Constant -value "$PSScriptRoot\ReallifeGamemode.Client" +Set-Variable sourceAssetsPath -option Constant -value "$PSScriptRoot\ReallifeGamemode.Client\assets" +Set-Variable sourceIndexJsPath -option Constant -value "$PSScriptRoot\ReallifeGamemode.Client\index.js" +Set-Variable sourceDlcPacksPath -option Constant -value "$PSScriptRoot\ReallifeGamemode.Client\dlcpacks" + +# set constant dirs +Set-Variable runtimeDir -option Constant -value "bridge\runtime" +Set-Variable resourcesDir -option Constant -value "bridge\resources" +Set-Variable gamemodeDir -option Constant -value "reallife-gamemode" +Set-Variable assetsDir -option Constant -value "client_packages\assets" +Set-Variable indexJsDir -option Constant -value "client_packages" +Set-Variable dlcPacksDir -option Constant -value "source_dlcpacks" +Set-Variable fullBuildDir -option Constant -value "$serverProjectPath\$buildDirectory" + +# create default config file if not exist +if (![System.IO.File]::Exists($configPath)) { + # resolve default server path (default: .\..) + $defaultServerPath = (Resolve-Path -Path "$PSScriptRoot\..") + if (!$defaultServerPath) { + Write-Error "resolving local server path failed" + exit 1 + } + + $defaultXmlContent = " + + + true + $defaultServerPath + + + true + true + + + false + false + false + + + + + false + 127.0.0.1 + 21 + USERNAME + PASSWORD + . + + + false + false + + + false + false + false + + + +" + + # create default content + New-Item $configPath + Set-Content $configPath $defaultXmlContent +} + +# load existing xml config file +[xml]$xmlConfig = Get-Content -Path $configPath +if (!$xmlConfig) { + throw "opening XML config file failed" +} + +# first compile typescript files if enabled in config file +if (($xmlConfig.config.local.update.client.indexJs -eq "true" -and $xmlConfig.config.local.enabled -eq "true") -or + ($xmlConfig.config.remote.update.client.indexJs -eq "true" -and $xmlConfig.config.remote.enabled -eq "true")) { + $path = $PSScriptRoot + Set-Location -Path $clientProjectPath + npx webpack --config webpack.config.build.js + Set-Location -Path $path +} + +# update local files if enabled in config file +if ($xmlConfig.config.local.enabled -eq "true") { + # get local server path from xml config file + Set-Variable serverPath -option Constant -value $xmlConfig.config.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 resources path exists + Set-Variable resourcesPath -option Constant -value "$serverPath\$resourcesDir" + if (!(Test-Path $resourcesPath)) { + Write-Error "local resources path ($resourcesPath) 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 gamemodePath -option Constant -value "$resourcesPath\$gamemodeDir" + if (!(Test-Path $gamemodePath)) { + New-Item -ItemType Directory -Force -Path $gamemodePath + } + + # copy compiled gamemode to local gamemode path + Copy-Item "$fullBuildDir\$buildFilename" $gamemodePath -Force + + # copy meta.xml to local gamemode path if 'local.update.server.metaXml' is set to 'true' in config file + if ($xmlConfig.config.local.update.server.metaXml -eq "true") { + Copy-Item "$fullBuildDir\meta.xml" $gamemodePath -Force + } + + # copy dependencies to local runtime path if 'local.update.server.allDependencies' is set to 'true' in config file + if ($xmlConfig.config.local.update.server.allDependencies -eq "true") { + # check if local runtime path exists + Set-Variable runtimePath -option Constant -value "$serverPath\$runtimeDir" + if (!(Test-Path $runtimePath)) { + Write-Error "local runtime path ($runtimePath) 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-Item "$fullBuildDir\*.dll" $runtimePath -Exclude "*$buildFilename*" -Force + } + + # copy assets to local client packages path if 'local.update.client.assets' is set to 'true' in config file + if ($xmlConfig.config.local.update.client.assets -eq "true") { + # create local assets path if not exist + Set-Variable assetsPath -option Constant -value "$serverPath\$assetsDir" + if (!(Test-Path $assetsPath)) { + New-Item -ItemType Directory -Force -Path $assetsPath + } + robocopy $sourceAssetsPath $assetsPath /MIR + } + + # copy index.js to local client packages path if 'local.update.client.indexJs' is set to 'true' in config file + if ($xmlConfig.config.local.update.client.indexJs -eq "true") { + # create local client packages if not exist + Set-Variable indexJsPath -option Constant -value "$serverPath\$indexJsDir" + if (!(Test-Path $indexJsPath)) { + New-Item -ItemType Directory -Force -Path $indexJsPath + } + Copy-Item $sourceIndexJsPath $indexJsPath -Force + } + + # copy dlc packs to local dlc packs path if 'local.update.client.dlcPacks' is set to 'true' in config file + if ($xmlConfig.config.local.update.client.dlcPacks -eq "true") { + # create local dlc packs path if not exist + Set-Variable dlcPacksPath -option Constant -value "$serverPath\$dlcPacksDir" + if (!(Test-Path $dlcPacksPath)) { + New-Item -ItemType Directory -Force -Path $dlcPacksPath + } + robocopy $sourceDlcPacksPath $dlcPacksPath /MIR + } +} + +# update remote files if enabled in config file +if ($xmlConfig.config.remote.enabled -eq "true") { + # TODO: connect to remote ftp server and update files +} + +exit 0 \ No newline at end of file