diff --git a/batchr.bat b/batchr.bat index 72f7646..2e919e1 100644 --- a/batchr.bat +++ b/batchr.bat @@ -6,7 +6,7 @@ REM Author: Flamur Veliqi (Netbie) setlocal enabledelayedexpansion -:MENU +:MAIN_MENU cls echo Batchr Menu Launcher echo. @@ -19,16 +19,57 @@ echo Author: Flamur Veliqi (Netbie) echo. echo ////////////////////////////////////////////////// echo. -echo Scanning /files directory... +echo Select script category: +echo. +echo [1] Own Scripts (from /files) +echo [2] Third-Party Scripts (from /files/third_party) +echo [0] Exit +echo. +echo ////////////////////////////////////////////////// +echo. +set /p CATEGORY="Select option: " + +if "%CATEGORY%"=="0" goto EXIT +if "%CATEGORY%"=="1" ( + set "SCRIPT_PATH=files" + set "API_PATH=files" + set "CATEGORY_NAME=Own Scripts" + goto MENU +) +if "%CATEGORY%"=="2" ( + set "SCRIPT_PATH=files/third_party" + set "API_PATH=files/third_party" + set "CATEGORY_NAME=Third-Party Scripts" + goto MENU +) + +echo Invalid selection! +timeout /t 2 >nul +goto MAIN_MENU + +:MENU +cls +echo Batchr Menu Launcher - !CATEGORY_NAME! +echo. +echo Powered by Weektab +echo Web: www.weektab.org +echo E-Mail: support@weektab.org +echo Project: Companas +echo Repository: git.weektab.org/companas/batchr +echo Author: Flamur Veliqi (Netbie) +echo. +echo ////////////////////////////////////////////////// +echo. +echo Scanning /!SCRIPT_PATH! directory... echo. -REM Use Gitea API to list files in /files directory -powershell -Command "$ProgressPreference = 'SilentlyContinue'; try { $response = Invoke-RestMethod -Uri 'https://git.weektab.org/api/v1/repos/companas/batchr/contents/files'; $batFiles = $response | Where-Object { $_.name -like '*.bat' } | Select-Object -ExpandProperty name | Sort-Object; if ($batFiles) { $batFiles | Out-File '%TEMP%\repo_scripts.txt' -Encoding ASCII -NoNewline:$false } else { 'NONE' | Out-File '%TEMP%\repo_scripts.txt' -Encoding ASCII } } catch { 'ERROR' | Out-File '%TEMP%\repo_scripts.txt' -Encoding ASCII }" 2>nul +REM Use Gitea API to list files in selected directory +powershell -Command "$ProgressPreference = 'SilentlyContinue'; try { $response = Invoke-RestMethod -Uri 'https://git.weektab.org/api/v1/repos/companas/batchr/contents/!API_PATH!'; $batFiles = $response | Where-Object { $_.name -like '*.bat' } | Select-Object -ExpandProperty name | Sort-Object; if ($batFiles) { $batFiles | Out-File '%TEMP%\repo_scripts.txt' -Encoding ASCII -NoNewline:$false } else { 'NONE' | Out-File '%TEMP%\repo_scripts.txt' -Encoding ASCII } } catch { 'ERROR' | Out-File '%TEMP%\repo_scripts.txt' -Encoding ASCII }" 2>nul if not exist "%TEMP%\repo_scripts.txt" ( echo ERROR: Unable to access repository API pause - exit /b 1 + goto MAIN_MENU ) REM Check for errors @@ -42,19 +83,19 @@ for /f "delims=" %%a in (%TEMP%\repo_scripts.txt) do ( if "%FIRST_LINE%"=="ERROR" ( echo ERROR: API request failed pause - exit /b 1 + goto MAIN_MENU ) if "%FIRST_LINE%"=="NONE" ( - echo No .bat files found in /files directory! + echo No .bat files found in /!SCRIPT_PATH! directory! pause - exit /b 1 + goto MAIN_MENU ) REM Get all script titles in one PowerShell call echo Extracting list... echo. -powershell -Command "$ProgressPreference = 'SilentlyContinue'; try { $files = Get-Content '%TEMP%\repo_scripts.txt'; $results = @(); foreach ($file in $files) { if ($file -and $file -ne '' -and $file -ne 'NONE' -and $file -ne 'ERROR') { try { $url = 'https://git.weektab.org/companas/batchr/raw/branch/main/files/' + $file; $content = (Invoke-WebRequest -Uri $url -UseBasicParsing).Content; if ($content -match 'REM\s*===\s*(.+?)\s*===') { $results += $file + '|' + $matches[1] } else { $results += $file + '|' } } catch { $results += $file + '|' } } }; $results | Out-File '%TEMP%\repo_titles.txt' -Encoding ASCII } catch { }" 2>nul +powershell -Command "$ProgressPreference = 'SilentlyContinue'; try { $files = Get-Content '%TEMP%\repo_scripts.txt'; $results = @(); foreach ($file in $files) { if ($file -and $file -ne '' -and $file -ne 'NONE' -and $file -ne 'ERROR') { try { $url = 'https://git.weektab.org/companas/batchr/raw/branch/main/!SCRIPT_PATH!/' + $file; $content = (Invoke-WebRequest -Uri $url -UseBasicParsing).Content; if ($content -match 'REM\s*===\s*(.+?)\s*===') { $results += $file + '|' + $matches[1] } else { $results += $file + '|' } } catch { $results += $file + '|' } } }; $results | Out-File '%TEMP%\repo_titles.txt' -Encoding ASCII } catch { }" 2>nul REM Display menu set INDEX=0 @@ -83,11 +124,12 @@ set TOTAL_SCRIPTS=%INDEX% if %TOTAL_SCRIPTS%==0 ( echo No .bat files found! pause - exit /b 1 + goto MAIN_MENU ) echo. echo [R] Refresh List +echo [B] Back to Category Selection echo [0] Exit echo. echo ////////////////////////////////////////////////// @@ -95,6 +137,7 @@ echo. set /p CHOICE="Select option: " if /i "%CHOICE%"=="R" goto MENU +if /i "%CHOICE%"=="B" goto MAIN_MENU if "%CHOICE%"=="0" goto EXIT REM Validate selection @@ -114,7 +157,7 @@ cls echo /// Executing: !DISPLAY[%CHOICE%]! echo. -set "SCRIPT_URL=https://git.weektab.org/companas/batchr/raw/branch/main/files/!SCRIPT_NAME[%CHOICE%]!" +set "SCRIPT_URL=https://git.weektab.org/companas/batchr/raw/branch/main/!SCRIPT_PATH!/!SCRIPT_NAME[%CHOICE%]!" set "TEMP_SCRIPT=%TEMP%\batch_script_%RANDOM%.bat" echo Downloading script... diff --git a/files/mas.bat b/third_party/mas.bat similarity index 100% rename from files/mas.bat rename to third_party/mas.bat