Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @echo off
- :: ----------------- USER CONFIGURATION ---------------------
- set WINRAR_PATH="C:\Program Files\WinRAR\WinRAR.exe"
- set PACKAGE_EXT=.xpi
- :: ----------------------------------------------------------
- :: PROGRAM CONFIGURATION
- title Package builder
- set package_name=package%PACKAGE_EXT%
- set package_file="%CD%\%package_name%"
- set package_path=%~1
- set package_content=
- :: INITIALIZE COLORS
- for /F "tokens=1,2 delims=#" %%a in ('"prompt #$H#$E# & echo on & for %%b in (1) do rem"') do (set "DEL=%%a")
- :: CHECK IF PATH TO WINRAR IS SET
- :check_winrar_path
- if defined WINRAR_PATH goto check_package_ext
- :: GET PATH TO WINRAR FROM USER INPUT
- :get_winrar_path
- set /p WINRAR_PATH=Path to WinRAR (WinRAR.exe):
- :: IF NOTHING IS GIVEN, ASK AGAIN
- if not defined WINRAR_PATH (
- call :colorText 04 "Path not defined!"
- goto get_winrar_path
- )
- :: IF PATH DOESN'T EXIST, ASK AGAIN
- if not exist WINRAR_PATH (
- call :colorText 04 "Path not found!"
- goto get_winrar_path
- )
- :: CHECK IF EXTENSION IS SET
- :check_package_ext
- if defined PACKAGE_EXT goto check_package_path
- :: GET EXTENSION FROM USER INPUT
- :get_package_ext
- set /p PACKAGE_EXT=Package extension (.zip, .jar, .xpi etc.):
- :: IF NOTHING IS GIVEN, ASK AGAIN
- if not defined PACKAGE_EXT (
- call :colorText 04 "Extension not defined!"
- goto get_package_ext
- )
- :: CHECK IF PATH TO PACKAGE IS SET
- :check_package_path
- if defined package_path goto get_package_name
- :: GET PATH TO PACKAGE FROM USER INPUT
- :get_package_path
- set /p package_path=Build a package from path:
- :: IF NOTHING IS GIVEN, ASK AGAIN
- if not defined package_path (
- call :colorText 04 "Path not defined!"
- goto get_package_path
- )
- :: IF PATH DOESN'T EXIST, ASK AGAIN
- if not exist %package_path% (
- call :colorText 04 "Path not found!"
- goto get_package_path
- )
- set package_path=%package_path:"=%
- :: GET PACKAGE NAME
- :get_package_name
- set tmp=%package_path%
- :: LOOP PATH TO GET NAME
- :_loop
- for /f "tokens=1* delims=\" %%A in ( "%tmp%" ) do (
- set package_name=%%A
- set tmp=%%B
- goto _loop
- )
- :: IF PACKAGE NAME IS SET, UPDATE FILE PATH
- if defined package_name if not "%package_name:"=%"=="" (
- set package_file="%CD%\%package_name%%PACKAGE_EXT%"
- )
- echo Building package "%package_name%%PACKAGE_EXT%" ...
- :: LOOP FOR EVERY FILE AND FOLDER
- for /f "tokens=*" %%f in ('dir "%package_path%" /A:D /B 2^> nul') do call set "package_content=%%package_content%%"%package_path%\%%f" "
- for /f "tokens=*" %%f in ('dir "%package_path%" /A:-D /B 2^> nul') do call set "package_content=%%package_content%%"%package_path%\%%f" "
- :: DELETE EXISTING FILE
- if not defined package_content goto fail
- if exist %package_file% del %package_file%
- :: BUILD PACKAGE
- %WINRAR_PATH% a -r -ep1 -ibck -inul -afzip -m5 %package_file% %package_content% > nul || goto fail
- call :colorText 02 "Building done!"
- timeout 1 > nul
- goto end
- :: FAIL LABEL
- :fail
- if %ERRORLEVEL% EQU 0 (
- call :colorText 04 "Building failed for unknown reason!"
- ) else (
- call :colorText 04 "Building failed with error code %ERRORLEVEL%!"
- )
- echo.
- pause
- goto end
- :: LABEL FOR COLORS
- :colorText
- <nul set /p ".=%DEL%" > "%~2"
- findstr /v /a:%1 /R "^$" "%~2" nul
- del "%~2" > nul 2>&1i
- echo.
- goto :eof
- :: PROGRAM END
- :end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement