1 Commits

Author SHA1 Message Date
bd56fbf35f develop/libraries/box_lib: Post-SVN tidy
All checks were successful
Build system / Check kernel codestyle (pull_request) Successful in 21s
Build system / Build (pull_request) Successful in 4m17s
- Move source code from `trunk` into program root directory.
- Update build files and ASM include paths. This touches *many* files.
- Note: Line endings standardised from `CRLF` > `LF`, so best to view diffs with whitespace changes hidden.
2025-05-25 11:38:47 +01:00
8 changed files with 9437 additions and 8712 deletions

View File

@@ -1,467 +1,465 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;;
;; Copyright (C) KolibriOS team 2009-2015. All rights reserved. ;;
;; Distributed under terms of the GNU General Public License ;;
;; ;;
;; downloader.asm - HTTP client for KolibriOS ;;
;; ;;
;; ;;
;; GNU GENERAL PUBLIC LICENSE ;;
;; Version 2, June 1991 ;;
;; ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
URLMAXLEN = 1024
BUFFERSIZE = 4096
__DEBUG__ = 1
__DEBUG_LEVEL__ = 1
format binary as ""
;--------------------------------------
frame_1:
.x = 5
.y = 10
.width = 350
.height = 55
;--------------------------------------
frame_2:
.x = 5
.y = 75
.width = 350
.height = 55
;---------------------------------------------------------------------
use32
org 0x0
db 'MENUET01' ; header
dd 0x01 ; header version
dd START ; entry point
dd IM_END ; image size
dd I_END ; required memory
dd stacktop ; esp
dd params ; I_PARAM
dd 0x0 ; I_Path
;---------------------------------------------------------------------
include '../../../../macros.inc'
include '../../../../proc32.inc'
include '../../../../dll.inc'
include '../../../../debug-fdo.inc'
include '../../box_lib/trunk/box_lib.mac'
include '../../http/http.inc'
virtual at 0
http_msg http_msg
end virtual
;---------------------------------------------------------------------
START:
mcall 68, 11 ; init heap so we can allocate memory dynamically
; load libraries
stdcall dll.Load, @IMPORT
test eax, eax
jnz exit
;---------------------------------------------------------------------
mov edi,filename_area
mov esi,start_temp_file_name
call copy_file_name_path
mov edi,fname_buf
mov esi,start_file_path
call copy_file_name_path
;OpenDialog initialisation
push dword OpenDialog_data
call [OpenDialog_Init]
; prepare for PathShow
push dword PathShow_data_1
call [PathShow_prepare]
;---------------------------------------------------------------------
; check parameters
cmp byte[params], 0 ; no parameters ?
je reset_events ; load the GUI
inc [silently]
download:
call download_1
test [silently], 0xff
jnz save
reset_events:
DEBUGF 1, "resetting events\n"
; Report events
; defaults + mouse
mcall 40,EVM_REDRAW+EVM_KEY+EVM_BUTTON+EVM_MOUSE+EVM_MOUSE_FILTER
;---------------------------------------------------------------------
redraw:
call draw_window
still:
;; DEBUGF 1, "waiting for events\n"
mcall 10 ; wait here for event
cmp eax, EV_REDRAW
je redraw
cmp eax, EV_KEY
je key
cmp eax, EV_BUTTON
je button
cmp eax, EV_MOUSE
je mouse
jmp still
;---------------------------------------------------------------------
key:
mcall 2 ; read key
stdcall [edit_box_key], dword edit1
cmp ax, 13 shl 8
je download
jmp still
;---------------------------------------------------------------------
button:
mcall 17 ; get id
cmp ah, 26
jne @f
; invoke OpenDialog
push dword OpenDialog_data
call [OpenDialog_Start]
cmp [OpenDialog_data.status],1
jne still
; prepare for PathShow
push dword PathShow_data_1
call [PathShow_prepare]
call draw_window
jmp still
@@:
cmp ah, 1 ; button id=1 ?
je exit
call download_1
jmp save
;---------------------------------------------------------------------
mouse:
stdcall [edit_box_mouse], edit1
jmp still
;---------------------------------------------------------------------
exit:
DEBUGF 1, "Exiting\n"
invoke HTTP_free, [identifier] ; free buffer
fail:
or eax, -1 ; close this program
mcall
;---------------------------------------------------------------------
download_1:
DEBUGF 1, "Starting download\n"
invoke HTTP_get, 0, 0, params, sz_add_header
test eax, eax
jz fail
mov [identifier], eax
.loop:
invoke HTTP_receive, [identifier]
test eax, eax
jnz .loop
mov eax, [identifier]
mov ebx, [eax + http_msg.content_length]
mov [final_size], ebx
mov ebx, [eax + http_msg.content_ptr]
mov [final_buffer], ebx
invoke HTTP_find_header, [identifier], sz_content_enc
test eax, eax
jz .no_deflate
; TODO: check if parameter equals "deflate"
DEBUGF 1, "deflating\n"
lea eax, [final_size]
invoke deflate_unpack, [final_buffer], eax
push eax
mcall 68, 13, [final_buffer] ; Free the compressed data
pop [final_buffer]
DEBUGF 1, "deflated size=%u bytes\n", [final_size]
.no_deflate:
invoke HTTP_free, [identifier]
mov [identifier], 0
ret
;---------------------------------------------------------------------
save:
cmp [final_buffer], 0
je still
mcall 70, fileinfo
DEBUGF 1, "File saved\n"
test [silently], 0xff
jnz exit
mov ecx, [sc.work_text]
or ecx, 0x80000000
mcall 4, <10, frame_2.y+frame_2.height+7>, , download_complete
jmp still
;---------------------------------------------------------------------
copy_file_name_path:
xor eax,eax
cld
@@:
lodsb
stosb
test eax,eax
jnz @r
ret
;---------------------------------------------------------------------
; *********************************************
; ******* WINDOW DEFINITIONS AND DRAW ********
; *********************************************
draw_window:
mcall 12, 1 ; start window draw
;-----------------------------------
; get system colors
mcall 48, 3, sc, 40
;-----------------------------------
; draw window
mov edx, [sc.work]
or edx, 0x34000000
mcall 0, <50, 370>, <350, 170>, , 0, title
;-----------------------------------
; draw frames
mov [frame_data.x],dword frame_1.x shl 16+frame_1.width
mov [frame_data.y],dword frame_1.y shl 16+frame_1.height
mov [frame_data.text_pointer],dword select_addr_text
mov eax,[sc.work]
mov [frame_data.font_backgr_color],eax
mov eax,[sc.work_text]
mov [frame_data.font_color],eax
push dword frame_data
call [Frame_draw]
;-----------------------------------
mov [frame_data.x],dword frame_2.x shl 16+frame_2.width
mov [frame_data.y],dword frame_2.y shl 16+frame_2.height
mov [frame_data.text_pointer],dword select_path_text
push dword frame_data
call [Frame_draw]
;-----------------------------------
; draw "url:" text
mov ecx, [sc.work_text]
or ecx, 80000000h
mcall 4, <frame_1.x+10, frame_1.y+15>, , type_pls
;-----------------------------------
; draw editbox
edit_boxes_set_sys_color edit1, editboxes_end, sc
stdcall [edit_box_draw], edit1
;-----------------------------------
; draw buttons
mcall 8,<frame_1.x+frame_1.width-(68+15+50+15),68>,<frame_1.y+30,16>,22,[sc.work_button] ; reload
mcall ,<frame_1.x+frame_1.width-(50+15),50>,<frame_1.y+30,16>, 24 ; stop
mcall , <frame_2.x+frame_2.width-(54+15),54>,<frame_2.y+30,16>,26 ; save
;-----------------------------------
; draw buttons text
mov ecx, [sc.work_button_text]
or ecx, 80000000h
mcall 4, <frame_1.x+frame_1.width-(68+15+50+15)+10,frame_1.y+35>, , button_text.1
mcall , <frame_1.x+frame_1.width-(50+15)+15,frame_1.y+35>, , button_text.2
mcall , <frame_2.x+frame_2.width-(54+15)+10,frame_2.y+35>, , button_text.3
mcall 13,<frame_2.x+17,frame_2.width-15*2>,<frame_2.y+10,15>,0xffffff
push dword PathShow_data_1
call [PathShow_draw]
mcall 12, 2 ; end window redraw
ret
;---------------------------------------------------------------------
; Data area
;-----------------------------------------------------------------------------
align 4
@IMPORT:
library lib_http, 'http.obj', \
box_lib, 'box_lib.obj', \
proc_lib, 'proc_lib.obj', \
archiver, 'archiver.obj'
import lib_http, \
HTTP_get, 'get' , \
HTTP_receive, 'receive', \
HTTP_find_header, 'find_header_field', \
HTTP_free, 'free'
import box_lib, \
edit_box_draw, 'edit_box_draw', \
edit_box_key, 'edit_box_key', \
edit_box_mouse, 'edit_box_mouse', \
PathShow_prepare, 'PathShow_prepare', \
PathShow_draw, 'PathShow_draw', \
Frame_draw, 'frame_draw'
import proc_lib, \
OpenDialog_Init, 'OpenDialog_init', \
OpenDialog_Start, 'OpenDialog_start'
import archiver,\
deflate_unpack, 'deflate_unpack'
;---------------------------------------------------------------------
fileinfo dd 2, 0, 0
final_size dd 0
final_buffer dd 0
db 0
dd fname_buf
;---------------------------------------------------------------------
mouse_dd dd 0
edit1 edit_box 295, 48, (frame_1.y+10), 0xffffff, 0xff, 0x80ff, 0, 0x8000, URLMAXLEN, document_user, mouse_dd, ed_focus+ed_always_focus, 7, 7
editboxes_end:
;---------------------------------------------------------------------
include_debug_strings
;---------------------------------------------------------------------
type_pls db 'URL:', 0
button_text:
.1: db 'DOWNLOAD',0
.2: db 'STOP',0
.3: db 'SELECT', 0
download_complete db 'FILE SAVED!', 0
title db 'HTTP Downloader', 0
silently db 0
sz_add_header db 'Accept-Encoding: deflate', 13, 10, 0 ; archiver.obj doesnt export unpack method for gzip yet :(
sz_content_enc db 'content-encoding', 0
;---------------------------------------------------------------------
select_addr_text db ' NETWORK ADDRESS: ',0
select_path_text db ' PATH TO SAVE FILE: ',0
;---------------------------------------------------------------------
frame_data:
.type dd 0 ;+0
.x:
.x_size dw 0 ;+4
.x_start dw 0 ;+6
.y:
.y_size dw 0 ;+8
.y_start dw 0 ;+10
.ext_fr_col dd 0x0 ;+12
.int_fr_col dd 0xffffff ;+16
.draw_text_flag dd 1 ;+20
.text_pointer dd 0 ;+24
.text_position dd 0 ;+28
.font_number dd 0 ;+32
.font_size_y dd 9 ;+36
.font_color dd 0x0 ;+40
.font_backgr_color dd 0xffffff ;+44
;---------------------------------------------------------------------
PathShow_data_1:
.type dd 0 ;+0
.start_y dw frame_2.y+14 ;+4
.start_x dw frame_2.x+20 ;+6
.font_size_x dw 6 ;+8 ; 6 - for font 0, 8 - for font 1
.area_size_x dw frame_2.width-35 ;+10
.font_number dd 0 ;+12 ; 0 - monospace, 1 - variable
.background_flag dd 0 ;+16
.font_color dd 0 ;+20
.background_color dd 0 ;+24
.text_pointer dd fname_buf ;+28
.work_area_pointer dd text_work_area ;+32
.temp_text_length dd 0 ;+36
;---------------------------------------------------------------------
OpenDialog_data:
.type dd 1 ; Save
.procinfo dd procinfo ;+4
.com_area_name dd communication_area_name ;+8
.com_area dd 0 ;+12
.opendir_path dd temp_dir_path ;+16
.dir_default_path dd communication_area_default_path ;+20
.start_path dd open_dialog_path ;+24
.draw_window dd draw_window ;+28
.status dd 0 ;+32
.openfile_pach dd fname_buf ;+36
.filename_area dd filename_area ;+40
.filter_area dd Filter
.x:
.x_size dw 420 ;+48 ; Window X size
.x_start dw 200 ;+50 ; Window X position
.y:
.y_size dw 320 ;+52 ; Window y size
.y_start dw 120 ;+54 ; Window Y position
communication_area_name:
db 'FFFFFFFF_open_dialog',0
open_dialog_path:
db '/sys/File Managers/opendial',0
communication_area_default_path:
db '/sys',0
Filter:
dd Filter.end - Filter
.1:
db 'IMG',0
db 'IMA',0
.end:
db 0
start_temp_file_name: db 'some.garbage',0
start_file_path: db '/sys/.download', 0
;---------------------------------------------------------------------
document_user db 'http://'
;---------------------------------------------------------------------
IM_END:
;---------------------------------------------------------------------
params rb URLMAXLEN
;---------------------------------------------------------------------
sc system_colors
;---------------------------------------------------------------------
identifier dd ?
;---------------------------------------------------------------------
filename_area:
rb 256
;---------------------------------------------------------------------
temp_dir_path:
rb 4096
;---------------------------------------------------------------------
procinfo:
rb 1024
;---------------------------------------------------------------------
fname_buf:
rb 4096
;---------------------------------------------------------------------
text_work_area:
rb 1024
;---------------------------------------------------------------------
rb 4096
stacktop:
;---------------------------------------------------------------------
I_END:
;---------------------------------------------------------------------
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;;
;; Copyright (C) KolibriOS team 2009-2015. All rights reserved. ;;
;; Distributed under terms of the GNU General Public License ;;
;; ;;
;; downloader.asm - HTTP client for KolibriOS ;;
;; ;;
;; ;;
;; GNU GENERAL PUBLIC LICENSE ;;
;; Version 2, June 1991 ;;
;; ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
URLMAXLEN = 1024
BUFFERSIZE = 4096
__DEBUG__ = 1
__DEBUG_LEVEL__ = 1
format binary as ""
;--------------------------------------
frame_1:
.x = 5
.y = 10
.width = 350
.height = 55
;--------------------------------------
frame_2:
.x = 5
.y = 75
.width = 350
.height = 55
;---------------------------------------------------------------------
use32
org 0x0
db 'MENUET01' ; header
dd 0x01 ; header version
dd START ; entry point
dd IM_END ; image size
dd I_END ; required memory
dd stacktop ; esp
dd params ; I_PARAM
dd 0x0 ; I_Path
;---------------------------------------------------------------------
include '../../../../macros.inc'
include '../../../../proc32.inc'
include '../../../../dll.inc'
include '../../../../debug-fdo.inc'
include '../../box_lib/box_lib.mac'
include '../../http/http.inc'
virtual at 0
http_msg http_msg
end virtual
;---------------------------------------------------------------------
START:
mcall 68, 11 ; init heap so we can allocate memory dynamically
; load libraries
stdcall dll.Load, @IMPORT
test eax, eax
jnz exit
;---------------------------------------------------------------------
mov edi,filename_area
mov esi,start_temp_file_name
call copy_file_name_path
mov edi,fname_buf
mov esi,start_file_path
call copy_file_name_path
;OpenDialog initialisation
push dword OpenDialog_data
call [OpenDialog_Init]
; prepare for PathShow
push dword PathShow_data_1
call [PathShow_prepare]
;---------------------------------------------------------------------
; check parameters
cmp byte[params], 0 ; no parameters ?
je reset_events ; load the GUI
inc [silently]
download:
call download_1
test [silently], 0xff
jnz save
reset_events:
DEBUGF 1, "resetting events\n"
; Report events
; defaults + mouse
mcall 40,EVM_REDRAW+EVM_KEY+EVM_BUTTON+EVM_MOUSE+EVM_MOUSE_FILTER
;---------------------------------------------------------------------
redraw:
call draw_window
still:
;; DEBUGF 1, "waiting for events\n"
mcall 10 ; wait here for event
cmp eax, EV_REDRAW
je redraw
cmp eax, EV_KEY
je key
cmp eax, EV_BUTTON
je button
cmp eax, EV_MOUSE
je mouse
jmp still
;---------------------------------------------------------------------
key:
mcall 2 ; read key
stdcall [edit_box_key], dword edit1
cmp ax, 13 shl 8
je download
jmp still
;---------------------------------------------------------------------
button:
mcall 17 ; get id
cmp ah, 26
jne @f
; invoke OpenDialog
push dword OpenDialog_data
call [OpenDialog_Start]
cmp [OpenDialog_data.status],1
jne still
; prepare for PathShow
push dword PathShow_data_1
call [PathShow_prepare]
call draw_window
jmp still
@@:
cmp ah, 1 ; button id=1 ?
je exit
call download_1
jmp save
;---------------------------------------------------------------------
mouse:
stdcall [edit_box_mouse], edit1
jmp still
;---------------------------------------------------------------------
exit:
DEBUGF 1, "Exiting\n"
invoke HTTP_free, [identifier] ; free buffer
fail:
or eax, -1 ; close this program
mcall
;---------------------------------------------------------------------
download_1:
DEBUGF 1, "Starting download\n"
invoke HTTP_get, 0, 0, params, sz_add_header
test eax, eax
jz fail
mov [identifier], eax
.loop:
invoke HTTP_receive, [identifier]
test eax, eax
jnz .loop
mov eax, [identifier]
mov ebx, [eax + http_msg.content_length]
mov [final_size], ebx
mov ebx, [eax + http_msg.content_ptr]
mov [final_buffer], ebx
invoke HTTP_find_header, [identifier], sz_content_enc
test eax, eax
jz .no_deflate
; TODO: check if parameter equals "deflate"
DEBUGF 1, "deflating\n"
lea eax, [final_size]
invoke deflate_unpack, [final_buffer], eax
push eax
mcall 68, 13, [final_buffer] ; Free the compressed data
pop [final_buffer]
DEBUGF 1, "deflated size=%u bytes\n", [final_size]
.no_deflate:
invoke HTTP_free, [identifier]
mov [identifier], 0
ret
;---------------------------------------------------------------------
save:
cmp [final_buffer], 0
je still
mcall 70, fileinfo
DEBUGF 1, "File saved\n"
test [silently], 0xff
jnz exit
mov ecx, [sc.work_text]
or ecx, 0x80000000
mcall 4, <10, frame_2.y+frame_2.height+7>, , download_complete
jmp still
;---------------------------------------------------------------------
copy_file_name_path:
xor eax,eax
cld
@@:
lodsb
stosb
test eax,eax
jnz @r
ret
;---------------------------------------------------------------------
; *********************************************
; ******* WINDOW DEFINITIONS AND DRAW ********
; *********************************************
draw_window:
mcall 12, 1 ; start window draw
;-----------------------------------
; get system colors
mcall 48, 3, sc, 40
;-----------------------------------
; draw window
mov edx, [sc.work]
or edx, 0x34000000
mcall 0, <50, 370>, <350, 170>, , 0, title
;-----------------------------------
; draw frames
mov [frame_data.x],dword frame_1.x shl 16+frame_1.width
mov [frame_data.y],dword frame_1.y shl 16+frame_1.height
mov [frame_data.text_pointer],dword select_addr_text
mov eax,[sc.work]
mov [frame_data.font_backgr_color],eax
mov eax,[sc.work_text]
mov [frame_data.font_color],eax
push dword frame_data
call [Frame_draw]
;-----------------------------------
mov [frame_data.x],dword frame_2.x shl 16+frame_2.width
mov [frame_data.y],dword frame_2.y shl 16+frame_2.height
mov [frame_data.text_pointer],dword select_path_text
push dword frame_data
call [Frame_draw]
;-----------------------------------
; draw "url:" text
mov ecx, [sc.work_text]
or ecx, 80000000h
mcall 4, <frame_1.x+10, frame_1.y+15>, , type_pls
;-----------------------------------
; draw editbox
edit_boxes_set_sys_color edit1, editboxes_end, sc
stdcall [edit_box_draw], edit1
;-----------------------------------
; draw buttons
mcall 8,<frame_1.x+frame_1.width-(68+15+50+15),68>,<frame_1.y+30,16>,22,[sc.work_button] ; reload
mcall ,<frame_1.x+frame_1.width-(50+15),50>,<frame_1.y+30,16>, 24 ; stop
mcall , <frame_2.x+frame_2.width-(54+15),54>,<frame_2.y+30,16>,26 ; save
;-----------------------------------
; draw buttons text
mov ecx, [sc.work_button_text]
or ecx, 80000000h
mcall 4, <frame_1.x+frame_1.width-(68+15+50+15)+10,frame_1.y+35>, , button_text.1
mcall , <frame_1.x+frame_1.width-(50+15)+15,frame_1.y+35>, , button_text.2
mcall , <frame_2.x+frame_2.width-(54+15)+10,frame_2.y+35>, , button_text.3
mcall 13,<frame_2.x+17,frame_2.width-15*2>,<frame_2.y+10,15>,0xffffff
push dword PathShow_data_1
call [PathShow_draw]
mcall 12, 2 ; end window redraw
ret
;---------------------------------------------------------------------
; Data area
;-----------------------------------------------------------------------------
align 4
@IMPORT:
library lib_http, 'http.obj', \
box_lib, 'box_lib.obj', \
proc_lib, 'proc_lib.obj', \
archiver, 'archiver.obj'
import lib_http, \
HTTP_get, 'get' , \
HTTP_receive, 'receive', \
HTTP_find_header, 'find_header_field', \
HTTP_free, 'free'
import box_lib, \
edit_box_draw, 'edit_box_draw', \
edit_box_key, 'edit_box_key', \
edit_box_mouse, 'edit_box_mouse', \
PathShow_prepare, 'PathShow_prepare', \
PathShow_draw, 'PathShow_draw', \
Frame_draw, 'frame_draw'
import proc_lib, \
OpenDialog_Init, 'OpenDialog_init', \
OpenDialog_Start, 'OpenDialog_start'
import archiver,\
deflate_unpack, 'deflate_unpack'
;---------------------------------------------------------------------
fileinfo dd 2, 0, 0
final_size dd 0
final_buffer dd 0
db 0
dd fname_buf
;---------------------------------------------------------------------
mouse_dd dd 0
edit1 edit_box 295, 48, (frame_1.y+10), 0xffffff, 0xff, 0x80ff, 0, 0x8000, URLMAXLEN, document_user, mouse_dd, ed_focus+ed_always_focus, 7, 7
editboxes_end:
;---------------------------------------------------------------------
include_debug_strings
;---------------------------------------------------------------------
type_pls db 'URL:', 0
button_text:
.1: db 'DOWNLOAD',0
.2: db 'STOP',0
.3: db 'SELECT', 0
download_complete db 'FILE SAVED!', 0
title db 'HTTP Downloader', 0
silently db 0
sz_add_header db 'Accept-Encoding: deflate', 13, 10, 0 ; archiver.obj doesnt export unpack method for gzip yet :(
sz_content_enc db 'content-encoding', 0
;---------------------------------------------------------------------
select_addr_text db ' NETWORK ADDRESS: ',0
select_path_text db ' PATH TO SAVE FILE: ',0
;---------------------------------------------------------------------
frame_data:
.type dd 0 ;+0
.x:
.x_size dw 0 ;+4
.x_start dw 0 ;+6
.y:
.y_size dw 0 ;+8
.y_start dw 0 ;+10
.ext_fr_col dd 0x0 ;+12
.int_fr_col dd 0xffffff ;+16
.draw_text_flag dd 1 ;+20
.text_pointer dd 0 ;+24
.text_position dd 0 ;+28
.font_number dd 0 ;+32
.font_size_y dd 9 ;+36
.font_color dd 0x0 ;+40
.font_backgr_color dd 0xffffff ;+44
;---------------------------------------------------------------------
PathShow_data_1:
.type dd 0 ;+0
.start_y dw frame_2.y+14 ;+4
.start_x dw frame_2.x+20 ;+6
.font_size_x dw 6 ;+8 ; 6 - for font 0, 8 - for font 1
.area_size_x dw frame_2.width-35 ;+10
.font_number dd 0 ;+12 ; 0 - monospace, 1 - variable
.background_flag dd 0 ;+16
.font_color dd 0 ;+20
.background_color dd 0 ;+24
.text_pointer dd fname_buf ;+28
.work_area_pointer dd text_work_area ;+32
.temp_text_length dd 0 ;+36
;---------------------------------------------------------------------
OpenDialog_data:
.type dd 1 ; Save
.procinfo dd procinfo ;+4
.com_area_name dd communication_area_name ;+8
.com_area dd 0 ;+12
.opendir_path dd temp_dir_path ;+16
.dir_default_path dd communication_area_default_path ;+20
.start_path dd open_dialog_path ;+24
.draw_window dd draw_window ;+28
.status dd 0 ;+32
.openfile_pach dd fname_buf ;+36
.filename_area dd filename_area ;+40
.filter_area dd Filter
.x:
.x_size dw 420 ;+48 ; Window X size
.x_start dw 200 ;+50 ; Window X position
.y:
.y_size dw 320 ;+52 ; Window y size
.y_start dw 120 ;+54 ; Window Y position
communication_area_name:
db 'FFFFFFFF_open_dialog',0
open_dialog_path:
db '/sys/File Managers/opendial',0
communication_area_default_path:
db '/sys',0
Filter:
dd Filter.end - Filter
.1:
db 'IMG',0
db 'IMA',0
.end:
db 0
start_temp_file_name: db 'some.garbage',0
start_file_path: db '/sys/.download', 0
;---------------------------------------------------------------------
document_user db 'http://'
;---------------------------------------------------------------------
IM_END:
;---------------------------------------------------------------------
params rb URLMAXLEN
;---------------------------------------------------------------------
sc system_colors
;---------------------------------------------------------------------
identifier dd ?
;---------------------------------------------------------------------
filename_area:
rb 256
;---------------------------------------------------------------------
temp_dir_path:
rb 4096
;---------------------------------------------------------------------
procinfo:
rb 1024
;---------------------------------------------------------------------
fname_buf:
rb 4096
;---------------------------------------------------------------------
text_work_area:
rb 1024
;---------------------------------------------------------------------
rb 4096
stacktop:
;---------------------------------------------------------------------
I_END:
;---------------------------------------------------------------------

View File

@@ -1,434 +1,432 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;;
;; Copyright (C) KolibriOS team 2009-2015. All rights reserved. ;;
;; Distributed under terms of the GNU General Public License ;;
;; ;;
;; downloader.asm - HTTP client for KolibriOS ;;
;; ;;
;; ;;
;; GNU GENERAL PUBLIC LICENSE ;;
;; Version 2, June 1991 ;;
;; ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
URLMAXLEN = 1024
BUFFERSIZE = 4096
__DEBUG__ = 1
__DEBUG_LEVEL__ = 1
format binary as ""
;--------------------------------------
frame_1:
.x = 5
.y = 10
.width = 350
.height = 55
;--------------------------------------
frame_2:
.x = 5
.y = 75
.width = 350
.height = 55
;---------------------------------------------------------------------
use32
org 0x0
db 'MENUET01' ; header
dd 0x01 ; header version
dd START ; entry point
dd IM_END ; image size
dd I_END ; required memory
dd stacktop ; esp
dd params ; I_PARAM
dd 0x0 ; I_Path
;---------------------------------------------------------------------
include '../../../../macros.inc'
include '../../../../proc32.inc'
include '../../../../dll.inc'
include '../../../../debug-fdo.inc'
include '../../box_lib/trunk/box_lib.mac'
include '../../http/http.inc'
virtual at 0
http_msg http_msg
end virtual
;---------------------------------------------------------------------
START:
mcall 68, 11 ; init heap so we can allocate memory dynamically
; load libraries
stdcall dll.Load, @IMPORT
test eax, eax
jnz exit
;---------------------------------------------------------------------
mov edi,filename_area
mov esi,start_temp_file_name
call copy_file_name_path
mov edi,fname_buf
mov esi,start_file_path
call copy_file_name_path
;OpenDialog initialisation
push dword OpenDialog_data
call [OpenDialog_Init]
; prepare for PathShow
push dword PathShow_data_1
call [PathShow_prepare]
;---------------------------------------------------------------------
; check parameters
cmp byte[params], 0 ; no parameters ?
je reset_events ; load the GUI
inc [silently]
download:
call download_1
test [silently], 0xff
jnz save
reset_events:
DEBUGF 1, "resetting events\n"
; Report events
; defaults + mouse
mcall 40,EVM_REDRAW+EVM_KEY+EVM_BUTTON+EVM_MOUSE+EVM_MOUSE_FILTER
;---------------------------------------------------------------------
redraw:
call draw_window
still:
;; DEBUGF 1, "waiting for events\n"
mcall 10 ; wait here for event
cmp eax, EV_REDRAW
je redraw
cmp eax, EV_KEY
je key
cmp eax, EV_BUTTON
je button
cmp eax, EV_MOUSE
je mouse
jmp still
;---------------------------------------------------------------------
key:
mcall 2 ; read key
stdcall [edit_box_key], dword edit1
cmp ax, 13 shl 8
je download
jmp still
;---------------------------------------------------------------------
button:
mcall 17 ; get id
cmp ah, 26
jne @f
; invoke OpenDialog
push dword OpenDialog_data
call [OpenDialog_Start]
cmp [OpenDialog_data.status],1
jne still
; prepare for PathShow
push dword PathShow_data_1
call [PathShow_prepare]
call draw_window
jmp still
@@:
cmp ah, 1 ; button id=1 ?
je exit
call download_1
jmp save
;---------------------------------------------------------------------
mouse:
stdcall [edit_box_mouse], edit1
jmp still
;---------------------------------------------------------------------
exit:
DEBUGF 1, "Exiting\n"
invoke HTTP_free, [identifier] ; free buffer
fail:
or eax, -1 ; close this program
mcall
;---------------------------------------------------------------------
download_1:
DEBUGF 1, "Starting download\n"
invoke HTTP_get, document_user, 0, params, 0
test eax, eax
jz fail
mov [identifier], eax
.loop:
invoke HTTP_receive, [identifier]
test eax, eax
jnz .loop
ret
;---------------------------------------------------------------------
save:
mov ebp, [identifier]
mov eax, [ebp + http_msg.content_received]
mov [final_size], eax
mov ebx, [ebp + http_msg.content_ptr]
mov [final_buffer], ebx
mcall 70, fileinfo
DEBUGF 1, "File saved\n"
test [silently], 0xff
jnz exit
mov ecx, [sc.work_text]
or ecx, 0x80000000
mcall 4, <10, frame_2.y+frame_2.height+7>, , download_complete
jmp still
;---------------------------------------------------------------------
copy_file_name_path:
xor eax,eax
cld
@@:
lodsb
stosb
test eax,eax
jnz @r
ret
;---------------------------------------------------------------------
; *********************************************
; ******* WINDOW DEFINITIONS AND DRAW ********
; *********************************************
draw_window:
mcall 12, 1 ; start window draw
;-----------------------------------
; get system colors
mcall 48, 3, sc, 40
;-----------------------------------
; draw window
mov edx, [sc.work]
or edx, 0x34000000
mcall 0, <50, 370>, <350, 170>, , 0, title
;-----------------------------------
; draw frames
mov [frame_data.x],dword frame_1.x shl 16+frame_1.width
mov [frame_data.y],dword frame_1.y shl 16+frame_1.height
mov [frame_data.text_pointer],dword select_addr_text
mov eax,[sc.work]
mov [frame_data.font_backgr_color],eax
mov eax,[sc.work_text]
mov [frame_data.font_color],eax
push dword frame_data
call [Frame_draw]
;-----------------------------------
mov [frame_data.x],dword frame_2.x shl 16+frame_2.width
mov [frame_data.y],dword frame_2.y shl 16+frame_2.height
mov [frame_data.text_pointer],dword select_path_text
push dword frame_data
call [Frame_draw]
;-----------------------------------
; draw "url:" text
mov ecx, [sc.work_text]
or ecx, 80000000h
mcall 4, <frame_1.x+10, frame_1.y+15>, , type_pls
;-----------------------------------
; draw editbox
edit_boxes_set_sys_color edit1, editboxes_end, sc
stdcall [edit_box_draw], edit1
;-----------------------------------
; draw buttons
mcall 8,<frame_1.x+frame_1.width-(68+15+50+15),68>,<frame_1.y+30,16>,22,[sc.work_button] ; reload
mcall ,<frame_1.x+frame_1.width-(50+15),50>,<frame_1.y+30,16>, 24 ; stop
mcall , <frame_2.x+frame_2.width-(54+15),54>,<frame_2.y+30,16>,26 ; save
;-----------------------------------
; draw buttons text
mov ecx, [sc.work_button_text]
or ecx, 80000000h
mcall 4, <frame_1.x+frame_1.width-(68+15+50+15)+10,frame_1.y+35>, , button_text.1
mcall , <frame_1.x+frame_1.width-(50+15)+15,frame_1.y+35>, , button_text.2
mcall , <frame_2.x+frame_2.width-(54+15)+10,frame_2.y+35>, , button_text.3
mcall 13,<frame_2.x+17,frame_2.width-15*2>,<frame_2.y+10,15>,0xffffff
push dword PathShow_data_1
call [PathShow_draw]
mcall 12, 2 ; end window redraw
ret
;---------------------------------------------------------------------
; Data area
;-----------------------------------------------------------------------------
align 4
@IMPORT:
library lib_http, 'http.obj', \
box_lib, 'box_lib.obj', \
proc_lib, 'proc_lib.obj'
import lib_http, \
HTTP_get , 'get', \
HTTP_receive , 'receive', \
HTTP_free , 'free'
import box_lib, \
edit_box_draw, 'edit_box_draw', \
edit_box_key, 'edit_box_key', \
edit_box_mouse, 'edit_box_mouse', \
PathShow_prepare, 'PathShow_prepare', \
PathShow_draw, 'PathShow_draw', \
Frame_draw, 'frame_draw'
import proc_lib, \
OpenDialog_Init, 'OpenDialog_init', \
OpenDialog_Start, 'OpenDialog_start'
;---------------------------------------------------------------------
fileinfo dd 2, 0, 0
final_size dd 0
final_buffer dd 0
db 0
dd fname_buf
;---------------------------------------------------------------------
mouse_dd dd 0
edit1 edit_box 295, 48, (frame_1.y+10), 0xffffff, 0xff, 0x80ff, 0, 0x8000, URLMAXLEN, document_user, mouse_dd, ed_focus+ed_always_focus, 7, 7
editboxes_end:
;---------------------------------------------------------------------
include_debug_strings
;---------------------------------------------------------------------
type_pls db 'URL:', 0
button_text:
.1: db 'DOWNLOAD',0
.2: db 'STOP',0
.3: db 'SELECT', 0
download_complete db 'FILE SAVED!', 0
title db 'HTTP Downloader', 0
silently db 0
;---------------------------------------------------------------------
select_addr_text db ' NETWORK ADDRESS: ',0
select_path_text db ' PATH TO SAVE FILE: ',0
;---------------------------------------------------------------------
frame_data:
.type dd 0 ;+0
.x:
.x_size dw 0 ;+4
.x_start dw 0 ;+6
.y:
.y_size dw 0 ;+8
.y_start dw 0 ;+10
.ext_fr_col dd 0x0 ;+12
.int_fr_col dd 0xffffff ;+16
.draw_text_flag dd 1 ;+20
.text_pointer dd 0 ;+24
.text_position dd 0 ;+28
.font_number dd 0 ;+32
.font_size_y dd 9 ;+36
.font_color dd 0x0 ;+40
.font_backgr_color dd 0xffffff ;+44
;---------------------------------------------------------------------
PathShow_data_1:
.type dd 0 ;+0
.start_y dw frame_2.y+14 ;+4
.start_x dw frame_2.x+20 ;+6
.font_size_x dw 6 ;+8 ; 6 - for font 0, 8 - for font 1
.area_size_x dw frame_2.width-35 ;+10
.font_number dd 0 ;+12 ; 0 - monospace, 1 - variable
.background_flag dd 0 ;+16
.font_color dd 0 ;+20
.background_color dd 0 ;+24
.text_pointer dd fname_buf ;+28
.work_area_pointer dd text_work_area ;+32
.temp_text_length dd 0 ;+36
;---------------------------------------------------------------------
OpenDialog_data:
.type dd 1 ; Save
.procinfo dd procinfo ;+4
.com_area_name dd communication_area_name ;+8
.com_area dd 0 ;+12
.opendir_path dd temp_dir_path ;+16
.dir_default_path dd communication_area_default_path ;+20
.start_path dd open_dialog_path ;+24
.draw_window dd draw_window ;+28
.status dd 0 ;+32
.openfile_pach dd fname_buf ;+36
.filename_area dd filename_area ;+40
.filter_area dd Filter
.x:
.x_size dw 420 ;+48 ; Window X size
.x_start dw 200 ;+50 ; Window X position
.y:
.y_size dw 320 ;+52 ; Window y size
.y_start dw 120 ;+54 ; Window Y position
communication_area_name:
db 'FFFFFFFF_open_dialog',0
open_dialog_path:
db '/sys/File Managers/opendial',0
communication_area_default_path:
db '/sys',0
Filter:
dd Filter.end - Filter
.1:
db 'IMG',0
db 'IMA',0
.end:
db 0
start_temp_file_name: db 'some.garbage',0
start_file_path: db '/sys/.download', 0
;---------------------------------------------------------------------
document_user db 'http://'
;---------------------------------------------------------------------
IM_END:
;---------------------------------------------------------------------
params rb URLMAXLEN
;---------------------------------------------------------------------
sc system_colors
;---------------------------------------------------------------------
identifier dd ?
;---------------------------------------------------------------------
filename_area:
rb 256
;---------------------------------------------------------------------
temp_dir_path:
rb 4096
;---------------------------------------------------------------------
procinfo:
rb 1024
;---------------------------------------------------------------------
fname_buf:
rb 4096
;---------------------------------------------------------------------
text_work_area:
rb 1024
;---------------------------------------------------------------------
rb 4096
stacktop:
;---------------------------------------------------------------------
I_END:
;---------------------------------------------------------------------
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;;
;; Copyright (C) KolibriOS team 2009-2015. All rights reserved. ;;
;; Distributed under terms of the GNU General Public License ;;
;; ;;
;; downloader.asm - HTTP client for KolibriOS ;;
;; ;;
;; ;;
;; GNU GENERAL PUBLIC LICENSE ;;
;; Version 2, June 1991 ;;
;; ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
URLMAXLEN = 1024
BUFFERSIZE = 4096
__DEBUG__ = 1
__DEBUG_LEVEL__ = 1
format binary as ""
;--------------------------------------
frame_1:
.x = 5
.y = 10
.width = 350
.height = 55
;--------------------------------------
frame_2:
.x = 5
.y = 75
.width = 350
.height = 55
;---------------------------------------------------------------------
use32
org 0x0
db 'MENUET01' ; header
dd 0x01 ; header version
dd START ; entry point
dd IM_END ; image size
dd I_END ; required memory
dd stacktop ; esp
dd params ; I_PARAM
dd 0x0 ; I_Path
;---------------------------------------------------------------------
include '../../../../macros.inc'
include '../../../../proc32.inc'
include '../../../../dll.inc'
include '../../../../debug-fdo.inc'
include '../../box_lib/box_lib.mac'
include '../../http/http.inc'
virtual at 0
http_msg http_msg
end virtual
;---------------------------------------------------------------------
START:
mcall 68, 11 ; init heap so we can allocate memory dynamically
; load libraries
stdcall dll.Load, @IMPORT
test eax, eax
jnz exit
;---------------------------------------------------------------------
mov edi,filename_area
mov esi,start_temp_file_name
call copy_file_name_path
mov edi,fname_buf
mov esi,start_file_path
call copy_file_name_path
;OpenDialog initialisation
push dword OpenDialog_data
call [OpenDialog_Init]
; prepare for PathShow
push dword PathShow_data_1
call [PathShow_prepare]
;---------------------------------------------------------------------
; check parameters
cmp byte[params], 0 ; no parameters ?
je reset_events ; load the GUI
inc [silently]
download:
call download_1
test [silently], 0xff
jnz save
reset_events:
DEBUGF 1, "resetting events\n"
; Report events
; defaults + mouse
mcall 40,EVM_REDRAW+EVM_KEY+EVM_BUTTON+EVM_MOUSE+EVM_MOUSE_FILTER
;---------------------------------------------------------------------
redraw:
call draw_window
still:
;; DEBUGF 1, "waiting for events\n"
mcall 10 ; wait here for event
cmp eax, EV_REDRAW
je redraw
cmp eax, EV_KEY
je key
cmp eax, EV_BUTTON
je button
cmp eax, EV_MOUSE
je mouse
jmp still
;---------------------------------------------------------------------
key:
mcall 2 ; read key
stdcall [edit_box_key], dword edit1
cmp ax, 13 shl 8
je download
jmp still
;---------------------------------------------------------------------
button:
mcall 17 ; get id
cmp ah, 26
jne @f
; invoke OpenDialog
push dword OpenDialog_data
call [OpenDialog_Start]
cmp [OpenDialog_data.status],1
jne still
; prepare for PathShow
push dword PathShow_data_1
call [PathShow_prepare]
call draw_window
jmp still
@@:
cmp ah, 1 ; button id=1 ?
je exit
call download_1
jmp save
;---------------------------------------------------------------------
mouse:
stdcall [edit_box_mouse], edit1
jmp still
;---------------------------------------------------------------------
exit:
DEBUGF 1, "Exiting\n"
invoke HTTP_free, [identifier] ; free buffer
fail:
or eax, -1 ; close this program
mcall
;---------------------------------------------------------------------
download_1:
DEBUGF 1, "Starting download\n"
invoke HTTP_get, document_user, 0, params, 0
test eax, eax
jz fail
mov [identifier], eax
.loop:
invoke HTTP_receive, [identifier]
test eax, eax
jnz .loop
ret
;---------------------------------------------------------------------
save:
mov ebp, [identifier]
mov eax, [ebp + http_msg.content_received]
mov [final_size], eax
mov ebx, [ebp + http_msg.content_ptr]
mov [final_buffer], ebx
mcall 70, fileinfo
DEBUGF 1, "File saved\n"
test [silently], 0xff
jnz exit
mov ecx, [sc.work_text]
or ecx, 0x80000000
mcall 4, <10, frame_2.y+frame_2.height+7>, , download_complete
jmp still
;---------------------------------------------------------------------
copy_file_name_path:
xor eax,eax
cld
@@:
lodsb
stosb
test eax,eax
jnz @r
ret
;---------------------------------------------------------------------
; *********************************************
; ******* WINDOW DEFINITIONS AND DRAW ********
; *********************************************
draw_window:
mcall 12, 1 ; start window draw
;-----------------------------------
; get system colors
mcall 48, 3, sc, 40
;-----------------------------------
; draw window
mov edx, [sc.work]
or edx, 0x34000000
mcall 0, <50, 370>, <350, 170>, , 0, title
;-----------------------------------
; draw frames
mov [frame_data.x],dword frame_1.x shl 16+frame_1.width
mov [frame_data.y],dword frame_1.y shl 16+frame_1.height
mov [frame_data.text_pointer],dword select_addr_text
mov eax,[sc.work]
mov [frame_data.font_backgr_color],eax
mov eax,[sc.work_text]
mov [frame_data.font_color],eax
push dword frame_data
call [Frame_draw]
;-----------------------------------
mov [frame_data.x],dword frame_2.x shl 16+frame_2.width
mov [frame_data.y],dword frame_2.y shl 16+frame_2.height
mov [frame_data.text_pointer],dword select_path_text
push dword frame_data
call [Frame_draw]
;-----------------------------------
; draw "url:" text
mov ecx, [sc.work_text]
or ecx, 80000000h
mcall 4, <frame_1.x+10, frame_1.y+15>, , type_pls
;-----------------------------------
; draw editbox
edit_boxes_set_sys_color edit1, editboxes_end, sc
stdcall [edit_box_draw], edit1
;-----------------------------------
; draw buttons
mcall 8,<frame_1.x+frame_1.width-(68+15+50+15),68>,<frame_1.y+30,16>,22,[sc.work_button] ; reload
mcall ,<frame_1.x+frame_1.width-(50+15),50>,<frame_1.y+30,16>, 24 ; stop
mcall , <frame_2.x+frame_2.width-(54+15),54>,<frame_2.y+30,16>,26 ; save
;-----------------------------------
; draw buttons text
mov ecx, [sc.work_button_text]
or ecx, 80000000h
mcall 4, <frame_1.x+frame_1.width-(68+15+50+15)+10,frame_1.y+35>, , button_text.1
mcall , <frame_1.x+frame_1.width-(50+15)+15,frame_1.y+35>, , button_text.2
mcall , <frame_2.x+frame_2.width-(54+15)+10,frame_2.y+35>, , button_text.3
mcall 13,<frame_2.x+17,frame_2.width-15*2>,<frame_2.y+10,15>,0xffffff
push dword PathShow_data_1
call [PathShow_draw]
mcall 12, 2 ; end window redraw
ret
;---------------------------------------------------------------------
; Data area
;-----------------------------------------------------------------------------
align 4
@IMPORT:
library lib_http, 'http.obj', \
box_lib, 'box_lib.obj', \
proc_lib, 'proc_lib.obj'
import lib_http, \
HTTP_get , 'get', \
HTTP_receive , 'receive', \
HTTP_free , 'free'
import box_lib, \
edit_box_draw, 'edit_box_draw', \
edit_box_key, 'edit_box_key', \
edit_box_mouse, 'edit_box_mouse', \
PathShow_prepare, 'PathShow_prepare', \
PathShow_draw, 'PathShow_draw', \
Frame_draw, 'frame_draw'
import proc_lib, \
OpenDialog_Init, 'OpenDialog_init', \
OpenDialog_Start, 'OpenDialog_start'
;---------------------------------------------------------------------
fileinfo dd 2, 0, 0
final_size dd 0
final_buffer dd 0
db 0
dd fname_buf
;---------------------------------------------------------------------
mouse_dd dd 0
edit1 edit_box 295, 48, (frame_1.y+10), 0xffffff, 0xff, 0x80ff, 0, 0x8000, URLMAXLEN, document_user, mouse_dd, ed_focus+ed_always_focus, 7, 7
editboxes_end:
;---------------------------------------------------------------------
include_debug_strings
;---------------------------------------------------------------------
type_pls db 'URL:', 0
button_text:
.1: db 'DOWNLOAD',0
.2: db 'STOP',0
.3: db 'SELECT', 0
download_complete db 'FILE SAVED!', 0
title db 'HTTP Downloader', 0
silently db 0
;---------------------------------------------------------------------
select_addr_text db ' NETWORK ADDRESS: ',0
select_path_text db ' PATH TO SAVE FILE: ',0
;---------------------------------------------------------------------
frame_data:
.type dd 0 ;+0
.x:
.x_size dw 0 ;+4
.x_start dw 0 ;+6
.y:
.y_size dw 0 ;+8
.y_start dw 0 ;+10
.ext_fr_col dd 0x0 ;+12
.int_fr_col dd 0xffffff ;+16
.draw_text_flag dd 1 ;+20
.text_pointer dd 0 ;+24
.text_position dd 0 ;+28
.font_number dd 0 ;+32
.font_size_y dd 9 ;+36
.font_color dd 0x0 ;+40
.font_backgr_color dd 0xffffff ;+44
;---------------------------------------------------------------------
PathShow_data_1:
.type dd 0 ;+0
.start_y dw frame_2.y+14 ;+4
.start_x dw frame_2.x+20 ;+6
.font_size_x dw 6 ;+8 ; 6 - for font 0, 8 - for font 1
.area_size_x dw frame_2.width-35 ;+10
.font_number dd 0 ;+12 ; 0 - monospace, 1 - variable
.background_flag dd 0 ;+16
.font_color dd 0 ;+20
.background_color dd 0 ;+24
.text_pointer dd fname_buf ;+28
.work_area_pointer dd text_work_area ;+32
.temp_text_length dd 0 ;+36
;---------------------------------------------------------------------
OpenDialog_data:
.type dd 1 ; Save
.procinfo dd procinfo ;+4
.com_area_name dd communication_area_name ;+8
.com_area dd 0 ;+12
.opendir_path dd temp_dir_path ;+16
.dir_default_path dd communication_area_default_path ;+20
.start_path dd open_dialog_path ;+24
.draw_window dd draw_window ;+28
.status dd 0 ;+32
.openfile_pach dd fname_buf ;+36
.filename_area dd filename_area ;+40
.filter_area dd Filter
.x:
.x_size dw 420 ;+48 ; Window X size
.x_start dw 200 ;+50 ; Window X position
.y:
.y_size dw 320 ;+52 ; Window y size
.y_start dw 120 ;+54 ; Window Y position
communication_area_name:
db 'FFFFFFFF_open_dialog',0
open_dialog_path:
db '/sys/File Managers/opendial',0
communication_area_default_path:
db '/sys',0
Filter:
dd Filter.end - Filter
.1:
db 'IMG',0
db 'IMA',0
.end:
db 0
start_temp_file_name: db 'some.garbage',0
start_file_path: db '/sys/.download', 0
;---------------------------------------------------------------------
document_user db 'http://'
;---------------------------------------------------------------------
IM_END:
;---------------------------------------------------------------------
params rb URLMAXLEN
;---------------------------------------------------------------------
sc system_colors
;---------------------------------------------------------------------
identifier dd ?
;---------------------------------------------------------------------
filename_area:
rb 256
;---------------------------------------------------------------------
temp_dir_path:
rb 4096
;---------------------------------------------------------------------
procinfo:
rb 1024
;---------------------------------------------------------------------
fname_buf:
rb 4096
;---------------------------------------------------------------------
text_work_area:
rb 1024
;---------------------------------------------------------------------
rb 4096
stacktop:
;---------------------------------------------------------------------
I_END:
;---------------------------------------------------------------------

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

View File

@@ -1,354 +1,357 @@
;*****************************************************************************
; File Speed - for KolibriOS
; Copyright (c) 2014, Marat Zakiyanov aka Mario79, aka Mario
; All rights reserved.
;
; Redistribution and use in source and binary forms, with or without
; modification, are permitted provided that the following conditions are met:
; * Redistributions of source code must retain the above copyright
; notice, this list of conditions and the following disclaimer.
; * Redistributions in binary form must reproduce the above copyright
; notice, this list of conditions and the following disclaimer in the
; documentation and/or other materials provided with the distribution.
; * Neither the name of the <organization> nor the
; names of its contributors may be used to endorse or promote products
; derived from this software without specific prior written permission.
;
; THIS SOFTWARE IS PROVIDED BY Marat Zakiyanov ''AS IS'' AND ANY
; EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
; DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY
; DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
; (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
; ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
;*****************************************************************************
;-----------------------------------------------------------------------------
use32
org 0
db 'MENUET01'
dd 1
dd START
dd IM_END
dd I_END
dd STACK_TOP
dd 0
dd cur_dir_path
;-----------------------------------------------------------------------------
include 'lang.inc'
include '../../macros.inc'
define __DEBUG__ 1
define __DEBUG_LEVEL__ 1
include '../../debug-fdo.inc'
include '../../develop/libraries/box_lib/trunk/box_lib.mac'
include '../../KOSfuncs.inc'
include '../../load_lib.mac'
@use_library
;-----------------------------------------------------------------------------
struct RESULT_SLOT
text dd ?
read_speed dd ?
write_speed dd ?
chunk_size dd ?
ends
;-----------------------------------------------------------------------------
START:
DEBUGF 1,'FSPEED: start of programm\n'
;-----------------------------------------------------------------------------
mcall 68,11
test eax,eax
jz exit
;-----------------------------------------------------------------------------
load_libraries l_libs_start,end_l_libs
;if return code =-1 then exit, else nornary work
inc eax
test eax,eax
jz exit
;-----------------------------------------------------------------------------
;OpenDialog initialisation
push dword OpenDialog_data
call [OpenDialog_Init]
push check1
call [init_checkbox]
mcall 40,0x27
;-----------------------------------------------------------------------------
red:
call draw_window
;-----------------------------------------------------------------------------
still:
mcall 10
cmp eax,1
je red
cmp eax,2
je key
cmp eax,3
je button
push dword check1
call [check_box_mouse]
jmp still
;-----------------------------------------------------------------------------
key:
mcall 2
jmp still
;-----------------------------------------------------------------------------
button:
mcall 17
cmp ah,2
je select_file
cmp ah,3
je testing
cmp ah,1
jne still
;--------------------------------------
exit:
mcall -1
;-----------------------------------------------------------------------------
select_file:
; invoke OpenDialog
mov [OpenDialog_data.type],dword 0
push dword OpenDialog_data
call [OpenDialog_Start]
cmp [OpenDialog_data.status],1
jne still
; prepare for PathShow
push dword PathShow_data
call [PathShow_prepare]
call draw_PathShow
jmp still
;-----------------------------------------------------------------------------
draw_PathShow:
mcall 13,<5,400-20>,<5,15>,0xffffff
; draw for PathShow
push dword PathShow_data
call [PathShow_draw]
ret
;-----------------------------------------------------------------------------
draw_window:
mcall 48,3,app_colours,4*10 ; get current colors
mcall 12,1
xor esi,esi
xor ebp,ebp
mov edx,[w_work] ; color of work area RRGGBB,8->color
or edx,0x34000000
mcall 0,<100,400>,<100,300>,,,title
call draw_PathShow
mov eax,[w_work_text]
or eax,0x80000000
mov [check1.text_color],eax
push dword check1
call [check_box_draw]
mcall 8,<5,80>,<25,15>,2,[w_work_button]
mcall ,<400-65,50>,,3
mov ecx,[w_work_button_text]
or ecx,0x80000000
mcall 4,<5+10,25+4>,,s_text
mcall ,<400-65+10,25+4>,,r_text
mov ecx,[w_work_text]
or ecx,0x80000000
mcall ,<10,47>,,check_box_warning_text
mcall ,<10,65>,,result_table_text
mov edx,ecx
and edx,0xffffff
mcall 38,<5,400-15>,<59,59>
; draw result table
mov ebx,10 shl 16+77
mov ebp,result_table
mov ecx,18
;--------------------------------------
@@:
push ecx
mov ecx,[w_work_text]
or ecx,0x80000000
mcall 4,,,[ebp+RESULT_SLOT.text]
push ebx
mov edx,ebx
add edx,(11*6) shl 16
mov ebx,0x800a0000
mcall 47,,[ebp+RESULT_SLOT.read_speed],,[w_work_text]
add edx,(16*6) shl 16
mcall ,,[ebp+RESULT_SLOT.write_speed]
pop ebx
add ebx,6+5
add ebp,sizeof.RESULT_SLOT
pop ecx
dec ecx
jnz @b
mcall 12,2
ret
;-----------------------------------------------------------------------------;-----------------------------------------------------------------------------
testing:
mcall 70,fileinfo
test eax,eax
jz @f
DEBUGF 1,'FSPEED: file not found %s\n',fname
jmp still
;--------------------------------------
@@:
DEBUGF 1,'FSPEED: target file %s\n',fname
mov ebp,result_table
mov ecx,18
;--------------------------------------
@@:
push ecx
call read_chunk
pusha
call draw_window
popa
call write_chunk
pusha
call draw_window
popa
pop ecx
add ebp,sizeof.RESULT_SLOT
dec ecx
jnz @b
jmp still
;-----------------------------------------------------------------------------
read_chunk:
mov eax,[file_info+32] ; file size
cmp [ebp+RESULT_SLOT.chunk_size],eax
jb @f
xor eax,eax ; small file size for current chunk size
mov [ebp+RESULT_SLOT.read_speed],eax
ret
;--------------------------------------
@@:
mcall 68,12,[ebp+RESULT_SLOT.chunk_size]
mov [fileread.return],eax
xor eax,eax
mov [fileread.offset],eax ; zero current offset
mcall 26,9 ; get start time
add eax,1600 ; 16 sec for iterations
mov esi,eax
mov ecx,1
mov eax,[ebp+RESULT_SLOT.chunk_size]
mov [fileread.size],eax
;--------------------------------------
.loop:
mcall 70,fileread
mcall 26,9 ; check current time
cmp esi,eax
jbe .end
; correct offset
mov edx,[ebp+RESULT_SLOT.chunk_size]
add [fileread.offset],edx ; current offset
; check offset and file size
mov edx,[file_info+32] ; file size
sub edx,[ebp+RESULT_SLOT.chunk_size]
cmp [fileread.offset],edx
jbe @f
xor edx,edx
mov [fileread.offset],edx ; zero current offset
;--------------------------------------
@@:
inc ecx
jmp .loop
;--------------------------------------
.end:
mov eax,[ebp+RESULT_SLOT.chunk_size]
xor edx,edx
mul ecx
shr eax,10+4 ;div 1024 ; div 16
shl edx,18
add eax,edx
mov [ebp+RESULT_SLOT.read_speed],eax ; speed KB/s
DEBUGF 1,'FSPEED: read chunk size: %s iterations: %d speed: %d KB/s\n',\
[ebp+RESULT_SLOT.text],ecx,eax
mcall 68,13,[fileread.return]
ret
;-----------------------------------------------------------------------------
write_chunk:
test [check1.flags],dword 10b
jz .exit
mov eax,[file_info+32] ; file size
cmp [ebp+RESULT_SLOT.chunk_size],eax
jb @f
;--------------------------------------
.exit:
xor eax,eax ; small file size for current chunk size
mov [ebp+RESULT_SLOT.write_speed],eax
ret
;--------------------------------------
@@:
mcall 68,12,[ebp+RESULT_SLOT.chunk_size]
mov [filewrite.data],eax
xor eax,eax
mov [filewrite.offset],eax ; zero current offset
mcall 26,9 ; get start time
add eax,1600 ; 16 sec for iterations
mov esi,eax
mov ecx,1
mov eax,[ebp+RESULT_SLOT.chunk_size]
mov [filewrite.size],eax
;--------------------------------------
.loop:
mcall 70,filewrite
mcall 26,9 ; check current time
cmp esi,eax
jbe .end
; correct offset
mov edx,[ebp+RESULT_SLOT.chunk_size]
add [filewrite.offset],edx ; current offset
; check offset and file size
mov edx,[file_info+32] ; file size
sub edx,[ebp+RESULT_SLOT.chunk_size]
cmp [filewrite.offset],edx
jbe @f
xor edx,edx
mov [filewrite.offset],edx ; zero current offset
;--------------------------------------
@@:
inc ecx
jmp .loop
;--------------------------------------
.end:
mov eax,[ebp+RESULT_SLOT.chunk_size]
xor edx,edx
mul ecx
shr eax,10+4 ;div 1024 ; div 16
shl edx,18
add eax,edx
mov [ebp+RESULT_SLOT.write_speed],eax ; speed KB/s
DEBUGF 1,'FSPEED: write chunk size: %s iterations: %d speed: %d KB/s\n',\
[ebp+RESULT_SLOT.text],ecx,eax
mcall 68,13,[filewrite.data]
ret
;-----------------------------------------------------------------------------
include 'idata.inc'
;-----------------------------------------------------------------------------
IM_END:
;-----------------------------------------------------------------------------
include 'udata.inc'
;-----------------------------------------------------------------------------
I_END:
;-----------------------------------------------------------------------------
; SPDX-License-Identifier: NOASSERTION
;
;*****************************************************************************
; File Speed - for KolibriOS
; Copyright (c) 2014, Marat Zakiyanov aka Mario79, aka Mario
; All rights reserved.
;
; Redistribution and use in source and binary forms, with or without
; modification, are permitted provided that the following conditions are met:
; * Redistributions of source code must retain the above copyright
; notice, this list of conditions and the following disclaimer.
; * Redistributions in binary form must reproduce the above copyright
; notice, this list of conditions and the following disclaimer in the
; documentation and/or other materials provided with the distribution.
; * Neither the name of the <organization> nor the
; names of its contributors may be used to endorse or promote products
; derived from this software without specific prior written permission.
;
; THIS SOFTWARE IS PROVIDED BY Marat Zakiyanov ''AS IS'' AND ANY
; EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
; DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY
; DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
; (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
; ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
;*****************************************************************************
;-----------------------------------------------------------------------------
use32
org 0
db 'MENUET01'
dd 1
dd START
dd IM_END
dd I_END
dd STACK_TOP
dd 0
dd cur_dir_path
;-----------------------------------------------------------------------------
include 'lang.inc'
include '../../macros.inc'
define __DEBUG__ 1
define __DEBUG_LEVEL__ 1
include '../../debug-fdo.inc'
include '../../develop/libraries/box_lib/box_lib.mac'
include '../../KOSfuncs.inc'
include '../../load_lib.mac'
@use_library
;-----------------------------------------------------------------------------
struct RESULT_SLOT
text dd ?
read_speed dd ?
write_speed dd ?
chunk_size dd ?
ends
;-----------------------------------------------------------------------------
START:
DEBUGF 1,'FSPEED: start of programm\n'
;-----------------------------------------------------------------------------
mcall 68,11
test eax,eax
jz exit
;-----------------------------------------------------------------------------
load_libraries l_libs_start,end_l_libs
;if return code =-1 then exit, else nornary work
inc eax
test eax,eax
jz exit
;-----------------------------------------------------------------------------
;OpenDialog initialisation
push dword OpenDialog_data
call [OpenDialog_Init]
push check1
call [init_checkbox]
mcall 40,0x27
;-----------------------------------------------------------------------------
red:
call draw_window
;-----------------------------------------------------------------------------
still:
mcall 10
cmp eax,1
je red
cmp eax,2
je key
cmp eax,3
je button
push dword check1
call [check_box_mouse]
jmp still
;-----------------------------------------------------------------------------
key:
mcall 2
jmp still
;-----------------------------------------------------------------------------
button:
mcall 17
cmp ah,2
je select_file
cmp ah,3
je testing
cmp ah,1
jne still
;--------------------------------------
exit:
mcall -1
;-----------------------------------------------------------------------------
select_file:
; invoke OpenDialog
mov [OpenDialog_data.type],dword 0
push dword OpenDialog_data
call [OpenDialog_Start]
cmp [OpenDialog_data.status],1
jne still
; prepare for PathShow
push dword PathShow_data
call [PathShow_prepare]
call draw_PathShow
jmp still
;-----------------------------------------------------------------------------
draw_PathShow:
mcall 13,<5,400-20>,<5,15>,0xffffff
; draw for PathShow
push dword PathShow_data
call [PathShow_draw]
ret
;-----------------------------------------------------------------------------
draw_window:
mcall 48,3,app_colours,4*10 ; get current colors
mcall 12,1
xor esi,esi
xor ebp,ebp
mov edx,[w_work] ; color of work area RRGGBB,8->color
or edx,0x34000000
mcall 0,<100,400>,<100,300>,,,title
call draw_PathShow
mov eax,[w_work_text]
or eax,0x80000000
mov [check1.text_color],eax
push dword check1
call [check_box_draw]
mcall 8,<5,80>,<25,15>,2,[w_work_button]
mcall ,<400-65,50>,,3
mov ecx,[w_work_button_text]
or ecx,0x80000000
mcall 4,<5+10,25+4>,,s_text
mcall ,<400-65+10,25+4>,,r_text
mov ecx,[w_work_text]
or ecx,0x80000000
mcall ,<10,47>,,check_box_warning_text
mcall ,<10,65>,,result_table_text
mov edx,ecx
and edx,0xffffff
mcall 38,<5,400-15>,<59,59>
; draw result table
mov ebx,10 shl 16+77
mov ebp,result_table
mov ecx,18
;--------------------------------------
@@:
push ecx
mov ecx,[w_work_text]
or ecx,0x80000000
mcall 4,,,[ebp+RESULT_SLOT.text]
push ebx
mov edx,ebx
add edx,(11*6) shl 16
mov ebx,0x800a0000
mcall 47,,[ebp+RESULT_SLOT.read_speed],,[w_work_text]
add edx,(16*6) shl 16
mcall ,,[ebp+RESULT_SLOT.write_speed]
pop ebx
add ebx,6+5
add ebp,sizeof.RESULT_SLOT
pop ecx
dec ecx
jnz @b
mcall 12,2
ret
;-----------------------------------------------------------------------------;-----------------------------------------------------------------------------
testing:
mcall 70,fileinfo
test eax,eax
jz @f
DEBUGF 1,'FSPEED: file not found %s\n',fname
jmp still
;--------------------------------------
@@:
DEBUGF 1,'FSPEED: target file %s\n',fname
mov ebp,result_table
mov ecx,18
;--------------------------------------
@@:
push ecx
call read_chunk
pusha
call draw_window
popa
call write_chunk
pusha
call draw_window
popa
pop ecx
add ebp,sizeof.RESULT_SLOT
dec ecx
jnz @b
jmp still
;-----------------------------------------------------------------------------
read_chunk:
mov eax,[file_info+32] ; file size
cmp [ebp+RESULT_SLOT.chunk_size],eax
jb @f
xor eax,eax ; small file size for current chunk size
mov [ebp+RESULT_SLOT.read_speed],eax
ret
;--------------------------------------
@@:
mcall 68,12,[ebp+RESULT_SLOT.chunk_size]
mov [fileread.return],eax
xor eax,eax
mov [fileread.offset],eax ; zero current offset
mcall 26,9 ; get start time
add eax,1600 ; 16 sec for iterations
mov esi,eax
mov ecx,1
mov eax,[ebp+RESULT_SLOT.chunk_size]
mov [fileread.size],eax
;--------------------------------------
.loop:
mcall 70,fileread
mcall 26,9 ; check current time
cmp esi,eax
jbe .end
; correct offset
mov edx,[ebp+RESULT_SLOT.chunk_size]
add [fileread.offset],edx ; current offset
; check offset and file size
mov edx,[file_info+32] ; file size
sub edx,[ebp+RESULT_SLOT.chunk_size]
cmp [fileread.offset],edx
jbe @f
xor edx,edx
mov [fileread.offset],edx ; zero current offset
;--------------------------------------
@@:
inc ecx
jmp .loop
;--------------------------------------
.end:
mov eax,[ebp+RESULT_SLOT.chunk_size]
xor edx,edx
mul ecx
shr eax,10+4 ;div 1024 ; div 16
shl edx,18
add eax,edx
mov [ebp+RESULT_SLOT.read_speed],eax ; speed KB/s
DEBUGF 1,'FSPEED: read chunk size: %s iterations: %d speed: %d KB/s\n',\
[ebp+RESULT_SLOT.text],ecx,eax
mcall 68,13,[fileread.return]
ret
;-----------------------------------------------------------------------------
write_chunk:
test [check1.flags],dword 10b
jz .exit
mov eax,[file_info+32] ; file size
cmp [ebp+RESULT_SLOT.chunk_size],eax
jb @f
;--------------------------------------
.exit:
xor eax,eax ; small file size for current chunk size
mov [ebp+RESULT_SLOT.write_speed],eax
ret
;--------------------------------------
@@:
mcall 68,12,[ebp+RESULT_SLOT.chunk_size]
mov [filewrite.data],eax
xor eax,eax
mov [filewrite.offset],eax ; zero current offset
mcall 26,9 ; get start time
add eax,1600 ; 16 sec for iterations
mov esi,eax
mov ecx,1
mov eax,[ebp+RESULT_SLOT.chunk_size]
mov [filewrite.size],eax
;--------------------------------------
.loop:
mcall 70,filewrite
mcall 26,9 ; check current time
cmp esi,eax
jbe .end
; correct offset
mov edx,[ebp+RESULT_SLOT.chunk_size]
add [filewrite.offset],edx ; current offset
; check offset and file size
mov edx,[file_info+32] ; file size
sub edx,[ebp+RESULT_SLOT.chunk_size]
cmp [filewrite.offset],edx
jbe @f
xor edx,edx
mov [filewrite.offset],edx ; zero current offset
;--------------------------------------
@@:
inc ecx
jmp .loop
;--------------------------------------
.end:
mov eax,[ebp+RESULT_SLOT.chunk_size]
xor edx,edx
mul ecx
shr eax,10+4 ;div 1024 ; div 16
shl edx,18
add eax,edx
mov [ebp+RESULT_SLOT.write_speed],eax ; speed KB/s
DEBUGF 1,'FSPEED: write chunk size: %s iterations: %d speed: %d KB/s\n',\
[ebp+RESULT_SLOT.text],ecx,eax
mcall 68,13,[filewrite.data]
ret
;-----------------------------------------------------------------------------
include 'idata.inc'
;-----------------------------------------------------------------------------
IM_END:
;-----------------------------------------------------------------------------
include 'udata.inc'
;-----------------------------------------------------------------------------
I_END:
;-----------------------------------------------------------------------------

File diff suppressed because it is too large Load Diff