#COMPILE EXE "vlcrun.exe" #RESOURCE "vlcrun.pbr" #INCLUDE ONCE "Win32Api.inc" #INCLUDE ONCE "Registry.inc" #INCLUDE ONCE "Ini.inc" GLOBAL g_vlcpath AS STRING GLOBAL g_inifile AS STRING '------------------------------------------------------------------------------------------- SUB AutoDetectVlc() LOCAL e AS STRING ' Get VLC path from registry LET g_vlcpath = GETREGVALUE(%HKEY_LOCAL_MACHINE, "SOFTWARE\VideoLAN\VLC", "") IF g_vlcpath <> "" THEN EXIT SUB ' Not found in default key > try another key LET g_vlcpath = GETREGVALUE(%HKEY_LOCAL_MACHINE, "SOFTWARE\VideoLAN\VLC", "InstallDir") IF g_vlcpath <> "" THEN g_vlcpath += "\vlc.exe" : EXIT SUB ' Not found via registry > try a manual method g_vlcpath = "C:\Program Files (x86)\VideoLAN\VLC\" e = DIR$(g_vlcpath + "vlc.exe") : DIR$ CLOSE IF e <> "" THEN g_vlcpath += e : EXIT SUB ' Last attempt... g_vlcpath = "C:\Program Files\VideoLAN\VLC\" e = DIR$(g_vlcpath + "vlc.exe") : DIR$ CLOSE IF e <> "" THEN g_vlcpath += e : EXIT SUB ' Definitely not found :( g_vlcpath = "" END SUB '------------------------------------------------------------------------------------------- '------------------------------------------------------------------------------------------- FUNCTION PBMAIN () AS LONG ' Set path to ini file g_inifile = EXE.PATH$ + "vlcrun.ini" ' First time launch IF NOT EXISTS(g_inifile) THEN IF MSGBOX("This is your first time launching this program."+$CR+$CR _ +"Do you want to auto-detect VLC Media Player on your system?" _ ,%MB_ICONQUESTION OR %MB_YESNO, "vlcrun") = %IDYES THEN AutoDetectVlc() END IF WriteIni() END IF ' Get VLC path from ini file ReadIni() IF g_vlcpath = "" OR NOT EXISTS(g_vlcpath) THEN MSGBOX "VLC Media Player not found."+$CR+$CR _ +"Please manually set the 'vlc.exe' filepath"+$CR _ +"into "+$DQ+g_inifile+$DQ _ ,%MB_ICONINFORMATION, "vlcrun" EXIT FUNCTION END IF IF LCASE$(COMMAND$) = "/hidden" THEN ' Special command to run a hidden instance of vlc to fix perf issue: "vlc.exe /hidden" ShellExecute %NULL, "open", (g_vlcpath), "", "", %SW_SHOWMINNOACTIVE ELSE ' Any other call: run vlc with the requested parameters ShellExecute %NULL, "open", (g_vlcpath), COMMAND$, "", %SW_SHOW END IF END FUNCTION '------------------------------------------------------------------------------------------- '------------------------------------------------------------------------------------------- SUB WriteIni() LOCAL ff AS LONG ff = FREEFILE OPEN g_inifile FOR OUTPUT AS #ff PRINT #ff, "[vlcrun]" PRINT #ff, "# Replace the following with any 'vlc.exe' filepath you want to use:" PRINT #ff, "vlcpath=" + g_vlcpath CLOSE #ff END SUB '------------------------------------------------------------------------------------------- '------------------------------------------------------------------------------------------- SUB ReadIni() g_vlcpath = GetIniS(g_inifile, "vlcrun", "vlcpath") END SUB '------------------------------------------------------------------------------------------- '------------------------------------------------------------------------------------------- FUNCTION EXISTS(BYVAL f AS STRING) AS LONG LOCAL i AS LONG i = GETATTR(f) FUNCTION = (ERRCLEAR = 0) END FUNCTION '-------------------------------------------------------------------------------------------