Advertisement
Guest User

deleteMyGpuCache

a guest
Jan 26th, 2020
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 5.64 KB | None | 0 0
  1. @echo off
  2. REM : ------------------------------------------------------------------
  3. REM : main
  4.  
  5.  
  6.     setlocal enabledelayedexpansion
  7.  
  8.     set "THIS_SCRIPT=%~0"
  9.     REM : checking THIS_SCRIPT path
  10.     call:checkPathForDos "!THIS_SCRIPT!" > NUL 2>&1
  11.     set /A "cr=!ERRORLEVEL!"
  12.     if !cr! NEQ 0 (
  13.         echo ERROR ^: Remove DOS reserved characters from the path "!THIS_SCRIPT!" ^(such as ^&^, %% or ^^!^)^, cr=!cr!
  14.         pause
  15.         exit 1
  16.     )
  17.  
  18.     REM : parent directory of script
  19.     pushd "%~dp0" >NUL && set "BFW_TOOLS_PATH="!CD!"" && popd >NUL
  20.  
  21.     for %%a in (!BFW_TOOLS_PATH!) do set "basename="%%~dpa""
  22.     set "BFW_PATH=!basename:~0,-2!""
  23.  
  24.    set "logFile="!BFW_PATH:"=!\logs\Host_!USERDOMAIN!.log""
  25.    
  26.     REM : set current char codeset
  27.     call:setCharSetAndLocale
  28.  
  29.     REM : cd to BFW_TOOLS_PATH
  30.     pushd !BFW_TOOLS_PATH!
  31.  
  32.     REM : get current date
  33.     for /F "usebackq tokens=1,2 delims==" %%i in (`wmic os get LocalDateTime /VALUE 2^>NUL`) do if '.%%i.'=='.LocalDateTime.' set "ldt=%%j"
  34.     set "ldt=%ldt:~0,4%-%ldt:~4,2%-%ldt:~6,2%_%ldt:~8,2%-%ldt:~10,2%-%ldt:~12,6%"
  35.     set "DATE=%ldt%"
  36.  
  37.     REM : search your current GLCache
  38.     REM : check last path saved in log file
  39.  
  40.     REM : search in logFile, getting only the last occurence
  41.  
  42.     set "OPENGL_CACHE="NOT_FOUND""
  43.     for /F "tokens=2 delims=~=" %%i in ('type !logFile! ^| find /I "OPENGL_CACHE" 2^>NUL') do set "OPENGL_CACHE=%%i"
  44.  
  45.     if not [!OPENGL_CACHE!] == ["NOT_FOUND"] if exist !OPENGL_CACHE! goto:glCacheFound
  46.    
  47.     REM : else search it
  48.     pushd "%USERPROFILE%\AppData"
  49.     for /F "delims=" %%x in ('dir /b /o:n /a:d /s GLCache 2^>NUL') do set "OPENGL_CACHE="%%x""
  50.     pushd !BFW_TOOLS_PATH!
  51.  
  52.     if [!OPENGL_CACHE!] == ["NOT_FOUND"] (
  53.         @echo Unable to find your GPU GLCache folder ^? cancelling
  54.         goto:eof
  55.     )
  56.    
  57.     REM : save path to log file
  58.     set "msg="OPENGL_CACHE=!OPENGL_CACHE!""
  59.     call:log2HostFile !msg!
  60.  
  61.     REM : openGL cache location
  62.     :glCacheFound
  63.     choice /C y /T 4 /D y /N /M "Flush !OPENGL_CACHE:"=! ? (y/n : yes by default in 4s)"
  64.    if %ERRORLEVEL% EQU 2 (
  65.        choice /C y /T 2 /D y /N /M "> Cancelled by user, exiting in 2s"
  66.        goto:endScript
  67.    )
  68.    rmdir /Q /S !OPENGL_CACHE! > NUL
  69.    mkdir !OPENGL_CACHE! > NUL
  70.  
  71.    @echo ^> !OPENGL_CACHE:"=! was cleared ^!
  72.  
  73.     :log
  74.     set "msg="!DATE!-!USERNAME! empty GPU OpenGL cache=!OPENGL_CACHE:"=!""
  75.    call:log2HostFile !msg!
  76.  
  77.    timeout /T 3 > NUL
  78.  
  79.    :endScript
  80.    endlocal
  81.    exit /b 0
  82.  
  83.    goto:eof
  84.  
  85.    REM : ------------------------------------------------------------------
  86.  
  87.  
  88. REM : ------------------------------------------------------------------
  89. REM : functions
  90.  
  91.    REM : function to get char set code for current host
  92.    :setCharSetAndLocale
  93.  
  94.        REM : get charset code for current HOST
  95.        set "CHARSET=NOT_FOUND"
  96.        for /F "tokens=2 delims==" %%f in ('wmic os get codeset /value ^| find "="') do set "CHARSET=%%f"
  97.  
  98.        if ["%CHARSET%"] == ["NOT_FOUND"] (
  99.            @echo Host char codeSet not found ^?^, exiting 1
  100.            pause
  101.            exit /b 9
  102.        )
  103.        REM : set char code set, output to host log file
  104.  
  105.        chcp %CHARSET% > NUL
  106.        call:log2HostFile "charCodeSet=%CHARSET%"
  107.  
  108.        REM : get locale for current HOST
  109.        set "L0CALE_CODE=NOT_FOUND"
  110.        for /F "tokens=2 delims==" %%f in ('wmic path Win32_OperatingSystem get Locale /value ^| find "="') do set "L0CALE_CODE=%%f"
  111.  
  112.        REM : set YES/NO according to locale (used to protect cmd windows when closing then with mouse)
  113.        REM : default = ENG
  114.        set "yes=y"
  115.        set "no=n"
  116.  
  117.        if ["%L0CALE_CODE%"] == ["0407"] (
  118.            REM : locale = GER
  119.            set "yes=j"
  120.            set "no=n"
  121.        )
  122.        if ["%L0CALE_CODE%"] == ["0C0a"] (
  123.            REM : locale = SPA
  124.            set "yes=s"
  125.            set "no=n"
  126.        )
  127.        if ["%L0CALE_CODE%"] == ["040c"] (
  128.            REM : locale = FRA
  129.            set "yes=o"
  130.            set "no=n"
  131.        )
  132.  
  133.    goto:eof
  134.    REM : ------------------------------------------------------------------
  135.  
  136.    :checkPathForDos
  137.  
  138.        set "toCheck=%1"
  139.  
  140.        REM : if implicit expansion failed (when calling this script)
  141.        if ["!toCheck!"] == [""] (
  142.            @echo Remove specials characters from %1 ^(such as ^&,^(,^),^!^)^, exiting 13
  143.            exit /b 13
  144.        )
  145.  
  146.        REM : try to resolve
  147.        if not exist !toCheck! (
  148.            @echo This path ^(!toCheck!^) is not compatible with DOS^. Remove specials characters from this path ^(such as ^&,^(,^),^!^)^, exiting 11
  149.            exit /b 11
  150.        )
  151.  
  152.        REM : try to list
  153.        dir !toCheck! > NUL
  154.        if !ERRORLEVEL! NEQ 0 (
  155.            @echo This path ^(!toCheck!^) is not compatible with DOS^. Remove specials characters from this path ^(such as ^&,^(,^),^!^)^, exiting 12
  156.            exit /b 12
  157.        )
  158.  
  159.        exit /b 0
  160.    goto:eof
  161.    REM : ------------------------------------------------------------------
  162.  
  163.    REM : function to log info for current host
  164.    :log2HostFile
  165.        REM : arg1 = msg
  166.        set "msg=%~1"
  167.  
  168.        if not exist !logFile! (
  169.            set "logFolder="!BFW_PATH:"=!\logs""
  170.             if not exist !logFolder! mkdir !logFolder! > NUL
  171.             goto:logMsg2HostFile
  172.         )
  173.         REM : check if the message is not already entierely present
  174.         for /F %%i in ('type !logFile! ^| find /I "!msg!"') do goto:eof
  175.         :logMsg2HostFile
  176.         echo !msg!>> !logFile!
  177.  
  178.     goto:eof
  179.     REM : ------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement