Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @echo off
- REM : ------------------------------------------------------------------
- REM : main
- setlocal enabledelayedexpansion
- set "THIS_SCRIPT=%~0"
- REM : checking THIS_SCRIPT path
- call:checkPathForDos "!THIS_SCRIPT!" > NUL 2>&1
- set /A "cr=!ERRORLEVEL!"
- if !cr! NEQ 0 (
- echo ERROR ^: Remove DOS reserved characters from the path "!THIS_SCRIPT!" ^(such as ^&^, %% or ^^!^)^, cr=!cr!
- pause
- exit 1
- )
- REM : parent directory of script
- pushd "%~dp0" >NUL && set "BFW_TOOLS_PATH="!CD!"" && popd >NUL
- for %%a in (!BFW_TOOLS_PATH!) do set "basename="%%~dpa""
- set "BFW_PATH=!basename:~0,-2!""
- set "logFile="!BFW_PATH:"=!\logs\Host_!USERDOMAIN!.log""
- REM : set current char codeset
- call:setCharSetAndLocale
- REM : cd to BFW_TOOLS_PATH
- pushd !BFW_TOOLS_PATH!
- REM : get current date
- for /F "usebackq tokens=1,2 delims==" %%i in (`wmic os get LocalDateTime /VALUE 2^>NUL`) do if '.%%i.'=='.LocalDateTime.' set "ldt=%%j"
- set "ldt=%ldt:~0,4%-%ldt:~4,2%-%ldt:~6,2%_%ldt:~8,2%-%ldt:~10,2%-%ldt:~12,6%"
- set "DATE=%ldt%"
- REM : search your current GLCache
- REM : check last path saved in log file
- REM : search in logFile, getting only the last occurence
- set "OPENGL_CACHE="NOT_FOUND""
- for /F "tokens=2 delims=~=" %%i in ('type !logFile! ^| find /I "OPENGL_CACHE" 2^>NUL') do set "OPENGL_CACHE=%%i"
- if not [!OPENGL_CACHE!] == ["NOT_FOUND"] if exist !OPENGL_CACHE! goto:glCacheFound
- REM : else search it
- pushd "%USERPROFILE%\AppData"
- for /F "delims=" %%x in ('dir /b /o:n /a:d /s GLCache 2^>NUL') do set "OPENGL_CACHE="%%x""
- pushd !BFW_TOOLS_PATH!
- if [!OPENGL_CACHE!] == ["NOT_FOUND"] (
- @echo Unable to find your GPU GLCache folder ^? cancelling
- goto:eof
- )
- REM : save path to log file
- set "msg="OPENGL_CACHE=!OPENGL_CACHE!""
- call:log2HostFile !msg!
- REM : openGL cache location
- :glCacheFound
- choice /C y /T 4 /D y /N /M "Flush !OPENGL_CACHE:"=! ? (y/n : yes by default in 4s)"
- if %ERRORLEVEL% EQU 2 (
- choice /C y /T 2 /D y /N /M "> Cancelled by user, exiting in 2s"
- goto:endScript
- )
- rmdir /Q /S !OPENGL_CACHE! > NUL
- mkdir !OPENGL_CACHE! > NUL
- @echo ^> !OPENGL_CACHE:"=! was cleared ^!
- :log
- set "msg="!DATE!-!USERNAME! empty GPU OpenGL cache=!OPENGL_CACHE:"=!""
- call:log2HostFile !msg!
- timeout /T 3 > NUL
- :endScript
- endlocal
- exit /b 0
- goto:eof
- REM : ------------------------------------------------------------------
- REM : ------------------------------------------------------------------
- REM : functions
- REM : function to get char set code for current host
- :setCharSetAndLocale
- REM : get charset code for current HOST
- set "CHARSET=NOT_FOUND"
- for /F "tokens=2 delims==" %%f in ('wmic os get codeset /value ^| find "="') do set "CHARSET=%%f"
- if ["%CHARSET%"] == ["NOT_FOUND"] (
- @echo Host char codeSet not found ^?^, exiting 1
- pause
- exit /b 9
- )
- REM : set char code set, output to host log file
- chcp %CHARSET% > NUL
- call:log2HostFile "charCodeSet=%CHARSET%"
- REM : get locale for current HOST
- set "L0CALE_CODE=NOT_FOUND"
- for /F "tokens=2 delims==" %%f in ('wmic path Win32_OperatingSystem get Locale /value ^| find "="') do set "L0CALE_CODE=%%f"
- REM : set YES/NO according to locale (used to protect cmd windows when closing then with mouse)
- REM : default = ENG
- set "yes=y"
- set "no=n"
- if ["%L0CALE_CODE%"] == ["0407"] (
- REM : locale = GER
- set "yes=j"
- set "no=n"
- )
- if ["%L0CALE_CODE%"] == ["0C0a"] (
- REM : locale = SPA
- set "yes=s"
- set "no=n"
- )
- if ["%L0CALE_CODE%"] == ["040c"] (
- REM : locale = FRA
- set "yes=o"
- set "no=n"
- )
- goto:eof
- REM : ------------------------------------------------------------------
- :checkPathForDos
- set "toCheck=%1"
- REM : if implicit expansion failed (when calling this script)
- if ["!toCheck!"] == [""] (
- @echo Remove specials characters from %1 ^(such as ^&,^(,^),^!^)^, exiting 13
- exit /b 13
- )
- REM : try to resolve
- if not exist !toCheck! (
- @echo This path ^(!toCheck!^) is not compatible with DOS^. Remove specials characters from this path ^(such as ^&,^(,^),^!^)^, exiting 11
- exit /b 11
- )
- REM : try to list
- dir !toCheck! > NUL
- if !ERRORLEVEL! NEQ 0 (
- @echo This path ^(!toCheck!^) is not compatible with DOS^. Remove specials characters from this path ^(such as ^&,^(,^),^!^)^, exiting 12
- exit /b 12
- )
- exit /b 0
- goto:eof
- REM : ------------------------------------------------------------------
- REM : function to log info for current host
- :log2HostFile
- REM : arg1 = msg
- set "msg=%~1"
- if not exist !logFile! (
- set "logFolder="!BFW_PATH:"=!\logs""
- if not exist !logFolder! mkdir !logFolder! > NUL
- goto:logMsg2HostFile
- )
- REM : check if the message is not already entierely present
- for /F %%i in ('type !logFile! ^| find /I "!msg!"') do goto:eof
- :logMsg2HostFile
- echo !msg!>> !logFile!
- goto:eof
- REM : ------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement