Added "Init" function.
+ some fixes.
This commit is contained in:
@@ -24,8 +24,8 @@ if not exist "Logs\" mkdir "Logs"
|
||||
set init=0
|
||||
set update=0
|
||||
|
||||
if /i %1 equ "/I" set init=1
|
||||
if /i %1 equ "/U" set update=1
|
||||
if /i "%1" equ "/I" set init=1
|
||||
if /i "%1" equ "/U" set update=1
|
||||
|
||||
@REM powershell -ExecutionPolicy RemoteSigned -File wDayzManager.ps1 -Init %init% -Update %update%
|
||||
powershell -ExecutionPolicy RemoteSigned -File wDayzManager.ps1 -Init %init% -Update %update% > Logs\%filename%
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# wDayzManager v0.7
|
||||
# wDayzManager v0.8
|
||||
# Copyright (c) 2024 Vladislav Salikov aka W0LF aka 'dreamforce'
|
||||
# https://github.com/dreamforceinc
|
||||
# Required module: PSIni
|
||||
@@ -22,18 +22,18 @@ Param (
|
||||
################################################################ [ !!! DON'T EDIT BELOW !!! ] #################################################################
|
||||
|
||||
[string]$myName = "wDayzManager"
|
||||
[string]$myVersion = "v0.7"
|
||||
[string]$myVersion = "v0.8"
|
||||
[string]$iniFile = $myName + ".ini"
|
||||
[string]$steamScript = $myName + ".txt"
|
||||
|
||||
if (($init -eq $true) -or ($update -eq $true)) {
|
||||
if (($init -eq $true) -and ($update -eq $true)) {
|
||||
Write-Error "Only one parameter is accepted - either 'Init' or 'Update'."
|
||||
Exit
|
||||
}
|
||||
|
||||
[string]$steamScript = $myName + ".txt"
|
||||
[string]$iniFile = $myName + ".ini"
|
||||
if (-not (Test-Path -Path $iniFile)) {
|
||||
Write-Warning "Can't find file '$iniFile', creating new..."
|
||||
function Init {
|
||||
New-Item -ItemType File -Path $iniFile -Value "; $($iniFile)" | Out-Null
|
||||
if (!$?) { Exit }
|
||||
$content = "
|
||||
[Config]
|
||||
serverLocation=Z:\Servers\DayzServer
|
||||
@@ -88,11 +88,17 @@ startupServerMods=
|
||||
additionalParams= -name=Server -AdminLog -FilePatching
|
||||
namalskMission=
|
||||
"
|
||||
Add-Content -Path $iniFile -Value $content -Encoding UTF8
|
||||
Add-Content -Path $iniFile -Value $content -Encoding ASCII
|
||||
$content = $null
|
||||
Exit
|
||||
}
|
||||
|
||||
if ($init) { Init ; Exit }
|
||||
if (-not (Test-Path -Path $iniFile)) {
|
||||
Write-Warning "Can't find file '$iniFile'. You probably need to run the bat-script with the '/I' parameter."
|
||||
Exit
|
||||
}
|
||||
|
||||
$date = Get-Date
|
||||
[int]$currentDayOfWeek = ([datetime]$date).DayOfWeek
|
||||
[int]$currentDay = ([datetime]$date).Day
|
||||
@@ -127,14 +133,6 @@ $config = $ini.Config
|
||||
[string]$updatePeriod = $config.updatePeriod
|
||||
[bool]$rotateLogs = [int]$config.rotateLogs
|
||||
|
||||
function Init {
|
||||
|
||||
}
|
||||
|
||||
function Update {
|
||||
|
||||
}
|
||||
|
||||
$clientMods = New-Object 'Collections.Generic.List[Tuple[string,string]]'
|
||||
foreach ($mod in $ini.ClientMods.GetEnumerator()) {
|
||||
if ($mod.Key -notlike "Comment*" ) {
|
||||
@@ -149,15 +147,19 @@ foreach ($mod in $ini.ServerMods.GetEnumerator()) {
|
||||
}
|
||||
}
|
||||
|
||||
function Update {
|
||||
|
||||
}
|
||||
|
||||
switch ($updatePeriod) {
|
||||
D { if ($currentHour -eq $updateHour) { $update = $true } }
|
||||
W { if (($currentDayOfWeek -eq $updateDay) -and ($currentHour -eq $updateHour)) { $update = $true } }
|
||||
M { if (($currentDay -eq $updateDay) -and ($currentHour -eq $updateHour)) { $update = $true } }
|
||||
Default { $update = $param }
|
||||
default { $update = $false }
|
||||
}
|
||||
|
||||
if ($update) {
|
||||
If (-NOT ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) {
|
||||
if (-not ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) {
|
||||
Write-Warning "You do not have Administrator rights to run this script!`nPlease re-run this script as an Administrator!"
|
||||
Exit
|
||||
}
|
||||
@@ -181,8 +183,8 @@ if ($update) {
|
||||
$arr += "quit"
|
||||
|
||||
# Saving Steam script
|
||||
"// $($steamScript) - Steam script" | Out-File -FilePath "$($currentPath)\$($steamScript)" -Encoding Ascii
|
||||
$arr | Out-File -FilePath "$($currentPath)\$($steamScript)" -Encoding Ascii -Append
|
||||
"// $($steamScript) - Steam script" | Out-File -FilePath "$($currentPath)\$($steamScript)" -Encoding ASCII
|
||||
$arr | Out-File -FilePath "$($currentPath)\$($steamScript)" -Encoding ASCII -Append
|
||||
|
||||
# Run Steam script
|
||||
Write-Host "Run Steam script from `"$($currentPath)\$($steamScript)`""
|
||||
@@ -376,14 +378,14 @@ foreach ($srv in $servers) {
|
||||
$atLogsLocation += '\' + $logsName
|
||||
}
|
||||
|
||||
If (!(Test-Path -PathType Container $rotatedLogsLocation)) {
|
||||
If (-not (Test-Path -PathType Container $rotatedLogsLocation)) {
|
||||
New-Item -ItemType Directory -Path $rotatedLogsLocation | Out-Null
|
||||
Write-Host "Created new folder: $($rotatedLogsLocation)"
|
||||
}
|
||||
|
||||
if ($noDelete) {
|
||||
$destDelDir = "$($rotatedLogsLocation)\DeletedLogs"
|
||||
If (!(Test-Path -PathType Container $destDelDir)) {
|
||||
If (-not (Test-Path -PathType Container $destDelDir)) {
|
||||
New-Item -ItemType Directory -Path $destDelDir | Out-Null
|
||||
Write-Host "Created new folder: $($destDelDir)"
|
||||
}
|
||||
@@ -424,7 +426,7 @@ foreach ($srv in $servers) {
|
||||
if ($becLocation) {
|
||||
$becDestDir = "$($rotatedLogsLocation)\$($becFolderName)"
|
||||
|
||||
If (!(Test-Path -PathType Container $becDestDir)) {
|
||||
If (-not (Test-Path -PathType Container $becDestDir)) {
|
||||
New-Item -ItemType Directory -Path $becDestDir | Out-Null
|
||||
Write-Host "Created new folder: $($becDestDir)"
|
||||
}
|
||||
@@ -464,7 +466,7 @@ foreach ($srv in $servers) {
|
||||
if ($atLogsLocation) {
|
||||
$atDestDir = "$($rotatedLogsLocation)\$($atFolderName)"
|
||||
|
||||
If (!(Test-Path -PathType Container $atDestDir)) {
|
||||
If (-not (Test-Path -PathType Container $atDestDir)) {
|
||||
New-Item -ItemType Directory -Path $atDestDir | Out-Null
|
||||
Write-Host "Created new folder: $($atDestDir)"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user