forked from KolibriOS/kolibrios
downloader: added status message, bugfixes.
git-svn-id: svn://kolibrios.org@5543 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
parent
cabc9ee63e
commit
4094e1f523
@ -50,7 +50,7 @@ START:
|
|||||||
; load libraries
|
; load libraries
|
||||||
stdcall dll.Load, @IMPORT
|
stdcall dll.Load, @IMPORT
|
||||||
test eax, eax
|
test eax, eax
|
||||||
jnz exit
|
jnz mainloop.exit
|
||||||
|
|
||||||
; wanted events
|
; wanted events
|
||||||
mcall 40, EVM_REDRAW + EVM_KEY + EVM_BUTTON + EVM_MOUSE + EVM_MOUSE_FILTER
|
mcall 40, EVM_REDRAW + EVM_KEY + EVM_BUTTON + EVM_MOUSE + EVM_MOUSE_FILTER
|
||||||
@ -98,7 +98,7 @@ mainloop:
|
|||||||
.button:
|
.button:
|
||||||
mcall 17 ; get id
|
mcall 17 ; get id
|
||||||
cmp ah, 1 ; button id=1 ?
|
cmp ah, 1 ; button id=1 ?
|
||||||
je exit
|
je .exit
|
||||||
|
|
||||||
cmp [btn_text], sz_download
|
cmp [btn_text], sz_download
|
||||||
je download
|
je download
|
||||||
@ -106,20 +106,20 @@ mainloop:
|
|||||||
cmp [btn_text], sz_open
|
cmp [btn_text], sz_open
|
||||||
je open_file
|
je open_file
|
||||||
|
|
||||||
|
.exit:
|
||||||
|
mcall -1 ; exit
|
||||||
|
|
||||||
.mouse:
|
.mouse:
|
||||||
invoke edit_box_mouse, edit1
|
invoke edit_box_mouse, edit1
|
||||||
jmp mainloop
|
jmp mainloop
|
||||||
|
|
||||||
|
|
||||||
open_file:
|
open_file:
|
||||||
; mcall 70, ...
|
mcall 70, fileopen
|
||||||
jmp mainloop
|
jmp mainloop
|
||||||
|
|
||||||
exit:
|
|
||||||
error:
|
|
||||||
mcall -1 ; exit
|
|
||||||
|
|
||||||
download:
|
download:
|
||||||
; int 3
|
|
||||||
; Extract the filename from URL
|
; Extract the filename from URL
|
||||||
mov edi, url
|
mov edi, url
|
||||||
xor al, al
|
xor al, al
|
||||||
@ -149,7 +149,7 @@ download:
|
|||||||
mcall 40, EVM_REDRAW + EVM_BUTTON + EVM_STACK
|
mcall 40, EVM_REDRAW + EVM_BUTTON + EVM_STACK
|
||||||
call draw_window
|
call draw_window
|
||||||
|
|
||||||
; Create the file
|
; Create the local file
|
||||||
mov [fileinfo], 2 ; create/write to file
|
mov [fileinfo], 2 ; create/write to file
|
||||||
xor eax, eax
|
xor eax, eax
|
||||||
mov [fileinfo.offset], eax
|
mov [fileinfo.offset], eax
|
||||||
@ -157,19 +157,35 @@ download:
|
|||||||
mov [fileinfo.size], eax
|
mov [fileinfo.size], eax
|
||||||
mcall 70, fileinfo
|
mcall 70, fileinfo
|
||||||
test eax, eax
|
test eax, eax
|
||||||
jnz error ; TODO: print error message
|
jnz create_error
|
||||||
|
|
||||||
; And start the download
|
; Start the download
|
||||||
invoke HTTP_get, url, 0, FLAG_STREAM or FLAG_REUSE_BUFFER, 0
|
invoke HTTP_get, url, 0, FLAG_STREAM or FLAG_REUSE_BUFFER, 0
|
||||||
test eax, eax
|
test eax, eax
|
||||||
jz error ; TODO: print error message
|
jz get_error
|
||||||
|
|
||||||
mov [identifier], eax
|
mov [identifier], eax
|
||||||
mov [offset], 0
|
mov [offset], 0
|
||||||
mov [btn_text], sz_cancel
|
mov [btn_text], sz_cancel
|
||||||
|
mov [status], sz_downloading
|
||||||
or [edit1.flags], ed_figure_only
|
or [edit1.flags], ed_figure_only
|
||||||
|
and [edit1.flags], not ed_focus
|
||||||
|
push [sc.work]
|
||||||
|
pop [edit1.color]
|
||||||
call draw_window
|
call draw_window
|
||||||
|
|
||||||
|
jmp download_loop
|
||||||
|
|
||||||
|
get_error:
|
||||||
|
mov [btn_text], sz_exit
|
||||||
|
mov [status], sz_err_http
|
||||||
|
jmp redraw
|
||||||
|
|
||||||
|
create_error:
|
||||||
|
mov [btn_text], sz_exit
|
||||||
|
mov [status], sz_err_create
|
||||||
|
jmp redraw
|
||||||
|
|
||||||
download_loop:
|
download_loop:
|
||||||
mcall 10
|
mcall 10
|
||||||
cmp eax, EV_REDRAW
|
cmp eax, EV_REDRAW
|
||||||
@ -179,15 +195,7 @@ download_loop:
|
|||||||
|
|
||||||
invoke HTTP_receive, [identifier]
|
invoke HTTP_receive, [identifier]
|
||||||
test eax, eax
|
test eax, eax
|
||||||
jz save_chunk
|
jz got_data
|
||||||
|
|
||||||
mov eax, [identifier]
|
|
||||||
push [eax + http_msg.content_length]
|
|
||||||
pop [pb.max]
|
|
||||||
push [eax + http_msg.content_received]
|
|
||||||
pop [pb.value]
|
|
||||||
|
|
||||||
invoke progressbar_draw, pb
|
|
||||||
jmp download_loop
|
jmp download_loop
|
||||||
|
|
||||||
.redraw:
|
.redraw:
|
||||||
@ -197,23 +205,34 @@ download_loop:
|
|||||||
.button:
|
.button:
|
||||||
jmp http_free
|
jmp http_free
|
||||||
|
|
||||||
save_chunk:
|
got_data:
|
||||||
mov ebp, [identifier]
|
mov ebp, [identifier]
|
||||||
test [ebp + http_msg.flags], 0xffff0000 ; error?
|
test [ebp + http_msg.flags], 0xffff0000 ; error?
|
||||||
jnz http_free
|
jnz http_error
|
||||||
|
|
||||||
|
cmp [fileinfo], 3 ; Did we write before?
|
||||||
|
je .write
|
||||||
|
|
||||||
|
test [ebp + http_msg.flags], FLAG_CONTENT_LENGTH
|
||||||
|
jz .first_write
|
||||||
|
|
||||||
cmp [fileinfo], 3
|
|
||||||
je @f
|
|
||||||
DEBUGF 1, "new file size=%u\n", [ebp + http_msg.content_length]
|
|
||||||
mov [fileinfo], 4 ; set end of file
|
|
||||||
mov eax, [ebp + http_msg.content_length]
|
mov eax, [ebp + http_msg.content_length]
|
||||||
|
mov [pb.max], eax
|
||||||
|
|
||||||
|
DEBUGF 1, "new file size=%u\n", eax
|
||||||
|
mov [fileinfo], 4 ; set end of file
|
||||||
mov [fileinfo.offset], eax ; new file size
|
mov [fileinfo.offset], eax ; new file size
|
||||||
mcall 70, fileinfo
|
mcall 70, fileinfo
|
||||||
|
test eax, eax
|
||||||
|
jnz write_error
|
||||||
|
|
||||||
|
|
||||||
|
.first_write:
|
||||||
mov [fileinfo], 3 ; write to existing file
|
mov [fileinfo], 3 ; write to existing file
|
||||||
@@:
|
.write:
|
||||||
mov ecx, [ebp + http_msg.content_received]
|
mov ecx, [ebp + http_msg.content_received]
|
||||||
sub ecx, [offset]
|
sub ecx, [offset]
|
||||||
|
jz download_loop ; more then 0 data bytes?
|
||||||
mov [fileinfo.size], ecx
|
mov [fileinfo.size], ecx
|
||||||
mov eax, [ebp + http_msg.content_ptr]
|
mov eax, [ebp + http_msg.content_ptr]
|
||||||
mov [fileinfo.buffer], eax
|
mov [fileinfo.buffer], eax
|
||||||
@ -221,14 +240,37 @@ save_chunk:
|
|||||||
mov [fileinfo.offset], ebx
|
mov [fileinfo.offset], ebx
|
||||||
DEBUGF 1, "Writing to disk: size=%u offset=%u\n", ecx, ebx
|
DEBUGF 1, "Writing to disk: size=%u offset=%u\n", ecx, ebx
|
||||||
mcall 70, fileinfo
|
mcall 70, fileinfo
|
||||||
|
test eax, eax ; check error code
|
||||||
|
jnz write_error
|
||||||
|
cmp ebx, ecx ; check if all bytes were written to disk
|
||||||
|
jne write_error
|
||||||
|
|
||||||
mov eax, [ebp + http_msg.content_received]
|
mov eax, [ebp + http_msg.content_received]
|
||||||
mov [offset], eax
|
mov [offset], eax
|
||||||
|
mov [pb.value], eax
|
||||||
|
|
||||||
|
invoke progressbar_draw, pb
|
||||||
|
|
||||||
test [ebp + http_msg.flags], FLAG_GOT_ALL_DATA
|
test [ebp + http_msg.flags], FLAG_GOT_ALL_DATA
|
||||||
jz download_loop
|
jz download_loop
|
||||||
|
|
||||||
|
; Download completed successfully
|
||||||
|
mov [status], sz_complete
|
||||||
mov [pb.progress_color], 0x0000c800 ; green
|
mov [pb.progress_color], 0x0000c800 ; green
|
||||||
|
mov [btn_text], sz_open
|
||||||
|
jmp http_free
|
||||||
|
|
||||||
|
write_error:
|
||||||
|
mov [status], sz_err_full
|
||||||
|
mov [pb.progress_color], 0x00c80000 ; red
|
||||||
|
mov [btn_text], sz_exit
|
||||||
|
jmp http_free
|
||||||
|
|
||||||
|
http_error:
|
||||||
|
mov [status], sz_err_http
|
||||||
|
mov [pb.progress_color], 0x00c80000 ; red
|
||||||
|
mov [btn_text], sz_exit
|
||||||
|
; jmp http_free
|
||||||
|
|
||||||
http_free:
|
http_free:
|
||||||
mcall 40, EVM_REDRAW + EVM_BUTTON
|
mcall 40, EVM_REDRAW + EVM_BUTTON
|
||||||
@ -240,14 +282,8 @@ http_free:
|
|||||||
jz @f
|
jz @f
|
||||||
mcall 68, 13 ; free the buffer
|
mcall 68, 13 ; free the buffer
|
||||||
@@:
|
@@:
|
||||||
|
|
||||||
invoke HTTP_free, [identifier] ; free headers and connection
|
invoke HTTP_free, [identifier] ; free headers and connection
|
||||||
|
jmp redraw
|
||||||
mov [btn_text], sz_open
|
|
||||||
call draw_window
|
|
||||||
jmp mainloop
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
draw_window:
|
draw_window:
|
||||||
mcall 12, 1 ; start window draw
|
mcall 12, 1 ; start window draw
|
||||||
@ -261,13 +297,18 @@ draw_window:
|
|||||||
mcall 0, <50, 320>, <350, 110>, , 0, title
|
mcall 0, <50, 320>, <350, 110>, , 0, title
|
||||||
|
|
||||||
; draw button
|
; draw button
|
||||||
mcall 8, <229,75>, <60,16>, 22, [sc.work_button] ; download
|
mcall 8, <229,75>, <60,16>, 22, [sc.work_button]
|
||||||
|
|
||||||
; draw button text
|
; draw button text
|
||||||
mov ecx, [sc.work_button_text]
|
mov ecx, [sc.work_button_text]
|
||||||
or ecx, 80000000h
|
or ecx, 80000000h
|
||||||
mcall 4, <240,65>, , [btn_text]
|
mcall 4, <240,65>, , [btn_text]
|
||||||
|
|
||||||
|
; draw status text
|
||||||
|
mov ecx, [sc.work_text]
|
||||||
|
or ecx, 80000000h
|
||||||
|
mcall 4, <10,65>, , [status]
|
||||||
|
|
||||||
; draw editbox
|
; draw editbox
|
||||||
edit_boxes_set_sys_color edit1, editboxes_end, sc
|
edit_boxes_set_sys_color edit1, editboxes_end, sc
|
||||||
invoke edit_box_draw, edit1
|
invoke edit_box_draw, edit1
|
||||||
@ -278,11 +319,8 @@ draw_window:
|
|||||||
invoke progressbar_draw, pb
|
invoke progressbar_draw, pb
|
||||||
@@:
|
@@:
|
||||||
mcall 12, 2 ; end window draw
|
mcall 12, 2 ; end window draw
|
||||||
ret
|
|
||||||
|
|
||||||
|
|
||||||
dont_draw:
|
dont_draw:
|
||||||
|
|
||||||
ret
|
ret
|
||||||
|
|
||||||
;---------------------------------------------------------------------
|
;---------------------------------------------------------------------
|
||||||
@ -319,14 +357,30 @@ fileinfo dd 2
|
|||||||
db 0
|
db 0
|
||||||
dd fname_buf
|
dd fname_buf
|
||||||
|
|
||||||
|
fileopen dd 7
|
||||||
|
dd 0 ; flags
|
||||||
|
dd fname_buf ; parameters
|
||||||
|
dd 0 ; reserved
|
||||||
|
dd 0 ; reserved
|
||||||
|
db "/sys/@open", 0 ; path
|
||||||
|
|
||||||
edit1 edit_box 299, 5, 10, 0xffffff, 0x0000ff, 0x0080ff, 0x000000, 0x8000, URLMAXLEN, url, mouse_dd, ed_focus+ed_always_focus, 0, 0
|
edit1 edit_box 299, 5, 10, 0xffffff, 0x0000ff, 0x0080ff, 0x000000, 0x8000, URLMAXLEN, url, mouse_dd, ed_focus+ed_always_focus, 0, 0
|
||||||
editboxes_end:
|
editboxes_end:
|
||||||
|
|
||||||
identifier dd 0
|
identifier dd 0
|
||||||
btn_text dd sz_download
|
btn_text dd sz_download
|
||||||
|
status dd sz_null
|
||||||
sz_download db 'Download', 0
|
sz_download db 'Download', 0
|
||||||
sz_cancel db ' Cancel ', 0
|
sz_cancel db ' Cancel ', 0
|
||||||
sz_open db ' Open ', 0
|
sz_open db ' Open ', 0
|
||||||
|
sz_exit db ' Exit ', 0
|
||||||
|
|
||||||
|
sz_null db 0
|
||||||
|
sz_downloading db 'Downloading..', 0
|
||||||
|
sz_complete db 'Download completed', 0
|
||||||
|
sz_err_create db 'Could not create the local file!', 0
|
||||||
|
sz_err_full db 'Disk full!', 0
|
||||||
|
sz_err_http db 'HTTP error!', 0
|
||||||
title db 'HTTP Downloader', 0
|
title db 'HTTP Downloader', 0
|
||||||
|
|
||||||
OpenDialog_data:
|
OpenDialog_data:
|
||||||
|
Loading…
Reference in New Issue
Block a user