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