The game downloader is coming nicely.
I'm currently encountering some strange incompatibilities with IE, the code is incredibly messy, and I need some way to grab the full URL for a web file out of a relative URL.
Getting the full web URL will probably require a worthy change to PluginBase.dll.
Download packages will be distributed as .gh files (really just Zip files, but renamed so I can have a file extension of my own), and are automatically installed by ghDownload.
There are two installation options:
-Full plugin install, which actually installs the plugin straight into the browser plugins directory so the new download is a complete web plugin.
-Normal install, which has the new download as a parent of ghDownload, which can optionally be saved forever so it only has to be downloaded once, or updated constantly.
This thing should make things nice and easy when it's done...
The present frightening state of it all, which does not yet have the full plugin install option, but soon would have if I had not decided to rewrite the appalling thing:
;Online Game Downloader for Grasshopper Web Plugin System v0.32
;(C) 2005, Dylan McCall
;I am well aware that this is VERY ugly code.
Include "blitzget.bb"
Include "file.bb"
ghInit(SystemProperty("AppHWND"),CommandLine()) ;Initiate Grasshopper's embedder.
Global appwidth=ghGetArg("width"),appheight=ghGetArg("height") ;Grabs arguments (width and height, in this case)
Graphics appwidth,appheight,0,2
ghEmbedWindow() ;Embeds application window in web browser
Global downloadPath$=SystemProperty("appdir");SystemProperty("tempdir")
Global downloadName$,downloadExt$
SetBuffer(BackBuffer())
ClsColor 255,255,255
SetFont(LoadFont("Arial",12))
progX=20
progY=50
progWidth=appwidth-40
progHeight=60
Global src$=ghGetArg("source")
If src<>""
DownloadProgram()
Else
Error("No Source Specified")
EndIf
Function DownloadProgram()
downloadName$=ExtractFileName( Replace(src,"/","") )
ChangeDir(downloadPath)
If FileType("gh"+RemoveFileExt(downloadName)+".txt")=1
exeData=ReadFile("gh"+RemoveFileExt(downloadName)+".txt")
If Not exeData Then Error("Cannot Find Data File")
;Absurdly ugly file parser
Local ToExecute$,alwaysdownload=0
Repeat
Local inLine$=ReadLine(exeData)
seperator=Instr(inLine,"=")
Local keyName$=Lower(Trim(Mid(inLine,1,seperator-1)))
Local keyValue$=Trim(Mid(inLine,seperator+1,Len(inLine)-1))
Select keyName
Case "alwaysdownload"
alwaysdownload=Int(keyValue$)
Case "mainprogram"
ToExecute$=keyValue$
End Select
Until Eof(exeData)
If alwaysdownload=0
ChangeDir(ExtractFilePath(downloadPath+ToExecute))
ExecFile(Chr(34)+downloadPath+ToExecute+Chr(34)+" "+CommandLine())
End
Else
;go on to the next step
EndIf
EndIf
If BlitzGet(src,downloadPath,downloadName,1000)
LaunchProgram(downloadName$)
Else
RuntimeError BlitzGet_ErrorMsg$
EndIf
End Function
Function LaunchProgram(downloadName$)
downloadExt$=ExtractFileExt(downloadName)
ChangeDir(downloadPath)
Select Lower(downloadExt)
Case "zip","7z","gzip","z","tar"
If UnZip(downloadPath+downloadName)
exeData=ReadFile("gh"+RemoveFileExt(downloadName)+".txt")
;Absurdly ugly file parser (again)
If Not exeData Then Error("Cannot Find Data File")
Local ToExecute$
Repeat
Local inLine$=ReadLine(exeData)
seperator=Instr(inLine,"=")
Local keyName$=Lower(Trim(Mid(inLine,1,seperator-1)))
Local keyValue$=Trim(Mid(inLine,seperator+1,Len(inLine)-1))
Select keyName
Case "mainprogram"
ToExecute$=keyValue$
End Select
Until Eof(exeData)
CloseFile exeData
ChangeDir(ExtractFilePath(downloadPath+ToExecute))
ExecFile(Chr(34)+downloadPath+ToExecute+Chr(34)+CommandLine())
End
Else
Error("Could not Unzip Download")
EndIf
Default
ChangeDir(ExtractFilePath(downloadPath+ToExecute))
ExecFile(Chr(34)+downloadPath+downloadName+Chr(34)+CommandLine())
End
End Select
End Function
Function BytesReceived (posByte,totalBytes) ;Called every loop by BlitzGet
If ghQuit()
DeleteFile(downloadPath+downloadName)
End
EndIf
Color 0,0,0
Text progX,progY+progHeight+10,Percent(posByte,totalBytes)+"% of "+src
Text progX,progY+progHeight+40,Str(posByte/1000)+"kB / "+Str(totalBytes/1000)+"kB"
Flip
Cls
End Function
Function UnZip(path$)
unzipper=RunProgram(Chr(34)+SystemProperty("appdir")+"7-Zip\7za.exe"+Chr(34)+" x "+path$+" -y",False)
If unzipper<>0
Repeat
Until ProgramEnded(unzipper)
DeleteFile(path$)
Return 1
EndIf
End Function
Function Error(message$)
If FileType(downloadPath+downloadName)
DeleteFile(downloadPath+downloadName)
EndIf
RuntimeError message$
End Function
Function RemoveFileExt$(file$)
ext$=ExtractFileExt(file$)
Return Mid(file$,1,Len(file)-Len(ext)-1)
End FunctionOn the topic of changes... can anybody confirm that the updater actually works?