mirror of
https://github.com/FellippeHeitor/InForm.git
synced 2025-01-15 03:49:56 +00:00
Fixes Download function - Addresses #95
This commit is contained in:
parent
0a005ccbb8
commit
36bea486e4
4 changed files with 70 additions and 185 deletions
|
@ -304,6 +304,7 @@ $END IF
|
|||
'$include:'xp.uitheme'
|
||||
'$include:'UiEditor.frm'
|
||||
'$include:'ini.bm'
|
||||
'$include:'extensions/download.bas'
|
||||
|
||||
'Event procedures: ---------------------------------------------------------------
|
||||
SUB __UI_Click (id AS LONG)
|
||||
|
@ -5219,67 +5220,6 @@ FUNCTION QuotedFilename$ (f$)
|
|||
$END IF
|
||||
END FUNCTION
|
||||
|
||||
FUNCTION Download$ (url$, file$, timelimit) STATIC
|
||||
'as seen on http://www.qb64.org/wiki/Downloading_Files
|
||||
'adapted for use with InForm
|
||||
|
||||
DIM theClient AS LONG, l AS LONG
|
||||
DIM prevUrl$, prevUrl2$, url2$, x AS LONG
|
||||
DIM e$, url3$, x$, t!, a2$, a$, i AS LONG
|
||||
DIM i2 AS LONG, i3 AS LONG, d$, fh AS LONG
|
||||
|
||||
IF url$ <> prevUrl$ OR url$ = "" THEN
|
||||
prevUrl$ = url$
|
||||
IF url$ = "" THEN
|
||||
IF theClient THEN CLOSE theClient: theClient = 0
|
||||
EXIT SUB
|
||||
END IF
|
||||
url2$ = url$
|
||||
x = INSTR(url2$, "/")
|
||||
IF x THEN url2$ = LEFT$(url$, x - 1)
|
||||
IF url2$ <> prevUrl2$ THEN
|
||||
prevUrl2$ = url2$
|
||||
IF theClient THEN CLOSE theClient: theClient = 0
|
||||
theClient = _OPENCLIENT("TCP/IP:80:" + url2$)
|
||||
IF theClient = 0 THEN Download = MKI$(2): prevUrl$ = "": EXIT FUNCTION
|
||||
END IF
|
||||
e$ = CHR$(13) + CHR$(10) ' end of line characters
|
||||
url3$ = RIGHT$(url$, LEN(url$) - x + 1)
|
||||
x$ = "GET " + url3$ + " HTTP/1.1" + e$
|
||||
x$ = x$ + "Host: " + url2$ + e$ + e$
|
||||
PUT #theClient, , x$
|
||||
t! = TIMER ' start time
|
||||
END IF
|
||||
|
||||
GET #theClient, , a2$
|
||||
a$ = a$ + a2$
|
||||
i = INSTR(a$, "Content-Length:")
|
||||
IF i THEN
|
||||
i2 = INSTR(i, a$, e$)
|
||||
IF i2 THEN
|
||||
l = VAL(MID$(a$, i + 15, i2 - i - 14))
|
||||
i3 = INSTR(i2, a$, e$ + e$)
|
||||
IF i3 THEN
|
||||
i3 = i3 + 4 'move i3 to start of data
|
||||
IF (LEN(a$) - i3 + 1) = l THEN
|
||||
d$ = MID$(a$, i3, l)
|
||||
fh = FREEFILE
|
||||
OPEN file$ FOR OUTPUT AS #fh: CLOSE #fh 'Warning! Clears data from existing file
|
||||
OPEN file$ FOR BINARY AS #fh
|
||||
PUT #fh, , d$
|
||||
CLOSE #fh
|
||||
Download = MKI$(1) + MKL$(l) 'indicates download was successful
|
||||
prevUrl$ = ""
|
||||
a$ = ""
|
||||
EXIT FUNCTION
|
||||
END IF ' availabledata = l
|
||||
END IF ' i3
|
||||
END IF ' i2
|
||||
END IF ' i
|
||||
IF TIMER > t! + timelimit THEN CLOSE theClient: theClient = 0: Download = MKI$(3): prevUrl$ = "": EXIT FUNCTION
|
||||
Download = MKI$(0) 'still working
|
||||
END FUNCTION
|
||||
|
||||
'---------------------------------------------------------------------------------
|
||||
FUNCTION SpecialCharsToEscapeCode$ (Text$)
|
||||
DIM i AS LONG, Temp$
|
||||
|
|
63
InForm/extensions/download.bas
Normal file
63
InForm/extensions/download.bas
Normal file
|
@ -0,0 +1,63 @@
|
|||
FUNCTION Download$ (url$, file$, timelimit) STATIC
|
||||
'as seen on http://www.qb64.org/wiki/Downloading_Files
|
||||
'adapted for use with InForm
|
||||
|
||||
DIM theClient AS LONG, l AS LONG
|
||||
DIM prevUrl$, prevUrl2$, url2$, x AS LONG
|
||||
DIM e$, url3$, x$, t!, a2$, a$, i AS LONG
|
||||
DIM i2 AS LONG, i3 AS LONG, d$, fh AS LONG
|
||||
|
||||
IF url$ <> prevUrl$ OR url$ = "" THEN
|
||||
prevUrl$ = url$
|
||||
IF url$ = "" THEN
|
||||
IF theClient THEN CLOSE theClient: theClient = 0
|
||||
EXIT SUB
|
||||
END IF
|
||||
url2$ = url$
|
||||
x = INSTR(url2$, "/")
|
||||
IF x THEN url2$ = LEFT$(url$, x - 1)
|
||||
IF url2$ <> prevUrl2$ THEN
|
||||
prevUrl2$ = url2$
|
||||
IF theClient THEN CLOSE theClient: theClient = 0
|
||||
theClient = _OPENCLIENT("TCP/IP:80:" + url2$)
|
||||
IF theClient = 0 THEN Download = MKI$(2): prevUrl$ = "": EXIT FUNCTION
|
||||
END IF
|
||||
e$ = CHR$(13) + CHR$(10) ' end of line characters
|
||||
url3$ = RIGHT$(url$, LEN(url$) - x + 1)
|
||||
x$ = "GET " + url3$ + " HTTP/1.1" + e$
|
||||
x$ = x$ + "Host: " + url2$ + e$ + e$
|
||||
PUT #theClient, , x$
|
||||
t! = TIMER ' start time
|
||||
END IF
|
||||
|
||||
GET #theClient, , a2$
|
||||
a$ = a$ + a2$
|
||||
i = INSTR(a$, "Content-Length:")
|
||||
IF i THEN
|
||||
i2 = INSTR(i, a$, e$)
|
||||
IF i2 THEN
|
||||
l = VAL(MID$(a$, i + 15, i2 - i - 14))
|
||||
i3 = INSTR(i2, a$, e$ + e$)
|
||||
IF i3 THEN
|
||||
i3 = i3 + 4 'move i3 to start of data
|
||||
IF (LEN(a$) - i3 + 1) = l THEN
|
||||
d$ = MID$(a$, i3, l)
|
||||
fh = FREEFILE
|
||||
OPEN file$ FOR OUTPUT AS #fh: CLOSE #fh 'Warning! Clears data from existing file
|
||||
OPEN file$ FOR BINARY AS #fh
|
||||
PUT #fh, , d$
|
||||
CLOSE #fh
|
||||
Download = MKI$(1) + MKL$(l) 'indicates download was successful
|
||||
prevUrl$ = ""
|
||||
prevUrl2$ = ""
|
||||
a$ = ""
|
||||
CLOSE theClient
|
||||
theClient = 0
|
||||
EXIT FUNCTION
|
||||
END IF ' availabledata = l
|
||||
END IF ' i3
|
||||
END IF ' i2
|
||||
END IF ' i
|
||||
IF TIMER > t! + timelimit THEN CLOSE theClient: theClient = 0: Download = MKI$(3): prevUrl$ = "": EXIT FUNCTION
|
||||
Download = MKI$(0) 'still working
|
||||
END FUNCTION
|
|
@ -43,6 +43,7 @@ $END IF
|
|||
'$INCLUDE:'../xp.uitheme'
|
||||
'$INCLUDE:'InFormSetup.frm'
|
||||
'$INCLUDE:'../ini.bm'
|
||||
'$include:'../extensions/download.bas'
|
||||
|
||||
'Icon:
|
||||
'http://www.iconarchive.com/show/oxygen-icons-by-oxygen-icons.org/Apps-system-software-update-icon.html
|
||||
|
@ -157,7 +158,9 @@ SUB __UI_BeforeUpdateDisplay STATIC
|
|||
CASE 1 'Success
|
||||
'Checksum:
|
||||
IF getChecksum(outputFileName$) <> checksum$ THEN
|
||||
Report "Failed."
|
||||
Report "Checksum failed."
|
||||
Report "Please contact fellippe@qb64.org -
|
||||
Report "or @fellippeheitor on Twitter."
|
||||
ThisStep = -1
|
||||
NextEvent = True
|
||||
EXIT SUB
|
||||
|
@ -233,7 +236,7 @@ SUB __UI_BeforeUpdateDisplay STATIC
|
|||
CASE ELSE
|
||||
IF NextEvent THEN NextEvent = False: Report "Installation failed.": AddItem ListBox1, ""
|
||||
Result$ = Download$("", "", 30) 'close client
|
||||
KILL "InFormSetup.ini"
|
||||
IF _FILEEXISTS("InFormSetup.ini") THEN KILL "InFormSetup.ini"
|
||||
Control(RetryBT).Hidden = False
|
||||
Control(ActivityIndicator).Hidden = True
|
||||
END SELECT
|
||||
|
@ -317,67 +320,6 @@ FUNCTION crc32~& (buf AS STRING)
|
|||
crc32~& = NOT crc
|
||||
END FUNCTION
|
||||
|
||||
FUNCTION Download$ (url$, file$, timelimit) STATIC
|
||||
'as seen on http://www.qb64.org/wiki/Downloading_Files
|
||||
'adapted for use with InForm
|
||||
|
||||
DIM client AS LONG, l AS LONG
|
||||
|
||||
IF url$ = "" THEN
|
||||
IF client THEN CLOSE client: client = 0
|
||||
prevUrl$ = ""
|
||||
EXIT SUB
|
||||
END IF
|
||||
|
||||
IF url$ <> prevUrl$ THEN
|
||||
prevUrl$ = url$
|
||||
a$ = ""
|
||||
url2$ = url$
|
||||
x = INSTR(url2$, "/")
|
||||
IF x THEN url2$ = LEFT$(url$, x - 1)
|
||||
IF url2$ <> prevUrl2$ THEN
|
||||
prevUrl2$ = url2$
|
||||
IF client THEN CLOSE client: client = 0
|
||||
client = _OPENCLIENT("TCP/IP:80:" + url2$)
|
||||
IF client = 0 THEN Download = MKI$(2): prevUrl$ = "": EXIT FUNCTION
|
||||
END IF
|
||||
e$ = CHR$(13) + CHR$(10) ' end of line characters
|
||||
url3$ = RIGHT$(url$, LEN(url$) - x + 1)
|
||||
x$ = "GET " + url3$ + " HTTP/1.1" + e$
|
||||
x$ = x$ + "Host: " + url2$ + e$ + e$
|
||||
PUT #client, , x$
|
||||
t! = TIMER ' start time
|
||||
END IF
|
||||
|
||||
GET #client, , a2$
|
||||
a$ = a$ + a2$
|
||||
i = INSTR(a$, "Content-Length:")
|
||||
IF i THEN
|
||||
i2 = INSTR(i, a$, e$)
|
||||
IF i2 THEN
|
||||
l = VAL(MID$(a$, i + 15, i2 - i - 14))
|
||||
i3 = INSTR(i2, a$, e$ + e$)
|
||||
IF i3 THEN
|
||||
i3 = i3 + 4 'move i3 to start of data
|
||||
IF (LEN(a$) - i3 + 1) = l THEN
|
||||
d$ = MID$(a$, i3, l)
|
||||
fh = FREEFILE
|
||||
OPEN file$ FOR OUTPUT AS #fh: CLOSE #fh 'Warning! Clears data from existing file
|
||||
OPEN file$ FOR BINARY AS #fh
|
||||
PUT #fh, , d$
|
||||
CLOSE #fh
|
||||
Download = MKI$(1) + MKL$(l) 'indicates download was successful
|
||||
prevUrl$ = ""
|
||||
a$ = ""
|
||||
EXIT FUNCTION
|
||||
END IF ' availabledata = l
|
||||
END IF ' i3
|
||||
END IF ' i2
|
||||
END IF ' i
|
||||
IF TIMER > t! + timelimit THEN CLOSE client: client = 0: Download = MKI$(3): prevUrl$ = "": EXIT FUNCTION
|
||||
Download = MKI$(0) 'still working
|
||||
END FUNCTION
|
||||
|
||||
SUB CircleFill (x AS LONG, y AS LONG, R AS LONG, C AS _UNSIGNED LONG)
|
||||
DIM x0 AS SINGLE, y0 AS SINGLE
|
||||
DIM e AS SINGLE
|
||||
|
|
|
@ -31,6 +31,7 @@ $END IF
|
|||
'$INCLUDE:'../xp.uitheme'
|
||||
'$INCLUDE:'InFormUpdater.frm'
|
||||
'$INCLUDE:'../ini.bm'
|
||||
'$include:'../extensions/download.bas'
|
||||
|
||||
': Event procedures: ---------------------------------------------------------------
|
||||
SUB __UI_BeforeInit
|
||||
|
@ -305,67 +306,6 @@ FUNCTION crc32~& (buf AS STRING)
|
|||
crc32~& = NOT crc
|
||||
END FUNCTION
|
||||
|
||||
FUNCTION Download$ (url$, file$, timelimit) STATIC
|
||||
'as seen on http://www.qb64.org/wiki/Downloading_Files
|
||||
'adapted for use with InForm
|
||||
|
||||
DIM client AS LONG, l AS LONG
|
||||
|
||||
IF url$ = "" THEN
|
||||
IF client THEN CLOSE client: client = 0
|
||||
prevUrl$ = ""
|
||||
EXIT SUB
|
||||
END IF
|
||||
|
||||
IF url$ <> prevUrl$ THEN
|
||||
prevUrl$ = url$
|
||||
a$ = ""
|
||||
url2$ = url$
|
||||
x = INSTR(url2$, "/")
|
||||
IF x THEN url2$ = LEFT$(url$, x - 1)
|
||||
IF url2$ <> prevUrl2$ THEN
|
||||
prevUrl2$ = url2$
|
||||
IF client THEN CLOSE client: client = 0
|
||||
client = _OPENCLIENT("TCP/IP:80:" + url2$)
|
||||
IF client = 0 THEN Download = MKI$(2): prevUrl$ = "": EXIT FUNCTION
|
||||
END IF
|
||||
e$ = CHR$(13) + CHR$(10) ' end of line characters
|
||||
url3$ = RIGHT$(url$, LEN(url$) - x + 1)
|
||||
x$ = "GET " + url3$ + " HTTP/1.1" + e$
|
||||
x$ = x$ + "Host: " + url2$ + e$ + e$
|
||||
PUT #client, , x$
|
||||
t! = TIMER ' start time
|
||||
END IF
|
||||
|
||||
GET #client, , a2$
|
||||
a$ = a$ + a2$
|
||||
i = INSTR(a$, "Content-Length:")
|
||||
IF i THEN
|
||||
i2 = INSTR(i, a$, e$)
|
||||
IF i2 THEN
|
||||
l = VAL(MID$(a$, i + 15, i2 - i - 14))
|
||||
i3 = INSTR(i2, a$, e$ + e$)
|
||||
IF i3 THEN
|
||||
i3 = i3 + 4 'move i3 to start of data
|
||||
IF (LEN(a$) - i3 + 1) = l THEN
|
||||
d$ = MID$(a$, i3, l)
|
||||
fh = FREEFILE
|
||||
OPEN file$ FOR OUTPUT AS #fh: CLOSE #fh 'Warning! Clears data from existing file
|
||||
OPEN file$ FOR BINARY AS #fh
|
||||
PUT #fh, , d$
|
||||
CLOSE #fh
|
||||
Download = MKI$(1) + MKL$(l) 'indicates download was successful
|
||||
prevUrl$ = ""
|
||||
a$ = ""
|
||||
EXIT FUNCTION
|
||||
END IF ' availabledata = l
|
||||
END IF ' i3
|
||||
END IF ' i2
|
||||
END IF ' i
|
||||
IF TIMER > t! + timelimit THEN CLOSE client: client = 0: Download = MKI$(3): prevUrl$ = "": EXIT FUNCTION
|
||||
Download = MKI$(0) 'still working
|
||||
END FUNCTION
|
||||
|
||||
SUB CircleFill (x AS LONG, y AS LONG, R AS LONG, C AS _UNSIGNED LONG)
|
||||
DIM x0 AS SINGLE, y0 AS SINGLE
|
||||
DIM e AS SINGLE
|
||||
|
|
Loading…
Reference in a new issue