-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsoftlink.bat
More file actions
144 lines (121 loc) · 3.98 KB
/
softlink.bat
File metadata and controls
144 lines (121 loc) · 3.98 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
134
135
136
137
138
139
140
141
142
143
144
@echo off
setlocal
:: === Configuration ===
:: Define expected files and their SHA256 hashes
:: Comment out EXE_VANILLA and/or EXE_EXTREME to skip hash check
:: Western 1.41
set "EXE_VANILLA=Stronghold Crusader.exe"
set "HASH_VANILLA=3bb0a8c1e72331b3a30a5aa93ed94beca0081b476b04c1960e26d5b45387ac5a"
:: Western 1.41.1-E
set "EXE_EXTREME=Stronghold_Crusader_Extreme.exe"
set "HASH_EXTREME=55648e6b05d67d37a5773fe699bbb17a2d6ad4de1bb9dbded9a21caef82bd7fb"
:: === Parameter or user input ===
set "INTERACTIVE=0"
if "%~1"=="" set "INTERACTIVE=1"
:: --- Check for Administrator privileges ---
net session >nul 2>&1
if %errorlevel% neq 0 (
echo [ERROR] Administrator privileges required to run this script.
echo Please run the script as Administrator.
if "%INTERACTIVE%"=="1" pause
exit /b 1
)
:: Change working directory to the folder where the script is located
cd /d "%~dp0" || (
echo [ERROR] Failed to set working directory to script location: %~dp0
if "%INTERACTIVE%"=="1" pause
exit /b 1
)
:: Set path or ask for it
if "%INTERACTIVE%"=="1" (
echo No path provided as parameter.
set /p "TARGET=Please enter the full path to the folder: "
) else (
set "TARGET=%~1"
)
:: Trim possible quotes
set "TARGET=%TARGET:"=%"
:: === Path validation ===
if not exist "%TARGET%\" (
echo [ERROR] Path does not exist or is not a folder: "%TARGET%"
if "%INTERACTIVE%"=="1" pause
exit /b 1
)
echo.
echo === Validating Files in "%TARGET%" ===
:: ====================================================
:: === Check 1: Stronghold Crusader.exe (Vanilla)
:: ====================================================
if defined EXE_VANILLA (
echo Checking "%EXE_VANILLA%"...
if not exist "%TARGET%\%EXE_VANILLA%" (
echo [ERROR] Missing file: %EXE_VANILLA%
if "%INTERACTIVE%"=="1" pause
exit /b 1
)
:: Get SHA256 hash reliably
for /f "skip=1 delims=" %%H in ('certutil -hashfile "%TARGET%\%EXE_VANILLA%" SHA256') do (
set "ACTUAL_HASH_VANILLA=%%H"
goto :gotVanillaHash
)
:gotVanillaHash
set "ACTUAL_HASH_VANILLA=%ACTUAL_HASH_VANILLA: =%"
if /i not "%ACTUAL_HASH_VANILLA%"=="%HASH_VANILLA%" (
echo [ERROR] Hash mismatch for Western 1.41 %EXE_VANILLA%
echo Expected: %HASH_VANILLA%
echo Found: %ACTUAL_HASH_VANILLA%
if "%INTERACTIVE%"=="1" pause
exit /b 1
)
echo [OK] %EXE_VANILLA% hash verified.
echo.
)
:: ====================================================
:: === Check 2: Stronghold_Crusader_Extreme.exe (Extreme)
:: ====================================================
if defined EXE_EXTREME (
echo Checking "%EXE_EXTREME%"...
if not exist "%TARGET%\%EXE_EXTREME%" (
echo [ERROR] Missing file: %EXE_EXTREME%
if "%INTERACTIVE%"=="1" pause
exit /b 1
)
:: Get SHA256 hash reliably
for /f "skip=1 delims=" %%H in ('certutil -hashfile "%TARGET%\%EXE_EXTREME%" SHA256') do (
set "ACTUAL_HASH_EXTREME=%%H"
goto :gotExtremeHash
)
:gotExtremeHash
set "ACTUAL_HASH_EXTREME=%ACTUAL_HASH_EXTREME: =%"
if /i not "%ACTUAL_HASH_EXTREME%"=="%HASH_EXTREME%" (
echo [ERROR] Hash mismatch for %EXE_EXTREME%
echo Expected: %HASH_EXTREME%
echo Found: %ACTUAL_HASH_EXTREME%
if "%INTERACTIVE%"=="1" pause
exit /b 1
)
echo [OK] %EXE_EXTREME% hash verified.
echo.
)
echo All required files passed integrity check.
:: === Remove existing _original safely ===
if exist "_original" (
attrib -r "_original" 2>nul
if exist "_original\" (
rmdir "_original" 2>nul
) else (
del "_original" 2>nul
)
)
:: === Create symbolic link ===
echo Creating symbolic link "_original" -^> "%TARGET%"
mklink /D "_original" "%TARGET%"
if %errorlevel% neq 0 (
echo [ERROR] Failed to create symbolic link. Try running as Administrator.
if "%INTERACTIVE%"=="1" pause
exit /b 1
)
echo [SUCCESS] Link created successfully.
if "%INTERACTIVE%"=="1" pause
endlocal
exit /b 0