QB64 Phoenix Edition
Testing for program Install routine. Cross Platform Compatible. - Printable Version

+- QB64 Phoenix Edition (https://qb64phoenix.com/forum)
+-- Forum: QB64 Rising (https://qb64phoenix.com/forum/forumdisplay.php?fid=1)
+--- Forum: Code and Stuff (https://qb64phoenix.com/forum/forumdisplay.php?fid=3)
+---- Forum: Help Me! (https://qb64phoenix.com/forum/forumdisplay.php?fid=10)
+---- Thread: Testing for program Install routine. Cross Platform Compatible. (/showthread.php?tid=3689)



Testing for program Install routine. Cross Platform Compatible. - ahenry3068 - 05-13-2025

The following should work on all 3 major platforms   Linux, Windows & MACOS.

I'm hoping for people to test this though.   (I have no way of testing on MAC & Windows is actually
inconvenient (but possible) for me to test)

This little program should check if ffmpeg is installed and IF NOT, should facilitate it's installation.
(No way this is 100% Internet could be down, system might not be ready etc)

But this should be as good as possible.

Comments and results requested and appreciated.

Code: (Select All)

$Console:Only

Dim Shared Slash$
Dim Shared NULL$
Dim Shared CopyCmd$
Dim Shared MoveCmd$
Dim Shared SystemOpen$
Dim Shared HomeDir$


$If WINDOWS Then
    Slash$ = "\"
    NULL$ = "NUL"
    CopyCmd$ = "COPY "
    MoveCmd$ = "MOVE "
    SystemOpen$ = "START "
    HomeDir$=_DIR$("APPDATA")
    HomeDir$=LEFT$(HomeDir$,(LEN(HomeDir$)-1))
$Else
    Slash$ = "/"
    NULL$ = "/dev/null"
    CopyCmd$ = "cp "
    MoveCmd$ = "mv "
    HomeDir$ = Environ$("HOME")
    $If MAC Then
        SystemOpen$="open "
    $Else
        SystemOpen$ = "xdg-open "
    $End If
$End If

If IsInstalled("ffmpeg") Then
    Print "ffmpeg was found"
Else
    InstallFFMPEG
End If
End

Function IsInstalled% (trycmd$)
    Dim GetInstalled As Integer
    $If WINDOWS Then
      GetInstalled = (shell("where "+trycmd$)=0)
    $Else
        GetInstalled = (Shell("which " + trycmd$) = 0)
    $End If

    IsInstalled = GetInstalled
End Function


Sub InstallFFMPEG
    HomePage$ = "https://www.ffmpeg.org"
    X = _MessageBox("Open FFMPEG Home Page", "Missing ffmpeg or ffprobe." + Chr$(13) + "Do You want to Open the FFMPEG Home Page ?", "yesno", "question", 0)
    If X = 1 Then Shell SystemOpen$ + HomePage$

    $If WINDOWS Then
      J = _MessageBox("Attempt Direct Download of FFMPEG archive ", "Do You want to download Now ?", "yesno", "question", 0)
      if j = 1 then
        X = _MessageBox("Attempt Download of source #1", "Do You want to download from "+CHR$(13)+"https://github.com/BtbN/FFmpeg-Builds/", "yesno", "question", 0)
        If X = 1 then Shell("start  https://github.com/BtbN/FFmpeg-Builds/releases/download/latest/ffmpeg-master-latest-win64-gpl-shared.zip")
        If X = 1 then GOTO EndWinInstall
        X = _MessageBox("Attempt Download of source #2", "Do You want to download from "+CHR$(13)+"https://www.gyan.dev", "yesno", "question", 0)
        If X = 1 then Shell("start https://www.gyan.dev/ffmpeg/builds/packages/ffmpeg-2025-05-07-git-1b643e3f65-essentials_build.7z")
        EndWinInstall:
        GOTO Finish_F_Install
      end if
    $End If

    $If LINUX Then
        If IsInstalled("apt") Then
            X = _MessageBox("Install with apt", "Attempt FFMPEG install with apt ?" + Chr$(13) + "(Must have a visible console Window)", "yesno", "question", 0)
            If X = 1 Then
                Shell ("apt install ffmpeg")
                GoTo FinishFInstall
            End If
        End If
        If IsInstalled("yum") Then
            X = _MessageBox("Install with Yum", "Attempt FFMPEG install with Yum ?" + Chr$(13) + "(Must have a visible console Window)", "yesno", "question", 0)
            If X = 1 Then
                Shell ("yum install ffmpeg")
                GoTo FinishFInstall
            End If
        End If
        If IsInstalled("brew") Then
            X = _MessageBox("Install with Brew", "Attempt FFMPEG install with HomeBrew ?" + Chr$(13) + "(Must have a visible console Window)", "yesno", "question", 0)
            If X = 1 Then
                Shell ("brew install ffmpeg")
                GoTo FinishFInstall
            End If
        End If
    $End If

    $If MAC Then
        If IsInstalled("brew") Then
            X = _MessageBox("Install with Brew", "Attempt FFMPEG install with HomeBrew ?" + Chr$(13) + "(Must have a visible console Window)", "yesno", "question", 0)
            If X = 1 Then
                Shell ("brew install ffmpeg")
                GoTo FinishFInstall
            End If
        End If
    $End If

    FinishFInstall:
    X = _MessageBox("X16 Movie Maker ", "Continue Opening X16 Movie Maker ? " + Chr$(13) + "(If you have installed the FFMPEG package.)", "yesno", "question", 0)
    If X <> 1 Then System
End Sub



RE: Testing for program Install routine. Cross Platform Compatible. - hsiangch_ong - 05-14-2025

this might be good enough on any unix descendant:

Code: (Select All)
if not _fileexists("/usr/bin/the-program") then
'    offer to install "the-program"
end if
unless it's a program that someone preferred to install "locally."  usually his/her home directory.  or less often in "/usr/local/bin".

otherwise i'm not keen about "which" or "find".  could use "stat" instead.  "stat" could always give the user a message.  whether or not the file exists.  dislike "which" giving a stony silence when a file doesn't exist.  must rely then on a created zero-length file and it's one of my peeves on linux.

about opening a web browser to install any program.  that is something to consider carefully.  some people expect "rapid service" and dislike command-line package managers.  some people dislike even more like what manjaro does.  from their site in the web browser.  the appearance is that any program could be installed without any other intervention.  but it has to call "pacman" in the least.  more realistically, it has to summon "pamac".  only on that system.  also the command line to install the program is given, in case it doesn't work in the "convenient" way.

you could add "-y" option to "apt install" so it's done automatically.  (on debian, ubuntu or compatible.)  but also add a warning in the message box, that the system will work to install the program.  this is so there is less chance of the user's confusion.

could also add "pacman" for arch linux and compatible (endeavouros, manjaro, cachyos) but this is a pita.  usually must update repositories first.  it could decide to complain it requires a full system update.  the operating system people recommend a full update if someone needs to install or upgrade one program.  otherwise this should have been good enough:

Code: (Select All)
pacman -Sy ffmpeg
not sure anymore what the package for "ffmpeg" is called on arch.


RE: Testing for program Install routine. Cross Platform Compatible. - hsiangch_ong - 05-14-2025

could one use start terminal command on windows to download a file?  that's peculiar.  then again it might not be the command for "cmd.exe" anymore.


RE: Testing for program Install routine. Cross Platform Compatible. - ahenry3068 - 05-14-2025

(05-14-2025, 04:17 AM)hsiangch_ong Wrote: could one use start terminal command on windows to download a file?  that's peculiar.  then again it might not be the command for "cmd.exe" anymore.

START     works on any file the system can open.   If it's not an executable it opens the program associated with it.    In the case of a URL that is going to be the default browser.


RE: Testing for program Install routine. Cross Platform Compatible. - Ed Davis - 05-15-2025

(05-13-2025, 09:38 PM)ahenry3068 Wrote: The following should work on all 3 major platforms   Linux, Windows & MACOS.

Code: (Select All)

$If WINDOWS Then
    Slash$ = "\"
    NULL$ = "NUL"
    CopyCmd$ = "COPY "
    MoveCmd$ = "MOVE "
    SystemOpen$ = "START "
    HomeDir$=_DIR$("APPDATA")
    HomeDir$=LEFT$(HomeDir$,(LEN(HomeDir$)-1))
$Else
This is very cool!  I greatly appreciate multiplatform stuff.  Thanks for sharing it.

Just a comment - Windows is so goofy.  On my machine, APPDATA is:

C:\Users\Ed\AppData\Roaming

I mean come on, "Roaming"?  Couldn't they have come up with a better name?  And sure enough, tons of things are installed in "Roaming".  
Interestingly, under AppData is Local, LocalLow and Roaming.  Looks like I have lots of applications also installed in Local.  I wish they could make up their minds! Smile

Again, thanks for sharing this!


RE: Testing for program Install routine. Cross Platform Compatible. - bplus - 05-15-2025

You can't even find AppData from the Windows File navigator! They do there best to hide it from users.


RE: Testing for program Install routine. Cross Platform Compatible. - SMcNeill - 05-15-2025

Just click the option to show hidden and system files...


RE: Testing for program Install routine. Cross Platform Compatible. - bplus - 05-15-2025

Good thanks!