Skip to content

Commit

Permalink
Merge pull request #193 from Robomikel/pre-release/stabilizing
Browse files Browse the repository at this point in the history
Pre release/stabilizing
  • Loading branch information
Robomikel authored Oct 11, 2024
2 parents 2527b61 + 88b3e3d commit 4f5846c
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 5 deletions.
11 changes: 11 additions & 0 deletions functions/command_start.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,17 @@ Function Get-StartServer {
Start-Process CMD "/c start $launchParams" -NoNewWindow
Write-Log "info: Start-Process CMD /c start $launchParams -NoNewWindow"
}
# Get-WmiObject Win32_process -filter 'name = `"valheim_server`"' | foreach-object { $_.SetPriority(256) }
# Get-WmiObject Win32_process | ? { $_.Name -like "*valheim_server*"}| foreach-object { $_.SetPriority(256) }
# Write-Log "info: Get-WmiObject Win32_process -filter 'name = `"$process`"' | foreach-object { $_.SetPriority(256) }"
If ($psSeven -eq $true) {
Set-ProcessPriority -Name ($process + '.exe') -Priority High
Write-Log "info: Set-ProcessPriority -Name ($process + '.exe') -Priority High"
}
Else {
Get-WmiObject Win32_process | ? { $_.Name -like "*$process*" } | foreach-object { $_.SetPriority(256) }
Write-Log "info: Get-WmiObject Win32_process | ? { $_.Name -like "*$process*"}| foreach-object { $_.SetPriority(256) }"
}
Pop-Location
}
}
Expand Down
42 changes: 37 additions & 5 deletions functions/core_functions.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -404,11 +404,16 @@ Function New-ServerLog {
# Write-log "info: Found $consolelog"
$log = (Get-ChildItem -Depth 1 $logdirectory -Filter $consolelog | Sort-Object LastWriteTime -Descending | Select-Object -First 1).Name
Write-log "info: Found $log"
try {
Copy-Item -Path "$logdirectory\$log" -Destination "$currentdir\log\$serverfiles-$date.log" -Force
}
Catch {
Write-log $_.Exception.Message
Copy-Item -Path $logdirectory\$log -Destination "$currentdir\log\$serverfiles-$date.log"
If (!(Test-Path "$currentdir\log\$serverfiles-$date.log") ) {
New-Item -Path "$currentdir\log\$serverfiles-$date.log" >$null 2>&1
$slog = Get-Content -Path $logdirectory\$log
If ($slog) {
Add-Content -Value $slog -Path "$currentdir\log\$serverfiles-$date.log"
}
Else {
Write-log "Warning: Failed Copy serverlog and Create New serverlog"
}
}
If ($?) {
If ($pastebinconsolelog -eq "on") {
Expand Down Expand Up @@ -1687,4 +1692,31 @@ Function Get-GithubRestAPIntop {
return
}
}
Function Set-ProcessPriority {
[CmdletBinding()]
param (
[Parameter(Mandatory = $true, ParameterSetName = 'ProcessName')]
[ValidateScript({ (Get-CimInstance -ClassName Win32_Process).Name -contains $PSItem })]
[string] $Name,
[Parameter(Mandatory = $true, ParameterSetName = 'ProcessName')]
[ValidateSet('Idle', 'BelowNormal', 'AboveNormal', 'High', 'Realtime')]
[string] $Priority
)
# https://www.powershellgallery.com/packages/ProcessPriority/0.2.3
# Documentation here: https://docs.microsoft.com/en-us/windows/win32/cimwin32prov/setpriority-method-in-class-win32-process
$PriorityMapping = @{
Idle = 64
BelowNormal = 16384
Normal = 32
AboveNormal = 32768
High = 128
Realtime = 256
}

$ProcessList = Get-CimInstance -ClassName Win32_Process -Filter "Name = '$Name'"

foreach ($Process in $ProcessList) {
Invoke-CimMethod -InputObject $Process -MethodName SetPriority -Arguments @{ Priority = $PriorityMapping.$Priority } >$null 2>&1
Write-Verbose -Message ('Set process priority to {0} for process ID {1}' -f $Priority, $Process.ProcessId)
}
}

0 comments on commit 4f5846c

Please sign in to comment.