@ECHO OFF
SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION
COLOR 0A
TITLE CREATE 7-Zip ARCHIVE OF ALL FILES INSIDE THE SCRIPT DIRECTORY

:---------------------------------------------------------------------------------------------------

PUSHD "%~dp0"
IF NOT "%1"=="MAX" START /MAX CMD /D /C %0 MAX & GOTO :EOF

:---------------------------------------------------------------------------------------------------

REM SAVE PARENT FOLDER FULL PATH IN SAVEDIR
FOR /F "TOKENS=*" %%G IN ("%~dp0") DO SET "SAVEDIR=%%G"
REM REMOVE TRAILING BACKSLASH FROM SAVEDIR
IF "!SAVEDIR:~-1!"=="\" SET "SAVEDIR=!SAVEDIR:~0,-1!"
REM SAVE FULL PARENT PATH WITHOUT THE TRAILING BACKSLASH
FOR /F "TOKENS=*" %%H IN ("!SAVEDIR!") DO SET "SAVEDIR=%%~nH"

REM MASTER PResetS
SET "ARCHIVE_TYPE=7z"
SET "COMPRESSION=9"
SET "FAST_BYTES=273"
SET "SOLID_BLOCK=-ms"
SET "DICTIONARY1=31"
SET "ANALYSIS=9"
SET "MOD_TIME=-"
SET "THREADS=-mmt"
SET "THREADS_FILTER=-mmtf"
SET "DICTIONARY2=1536m"
SET "MATCH_FINDER=bt3"
SET "CYCLES=10000"
SET "POS_BITS=0"
SET "LITERAL_CONTEXT_BITS=0"
SET "STOP_ON_FAIL=-sse"
SET "EXCLUDED=%~nx0"
SET "SHOW_OUTPUT=-bsp2"
SET "DELETE_FILES=-sdel"

REM SET INPUT AND OUTPUT FILE PATHS
SET "SEVENZIP=!ProgramFiles!\7-Zip\7z.exe"
SET "FIN=.\*"
SET "FOUT=%CD%\!SAVEDIR!.!ARCHIVE_TYPE!"

:---------------------------------------------------------------------------------------------------

REM PROMPT USER CHOICES
CLS & ECHO=
ECHO VERIFY COMMAND-LINE BEFORE CONTINUING: & ECHO=
ECHO=
ECHO [1] CREATE ARCHIVE: !SAVEDIR!.!ARCHIVE_TYPE!
ECHO [2] EXIT & ECHO=

REM ECHO COMMAND LINE TO VERIFY BEFORE EXECUTING
ECHO "!SEVENZIP!" a -y -t!ARCHIVE_TYPE! -mx=!COMPRESSION! -mfb=!FAST_BYTES! !SOLID_BLOCK! -md=!DICTIONARY1! -myx=!ANALYSIS! -mtm=!MOD_TIME! !THREADS! !THREADS_FILTER! -md=!DICTIONARY2! -mmf=!MATCH_FINDER! -mmc=!CYCLES! -mpb=!POS_BITS! -mlc=!LITERAL_CONTEXT_BITS! !STOP_ON_FAIL! -xr^^!!!EXCLUDED! !SHOW_OUTPUT! !DELETE_FILES! "!FOUT!" "!FIN!" & ECHO=

CHOICE /C 12 /N /M "CHOOSE A NUMBER: " & CLS & ECHO=

IF ERRORLEVEL 2 GOTO :EOF

IF ERRORLEVEL 1 (
	"!SEVENZIP!" a -y -t!ARCHIVE_TYPE! -mx=!COMPRESSION! -mfb=!FAST_BYTES! !SOLID_BLOCK! -md=!DICTIONARY1! -myx=!ANALYSIS! -mtm=!MOD_TIME! !THREADS! !THREADS_FILTER! -md=!DICTIONARY2! -mmf=!MATCH_FINDER! -mmc=!CYCLES! -mpb=!POS_BITS! -mlc=!LITERAL_CONTEXT_BITS! !STOP_ON_FAIL! -xr^^!!!EXCLUDED! !SHOW_OUTPUT! !DELETE_FILES! "!FOUT!" "!FIN!"
)

:---------------------------------------------------------------------------------------------------

ECHO=
PAUSE
