View Full Version : Re: Do you need to download pages/files from internet?
ErosOlmi
17-10-2006, 18:48
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.
'----------------------------------------------------------------------------
'----------------------------------------------------------------------------
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/products/thinBasic/Version/OnlineCheckVersion.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
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
ErosOlmi
17-10-2006, 20:43
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.
catventure
17-10-2006, 21:07
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.
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"
What U think? Any comments?
Regards,
catventure.
ErosOlmi
17-10-2006, 21:44
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:
TAB_Editor.tBasic GETVERSION
It will create a file with current installed version.
Here is the code to add to TAB_Editor.tbasic:
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
...
Just ideas coming out from brain. Anyhow you've done a good job.
ErosOlmi
17-10-2006, 21:48
Maybe better to continue into TAB specific forum. If you agree I will move part of the topic.
catventure
17-10-2006, 22:27
Agreed. Maybe better to move part of topic.
catventure.
ErosOlmi
17-10-2006, 22:35
OK, moved here. Previous link: http://community.thinbasic.com/index.php?topic=407.0
catventure
17-10-2006, 22:53
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.
ErosOlmi
17-10-2006, 23:03
Yes, networking opens a lot of possibilities.
Limit is the fantasy, isn't? And time of course.
Petr Schreiber
18-10-2006, 16:56
Hi,
this is quick try which occured me last night ( based on samplescripts ):
'----------------------------------------------------------------------------(')
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
It needs the tabversion.txt with version number, and also tabgames.txt, which should look like:
Story about dragon;http://tab.thinbasic.com/Story.zip
Tutorial game;http://tab.thinbasic.com/Tutorial.zip
... just name of the game and URL separated by ";" on each line.
Bye,
Petr
catventure
18-10-2006, 18:50
Hi Psch,
I had just completed my version download idea. Now you have made an excellent idea/contribution so I will need some time to take a look and consider...
Many thanks for your code suggestion which I'll examine more offline.
Best Regards,
catventure.
catventure
18-10-2006, 20:46
Hi Petr,
OK. I've tried it out and works well.
The dialog is clean and simple and professional. Very Nice.
The idea of a gameslist, which Eros also mentioned is good. Having games collection in one place for easy download appeals.
Do you think should be a separate program or be activated from the TAB Editor?
I would not change much you have done apart from 'kill' ing the "tabversion.txt" and "tabgames.txt" files once finished with, making dlgwindow not sizable or maximizable, and maybe using Dialog_BrowseForFolder so user can pick download location folder instead of downloading to app_sourcepath as default.
I can alter the 'help' button on TAB Editor to 'TAB Online Services' ;)
I'm impressed with your example and think would be a useful addition to the program.
My code simply dealt with TAB version but I would be happy to include games list too as you have demonstrated.
catventure.
ErosOlmi
18-10-2006, 22:08
Really nice, nice code Petr.
Simple, linear, clean, documented, effective. This is your style ;)
catventure
19-10-2006, 15:05
Hi Psch,
I've made the amendments I mentioned to the code you posted. Below is the working example code to try. If you're happy or if you want to change anything let me know...
It is an easy adjustment to "plug it in" to the TAB Editor.
'TAB Online Updater
'----------------------------------------------------------------------------(')
USES "UI"
USES "INet"
USES "File"
'----------------------------------------------------------------------------(')
DIM sFile AS STRING
DIM Msg AS LONG
DIM wParam AS LONG
DIM lParam AS LONG
DIM hDlg AS LONG
DIM Count AS LONG
DIM tabversion 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" ))
'----------------------------------------------------------------------------(')
FILE_KILL( APP_SOURCEPATH + "tabversion.txt" )
FILE_KILL( 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, 0 TO hDlg
'----------------------------------------------------------------------------(')
%List01 = 405
%DOWNLOAD_TAB = 410
%DOWNLOAD_GAME = 411
%PROG_QUIT = 412
'----------------------------------------------------------------------------(')
tabversion = 14
'----------------------------------------------------------------------------(')
'---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
IF version > tabversion THEN
CONTROL ADD BUTTON, hDlg, %DOWNLOAD_TAB, "Download Latest Release" + STR$( version ), 5, 25, 200, 15
ELSE
CONTROL ADD LABEL, hdlg, - 1, ">>> You Already Have Latest Release" + STR$( version ) + " <<<", 5, 25, 200, 15, %SS_CENTER OR %SS_CENTERIMAGE OR %SS_SUNKEN
END IF
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, 110, 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
'dialog set color hDlg,-1,rgb(0,0,0)
'dialog redraw hDlg
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
sFile = DIALOG_BROWSEFORFOLDER( hdlg, "Select a Folder For Download|Please Choose Download Location", "C:\", %FALSE )
IF sFile <> "" THEN
MOUSEPTR 11
ret = INET_URLDOWNLOAD( ListGamesLink( i ), sFile + "/" + 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
END IF
CASE %DOWNLOAD_TAB
sFile = DIALOG_BROWSEFORFOLDER( hdlg, "Select a Folder For Download|Please Choose Download Location", "C:\", %FALSE )
IF sFile <> "" THEN
MOUSEPTR 11
ret = INET_URLDOWNLOAD( "http://tab.thinbasic.com/tab.zip", sFile + "\" + "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
END IF
CASE %PROG_QUIT
IF DlgMsg( "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
Petr, the second game in the onsite list does not exist at all. This was done on purpose to test the code for download problem.
If you alter var "tabversion=14" to "tabversion=15" the tab download button will not be shown but is replaced by a label which informs that they have latest version already.
Regards, catventure.
Petr Schreiber
19-10-2006, 17:08
Hi,
I'm glad you liked it :)
The idea with label when latest TAB is installed is nice!
Just few things - as Eros said, it would be nice if TAB could return the version requested by command line parameter.
Then TAB_Updater could shell it, check it and give the appropiate reaction.
I think it will be easier to keep downloader as separate application ( something like "STEAM" from Valve, but it does not take 5 minutes to start ;) ). TAB_Editor has already huge source... so it would be easier to maintain.
Regarding the downloader itself, I think maybe third parameter in the game list could be category, like "Sci-Fi", "Drama", "Comedy quest" ... and there would be one COMBOBOX more, where you could sort games by "<All>" and then the categories. I think it could be important when more TAB games come to keep it clear to search. Maybe even some brief description and release date for sorting...
Bye,
Petr
catventure
19-10-2006, 19:12
Hi Psch,
Well of course later on there may be a few more TAB games - but I'm not expecting a deluge of them just yet! ;)
When you say getting version by command line parameter (presume you mean thinbasic shell?)
Eros kindly posted this code:
$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 additional 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
I will add this to the top of the code listing if that is what you mean...
I agree that a separate program sounds better than including within TAB.
But then if I am not hardcoding the value of tabversion eg:
dim tabversion as long value = 15
How will I now check against the number contained in "tabversion.txt" on the site to see if user has earlier or uptodate version as it currently does in the code?
Regards,
catventure
catventure
19-10-2006, 19:21
Oh -alright, think I understand that now.
I check the value of $tabversion.....
Here is updated code:
'TAB Online Updater
'----------------------------------------------------------------------------(')
USES "UI"
USES "INet"
USES "File"
uses "OS"
'----------------------------------------------------------------------------(')
$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
'---------------------------------------
DIM sFile AS STRING
DIM Msg AS LONG
DIM wParam AS LONG
DIM lParam AS LONG
DIM hDlg AS LONG
DIM Count AS LONG
DIM tabversion 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" ))
'----------------------------------------------------------------------------(')
FILE_KILL( APP_SOURCEPATH + "tabversion.txt" )
FILE_KILL( 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, 0 TO hDlg
'----------------------------------------------------------------------------(')
%List01 = 405
%DOWNLOAD_TAB = 410
%DOWNLOAD_GAME = 411
%PROG_QUIT = 412
'----------------------------------------------------------------------------(')
tabversion = 14
'----------------------------------------------------------------------------(')
'---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
IF version > $tabversion THEN
CONTROL ADD BUTTON, hDlg, %DOWNLOAD_TAB, "Download Latest Release" + STR$( version ), 5, 25, 200, 15
ELSE
CONTROL ADD LABEL, hdlg, - 1, ">>> You Already Have Latest Release" + STR$( version ) + " <<<", 5, 25, 200, 15, %SS_CENTER OR %SS_CENTERIMAGE OR %SS_SUNKEN
END IF
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, 110, 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
'dialog set color hDlg,-1,rgb(0,0,0)
'dialog redraw hDlg
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
sFile = DIALOG_BROWSEFORFOLDER( hdlg, "Select a Folder For Download|Please Choose Download Location", "C:\", %FALSE )
IF sFile <> "" THEN
MOUSEPTR 11
ret = INET_URLDOWNLOAD( ListGamesLink( i ), sFile + "/" + 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
END IF
CASE %DOWNLOAD_TAB
sFile = DIALOG_BROWSEFORFOLDER( hdlg, "Select a Folder For Download|Please Choose Download Location", "C:\", %FALSE )
IF sFile <> "" THEN
MOUSEPTR 11
ret = INET_URLDOWNLOAD( "http://tab.thinbasic.com/tab.zip", sFile + "\" + "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
END IF
CASE %PROG_QUIT
IF DlgMsg( "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
catventure
catventure
19-10-2006, 19:41
I think I messed up in my previous post.
I think the Eros code should only be in TAB Editor and not in above code!!
So now have to re-think how to do this...
catventure.
ErosOlmi
19-10-2006, 22:23
catventure to summarize:
place the following code snipet at the very beginning of TAB_Editor.tBasic, just after "USES" clauses:
'---This is the only thing to change when TAB change version
$TABVERSION = "15"
'---
'In case TAB_Editor.tBasic is executed with "GETVERSION" parameter, file LocalVersion.TXT
'will be generated and progrma will immediately exit
'---
DIM NumberOfCommands AS LONG '---Number of parameters in the command line
DIM CountCommands AS LONG '---Looper
'---Now, get the number of parameters specified at command line.
'---This will return at least 1 because parameter number 1 is always the script name itself
NumberOfCommands = os_getcommands
'---Now, if number of parameters is > 1 it means something other than script name was
'---specified, so we will try to discover if one or more parameters are suitable for us
IF NumberOfCommands > 1 THEN
'---If more than 1 param, check if something is interesting ...
FOR CountCommands = 2 TO NumberOfCommands
SELECT CASE UCASE$(os_getcommand(CountCommands))
CASE "GETVERSION"
'---OK, found the request to report script version.
'---Just create a file in script dir containing version and exit
FILE_SAVE(App_SourcePath + "LocalVersion.TXT", $TABVERSION)
STOP
END SELECT
NEXT
end if
Now have a look at attached modified update code.
Ciao
Eros
catventure
19-10-2006, 22:50
Hi Eros,
I knew it was something like that with the OS_Commands but I was struggling to figure it out...
Your modified code worked well and explains how to accomplish what I could not work out. I simply could not get my head round it.
I suppose the advantage of doing it this way is that you do not need to continually alter the updater program and load it with the version number every time, which is good. Simply changing Editor var $tabversion in each new release is enough (+ site "tabversion.txt" also)
I now see why you were so keen to suggest this.
BTW, would it work if the updater and tab editor were obfuscated scripts?
catventure
ErosOlmi
19-10-2006, 23:42
Good. It is so satisfactory to have the option to help you. I really like it.
Obfuscation? Yes of course. And this is another advantage of using a temp local text file instead of my original idea to read source code in order to determine version number.
Just remember to change command line inside TAB_Update.
From source code .tBasic execution
dim sCommand as string = app_path & "thinBasic.exe " & $dq & app_sourcepath & "TAB_Editor.tBasic" & $dq & " GETVERSION"
to obfuscated .tBasicx execution
dim sCommand as string = app_path & "thinBasic.exe " & $dq & app_sourcepath & "TAB_Editor.tBasicx" & $dq & " GETVERSION"
Ciao
Eros
ErosOlmi
19-10-2006, 23:48
A little change you can make is
DIALOG_BROWSEFORFOLDER( hdlg, "Select a Folder For Download|Please Choose Download Location", APP_sourcepath, %FALSE )
instead of
DIALOG_BROWSEFORFOLDER( hdlg, "Select a Folder For Download|Please Choose Download Location", "C:\", %FALSE )
In this way user is already placed in source path directory without having to browse again and again from C:\ to where TAB is installed.
Ciao
Eros
catventure
20-10-2006, 01:02
Hi Eros,
I also found an improve. These 2 lines should be changed
DlgMsg( $DQ + ListGames( i ) + $DQ + $CRLF + $CRLF + "Successfully downloaded and saved as:" + $CRLF + app_sourcepath + PARSE$( ListGamesLink( i ), "/", - 1 ), %MB_ICONINFORMATION )
DlgMsg( "Latest T.A.B. release was successfully downloaded and saved as:" + $CRLF + app_sourcepath + "tab.zip", %MB_ICONINFORMATION )
to this:
DlgMsg( $DQ + ListGames( i ) + $DQ + $CRLF + $CRLF + "Successfully downloaded and saved as:" + $CRLF + sFile + "\"+ PARSE$( ListGamesLink( i ), "/", - 1 ), %MB_ICONINFORMATION )
DlgMsg( "Latest T.A.B. release was successfully downloaded and saved as:" + $CRLF + sFile + "\"+ "tab.zip", %MB_ICONINFORMATION )
This ensures the correct downloaded pathnames are printed in the msgbox!
( replaced "app_sourcepath" with sFile + "\" )
Not so important but I also file_kill'ed "localversion.txt" after use.
Bye,
catventure
Petr Schreiber
21-10-2006, 18:44
Hi catventure,
updater in new TAB Alpha Release 16 works perfectly.
Just little idea - maybe the tabversion.txt could also contain brief "What's new" information and maybe file size ( just general, like "about 100 KB").
Any change now could change "old" updaters, as they read all the file as on big string, little bit confused. Maybe it could be handled at lines level in future, where version number would be always on first line, new features on second line, separated by semicolon and so on...
Petr
catventure
21-10-2006, 23:02
Hi Petr,
Thanks for your report on the Updater try-out.
I just wanted to keep it simple at first, but I am sure it can and will get improved in future version.
Next TAB will be a major(ish) kind of update and may take a little time as I am developing the routines for commanding characters to perform actions. I'm making it so the player can ask a character to do something; like pick up/wear an object or give an object to another character...etc.
This will give another dimension to gameplay and puzzles that require getting character cooperation should make it more fun too :)
This will begin the use of the Character Speech Editor in the Character Editor.
I'm already 60% on the way with this but have to proceed carefully (already uncovered some TAB language bugs also in my investigations) and I have a lot of testing to do. A few of the language conditions/actions will have to renamed too - even so I am aiming to have it all ready in 7 to 10 days (hopefully) as I have a busy week coming up.
Best wishes,
catventure.