Page 1 of 3 123 LastLast
Results 1 to 10 of 25

Thread: Re: Do you need to download pages/files from internet?

  1. #1
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    58
    Posts
    8,886
    Rep Power
    10

    Re: Do you need to download pages/files from internet?

    Here another way I prepared some time ago using just TCP/IP. Mainly the program connect to a web server (in this case thinBasic) searching for a file (in this case a sinple text file) containing the current online version. Than online version is compared with local application version.
    [code=thinbasic] '----------------------------------------------------------------------------
    '----------------------------------------------------------------------------

    USES "FILE" '---Load File module
    USES "TcpUdp"
    USES "CONSOLE"

    '----------------------------------------------------------------------------
    ' Start Main Program
    '----------------------------------------------------------------------------

    dim thinCoreFileName as string = APP_PATH + "thinBasic.exe"
    dim thinCoreLocalVersion as string
    dim thinCoreRemoteVersion as string
    thinCoreLocalVersion = FILE_GetVersionString(thinCoreFileName)


    DIM MyPage AS STRING = "http://www.thinbasic.com/public/prod...ckVersion.txt"
    DIM MySite AS STRING = "www.thinbasic.com"

    DIM sBuffer AS STRING
    DIM sPage AS STRING
    DIM Count AS LONG
    DIM lError AS LONG

    DIM nFile AS LONG = Tcp_FreeFile

    console_WriteLine("Starting connection to " & MySite)
    lError = TCP_Open("http", MySite, nFile)

    IF lError = 0 THEN
    console_WriteLine("Connection established.")
    console_WriteLine("Now starting dowload page: " & MyPage)

    TCP_Print(nFile, "GET " & MyPage & " HTTP/1.0")
    TCP_Print(nFile, "Referer: http://www.thinbasic.com/")
    TCP_Print(nFile, "User-Agent: TCP Checking latest thinBasic version")
    TCP_Print(nFile, "")

    DO
    INCR Count
    sBuffer = TCP_Recv(nFile, 4096)
    sPage = sPage & sBuffer
    console_Write(".")
    LOOP WHILE ((LEN(sBuffer) > 0) AND (ERR = 0))
    Console_WriteLine("")
    Console_WriteLine("Operation finished.")

    Console_WriteLine("Closing connection.")
    TCP_Close(nFile)

    ELSE
    console_WriteLine("An error occur during connection. Error code is: " & lError)
    END IF


    sPage = trim$(sPage)
    if sPage = "" then
    else
    dim StartPos as long value instr(sPage, "[thinCore.dll]")
    dim EndPos as long
    if StartPos <> 0 then
    StartPos += 14
    EndPos = instr(StartPos, sPage, "#")
    thinCoreRemoteVersion = mid$(sPage, StartPos, EndPos - StartPos)
    Console_WriteLine("Local version: " & thinCoreLocalVersion)
    Console_WriteLine("Remote version: " & thinCoreRemoteVersion)
    end if
    end if

    Console_WriteLine("Press any key to finish.")
    Console_WaitKey[/code]

    Icon? For the moment it just means that scripts now will not show old-style general icon but thinBasic one. I think I will add possibility to change icon on the fly during script execution loading an .ico of .bmp file.

    Ciao
    Eros
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  2. #2
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    58
    Posts
    8,886
    Rep Power
    10

    Re: Do you need to download pages/files from internet?

    What about an online repository for TAB adventures files?
    With a download you can get the list to present to the user to download from the web.

    So you can do many things.
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  3. #3
    Senior Member catventure's Avatar
    Join Date
    Oct 2005
    Location
    UK
    Posts
    644
    Rep Power
    85

    Re: Do you need to download pages/files from internet?

    I put a txt file called "tabversion.txt" on to the TAB site containing just the latest version number: "15".

    This code seems to work OK.


    [code=thinbasic]
    USES "INet"
    USES "File"

    dim ret,Retcode as number
    '---current version of TAB (change to lower number to activate updater)
    dim tabversion as number value 15

    ret = INET_URLDownLoad("http://tab.thinbasic.com/tabversion.txt", APP_SOURCEPATH + "tabversion.txt")

    IF ret <> %TRUE THEN
    msgbox(0, "Error: " + ret)
    END IF

    Dim version As String Value File_Load( App_SourcePath + "tabversion.TXT" )

    '---wait until version.txt file downloaded...
    do
    if file_exists(app_sourcepath + "tabversion.txt") then exit do
    loop

    if val(version) > tabversion then
    Retcode=msgbox 0,"There is a later version available."+crlf+_
    "Do you wish to download later version?",%MB_YESNO,"TAB Request"

    select case Retcode
    case %idYES
    ret = inet_urldownload("http://tab.thinbasic.com/tab.zip",APP_SOURCEPATH + "tab.zip")

    IF ret <> %TRUE THEN
    msgbox(0, "Error: " + ret)
    END IF

    case %idNO
    msgbox 0,"OK"

    end select

    else

    msgbox 0, "You currently already have the latest version"


    end if

    if file_exists(app_sourcepath + "tabversion.txt") then
    file_kill(app_sourcepath + "tabversion.txt")
    end if

    msgbox 0, "End of test"
    [/code]

    What U think? Any comments?

    Regards,
    catventure.
    http://tab.thinbasic.com - Home Of The ThinBasic Adventure Builder Project. (Interactive Fiction/Text Adventure Maker)

  4. #4
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    58
    Posts
    8,886
    Rep Power
    10

    Re: Do you need to download pages/files from internet?

    catventure,

    seems to work but I've a question: why th DO/LOOP?
    INET_URLDownLoad function is syncronous so just checking the error code should be ok. Also file_exists is ok but not inside a lopp. Rick is to hang inside the loop if file will not exist.

    Another thing could be to get current local TAB version directly from TAB script. For example if you put a special comment line inside TAB source, you can search for it instead of hardcoding it inside "dim tabversion as number value 15"

    Another option could be to add a command line param parsing to your script in order to return a file with current TAB version. If you add the followinf code in TAB editor just after USES clauses, you will be able to call it from the shell with GETVERSION parameter:
    [code=dos]TAB_Editor.tBasic GETVERSION[/code]
    It will create a file with current installed version.

    Here is the code to add to TAB_Editor.tbasic:
    [code=thinbasic]USES "UI"
    USES "OS"
    USES "file"


    $TABVERSION = "15"

    DIM NumberOfCommands AS LONG
    DIM CountCommands AS LONG

    '---Returns the number of commands specified
    NumberOfCommands = os_getcommands

    '---If only 1 param it means no additiona parameters was passed
    IF NumberOfCommands > 1 THEN

    '---If more than 1 param, execute something ...
    FOR CountCommands = 2 TO NumberOfCommands
    SELECT CASE UCASE$(os_getcommand(CountCommands))
    CASE "GETVERSION"
    FILE_SAVE(App_SourcePath + "LocalVersion.TXT", $TABVERSION & $crlf)
    STOP
    END SELECT
    NEXT
    end if

    ...
    ...follow standard code
    ...
    [/code]

    Just ideas coming out from brain. Anyhow you've done a good job.
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  5. #5
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    58
    Posts
    8,886
    Rep Power
    10

    Re: Do you need to download pages/files from internet?

    Maybe better to continue into TAB specific forum. If you agree I will move part of the topic.
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  6. #6
    Senior Member catventure's Avatar
    Join Date
    Oct 2005
    Location
    UK
    Posts
    644
    Rep Power
    85

    Re: Do you need to download pages/files from internet?

    Agreed. Maybe better to move part of topic.

    catventure.
    http://tab.thinbasic.com - Home Of The ThinBasic Adventure Builder Project. (Interactive Fiction/Text Adventure Maker)

  7. #7
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    58
    Posts
    8,886
    Rep Power
    10

    Re: Do you need to download pages/files from internet?

    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  8. #8
    Senior Member catventure's Avatar
    Join Date
    Oct 2005
    Location
    UK
    Posts
    644
    Rep Power
    85

    Re: Do you need to download pages/files from internet?

    Hi Eros,

    Thanx for trying it and for ideas.

    I removed the DO...LOOP. It works Ok without it as you said
    and would avoid the 'hang' if the file not exist - so that is good.

    I can see there's lots of different things possible with a bit of thought...
    like your idea for a list of tab games for download without the need to visit the site.

    Catventure.
    http://tab.thinbasic.com - Home Of The ThinBasic Adventure Builder Project. (Interactive Fiction/Text Adventure Maker)

  9. #9
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    58
    Posts
    8,886
    Rep Power
    10

    Re: Do you need to download pages/files from internet?

    Yes, networking opens a lot of possibilities.
    Limit is the fantasy, isn't? And time of course.
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  10. #10
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,162
    Rep Power
    738

    Re: Do you need to download pages/files from internet?

    Hi,

    this is quick try which occured me last night ( based on samplescripts ):
    [code=thinbasic]'----------------------------------------------------------------------------(')

    USES "UI"
    USES "INet"
    USES "File"

    '----------------------------------------------------------------------------(')

    DIM Msg AS LONG
    DIM wParam AS LONG
    DIM lParam AS LONG
    DIM hDlg AS LONG
    DIM Count AS LONG
    DIM ret AS NUMBER

    '----------------------------------------------------------------------------(')

    ret = INET_URLDOWNLOAD( "http://tab.thinbasic.com/tabversion.txt", APP_SOURCEPATH + "tabversion.txt" )

    '----------------------------------------------------------------------------(')

    IF ret <> %TRUE THEN
    DlgMsg( "Error occured: " + ret + $CRLF + $CRLF + "Make sure you have opened internet connection", %MB_ICONERROR )
    STOP
    END IF

    '----------------------------------------------------------------------------(')

    ret = INET_URLDOWNLOAD( "http://tab.thinbasic.com/tabgames.txt", APP_SOURCEPATH + "tabgames.txt" )

    '----------------------------------------------------------------------------(')

    DIM version AS STRING VALUE FILE_LOAD( APP_SOURCEPATH + "tabversion.TXT" )
    DIM games AS STRING VALUE TRIM$( FILE_LOAD( APP_SOURCEPATH + "tabgames.TXT" ))
    DIM ListGames( PARSECOUNT( games, $CRLF )) AS STRING
    DIM ListGamesLink( PARSECOUNT( games, $CRLF )) AS STRING
    DIM i AS LONG
    DIM sLine AS STRING

    '----------------------------------------------------------------------------(')

    FOR i = 1 TO PARSECOUNT( games, $CRLF )
    sLine = PARSE$( games, $CRLF, i )
    ListGames( i ) = TRIM$( PARSE$( sLine, ";", 1 ))
    ListGamesLink( i ) = TRIM$( PARSE$( sLine, ";", 2 ))
    NEXT

    '----------------------------------------------------------------------------(')
    '---Create a new dialog
    '----------------------------------------------------------------------------(')

    DIALOG NEW 0, "T.A.B. - Online services manager", - 1, - 1, 210, 230, _
    %WS_DLGFRAME OR %DS_CENTER OR %WS_CAPTION OR %WS_SYSMENU OR %WS_OVERLAPPEDWINDOW, _
    0 TO hDlg

    '----------------------------------------------------------------------------(')

    %List01 = 405
    %DOWNLOAD_TAB = 410
    %DOWNLOAD_GAME = 411
    %PROG_QUIT = 412

    '----------------------------------------------------------------------------(')
    '---Show dialog in MODELESS state, the only managed state at the moment
    '----------------------------------------------------------------------------(')

    DIALOG SHOW MODELESS hDlg


    '----------------------------------------------------------------------------(')
    '---Start the main message loop
    '----------------------------------------------------------------------------(')

    WHILE ISWINDOW( hDlg )

    '---Get the message and fill wParam and lParam
    Msg = GETMESSAGE( hDlg, wParam, lParam )

    '---Now test the message
    SELECT CASE Msg

    CASE %WM_INITDIALOG '---Message fired at the very beginning when dialog is initialized
    '---This can be the right place to initialize dialog or create controls
    CONTROL ADD LABEL, hDlg, 1000, "T.A.B Online Services", 5, 5, 200, 15, %SS_CENTER OR %SS_CENTERIMAGE OR %SS_SUNKEN
    CONTROL ADD BUTTON, hDlg, %DOWNLOAD_TAB, "Download T.A.B, Release" + STR$( version ), 5, 25, 200, 15
    CONTROL ADD LINE, hDlg, - 1, "", 5, 45, 200, 1
    CONTROL ADD LABEL, hDlg, - 1, "Download latest T.A.B games:", 5, 55, 100, 15
    CONTROL ADD LISTBOX, hDlg, %List01, ListGames( ), 5, 70, 200, 100, 0, 0
    LISTBOX SELECT hDlg, %List01, 1
    CONTROL ADD BUTTON, hDlg, %DOWNLOAD_GAME, "Download game", 5, 180, 200, 15
    CONTROL ADD LINE, hDlg, - 1, "", 5, 200, 200, 1
    CONTROL ADD BUTTON, hDlg, %PROG_QUIT, "Exit program", 5, 210, 200, 15


    CASE %WM_COMMAND
    '---Test which control has been clicked
    SELECT CASE LOWRD( wParam )

    CASE %WM_KEYUP
    '---In case of ESC exit loop
    IF wParam = 27 THEN EXIT WHILE

    CASE %DOWNLOAD_GAME
    CONTROL SEND hDlg, %List01, %LB_GETCURSEL, 0, 0 TO i
    i = i + 1 ' zero based
    MOUSEPTR 11
    ret = INET_URLDOWNLOAD( ListGamesLink( i ), APP_SOURCEPATH + PARSE$( ListGamesLink( i ), "/", - 1 ))
    MOUSEPTR 1
    IF ret <> %TRUE THEN
    DlgMsg( $DQ + ListGames( i ) + $DQ + $CRLF + $CRLF + ListGamesLink( i ) + $CRLF + $CRLF + "File cannot be downloaded", %MB_ICONERROR )
    ELSE
    DlgMsg( $DQ + ListGames( i ) + $DQ + $CRLF + $CRLF + "Successfully downloaded and saved as:" + $CRLF + APP_SOURCEPATH + PARSE$( ListGamesLink( i ), "/", - 1 ), %MB_ICONINFORMATION )
    END IF

    CASE %DOWNLOAD_TAB
    MOUSEPTR 11
    ret = INET_URLDOWNLOAD( "http://tab.thinbasic.com/tab.zip", APP_SOURCEPATH + "tab.zip" )
    MOUSEPTR 1
    IF ret <> %TRUE THEN
    DlgMsg( "T.A.B could not be downloaded from:" + $CRLF + "http://tab.thinbasic.com/tab.zip", %MB_ICONERROR )
    ELSE
    DlgMsg( "Latest T.A.B release was successfully downloaded and saved as:" + $CRLF + APP_SOURCEPATH + "tab.zip", %MB_ICONINFORMATION )
    END IF

    CASE %PROG_QUIT
    if DlgMsg("Are you sure you want to quit?", %MB_YESNO) = %IDYES then EXIT WHILE

    END SELECT

    CASE %WM_SYSCOMMAND
    if wParam = %SC_CLOSE then EXIT WHILE

    END SELECT
    WEND


    DIALOG END hDlg


    FUNCTION DlgMsg( sText AS STRING, sStyle AS LONG ) AS LONG
    FUNCTION = MSGBOX( hDlg, sText, sStyle, "T.A.B. Online Services" )
    END FUNCTION
    [/code]

    It needs the tabversion.txt with version number, and also tabgames.txt, which should look like:
    ... just name of the game and URL separated by ";" on each line.


    Bye,
    Petr
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

Page 1 of 3 123 LastLast

Similar Threads

  1. Do you need to download pages/files from internet?
    By ErosOlmi in forum Sources, Templates, Code Snippets, Tips and Tricks, Do you know ...
    Replies: 2
    Last Post: 17-10-2006, 22:34

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •