@echo off

set TOOLS=%SystemDrive%\tools
set ARG1=null

IF "%~1" NEQ "" set ARG1=%1
if /I %ARG1% == /? goto usage

echo ####### %0 #######

set AKA=irfanview
set BINARY="%PROGRAMFILES%\IrfanView\i_view64.exe"
set SUFFIX=acr ani b3d bmp dib clp crw cr2 cr3 cur dcm ima dcx dds djvu iw44 dxf ^
           ecw emf eps ps exr g3 gif hdp jxr wdp heic ico iff lbm jls jp2 jpc j2k ^
           jpg jpeg jpe jpm mng jng pbm pcd pcx pgm png ppm psd psp ras sun raw rle ^
           sff sgi rgb sid tga tif tiff wbmp webp wmf xbm xpm swf flv ttf asf avi ^
           mpg mpe mpeg mov wmv aif mid rmi mp3 ogg au snd wav wma
call :SFTA

set AKA=SumatraPDF
set BINARY="%TOOLS%\SumatraPDF.exe"
set SUFFIX=pdf epub mobi fb2 fb2z pdb tcr cbz cbr cbt cb7 djv djvu chm xps oxps xod 
call :SFTA

set AKA=Presentations
set BINARY="%PROGRAMFILES%\Softmaker Office 2021\Presentations.exe"
set SUFFIX=prdx prsx prvx ppt pptx potx pot ppsx pps prd prv
call :SFTA

set AKA=PlanMaker
set BINARY="%PROGRAMFILES%\Softmaker Office 2021\Planmaker.exe"
set SUFFIX=pmd pmdx pmv pmvx xls xlsx xlsm xlt xltx xltm
call :SFTA

set AKA=TextMaker
set BINARY="%PROGRAMFILES%\Softmaker Office 2021\Textmaker.exe"
set SUFFIX=doc docx dot dotx odt tmd tmdx tmv tmvx rtf psw pwd
call :SFTA

set AKA=PureBasic
set BINARY="%PROGRAMFILES%\PureBasic\PureBasic.exe"
set SUFFIX=pb pbi pbp pbf
call :SFTA

set AKA=emClient
set BINARY="%PROGRAMFILES(x86)%\eM Client\MailClient.exe"
set SUFFIX=eml
call :SFTA

set AKA=VScode
set BINARY="%PROGRAMFILES%\Microsoft VS Code\Code.exe"
set SUFFIX=c md sh bash py go
call :SFTA

set AKA=VLC
set BINARY="%PROGRAMFILES%\VideoLAN\VLC\vlc.exe"
set SUFFIX=3g2 3gp 3gp2 3gpp amv asf avi bik divx drc dv dvr-ms evo f4v flv gvi gxf m1v m2t m2ts m4v mkv mov ^
           mp2 mp2v mp4 mp4v mpe mpeg mpeg1 mpeg2 mpeg4 mpg mpv2 mts mtv mxf mxg nsv nuv ogg ogm ogv ogx ^
           rec rm rmvb rpl thp tod tp ts tts txd vob vro webm 3ga 669 a52 aac ac3 adt adts aif aifc aiff amb ^
           amr aob ape au awb caf dts flac it kar m4a m4b m4p m5p mid mka mlp mod mpa mp1 mp3 mpc mpga mus oga ^
           oma opus qcp ra rmi s3m sid spx tak thd tta voc vqf w64 wav wma wv xa xm asx b4s cue ifo m3u m3u8 ^
           pls sdp vlc xspf wvx
call :SFTA


set AKA=Python
set BINARY="%PROGRAMFILES%\Python39\python.exe"
set SUFFIX=py
call :SFTA

rem refresh desktop (W10 style)
ie4uinit.exe -show

echo ####### %0 #######
goto END

rem ####################################################
rem set filetypes with tool "sfta" ...

:SFTA
set FILETYPE_DONE="%LOCALAPPDATA%\.filetype_done.%AKA%"

if NOT EXIST %BINARY% (
  echo INFO: [ %BINARY% ] is not installed.
  goto :eof
) else (
  echo working on [ %AKA% ] ...
)

rem use the FORCE Luke!
if /I %ARG1% == /F (
  del /F /Q %FILETYPE_DONE% 2>nul
)

rem do the work HERE!
if NOT EXIST %FILETYPE_DONE% (
  for %%A in (
    %SUFFIX%
  ) do (
    echo registering file type [ .%%A ] for [ %AKA% ]...
    sfta --reg %BINARY% .%%A
  )
  rem create a statusfile ...
  echo 1 >%FILETYPE_DONE%
)

goto :eof
rem ####################################################

:USAGE
echo.
echo "usage: %0 [/F|/?]"
echo "  /F = force    "
echo "  /? = show help"
echo.

:END

