mirror of
https://github.com/SillyTavern/SillyTavern-Launcher.git
synced 2026-04-27 17:51:28 +00:00
7zip modular | Backup improvements
made 7-zip modular and added auto launcher restart after install Prompt user to install 7zip automatically when not found when trying to create a backup. Fixed backup date time, added option for custom backup name
This commit is contained in:
77
Launcher.bat
77
Launcher.bat
@@ -145,7 +145,7 @@ REM Define variables for the directories for App Installer
|
||||
set "app_installer_image_generation_dir=%functions_dir%\Toolbox\App_Installer\Image_Generation"
|
||||
set "app_installer_text_completion_dir=%functions_dir%\Toolbox\App_Installer\Text_Completion"
|
||||
set "app_installer_voice_generation_dir=%functions_dir%\Toolbox\App_Installer\Voice_Generation"
|
||||
|
||||
set "app_installer_core_utilities_dir=%functions_dir%\Toolbox\App_Installer\Core_Utilities"
|
||||
|
||||
REM Define variables for logging
|
||||
set "logs_stl_console_path=%log_dir%\stl.log"
|
||||
@@ -183,9 +183,9 @@ echo "%CD%"| findstr /R /C:"[!#\$%&()\*+,;<=>?@\[\]\^`{|}~]" >nul && (
|
||||
REM Check if launcher has updates
|
||||
title STL [UPDATE ST-LAUNCHER]
|
||||
git fetch origin
|
||||
|
||||
for /f %%i in ('git branch --show-current') do set stl_current_branch=%%i
|
||||
REM Get the list of commits between local and remote branch
|
||||
for /f %%i in ('git rev-list HEAD..%current_branch%@{upstream}') do (
|
||||
for /f %%i in ('git rev-list HEAD..%stl_current_branch%@{upstream}') do (
|
||||
goto :startupcheck_found_update
|
||||
)
|
||||
|
||||
@@ -2428,7 +2428,8 @@ set /p app_installer_core_util_choice=Choose Your Destiny:
|
||||
|
||||
REM ######## APP INSTALLER CORE UTILITIES - BACKEND ###########
|
||||
if "%app_installer_core_util_choice%"=="1" (
|
||||
call :install_7zip
|
||||
set "caller=install_7zip"
|
||||
call %app_installer_core_utilities_dir%\install_7zip.bat
|
||||
) else if "%app_installer_core_util_choice%"=="2" (
|
||||
call :install_ffmpeg
|
||||
) else if "%app_installer_core_util_choice%"=="3" (
|
||||
@@ -2451,44 +2452,7 @@ if "%app_installer_core_util_choice%"=="1" (
|
||||
)
|
||||
|
||||
|
||||
:install_7zip
|
||||
title STL [INSTALL-7Z]
|
||||
echo %blue_bg%[%time%]%reset% %blue_fg_strong%[INFO]%reset% Installing 7-Zip...
|
||||
winget install -e --id 7zip.7zip
|
||||
|
||||
rem Get the current PATH value from the registry
|
||||
for /f "tokens=2*" %%A in ('reg query "HKCU\Environment" /v PATH') do set "current_path=%%B"
|
||||
|
||||
rem Check if the paths are already in the current PATH
|
||||
echo %current_path% | find /i "%zip7_install_path%" > nul
|
||||
set "zip7_path_exists=%errorlevel%"
|
||||
|
||||
setlocal enabledelayedexpansion
|
||||
|
||||
REM Append the new paths to the current PATH only if they don't exist
|
||||
if %zip7_path_exists% neq 0 (
|
||||
set "new_path=%current_path%;%zip7_install_path%"
|
||||
echo.
|
||||
echo [DEBUG] "current_path is:%cyan_fg_strong% %current_path%%reset%"
|
||||
echo.
|
||||
echo [DEBUG] "zip7_install_path is:%cyan_fg_strong% %zip7_install_path%%reset%"
|
||||
echo.
|
||||
echo [DEBUG] "new_path is:%cyan_fg_strong% !new_path!%reset%"
|
||||
|
||||
REM Update the PATH value in the registry
|
||||
reg add "HKCU\Environment" /v PATH /t REG_EXPAND_SZ /d "!new_path!" /f
|
||||
|
||||
REM Update the PATH value for the current session
|
||||
setx PATH "!new_path!" > nul
|
||||
echo %blue_bg%[%time%]%reset% %blue_fg_strong%[INFO]%reset% %green_fg_strong%7-zip added to PATH.%reset%
|
||||
) else (
|
||||
set "new_path=%current_path%"
|
||||
echo %blue_fg_strong%[INFO] 7-Zip already exists in PATH.%reset%
|
||||
)
|
||||
|
||||
echo %blue_bg%[%time%]%reset% %blue_fg_strong%[INFO]%reset% %green_fg_strong%7-Zip installed successfully. Please restart the Launcher.%reset%
|
||||
pause
|
||||
exit
|
||||
|
||||
|
||||
:install_ffmpeg
|
||||
@@ -4097,7 +4061,7 @@ goto :editor_core_utilities
|
||||
|
||||
:create_st_ssl
|
||||
call "%functions_dir%\SSL\create_ssl.bat" no-pause
|
||||
:: Check the error level returned by the main batch file
|
||||
REM Check the error level returned by the main batch file
|
||||
if %errorlevel% equ 0 (
|
||||
echo %green_fg_strong%The SSL was created successfully.%reset%
|
||||
) else (
|
||||
@@ -4455,16 +4419,35 @@ REM ################# BACKUP - FRONTEND ########################
|
||||
REM ############################################################
|
||||
:backup
|
||||
title STL [BACKUP]
|
||||
cls
|
||||
|
||||
REM Check if 7-Zip is installed
|
||||
7z > nul 2>&1
|
||||
if %errorlevel% neq 0 (
|
||||
echo %red_bg%[%time%]%reset% %red_fg_strong%[ERROR] 7z command not found in PATH.%reset%
|
||||
echo %red_fg_strong%7-Zip is not installed or not found in the system PATH.%reset%
|
||||
echo %red_fg_strong%To install 7-Zip go to:%reset% %blue_bg%/ Toolbox / App Installer / Core Utilities / Install 7-Zip%reset%
|
||||
goto :7zip_prompt
|
||||
)
|
||||
else (
|
||||
goto :backup_options
|
||||
)
|
||||
|
||||
:7zip_prompt
|
||||
echo %red_bg%[%time%]%reset% %red_fg_strong%[ERROR] 7z command not found in PATH.%reset%
|
||||
echo %red_fg_strong%7-Zip is not installed or not found in the system PATH. 7-Zip is required for making backups%reset%
|
||||
REM Prompt user to install 7-Zip
|
||||
echo 1. Install 7-Zip
|
||||
echo 2. Cancel
|
||||
set /p zip_choice="Would you like to install 7-Zip Now? (this will require a launcher restart after install): "
|
||||
REM Check if the user wants to install 7-Zip
|
||||
if "%zip_choice%"=="1" (
|
||||
set "caller=backup"
|
||||
call "%app_installer_core_utilities_dir%\install_7zip.bat"
|
||||
) else (
|
||||
echo 7-Zip not installed, cannot create backups...
|
||||
pause
|
||||
goto :home
|
||||
goto :toolbox
|
||||
)
|
||||
cls
|
||||
:backup_options
|
||||
echo %blue_fg_strong%/ Home / Toolbox / Backup%reset%
|
||||
echo -------------------------------------------------------------
|
||||
echo What would you like to do?
|
||||
@@ -4478,7 +4461,7 @@ REM ################# BACKUP - BACKEND ########################
|
||||
if "%backup_choice%"=="1" (
|
||||
set "caller=backup"
|
||||
call %backup_dir%\create_backup.bat
|
||||
if %errorlevel% equ 1 (
|
||||
if %errorlevel% equ 1 (
|
||||
goto :home
|
||||
) else (
|
||||
goto :backup
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
@echo off
|
||||
|
||||
:install_7zip
|
||||
title STL [INSTALL-7Z]
|
||||
echo %blue_bg%[%time%]%reset% %blue_fg_strong%[INFO]%reset% Installing 7-Zip...
|
||||
winget install -e --id 7zip.7zip
|
||||
|
||||
rem Get the current PATH value from the registry
|
||||
for /f "tokens=2*" %%A in ('reg query "HKCU\Environment" /v PATH') do set "current_path=%%B"
|
||||
|
||||
rem Check if the paths are already in the current PATH
|
||||
echo %current_path% | find /i "%zip7_install_path%" > nul
|
||||
set "zip7_path_exists=%errorlevel%"
|
||||
|
||||
setlocal enabledelayedexpansion
|
||||
|
||||
REM Append the new paths to the current PATH only if they don't exist
|
||||
if %zip7_path_exists% neq 0 (
|
||||
set "new_path=%current_path%;%zip7_install_path%"
|
||||
echo.
|
||||
echo [DEBUG] "current_path is:%cyan_fg_strong% %current_path%%reset%"
|
||||
echo.
|
||||
echo [DEBUG] "zip7_install_path is:%cyan_fg_strong% %zip7_install_path%%reset%"
|
||||
echo.
|
||||
echo [DEBUG] "new_path is:%cyan_fg_strong% !new_path!%reset%"
|
||||
|
||||
REM Update the PATH value in the registry
|
||||
reg add "HKCU\Environment" /v PATH /t REG_EXPAND_SZ /d "!new_path!" /f
|
||||
|
||||
REM Update the PATH value for the current session
|
||||
setx PATH "!new_path!" > nul
|
||||
echo %blue_bg%[%time%]%reset% %blue_fg_strong%[INFO]%reset% %green_fg_strong%7-zip added to PATH.%reset%
|
||||
) else (
|
||||
set "new_path=%current_path%"
|
||||
echo %blue_fg_strong%[INFO] 7-Zip already exists in PATH.%reset%
|
||||
)
|
||||
|
||||
echo %blue_bg%[%time%]%reset% %blue_fg_strong%[INFO]%reset% %green_fg_strong%7-Zip installed successfully. You need to restart the launcher for it to become active.%reset%
|
||||
REM Prompt user to restart
|
||||
echo Restarting launcher in 5 seconds...
|
||||
timeout /t 5
|
||||
cd /d %stl_root%
|
||||
start %stl_root%Launcher.bat
|
||||
exit
|
||||
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
@echo off
|
||||
setlocal
|
||||
|
||||
:create_backup
|
||||
title STL [CREATE BACKUP]
|
||||
@@ -59,37 +60,44 @@ if "%selected_user_folder%"=="" (
|
||||
REM Replace backslashes with double backslashes in st_install_path
|
||||
set "escaped_st_install_path=%st_install_path:\=\\%"
|
||||
|
||||
REM Create a backup using 7zip
|
||||
7z a "%st_backup_path%\backup_.7z" ^
|
||||
"%st_install_path%\data\%selected_user_folder%\*" ^
|
||||
REM Prompt user for custom name
|
||||
set "use_custom_name=N"
|
||||
set "custom_name="
|
||||
set /p rename_choice="Do you want to give the backup file a custom name? (default is backup_datetime) (Y/N): "
|
||||
if /i "%rename_choice%"=="Y" (
|
||||
set "use_custom_name=Y"
|
||||
set /p custom_name="Enter the custom name for the backup file (without extension): "
|
||||
) else if "%rename_choice%"=="" (
|
||||
set "use_custom_name=N"
|
||||
)
|
||||
|
||||
REM Get current date and time components
|
||||
for /f "tokens=1-3 delims=/- " %%d in ("%date%") do (
|
||||
set "day=%%d"
|
||||
set "month=%%e"
|
||||
set "year=%%f"
|
||||
for /f "tokens=2-4 delims=/ " %%a in ('echo %date%') do (
|
||||
set "day=%%a"
|
||||
set "month=%%b"
|
||||
set "year=%%c"
|
||||
)
|
||||
|
||||
for /f "tokens=1-2 delims=:." %%h in ("%time%") do (
|
||||
set "hour=%%h"
|
||||
set "minute=%%i"
|
||||
for /f "tokens=1-2 delims=:. " %%a in ('echo %time%') do (
|
||||
set "hour=%%a"
|
||||
set "minute=%%b"
|
||||
)
|
||||
|
||||
REM Pad single digits with leading zeros
|
||||
set "day=0!day!"
|
||||
set "month=0!month!"
|
||||
set "hour=0!hour!"
|
||||
set "minute=0!minute!"
|
||||
REM Format the date and time
|
||||
set "formatted_date=%year%-%month%-%day%_%hour%-%minute%"
|
||||
|
||||
set "formatted_date=%month:~-2%-%day:~-2%-%year%_%hour:~-2%%minute:~-2%"
|
||||
REM Determine the backup file name
|
||||
if "%use_custom_name%"=="Y" (
|
||||
set "backup_filename=st_backup_%custom_name%.7z"
|
||||
) else (
|
||||
set "backup_filename=st_backup_%formatted_date%.7z"
|
||||
)
|
||||
|
||||
REM Rename the backup file with the formatted date and time
|
||||
rename "%st_backup_path%\backup_.7z" "backup_%formatted_date%.7z"
|
||||
REM Create a backup using 7zip
|
||||
7z a "%st_backup_path%\%backup_filename%" "%st_install_path%\data\%selected_user_folder%\*"
|
||||
|
||||
endlocal
|
||||
echo %green_fg_strong%Backup created at %st_backup_path%\%backup_filename%%reset%
|
||||
|
||||
|
||||
echo %green_fg_strong%Backup created at %st_backup_path%%reset%
|
||||
pause
|
||||
endlocal
|
||||
|
||||
@@ -97,4 +105,4 @@ if "%caller%"=="home" (
|
||||
exit /b 1
|
||||
) else (
|
||||
exit /b 0
|
||||
)
|
||||
)
|
||||
|
||||
@@ -9,7 +9,7 @@ echo =========================
|
||||
setlocal enabledelayedexpansion
|
||||
set "backup_count=0"
|
||||
|
||||
for %%F in ("%st_backup_path%\backup_*.7z") do (
|
||||
for %%F in ("%st_backup_path%\st_backup_*.7z") do (
|
||||
set /a "backup_count+=1"
|
||||
set "backup_files[!backup_count!]=%%~nF"
|
||||
echo !backup_count!. %cyan_fg_strong%%%~nF%reset%
|
||||
|
||||
Reference in New Issue
Block a user