@echo off&set FileName=%~n0&shift :: ============================================= :: AutoHelp PlugLab Concept: 2006 by Reatogo :: ============================================= :: Help Info: :: ======================= set Routine_Type=3 :: 1=Getting Data 2=Prompts 3=Getting Files 4=Creating Files 5=General set Routine_Vers=1 set Routine_Date=2007-02-15 set RoutineName=Extract set RoutineAuthor=Siegfried set Using_work_from= set Example_call_1=%%Extract%% "wun" "aawsepersonal.exe" "TargetFolderHERE" "InnerFolderHERE" "keep" "CheckFileHERE" set Example_call_2= set Example_call_3= set text_01=Universal extraction routine for various formats. set text_02=. set text_03=Param 1 specifies the extractor: set text_04=cab, unzip, 7za, urar, wun, ewise, innounp, isxunpack set text_05=. set text_06=If no target folder is given as param 3, target is curr. directory set text_07=Param 4 is an inner sub-folder to be removed. set text_08=If param 5 is not "keep", the compressed file will be deleted after extraction. set text_09=The check file in param 6 is a file that must exist in the target set text_10=folder after successful extraction. set text_11=This is only required for auto-detection of the right extractor. set text_12=If no extractor is specified, all extractors will be tried until success. set text_13=The successful extractor is then stored in FUNCs\EXTRACT.ini set text_14=and used in that plugin in the future for that file. set text_15=. set text_16=NOTE: param 1 is only needed for the extraction of setup-EXEs. set text_17=For zip, rar etc. it is derived from the file extension. set text_18=. set text_19=If the DWLD routine was called right before %%Extract%%, the file to be extracted set text_20=is already specified there and the setting is used in %%Extract%%. Param 2 may be empty then. set text_21=. set text_22=The xDWLD routine automatically calls %%Extract%% and will give normally results with set text_23=only minimal settings. set text_24=. set text_25=Use the "%%Exclude%% - %%ButKeep%%" feature to cleanUp the target folder: set text_26=set Exclude=Lang\*.awl, set text_27=set ButKeep=Lang\%%LANG%%.awl, set text_28=%%Extract%% "wun" "pllangs.exe" "Files" "" "keep" "" set text_29=. set text_30=This will only keep "Files\Lang\german.awl" on a german system. set text_31=The Exclude/ButKeep feature provides a simple way to remove any unwanted files from the target folder. set text_32=Specify any number of exclusions delimited by comma ",". set text_33=%%ButKeep%% can only be used together with %%Exclude%%. It is used to define one or several exceptions for a bulk-exclusion. A typical usage is in the context of language files cleanup. set text_34=. set text_35=The Exclude/ButKeep feature is available for the following routines: set text_36=%%GetFolder%%, %%xDWLD%% and %%Extract%% set Special_Sub_BTN_Frame=yes if "%~1" == "GetHelp" goto :EOF echo.&echo %* :: ============================================= :: Subroutine switch: set _PROC=%~1 if "%~1" == "" ( set _PROC=BATCH_RUN if "%~x2" == ".zip" set _PROC=unzip if "%~x2" == ".ZIP" set _PROC=unzip if "%~x2" == ".rar" set _PROC=unrar if "%~x2" == ".RAR" set _PROC=unrar if "%~x2" == ".7z" set _PROC=7za if "%~x2" == ".7Z" set _PROC=7za if "%~x2" == ".cab" set _PROC=cab if "%~x2" == ".CAB" set _PROC=cab ) shift /1 goto %_PROC% :: ============================================= :: Routines below this point :: ============================================= :BATCH_RUN :: ============================================= set SCAN_RUN=1 set EXTRACT_FILE=%~1 if "%~1" == "" if not "%DWLD_FILE%" == "" set EXTRACT_FILE=%DWLD_FILE% %IniGet% "%FUNCs%\EXTRACT.ini" "EXTRACTOR" "%EXTRACT_FILE%" if "%result%" == "$empty$" goto SCAN_OPTIONS if "%result%" == "$notfound$" goto SCAN_OPTIONS set SCAN_RUN= %EXTRACT% "%result%" "%~1" "%~2" "%~3" "%~4" "%~5" if "%_ERR%" == "0" goto :EOF :SCAN_OPTIONS :: wun ewise innounp isxunpack unzip 7za unrar set extrApp=wun %EXTRACT% "%extrApp%" "%~1" "%~2" "%~3" "%~4" "%~5" if "%_ERR%" == "0" call :SuccessPrompt&goto :EOF set extrApp=ewise %EXTRACT% "%extrApp%" "%~1" "%~2" "%~3" "%~4" "%~5" if "%_ERR%" == "0" call :SuccessPrompt&goto :EOF set extrApp=innounp %EXTRACT% "%extrApp%" "%~1" "%~2" "%~3" "%~4" "%~5" if "%_ERR%" == "0" call :SuccessPrompt&goto :EOF set extrApp=isxunpack %EXTRACT% "%extrApp%" "%~1" "%~2" "%~3" "%~4" "%~5" if "%_ERR%" == "0" call :SuccessPrompt&goto :EOF set extrApp=unzip %EXTRACT% "%extrApp%" "%~1" "%~2" "%~3" "%~4" "%~5" if "%_ERR%" == "0" call :SuccessPrompt&goto :EOF set extrApp=7za %EXTRACT% "%extrApp%" "%~1" "%~2" "%~3" "%~4" "%~5" if "%_ERR%" == "0" call :SuccessPrompt&goto :EOF set extrApp=unrar %EXTRACT% "%extrApp%" "%~1" "%~2" "%~3" "%~4" "%~5" if "%_ERR%" == "0" call :SuccessPrompt&goto :EOF set extrApp=cab %EXTRACT% "%extrApp%" "%~1" "%~2" "%~3" "%~4" "%~5" if "%_ERR%" == "0" call :SuccessPrompt&goto :EOF call :EXTRACT_FAILED_PROMPT goto :EOF :: ============================================= :CAB :UNZIP :7ZA :UNRAR :WUN :EWISE :INNOUNP :ISXUNPACK :: ============================================= :: example call: :: %EXTRACT% "wun" "aawsepersonal.exe" "Files" "InnerFolderHERE" "keep" "CheckFileHERE" :: Note: 3rd parameter is an "inner sub-folder" to be corrected :: if parameter 4 is not "keep", the compressed file will be deleted after extraction :: ============================================= set EXTRACT_FILE=%~1 if "%~1" == "" if not "%DWLD_FILE%" == "" set EXTRACT_FILE=%DWLD_FILE% set CheckFile=%~5 if not "%~3" == "" if not "%CheckFile%" == "" set CheckFile=%~3\%CheckFile% if not exist "%EXTRACT_FILE%" call :EXTR_FILE_MISSING&goto :EOF set EXTRACT_TARGET=&set EXTRACT_TARGET_SUB= set EXTRACT_TARGET_SUB="%~n1" if "%~2" == "" ( set EXTRACT_TARGET="%CD%" ) else ( if not exist "%~2" md "%~2" set EXTRACT_TARGET="%~2" ) if exist tempWiz rd tempWiz /s /q call :***%_PROC% if "%_ERR%" == "1" goto :EOF if not "%~3" == "" set INNER_FOLDER=%~3&call :CORRECT_INNER_FOLDER if not "%~4" == "keep" if exist "%EXTRACT_FILE%" del "%EXTRACT_FILE%" if "%SCAN_RUN%" == "1" if "%_ERR%" == "2" call :UN_CHECKED_PROMPT :: Remove quotes for exclude routine set TargetCopyDir=%EXTRACT_TARGET:~1,-1% set EXTRACT_TARGET=&set EXTRACT_TARGET_SUB= :: Preserve the %ButKeep% files before delete the excluded files and folders as per %Exclude% variable if "%ButKeep%" == "" goto NoButKeep if not exist ButKeep md ButKeep SETLOCAL ENABLEDELAYEDEXPANSION set cn=1 :tokloop1 for /f "tokens=%cn% delims=," %%i in ("%ButKeep%") do ( if "%%i"=="" goto tokloopDone1 if exist "%TargetCopyDir%\%%i\*.*" ( xcopy "%TargetCopyDir%\%%i\*.*" "ButKeep\%TargetCopyDir%\%%i" /I /E /R /Y /C /H echo Preserve: "%TargetCopyDir%\%%i" ) else ( set folder=%%~dpi set folder=!folder:%CD%\=! if "!folder:~-1!" == "\" set folder=!folder:~0,-1! echo Preserve: "%TargetCopyDir%\%%i" if exist "%TargetCopyDir%\%%i" ( if not exist "ButKeep\%TargetCopyDir%\!folder!" md "ButKeep\%TargetCopyDir%\!folder!" copy "%TargetCopyDir%\%%i" "ButKeep\%TargetCopyDir%\%%i" ) ) set /a cn +=1 goto tokloop1 ) :tokloopDone1 ENDLOCAL :NoButKeep :: delete the excluded files and folders as per %Exclude% variable if "%exclude%" == "" goto tokloopDone2 set cn=1 :tokloop2 for /f "tokens=%cn% delims=," %%a in ("%exclude%") do ( if "%%a"=="" goto tokloopDone2 if exist "%TargetCopyDir%\%%a\*.*" ( rd "%TargetCopyDir%\%%a" /s /q echo Excluding: "%TargetCopyDir%\%%a" ) else ( echo Excluding: "%TargetCopyDir%\%%a" if exist "%TargetCopyDir%\%%a" del "%TargetCopyDir%\%%a" /q ) set /a cn +=1 goto tokloop2 ) :tokloopDone2 :: Copy the "ButKeep items" back in after the cleanup if not "%ButKeep%" == "" ( xcopy "ButKeep\%TargetCopyDir%\*.*" "%TargetCopyDir%" /I /E /R /Y /C /H if exist ButKeep rd ButKeep /s /q ) set TargetCopyDir= set exclude= set ButKeep= goto :EOF :: ============================================= :***CAB :: ============================================= md tempWiz set _ERR=0 expand "%EXTRACT_FILE%" -F:* tempWiz if not exist "tempWiz\%CheckFile%" set _ERR=1&rd "tempWiz" /s /q&goto end_CAB if "%CheckFile%" == "" set _ERR=2 xcopy "tempWiz\*.*" "%EXTRACT_TARGET%\" /I /E /R /Y /C /H rd "tempWiz" /s /q :end_CAB echo CAB: _ERR is "%_ERR%" goto :EOF :: ============================================= :***UNZIP :: ============================================= set _ERR=0 %FINDAPP% "Unzip.exe" "%SharedAPPs%\Unzip.exe" -qq -o "%EXTRACT_FILE%" -d tempWiz if not exist "tempWiz\%CheckFile%" set _ERR=1&rd "tempWiz" /s /q&goto end_UNZIP if "%CheckFile%" == "" set _ERR=2 xcopy "tempWiz\*.*" "%EXTRACT_TARGET%\" /I /E /R /Y /C /H rd "tempWiz" /s /q :end_UNZIP echo UNZIP: _ERR is "%_ERR%" goto :EOF :: ============================================= :***7ZA :: ============================================= set _ERR=0 %FINDAPP% "7za.exe" "%SharedAPPs%\7za.exe" x -y "%EXTRACT_FILE%" -otempWiz if not exist "tempWiz" set _ERR=1&rd "tempWiz" /s /q&goto :end_7ZA if "%CheckFile%" == "" set _ERR=2 xcopy "tempWiz\*.*" "%EXTRACT_TARGET%\" /I /E /R /Y /C /H rd "tempWiz" /s /q :end_7ZA echo 7ZA: _ERR is "%_ERR%" goto :EOF :: ============================================= :***UNRAR :: ============================================= md tempWiz set _ERR=0 %FINDAPP% "unrar.exe" "%SharedAPPs%\unrar.exe" x -y "%EXTRACT_FILE%" *.* tempWiz if not exist "tempWiz\%CheckFile%" set _ERR=1&rd "tempWiz" /s /q&goto end_UNRAR if "%CheckFile%" == "" set _ERR=2 xcopy "tempWiz\*.*" "%EXTRACT_TARGET%\" /I /E /R /Y /C /H rd "tempWiz" /s /q :end_UNRAR echo UNRAR: _ERR is "%_ERR%" goto :EOF :: ============================================= :***WUN :: ============================================= set _ERR=0 %FINDAPP% "WUN.exe" "%SharedAPPs%\WUN.exe" "%EXTRACT_FILE%" tempWiz if not exist "tempWiz\MAINDIR" set _ERR=1&rd "tempWiz" /s /q&goto end_WUN if exist "tempWiz\MAINDIR" ( xcopy "tempWiz\MAINDIR\*.*" "%EXTRACT_TARGET%\" /I /E /R /Y /C /H rd "tempWiz\MAINDIR" /s /q xcopy "tempWiz\*.*" "EXTRA\" /I /E /R /Y /C /H rd tempWiz /s /q ) :end_WUN echo WUN: _ERR is "%_ERR%" goto :EOF :: ============================================= :***EWISE :: ============================================= set _ERR=0 %FINDAPP% "E_WISE.EXE" "%SharedAPPs%\E_WISE.EXE" "%EXTRACT_FILE%" tempWiz if not exist "tempWiz\00000000.BAT" set _ERR=1&rd "tempWiz" /s /q&goto end_EWISE pushd tempWiz call 00000000.BAT rd TEMP /s /q del 00000000.BAT /q del UNINSTALL_PATH /q popd if exist "tempWiz\MAINDIR" ( xcopy "tempWiz\MAINDIR\*.*" "%EXTRACT_TARGET%\" /I /E /R /Y /C /H rd "tempWiz\MAINDIR" /s /q xcopy "tempWiz\*.*" "EXTRA\" /I /E /R /Y /C /H rd tempWiz /s /q ) :end_EWISE echo EWISE: _ERR is "%_ERR%" goto :EOF :: ============================================= :***INNOUNP :: ============================================= set _ERR=0 %FINDAPP% "innounp.exe" "%SharedAPPs%\innounp.exe" -x -dtempWiz %EXTRACT_FILE% if not exist "tempWiz\{app}" set _ERR=1&rd "tempWiz" /s /q&goto end_INNOUNP if exist "tempWiz\{app}" ( xcopy "tempWiz\{app}\*.*" "%EXTRACT_TARGET%\" /I /E /R /Y /C /H rd "tempWiz\{app}" /s /q xcopy "tempWiz\*.*" "EXTRA\" /I /E /R /Y /C /H rd tempWiz /s /q ) :end_INNOUNP echo INNOUNP: _ERR is "%_ERR%" goto :EOF :: ============================================= :***ISXUNPACK :: ============================================= md tempWiz %FINDAPP% "IsXunpack.exe" copy "%EXTRACT_FILE%" "tempWiz\%EXTRACT_FILE%" copy "%SharedAPPs%\IsXunpack.exe" "tempWiz\IsXunpack.exe" set _ERR=0 pushd tempWiz IsXunpack.exe "%EXTRACT_FILE%" del IsXunpack.exe del "%EXTRACT_FILE%" popd if not exist "tempWiz\*.cab" set _ERR=1&rd "tempWiz" /s /q&goto end_ISXUNPACK if exist "tempWiz" ( xcopy "tempWiz\*.*" "%EXTRACT_TARGET%\" /I /E /R /Y /C /H rd tempWiz /s /q ) :end_ISXUNPACK echo ISXUNPACK: _ERR is "%_ERR%" goto :EOF :: ============================================= :CORRECT_INNER_FOLDER :: ============================================= if "%EXTRACT_TARGET%" == "" goto :EOF if "%INNER_FOLDER%" == "" goto :EOF xcopy "%EXTRACT_TARGET%\%INNER_FOLDER%\*.*" "%EXTRACT_TARGET%\" /I /E /R /Y /C /H if exist "%EXTRACT_TARGET%\%INNER_FOLDER%" rd "%EXTRACT_TARGET%\%INNER_FOLDER%" /s /q if exist "%EXTRACT_TARGET%\%EXTRACT_TARGET_SUB%" rd "%EXTRACT_TARGET%\%EXTRACT_TARGET_SUB%" /s /q goto :EOF :: ============================================= :EXTRACT_FAILED_PROMPT :: ============================================= set WAtext=~Extraction failed. set WAtext2=~ set WAtext3=~No suitaqble extactor available. %TEXTBOX% "1" "Extraction failed" "" goto :EOF :: ============================================= :UN_CHECKED_PROMPT :: ============================================= set WAtext=~You must set a Check File set WAtext2=~ set WAtext3=~Error checking for the %_PROC% routine is only possible if you define a Check File. set WAtext4=~ set WAtext5=~A check file should be the file that must be present in the root of the target folder after a successful extraction. set WAtext6=~ set WAtext7=~The check file is the last parameter in the call. %TEXTBOX% "1" "Set a Check File" "" goto :EOF :: ============================================= :SuccessPrompt :: ============================================= set WAtext=~Extraction successful ... set WAtext2=~ set WAtext3=~EXTRACTED: %EXTRACT_FILE% set WAtext4=~ set WAtext5=~USING: %extrApp%-Extractor set WAtext6=~ set WAtext7=~The setting has been stored in FUNCs\EXTRACT.ini set WAtext8=~and will be used in the future without this prompt. %TEXTBOX% "1" "Extraction successful" "" %IniSet% "%FUNCs%\EXTRACT.ini" "EXTRACTOR" "%EXTRACT_FILE%" "%extrApp%" goto :EOF :: ============================================= :EXTR_FILE_MISSING :: ============================================= set WAtext=~%~1 missing set WAtext2=~ set WAtext3=~The file %~1 is not present and thus can not be extracted. %TEXTBOX% "1" "%~1 missing" "" goto :EOF :: =============================================