Skip to content

Commit

Permalink
improv: Create user_jvm_args without BOM from PowerShell scripts, mak…
Browse files Browse the repository at this point in the history
…ing it compatible with NeoForge ServerStarterJar
  • Loading branch information
Griefed committed Jul 20, 2024
1 parent 6a4262a commit fd82ae7
Showing 1 changed file with 17 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,15 @@ Function DeleteFileSilently
$ErrorActionPreference = "Continue";
}

Function WriteFileUTF8NoBom
{
param ($FilePath, $Content)
$AbsolutePath = Join-Path -Path "$BaseDir" -ChildPath "$FilePath"
New-Item $AbsolutePath -type file
$Utf8NoBomEncoding = New-Object System.Text.UTF8Encoding $False
[IO.File]::WriteAllLines(($FilePath | Resolve-Path), $Content, $Utf8NoBomEncoding)
}

Function QuitServer
{
Write-Host "Exiting..."
Expand Down Expand Up @@ -284,15 +293,17 @@ Function global:SetupForge
Write-Host "Edit JAVA_ARGS in your variables.txt. Do not edit user_jvm_args.txt directly!"
Write-Host "Manually made changes to user_jvm_args.txt will be lost in the nether!"
DeleteFileSilently 'user_jvm_args.txt'
"# Xmx and Xms set the maximum and minimum RAM usage, respectively.`n" +
$Content = "# Xmx and Xms set the maximum and minimum RAM usage, respectively.`n" +
"# They can take any number, followed by an M or a G.`n" +
"# M means Megabyte, G means Gigabyte.`n" +
"# For example, to set the maximum to 3GB: -Xmx3G`n" +
"# To set the minimum to 2.5GB: -Xms2500M`n" +
"# A good default for a modded server is 4GB.`n" +
"# Uncomment the next line to set it.`n" +
"# -Xmx4G`n" +
"${script:JavaArgs}" | Out-File user_jvm_args.txt -encoding utf8
"${script:JavaArgs}"
WriteFileUTF8NoBom "user_jvm_args.txt" $Content

}
if ((DownloadIfNotExists "${ForgeJarLocation}" "forge-installer.jar" "${ForgeInstallerUrl}"))
{
Expand Down Expand Up @@ -345,15 +356,17 @@ Function global:SetupNeoForge
Write-Host "Edit JAVA_ARGS in your variables.txt. Do not edit user_jvm_args.txt directly!"
Write-Host "Manually made changes to user_jvm_args.txt will be lost in the nether!"
DeleteFileSilently 'user_jvm_args.txt'
"# Xmx and Xms set the maximum and minimum RAM usage, respectively.`n" +
$Content = "# Xmx and Xms set the maximum and minimum RAM usage, respectively.`n" +
"# They can take any number, followed by an M or a G.`n" +
"# M means Megabyte, G means Gigabyte.`n" +
"# For example, to set the maximum to 3GB: -Xmx3G`n" +
"# To set the minimum to 2.5GB: -Xms2500M`n" +
"# A good default for a modded server is 4GB.`n" +
"# Uncomment the next line to set it.`n" +
"# -Xmx4G`n" +
"${script:JavaArgs}" | Out-File user_jvm_args.txt -encoding utf8
"${script:JavaArgs}"
WriteFileUTF8NoBom "user_jvm_args.txt" $Content

if ((DownloadIfNotExists "${ForgeJarLocation}" "neoforge-installer.jar" "${NeoForgeInstallerUrl}"))
{
"NeoForge Installer downloaded. Installing..."
Expand Down

0 comments on commit fd82ae7

Please sign in to comment.