forked from ace-step/ACE-Step-1.5
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcheck_update.bat
More file actions
511 lines (451 loc) · 17.5 KB
/
check_update.bat
File metadata and controls
511 lines (451 loc) · 17.5 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
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
@echo off
REM Git Update Check Utility
REM This script checks for updates from GitHub and optionally updates the repository
setlocal enabledelayedexpansion
REM Configuration
set TIMEOUT_SECONDS=10
set GIT_PORTABLE_PATH=%~dp0PortableGit\bin\git.exe
set GIT_PATH=
set REPO_PATH=%~dp0
set PROXY_CONFIG_FILE=%~dp0proxy_config.txt
echo ========================================
echo ACE-Step Update Check
echo ========================================
echo.
REM Check for Git: first try PortableGit, then system Git
if exist "%GIT_PORTABLE_PATH%" (
set "GIT_PATH=%GIT_PORTABLE_PATH%"
echo [Git] Using PortableGit
) else (
REM Try to find git in system PATH
where git >nul 2>&1
if !ERRORLEVEL! EQU 0 (
for /f "tokens=*" %%i in ('where git 2^>nul') do (
if not defined GIT_PATH set "GIT_PATH=%%i"
)
echo [Git] Using system Git: !GIT_PATH!
) else (
echo [Error] Git not found.
echo - PortableGit not found at: %GIT_PORTABLE_PATH%
echo - System Git not found in PATH
echo.
echo Please either:
echo 1. Install PortableGit in the PortableGit folder, or
echo 2. Install Git and add it to your system PATH
echo.
echo ========================================
echo Press any key to close...
echo ========================================
pause >nul
exit /b 1
)
)
echo.
REM Check if this is a git repository
cd /d "%REPO_PATH%"
"!GIT_PATH!" rev-parse --git-dir >nul 2>&1
if %ERRORLEVEL% NEQ 0 (
echo [Error] Not a git repository.
echo This folder does not appear to be a git repository.
echo.
echo ========================================
echo Press any key to close...
echo ========================================
pause >nul
exit /b 1
)
REM Load proxy configuration if exists
set PROXY_ENABLED=0
set PROXY_URL=
if exist "%PROXY_CONFIG_FILE%" (
for /f "usebackq tokens=1,* delims==" %%a in ("%PROXY_CONFIG_FILE%") do (
if /i "%%a"=="PROXY_ENABLED" set PROXY_ENABLED=%%b
if /i "%%a"=="PROXY_URL" set PROXY_URL=%%b
)
if "!PROXY_ENABLED!"=="1" (
if not "!PROXY_URL!"=="" (
echo [Proxy] Using proxy server: !PROXY_URL!
"!GIT_PATH!" config --local http.proxy "!PROXY_URL!"
"!GIT_PATH!" config --local https.proxy "!PROXY_URL!"
echo.
)
)
)
echo [1/4] Checking current version...
REM Get current branch
for /f "tokens=*" %%i in ('"!GIT_PATH!" rev-parse --abbrev-ref HEAD 2^>nul') do set CURRENT_BRANCH=%%i
if "%CURRENT_BRANCH%"=="" set CURRENT_BRANCH=main
REM Get current commit
for /f "tokens=*" %%i in ('"!GIT_PATH!" rev-parse --short HEAD 2^>nul') do set CURRENT_COMMIT=%%i
echo Branch: %CURRENT_BRANCH%
echo Commit: %CURRENT_COMMIT%
echo.
echo [2/4] Checking for updates (timeout: %TIMEOUT_SECONDS%s)...
echo Connecting to GitHub...
:FetchRetry
REM Fetch remote with timeout
REM Use START /B to run in background and check timeout
set FETCH_SUCCESS=0
"!GIT_PATH!" fetch origin --quiet 2>nul
if %ERRORLEVEL% EQU 0 (
set FETCH_SUCCESS=1
) else (
REM Try with timeout using a temp marker file
set TEMP_MARKER=%TEMP%\acestep_git_fetch_%RANDOM%.tmp
REM Start fetch in background
set "FETCH_CMD=!GIT_PATH! fetch origin --quiet"
start /b "" cmd /c "!FETCH_CMD! >nul 2>&1 && echo SUCCESS > "!TEMP_MARKER!""
REM Wait with timeout
set /a COUNTER=0
:WaitLoop
if exist "!TEMP_MARKER!" (
set FETCH_SUCCESS=1
del "!TEMP_MARKER!" >nul 2>&1
goto :FetchDone
)
timeout /t 1 /nobreak >nul
set /a COUNTER+=1
if !COUNTER! LSS %TIMEOUT_SECONDS% goto :WaitLoop
REM Timeout reached
echo [Timeout] Could not connect to GitHub within %TIMEOUT_SECONDS% seconds.
)
:FetchDone
if %FETCH_SUCCESS% EQU 0 (
echo [Failed] Could not fetch from GitHub.
echo Please check your internet connection.
echo.
REM Ask if user wants to configure proxy
set /p PROXY_CHOICE="Do you want to configure a proxy server to retry? (Y/N): "
if /i "!PROXY_CHOICE!"=="Y" (
call :ConfigureProxy
if !ERRORLEVEL! EQU 0 (
echo.
echo [Proxy] Retrying with proxy configuration...
echo.
goto :FetchRetry
)
)
echo.
echo ========================================
echo Press any key to close...
echo ========================================
pause >nul
exit /b 2
)
echo [Success] Fetched latest information from GitHub.
echo.
echo [3/4] Comparing versions...
REM Get remote commit
for /f "tokens=*" %%i in ('"!GIT_PATH!" rev-parse --short origin/%CURRENT_BRANCH% 2^>nul') do set REMOTE_COMMIT=%%i
if "%REMOTE_COMMIT%"=="" (
echo [Warning] Remote branch 'origin/%CURRENT_BRANCH%' not found.
echo.
echo Your current branch '%CURRENT_BRANCH%' does not exist on the remote repository.
echo This might be a local development branch.
echo.
REM Try to get main branch instead
set FALLBACK_BRANCH=main
echo Checking main branch instead...
for /f "tokens=*" %%i in ('"!GIT_PATH!" rev-parse --short origin/!FALLBACK_BRANCH! 2^>nul') do set REMOTE_COMMIT=%%i
if "!REMOTE_COMMIT!"=="" (
echo [Error] Could not find remote main branch either.
echo Please ensure you are connected to the correct repository.
echo.
echo ========================================
echo Press any key to close...
echo ========================================
pause >nul
exit /b 1
)
echo Found main branch: !REMOTE_COMMIT!
echo.
echo Recommendation: Switch to main branch to check for official updates.
echo Command: git checkout main
echo.
set /p SWITCH_BRANCH="Do you want to switch to main branch now? (Y/N): "
if /i "!SWITCH_BRANCH!"=="Y" (
echo.
echo Switching to main branch...
"!GIT_PATH!" checkout main
if !ERRORLEVEL! EQU 0 (
echo [Success] Switched to main branch.
echo.
echo Please run this script again to check for updates.
echo.
echo ========================================
echo Press any key to close...
echo ========================================
pause >nul
exit /b 0
) else (
echo [Error] Failed to switch branch.
echo.
echo ========================================
echo Press any key to close...
echo ========================================
pause >nul
exit /b 1
)
) else (
echo.
echo Continuing with current branch comparison...
echo Note: This comparison may not reflect official updates.
echo.
set CURRENT_BRANCH=!FALLBACK_BRANCH!
)
)
echo Local: %CURRENT_COMMIT%
echo Remote: %REMOTE_COMMIT%
echo.
REM Compare commits
if "%CURRENT_COMMIT%"=="%REMOTE_COMMIT%" (
echo [4/4] Result: Already up to date!
echo You have the latest version.
echo.
echo ========================================
echo Press any key to close...
echo ========================================
pause >nul
exit /b 0
) else (
echo [4/4] Result: Update available!
REM Check if local is behind remote
"!GIT_PATH!" merge-base --is-ancestor HEAD origin/%CURRENT_BRANCH% 2>nul
if !ERRORLEVEL! EQU 0 (
echo A new version is available on GitHub.
echo.
REM Show commits behind
echo New commits:
"!GIT_PATH!" --no-pager log --oneline --graph --decorate HEAD..origin/%CURRENT_BRANCH% 2>nul
echo.
REM Ask if user wants to update
set /p UPDATE_CHOICE="Do you want to update now? (Y/N): "
if /i "!UPDATE_CHOICE!"=="Y" (
echo.
echo Updating...
REM First, refresh the index to avoid false positives from line ending changes
"!GIT_PATH!" update-index --refresh >nul 2>&1
REM Check for uncommitted changes
"!GIT_PATH!" diff-index --quiet HEAD -- 2>nul
if !ERRORLEVEL! NEQ 0 (
echo.
echo [Info] Checking for potential conflicts...
REM Get list of locally modified files
set TEMP_LOCAL_CHANGES=%TEMP%\acestep_local_changes_%RANDOM%.txt
"!GIT_PATH!" diff --name-only HEAD 2>nul > "!TEMP_LOCAL_CHANGES!"
REM Get list of files changed in remote
set TEMP_REMOTE_CHANGES=%TEMP%\acestep_remote_changes_%RANDOM%.txt
"!GIT_PATH!" diff --name-only HEAD..origin/%CURRENT_BRANCH% 2>nul > "!TEMP_REMOTE_CHANGES!"
REM Check for conflicts
set HAS_CONFLICTS=0
REM Use wmic to get locale-independent date/time format (YYYYMMDDHHMMSS)
for /f "tokens=2 delims==" %%a in ('wmic os get localdatetime /value 2^>nul') do set "DATETIME=%%a"
set "BACKUP_DIR=%~dp0.update_backup_!DATETIME:~0,8!_!DATETIME:~8,6!"
REM Find conflicting files
for /f "usebackq delims=" %%a in ("!TEMP_LOCAL_CHANGES!") do (
findstr /x /c:"%%a" "!TEMP_REMOTE_CHANGES!" >nul 2>&1
if !ERRORLEVEL! EQU 0 (
REM Found a conflict
set HAS_CONFLICTS=1
REM Create backup directory if not exists
if not exist "!BACKUP_DIR!" (
mkdir "!BACKUP_DIR!"
echo.
echo [Backup] Creating backup directory: !BACKUP_DIR!
)
REM Backup the file
echo [Backup] Backing up: %%a
set FILE_PATH=%%a
set FILE_DIR=
for %%i in ("!FILE_PATH!") do set FILE_DIR=%%~dpi
REM Create subdirectories in backup if needed
if not "!FILE_DIR!"=="" (
if not "!FILE_DIR!"=="." (
if not exist "!BACKUP_DIR!\!FILE_DIR!" (
mkdir "!BACKUP_DIR!\!FILE_DIR!" 2>nul
)
)
)
REM Copy file to backup
copy "%%a" "!BACKUP_DIR!\%%a" >nul 2>&1
)
)
REM Clean up temp files
del "!TEMP_LOCAL_CHANGES!" >nul 2>&1
del "!TEMP_REMOTE_CHANGES!" >nul 2>&1
if !HAS_CONFLICTS! EQU 1 (
echo.
echo ========================================
echo [Warning] Potential conflicts detected!
echo ========================================
echo.
echo Your modified files may conflict with remote updates.
echo Your changes have been backed up to:
echo !BACKUP_DIR!
echo.
echo Update will restore these files to the remote version.
echo You can manually merge your changes later.
echo.
set /p CONFLICT_CHOICE="Continue with update? (Y/N): "
if /i "!CONFLICT_CHOICE!"=="Y" (
echo.
echo [Restore] Proceeding with update...
echo [Restore] Files will be updated to remote version.
) else (
echo.
echo Update cancelled.
echo Your backup remains at: !BACKUP_DIR!
echo.
echo ========================================
echo Press any key to close...
echo ========================================
pause >nul
exit /b 0
)
) else (
echo.
echo [Info] No conflicts detected. Safe to stash and update.
echo.
set /p STASH_CHOICE="Stash your changes and continue? (Y/N): "
if /i "!STASH_CHOICE!"=="Y" (
echo Stashing changes...
"!GIT_PATH!" stash push -m "Auto-stash before update - %date% %time%"
) else (
echo.
echo Update cancelled.
echo.
echo ========================================
echo Press any key to close...
echo ========================================
pause >nul
exit /b 0
)
)
)
REM Pull changes
echo Pulling latest changes...
REM Force update by resetting to remote branch (discards any remaining local changes)
"!GIT_PATH!" reset --hard origin/%CURRENT_BRANCH% >nul 2>&1
if !ERRORLEVEL! EQU 0 (
echo.
echo ========================================
echo Update completed successfully!
echo ========================================
echo.
REM Check if backup was created
if defined BACKUP_DIR (
if exist "!BACKUP_DIR!" (
echo [Important] Your modified files were backed up to:
echo !BACKUP_DIR!
echo.
echo To restore your changes:
echo 1. Run merge_config.bat to compare and merge files
echo 2. Or manually compare backup with new version
echo.
echo Backed up files:
set "BACKUP_DIR_DISPLAY=!BACKUP_DIR!"
for /f "delims=" %%f in ('dir /b /s "!BACKUP_DIR!\*.*" 2^>nul') do (
set "FILEPATH=%%f"
REM Use call to safely handle the string replacement
call set "FILEPATH=%%FILEPATH:!BACKUP_DIR_DISPLAY!\=%%"
echo - !FILEPATH!
)
echo.
)
)
echo Please restart the application to use the new version.
echo.
echo ========================================
echo Press any key to close...
echo ========================================
pause >nul
exit /b 0
) else (
echo.
echo [Error] Update failed.
echo Please check the error messages above.
REM If backup exists, mention it
if defined BACKUP_DIR (
if exist "!BACKUP_DIR!" (
echo.
echo Your backup is still available at: !BACKUP_DIR!
)
)
echo.
echo ========================================
echo Press any key to close...
echo ========================================
pause >nul
exit /b 1
)
) else (
echo.
echo Update skipped.
echo.
echo ========================================
echo Press any key to close...
echo ========================================
pause >nul
exit /b 0
)
) else (
echo [Warning] Local version has diverged from remote.
echo This might be because you have local commits.
echo Please update manually or consult the documentation.
echo.
echo ========================================
echo Press any key to close...
echo ========================================
pause >nul
exit /b 0
)
)
REM ========================================
REM Function: ConfigureProxy
REM Configure proxy server for git
REM ========================================
:ConfigureProxy
echo.
echo ========================================
echo Proxy Server Configuration
echo ========================================
echo.
echo Please enter your proxy server URL.
echo.
echo Examples:
echo - HTTP proxy: http://127.0.0.1:7890
echo - HTTPS proxy: https://proxy.example.com:8080
echo - SOCKS5: socks5://127.0.0.1:1080
echo.
echo Leave empty to disable proxy.
echo.
set /p NEW_PROXY_URL="Proxy URL: "
if "!NEW_PROXY_URL!"=="" (
echo.
echo [Proxy] Disabling proxy...
REM Remove proxy configuration
"!GIT_PATH!" config --local --unset http.proxy 2>nul
"!GIT_PATH!" config --local --unset https.proxy 2>nul
REM Update config file
(
echo PROXY_ENABLED=0
echo PROXY_URL=
) > "%PROXY_CONFIG_FILE%"
echo [Proxy] Proxy disabled.
exit /b 0
) else (
echo.
echo [Proxy] Configuring proxy: !NEW_PROXY_URL!
REM Apply proxy to git
"!GIT_PATH!" config --local http.proxy "!NEW_PROXY_URL!"
"!GIT_PATH!" config --local https.proxy "!NEW_PROXY_URL!"
REM Save to config file
(
echo PROXY_ENABLED=1
echo PROXY_URL=!NEW_PROXY_URL!
) > "%PROXY_CONFIG_FILE%"
echo [Proxy] Proxy configured successfully.
echo [Proxy] Configuration saved to: %PROXY_CONFIG_FILE%
exit /b 0
)
endlocal