-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_batch.bat
More file actions
133 lines (119 loc) · 3.88 KB
/
example_batch.bat
File metadata and controls
133 lines (119 loc) · 3.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
@echo off
:: Factorio Dedicated Server Manager Batch Script
:: By: Ghostwheel
:: Last Updated: Space Age Release
:: Version 1.1
:: -----------------------------------------------
:: This script validates, manages, and runs a Factorio Dedicated Server
:: with support for save files, server settings, and elevated privileges.
:: Variables
set "BaseDir=%~dp0"
set "FactorioExe=%~dp0Factorio\bin\x64\factorio.exe"
set "ExampleSettings=%~dp0Factorio\data\server-settings.example.json"
set "SettingsFile=%~dp0Factorio\data\server-settings.json"
set "SavesDir=%APPDATA%\Factorio\saves"
set "MenuChoice="
:: Ensure Factorio executable exists
if not exist "%FactorioExe%" (
echo [WARN] Factorio executable not found at "%FactorioExe%".
echo Please run the PowerShell script first or use the Install option to download it.
pause
)
:: Ensure server-settings.json exists, create it if necessary
if not exist "%SettingsFile%" (
if exist "%ExampleSettings%" (
echo Creating server-settings.json from server-settings.example.json...
copy "%ExampleSettings%" "%SettingsFile%" >nul
echo server-settings.json created successfully.
) else (
echo [WARN] server-settings.example.json not found. Settings file not created.
)
)
:: Ensure Saves directory exists
if not exist "%SavesDir%" (
echo Creating Saves directory...
mkdir "%SavesDir%"
echo Saves directory created successfully.
)
:: Main Menu
:MainMenu
cls
echo =====================================================
echo Factorio Dedicated Server Manager (Batch)
echo =====================================================
echo [1] Load Latest Save
echo [2] Load Specific Save (Manual)
echo [3] Open server-settings.json for Editing
echo [4] Create New Save ^& Launch Server
echo [5] Exit
echo =====================================================
set /p "MenuChoice=Please enter your choice (1-5): "
if "%MenuChoice%"=="1" goto :LoadLatestSave
if "%MenuChoice%"=="2" goto :LoadSpecificSave
if "%MenuChoice%"=="3" goto :EditSettings
if "%MenuChoice%"=="4" goto :CreateSave
if "%MenuChoice%"=="5" goto :ExitScript
:: Invalid input handling
echo Invalid option! Please select a valid option.
pause
goto :MainMenu
:LoadLatestSave
cls
echo =====================================================
echo Loading the latest save file...
echo =====================================================
for /f "delims=" %%a in ('dir "%SavesDir%\*.zip" /b /o-d /tw 2^>nul') do (
set "LatestSave=%%a"
goto :LaunchLatest
)
echo ERROR: No save files found in %SavesDir%.
pause
goto :MainMenu
:LaunchLatest
echo Launching with %LatestSave%
"%FactorioExe%" --start-server "%SavesDir%\%LatestSave%" --server-settings "%SettingsFile%"
pause
goto :MainMenu
:LoadSpecificSave
cls
echo =====================================================
echo Enter the EXACT name of the save file (including .zip)
echo =====================================================
dir "%SavesDir%\*.zip" /b
echo.
set /p "SaveChoice=Save file name: "
if exist "%SavesDir%\%SaveChoice%" (
"%FactorioExe%" --start-server "%SavesDir%\%SaveChoice%" --server-settings "%SettingsFile%"
) else (
echo ERROR: Save file not found.
)
pause
goto :MainMenu
:EditSettings
cls
if exist "%SettingsFile%" (
notepad "%SettingsFile%"
) else (
echo ERROR: Settings file not found.
pause
)
goto :MainMenu
:CreateSave
cls
echo =====================================================
echo Create a new save
echo =====================================================
set /p "NewSaveName=Enter name for new save (without .zip): "
if "%NewSaveName%"=="" goto :MainMenu
set "NewSavePath=%SavesDir%\%NewSaveName%.zip"
"%FactorioExe%" --create "%NewSavePath%"
if exist "%NewSavePath%" (
echo Starting server with new save...
"%FactorioExe%" --start-server "%NewSavePath%" --server-settings "%SettingsFile%"
) else (
echo ERROR: Failed to create save.
)
pause
goto :MainMenu
:ExitScript
goto :EOF