forked from RimSort/RimSort
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate.bat
More file actions
289 lines (257 loc) · 9.51 KB
/
update.bat
File metadata and controls
289 lines (257 loc) · 9.51 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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
@echo off
setlocal EnableDelayedExpansion
REM Show the window
title RimSort Update
mode con: cols=100 lines=30
echo RimSort update in progress... Please wait.
REM ========================================================================
REM RimSort Updater Script (Windows 10 & 11 Compatible)
REM Safely backs up and updates RimSort from provided temp path
REM Usage: update.bat <temp_update_path> <log_path>
REM ========================================================================
REM Get arguments
set "TEMP_UPDATE_PATH=%~1"
set "LOG_PATH=%~2"
REM Validate arguments
if "%TEMP_UPDATE_PATH%" == "" (
echo ERROR: Temp update path is required as first argument.
if defined LOG_PATH (
echo [%date% %time%] ERROR: Temp update path is required as first argument. >> "%LOG_PATH%"
)
pause
exit /b 1
)
REM Log start
if defined LOG_PATH (
echo [%date% %time%] INFO: Starting RimSort update process... >> "%LOG_PATH%"
echo [%date% %time%] INFO: Temp update path: %TEMP_UPDATE_PATH% >> "%LOG_PATH%"
echo [%date% %time%] INFO: Log path: %LOG_PATH% >> "%LOG_PATH%"
) else (
echo [%date% %time%] INFO: Starting RimSort update process...
echo [%date% %time%] INFO: Temp update path: %TEMP_UPDATE_PATH%
)
REM Get current directory (should be application folder)
set "current_dir=%CD%"
if "%current_dir:~-1%"=="\" (
set "current_dir_no_slash=%current_dir:~0,-1%"
) else (
set "current_dir_no_slash=%current_dir%"
)
set "executable_path=%current_dir%\RimSort.exe"
set "update_source_folder=%TEMP_UPDATE_PATH%"
if defined LOG_PATH (
echo [%date% %time%] INFO: Current directory: %current_dir% >> "%LOG_PATH%"
echo [%date% %time%] INFO: Update source folder: %update_source_folder% >> "%LOG_PATH%"
echo [%date% %time%] INFO: Executable path: %executable_path% >> "%LOG_PATH%"
) else (
echo [%date% %time%] INFO: Current directory: %current_dir%
echo [%date% %time%] INFO: Update source folder: %update_source_folder%
echo [%date% %time%] INFO: Executable path: %executable_path%
)
REM Attempt to stop RimSort if it's already running
if defined LOG_PATH (
echo [%date% %time%] INFO: Stopping RimSort process... >> "%LOG_PATH%"
) else (
echo [%date% %time%] INFO: Stopping RimSort process...
)
taskkill /F /im RimSort.exe >nul 2>&1
if errorlevel 1 (
if defined LOG_PATH (
echo [%date% %time%] INFO: No running RimSort process found. >> "%LOG_PATH%"
) else (
echo [%date% %time%] INFO: No running RimSort process found.
)
) else (
if defined LOG_PATH (
echo [%date% %time%] INFO: RimSort process terminated. >> "%LOG_PATH%"
) else (
echo [%date% %time%] INFO: RimSort process terminated.
)
ping -n 3 127.0.0.1 >nul
)
REM Check if update folder exists
if not exist "%update_source_folder%" (
if defined LOG_PATH (
echo [%date% %time%] ERROR: Update source folder does not exist: %update_source_folder% >> "%LOG_PATH%"
) else (
echo [%date% %time%] ERROR: Update source folder does not exist: %update_source_folder%
)
pause
exit /b 1
)
REM Check if RimSort.exe exists in the update folder
if not exist "%update_source_folder%\RimSort.exe" (
if defined LOG_PATH (
echo [%date% %time%] ERROR: RimSort.exe not found in update source folder. >> "%LOG_PATH%"
) else (
echo [%date% %time%] ERROR: RimSort.exe not found in update source folder.
)
pause
exit /b 1
)
REM Show update information
echo.
echo ========================================================================
echo RimSort Update Ready
echo Source: %update_source_folder%
echo Target: %current_dir%
echo.
echo The update will start automatically...
echo ========================================================================
if defined LOG_PATH (
echo. >> "%LOG_PATH%"
echo RimSort Update Ready >> "%LOG_PATH%"
echo Source: %update_source_folder% >> "%LOG_PATH%"
echo Target: %current_dir% >> "%LOG_PATH%"
echo. >> "%LOG_PATH%"
echo The update will start automatically... >> "%LOG_PATH%"
echo ======================================================================== >> "%LOG_PATH%"
)
REM Begin update by copying files from temp update folder to app folder
if defined LOG_PATH (
echo [%date% %time%] INFO: Updating RimSort files... >> "%LOG_PATH%"
echo [%date% %time%] INFO: Source: %update_source_folder% >> "%LOG_PATH%"
echo [%date% %time%] INFO: Target: %current_dir_no_slash% >> "%LOG_PATH%"
) else (
echo [%date% %time%] INFO: Updating RimSort files...
echo [%date% %time%] INFO: Source: %update_source_folder%
echo [%date% %time%] INFO: Target: %current_dir_no_slash%
)
REM Use robocopy for file copying with error handling
if defined LOG_PATH (
echo [%date% %time%] INFO: Starting robocopy operation... >> "%LOG_PATH%"
)
robocopy "%update_source_folder%" "%current_dir_no_slash%" /E /COPY:DAT /R:3 /W:5 /NFL /NDL
set "robocopy_exit=%errorlevel%"
if defined LOG_PATH (
echo [%date% %time%] INFO: Robocopy completed with exit code: !robocopy_exit! >> "%LOG_PATH%"
)
REM Robocopy exit codes: 0=no errors, 1=files copied, 2=extra files, 4=mismatches, 8=some failures, 16=serious error
REM For update, 0, 1, 2, 4 are generally acceptable
if !robocopy_exit! LEQ 4 goto :robocopy_success
goto :robocopy_error
:robocopy_success
if defined LOG_PATH (
echo [%date% %time%] INFO: Files copied successfully. >> "%LOG_PATH%"
) else (
echo [%date% %time%] INFO: Files copied successfully.
)
goto :robocopy_done
:robocopy_error
if defined LOG_PATH (
echo [%date% %time%] ERROR: Update failed during file copy. >> "%LOG_PATH%"
) else (
echo [%date% %time%] ERROR: Update failed during file copy.
)
pause
exit /b 1
:robocopy_done
REM Give time for filesystem to sync
ping -n 4 127.0.0.1 >nul
REM Verify the new executable exists
if exist "%executable_path%" (
if defined LOG_PATH (
echo [%date% %time%] INFO: RimSort.exe verified after update. >> "%LOG_PATH%"
) else (
echo [%date% %time%] INFO: RimSort.exe verified after update.
)
) else (
if defined LOG_PATH (
echo [%date% %time%] ERROR: RimSort.exe not found after update. >> "%LOG_PATH%"
) else (
echo [%date% %time%] ERROR: RimSort.exe not found after update.
)
pause
exit /b 1
)
REM Cleanup temp update files
if defined LOG_PATH (
echo [%date% %time%] INFO: Cleaning up temporary files... >> "%LOG_PATH%"
echo [%date% %time%] INFO: Removing: %update_source_folder% >> "%LOG_PATH%"
) else (
echo [%date% %time%] INFO: Cleaning up temporary files...
echo [%date% %time%] INFO: Removing: %update_source_folder%
)
rd /s /q "%update_source_folder%" 2>nul
if exist "%update_source_folder%" (
if defined LOG_PATH (
echo [%date% %time%] WARNING: Failed to remove temporary folder. >> "%LOG_PATH%"
) else (
echo [%date% %time%] WARNING: Failed to remove temporary folder.
)
) else (
if defined LOG_PATH (
echo [%date% %time%] INFO: Temporary files cleaned up. >> "%LOG_PATH%"
) else (
echo [%date% %time%] INFO: Temporary files cleaned up.
)
)
REM Launch updated RimSort
if defined LOG_PATH (
echo [%date% %time%] INFO: Launching RimSort from: %executable_path% >> "%LOG_PATH%"
) else (
echo [%date% %time%] INFO: Launching RimSort from: %executable_path%
)
REM Give additional time for files to fully settle
ping -n 2 127.0.0.1 >nul
REM Start RimSort with better error handling
if exist "%executable_path%" (
echo Launching: %executable_path%
REM Change to app directory and launch with proper context
cd /d "%current_dir%"
REM Use PowerShell to start the process for better reliability
powershell -command "Start-Process '%executable_path%' -WorkingDirectory '%current_dir%'"
REM Wait for process to fully start (give it more time)
ping -n 6 127.0.0.1 >nul
) else (
if defined LOG_PATH (
echo [%date% %time%] ERROR: RimSort.exe not found at: %executable_path% >> "%LOG_PATH%"
) else (
echo [%date% %time%] ERROR: RimSort.exe not found at: %executable_path%
)
echo.
echo ERROR: RimSort.exe not found at expected location: %executable_path%
echo.
echo Press any key to close this window...
pause >nul
exit /b 1
)
REM Confirm process launch (retry up to 5 times with longer wait)
set "launch_confirmed=0"
set "attempt=0"
:check_launch
set /a attempt+=1
if !attempt! gtr 5 goto :launch_complete
tasklist /fi "imagename eq RimSort.exe" /fo csv | find /i "RimSort.exe" >nul
if not errorlevel 1 (
set "launch_confirmed=1"
goto :launch_success
)
ping -n 3 127.0.0.1 >nul
goto :check_launch
:launch_complete
:launch_success
if !launch_confirmed! EQU 1 (
if defined LOG_PATH (
echo [%date% %time%] INFO: RimSort update completed and launched successfully! >> "%LOG_PATH%"
) else (
echo [%date% %time%] INFO: RimSort update completed and launched successfully!
)
echo.
echo Update completed successfully! The new RimSort version is now running.
echo This window will close automatically in 5 seconds...
ping -n 6 127.0.0.1 >nul
) else (
if defined LOG_PATH (
echo [%date% %time%] WARNING: RimSort may not have started. >> "%LOG_PATH%"
echo [%date% %time%] INFO: You can start it manually from: %executable_path% >> "%LOG_PATH%"
) else (
echo [%date% %time%] WARNING: RimSort may not have started.
echo [%date% %time%] INFO: You can start it manually from: %executable_path%
)
echo.
echo Note: RimSort may still be starting in the background.
echo Press any key to close this window...
pause >nul
)
exit /b 0