Subversion Repositories Kolibri OS

Rev

Rev 5539 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
4158 hidnplayr 1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;                                                                 ;;
5534 hidnplayr 3
;; Copyright (C) KolibriOS team 2009-2015. All rights reserved.    ;;
4158 hidnplayr 4
;; Distributed under terms of the GNU General Public License       ;;
5
;;                                                                 ;;
6
;;  downloader.asm - HTTP client for KolibriOS                     ;;
7
;;                                                                 ;;
8
;;                                                                 ;;
9
;;          GNU GENERAL PUBLIC LICENSE                             ;;
10
;;             Version 2, June 1991                                ;;
11
;;                                                                 ;;
12
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13
 
14
URLMAXLEN       = 1024
15
BUFFERSIZE      = 4096
16
 
17
__DEBUG__       = 1
18
__DEBUG_LEVEL__ = 1
19
 
20
format binary as ""
4243 mario79 21
;--------------------------------------
22
frame_1:
23
  .x      = 5
24
  .y      = 10
25
  .width  = 350
26
  .height = 55
27
;--------------------------------------
28
frame_2:
29
  .x      = 5
30
  .y      = 75
31
  .width  = 350
32
  .height = 55
33
;---------------------------------------------------------------------
4158 hidnplayr 34
use32
35
        org     0x0
36
 
37
        db      'MENUET01'      ; header
38
        dd      0x01            ; header version
39
        dd      START           ; entry point
40
        dd      IM_END          ; image size
4243 mario79 41
        dd      I_END           ; required memory
42
        dd      stacktop        ; esp
4158 hidnplayr 43
        dd      params          ; I_PARAM
44
        dd      0x0             ; I_Path
4243 mario79 45
;---------------------------------------------------------------------
4160 hidnplayr 46
include '../../../../macros.inc'
47
include '../../../../proc32.inc'
48
include '../../../../dll.inc'
49
include '../../../../debug-fdo.inc'
50
include '../../box_lib/trunk/box_lib.mac'
51
include '../../http/http.inc'
4158 hidnplayr 52
 
53
virtual at 0
54
        http_msg http_msg
55
end virtual
4243 mario79 56
;---------------------------------------------------------------------
4158 hidnplayr 57
START:
58
 
59
        mcall   68, 11                  ; init heap so we can allocate memory dynamically
60
 
61
; load libraries
62
        stdcall dll.Load, @IMPORT
63
        test    eax, eax
64
        jnz     exit
4243 mario79 65
;---------------------------------------------------------------------
5534 hidnplayr 66
        mov     edi,filename_area
67
        mov     esi,start_temp_file_name
68
        call    copy_file_name_path
4158 hidnplayr 69
 
5534 hidnplayr 70
        mov     edi,fname_buf
71
        mov     esi,start_file_path
72
        call    copy_file_name_path
4243 mario79 73
 
74
;OpenDialog     initialisation
75
        push    dword OpenDialog_data
76
        call    [OpenDialog_Init]
77
 
78
; prepare for PathShow
79
        push    dword PathShow_data_1
80
        call    [PathShow_prepare]
81
;---------------------------------------------------------------------
4158 hidnplayr 82
; check parameters
83
        cmp     byte[params], 0         ; no parameters ?
84
        je      reset_events            ; load the GUI
85
 
4160 hidnplayr 86
        inc     [silently]
87
 
4158 hidnplayr 88
download:
5534 hidnplayr 89
        call    download_1
4158 hidnplayr 90
 
4160 hidnplayr 91
        test    [silently], 0xff
92
        jnz     save
93
 
4158 hidnplayr 94
reset_events:
95
        DEBUGF  1, "resetting events\n"
96
 
97
; Report events
98
; defaults + mouse
99
        mcall   40,EVM_REDRAW+EVM_KEY+EVM_BUTTON+EVM_MOUSE+EVM_MOUSE_FILTER
4243 mario79 100
;---------------------------------------------------------------------
4158 hidnplayr 101
redraw:
102
        call    draw_window
103
 
104
still:
105
;;        DEBUGF  1, "waiting for events\n"
106
 
107
        mcall   10      ; wait here for event
108
 
109
        cmp     eax, EV_REDRAW
110
        je      redraw
111
 
112
        cmp     eax, EV_KEY
113
        je      key
114
 
115
        cmp     eax, EV_BUTTON
116
        je      button
117
 
118
        cmp     eax, EV_MOUSE
119
        je      mouse
120
 
121
        jmp     still
4243 mario79 122
;---------------------------------------------------------------------
4158 hidnplayr 123
key:
124
        mcall   2       ; read key
125
 
126
        stdcall [edit_box_key], dword edit1
127
 
128
        cmp     ax, 13 shl 8
129
        je      download
130
 
131
        jmp     still
4243 mario79 132
;---------------------------------------------------------------------
4158 hidnplayr 133
button:
134
 
135
        mcall   17      ; get id
136
 
137
        cmp     ah, 26
138
        jne     @f
4243 mario79 139
; invoke OpenDialog
140
        push    dword OpenDialog_data
141
        call    [OpenDialog_Start]
142
        cmp     [OpenDialog_data.status],1
143
        jne     still
144
 
145
; prepare for PathShow
146
        push    dword PathShow_data_1
147
        call    [PathShow_prepare]
148
        call    draw_window
4158 hidnplayr 149
        jmp     still
4243 mario79 150
@@:
4158 hidnplayr 151
        cmp     ah, 1   ; button id=1 ?
152
        je      exit
153
 
5534 hidnplayr 154
        call    download_1
4243 mario79 155
        jmp     save
156
;---------------------------------------------------------------------
4158 hidnplayr 157
mouse:
158
        stdcall [edit_box_mouse], edit1
159
        jmp     still
4243 mario79 160
;---------------------------------------------------------------------
4158 hidnplayr 161
exit:
162
        DEBUGF  1, "Exiting\n"
4205 hidnplayr 163
        invoke  HTTP_free, [identifier] ; free buffer
4158 hidnplayr 164
fail:
165
        or      eax, -1 ; close this program
166
        mcall
4243 mario79 167
;---------------------------------------------------------------------
168
download_1:
169
        DEBUGF  1, "Starting download\n"
4158 hidnplayr 170
 
5534 hidnplayr 171
        invoke  HTTP_get, 0, 0, params, 0
4243 mario79 172
        test    eax, eax
173
        jz      fail
174
        mov     [identifier], eax
4158 hidnplayr 175
 
4243 mario79 176
  .loop:
5534 hidnplayr 177
        invoke  HTTP_receive, [identifier]
4243 mario79 178
        test    eax, eax
179
        jnz     .loop
5534 hidnplayr 180
        ret
4243 mario79 181
;---------------------------------------------------------------------
4158 hidnplayr 182
save:
183
        mov     ebp, [identifier]
4220 hidnplayr 184
        mov     eax, [ebp + http_msg.content_received]
4158 hidnplayr 185
        mov     [final_size], eax
5094 hidnplayr 186
        mov     ebx, [ebp + http_msg.content_ptr]
4158 hidnplayr 187
        mov     [final_buffer], ebx
188
        mcall   70, fileinfo
189
 
4243 mario79 190
        DEBUGF  1, "File saved\n"
191
 
4160 hidnplayr 192
        test    [silently], 0xff
193
        jnz     exit
4158 hidnplayr 194
 
195
        mov     ecx, [sc.work_text]
196
        or      ecx, 0x80000000
4243 mario79 197
        mcall   4, <10, frame_2.y+frame_2.height+7>, , download_complete
4158 hidnplayr 198
 
4160 hidnplayr 199
        jmp     still
4243 mario79 200
;---------------------------------------------------------------------
201
copy_file_name_path:
5534 hidnplayr 202
        xor     eax,eax
203
        cld
4243 mario79 204
@@:
5534 hidnplayr 205
        lodsb
206
        stosb
207
        test    eax,eax
208
        jnz     @r
209
        ret
4243 mario79 210
;---------------------------------------------------------------------
4158 hidnplayr 211
;   *********************************************
212
;   *******  WINDOW DEFINITIONS AND DRAW ********
213
;   *********************************************
214
 
215
draw_window:
216
 
217
        mcall   12, 1   ; start window draw
4243 mario79 218
;-----------------------------------
4158 hidnplayr 219
; get system colors
220
        mcall   48, 3, sc, 40
4243 mario79 221
;-----------------------------------
4158 hidnplayr 222
; draw window
223
        mov     edx, [sc.work]
224
        or      edx, 0x34000000
4243 mario79 225
        mcall   0, <50, 370>, <350, 170>, , 0, title
226
;-----------------------------------
227
; draw frames
5534 hidnplayr 228
        mov     [frame_data.x],dword frame_1.x shl 16+frame_1.width
229
        mov     [frame_data.y],dword frame_1.y shl 16+frame_1.height
230
        mov     [frame_data.text_pointer],dword select_addr_text
231
        mov     eax,[sc.work]
232
        mov     [frame_data.font_backgr_color],eax
233
        mov     eax,[sc.work_text]
234
        mov     [frame_data.font_color],eax
235
 
236
        push    dword frame_data
237
        call    [Frame_draw]
4243 mario79 238
;-----------------------------------
5534 hidnplayr 239
        mov     [frame_data.x],dword frame_2.x shl 16+frame_2.width
240
        mov     [frame_data.y],dword frame_2.y shl 16+frame_2.height
241
        mov     [frame_data.text_pointer],dword select_path_text
4158 hidnplayr 242
 
5534 hidnplayr 243
        push    dword frame_data
244
        call    [Frame_draw]
4243 mario79 245
;-----------------------------------
4158 hidnplayr 246
; draw "url:" text
247
        mov     ecx, [sc.work_text]
248
        or      ecx, 80000000h
4243 mario79 249
        mcall   4, , , type_pls
250
;-----------------------------------
4158 hidnplayr 251
; draw editbox
252
        edit_boxes_set_sys_color edit1, editboxes_end, sc
253
        stdcall [edit_box_draw], edit1
4243 mario79 254
;-----------------------------------
4158 hidnplayr 255
; draw buttons
4243 mario79 256
        mcall   8,,,22,[sc.work_button] ; reload
257
        mcall   ,,, 24 ; stop
5534 hidnplayr 258
 
4243 mario79 259
        mcall   , ,,26 ; save
260
;-----------------------------------
4158 hidnplayr 261
; draw buttons text
262
        mov     ecx, [sc.work_button_text]
263
        or      ecx, 80000000h
4243 mario79 264
        mcall   4, , , button_text.1
265
        mcall   , , , button_text.2
266
        mcall   , , , button_text.3
5534 hidnplayr 267
 
4243 mario79 268
        mcall   13,,,0xffffff
269
        push    dword PathShow_data_1
270
        call    [PathShow_draw]
5534 hidnplayr 271
 
4158 hidnplayr 272
        mcall   12, 2   ; end window redraw
273
 
274
        ret
4243 mario79 275
;---------------------------------------------------------------------
4158 hidnplayr 276
; Data area
277
;-----------------------------------------------------------------------------
278
align   4
279
@IMPORT:
280
 
281
library lib_http,       'http.obj', \
4243 mario79 282
        box_lib,        'box_lib.obj', \
283
        proc_lib,       'proc_lib.obj'
4158 hidnplayr 284
 
285
import  lib_http, \
5534 hidnplayr 286
        HTTP_get                , 'get', \
287
        HTTP_receive            , 'receive', \
4205 hidnplayr 288
        HTTP_free               , 'free'
4158 hidnplayr 289
 
290
import  box_lib, \
9568 IgorA 291
        edit_box_draw,    'edit_box_draw', \
4243 mario79 292
        edit_box_key,     'edit_box_key', \
293
        edit_box_mouse,   'edit_box_mouse', \
294
        PathShow_prepare, 'PathShow_prepare', \
295
        PathShow_draw,    'PathShow_draw', \
296
        Frame_draw,       'frame_draw'
4158 hidnplayr 297
 
4243 mario79 298
import  proc_lib, \
299
        OpenDialog_Init,  'OpenDialog_init', \
300
        OpenDialog_Start, 'OpenDialog_start'
4158 hidnplayr 301
;---------------------------------------------------------------------
302
fileinfo        dd 2, 0, 0
303
final_size      dd 0
304
final_buffer    dd 0
4243 mario79 305
                db 0
306
                dd fname_buf
4158 hidnplayr 307
;---------------------------------------------------------------------
308
 
309
mouse_dd        dd 0
4243 mario79 310
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
4158 hidnplayr 311
editboxes_end:
312
 
313
;---------------------------------------------------------------------
314
 
315
include_debug_strings
316
 
317
;---------------------------------------------------------------------
318
 
319
type_pls        db 'URL:', 0
4243 mario79 320
button_text:
321
.1:             db 'DOWNLOAD',0
322
.2:             db 'STOP',0
323
.3:             db 'SELECT', 0
324
download_complete db 'FILE SAVED!', 0
4158 hidnplayr 325
title           db 'HTTP Downloader', 0
4160 hidnplayr 326
silently        db 0
4158 hidnplayr 327
 
328
;---------------------------------------------------------------------
4243 mario79 329
select_addr_text db ' NETWORK ADDRESS: ',0
330
select_path_text db ' PATH TO SAVE FILE: ',0
331
;---------------------------------------------------------------------
332
frame_data:
5534 hidnplayr 333
.type                   dd 0 ;+0
4243 mario79 334
.x:
5534 hidnplayr 335
.x_size                 dw 0 ;+4
336
.x_start                dw 0 ;+6
4243 mario79 337
.y:
5534 hidnplayr 338
.y_size                 dw 0 ;+8
339
.y_start                dw 0 ;+10
340
.ext_fr_col             dd 0x0 ;+12
341
.int_fr_col             dd 0xffffff ;+16
342
.draw_text_flag         dd 1 ;+20
343
.text_pointer           dd 0 ;+24
344
.text_position          dd 0 ;+28
345
.font_number            dd 0 ;+32
346
.font_size_y            dd 9 ;+36
347
.font_color             dd 0x0 ;+40
348
.font_backgr_color      dd 0xffffff ;+44
4243 mario79 349
;---------------------------------------------------------------------
350
PathShow_data_1:
351
.type                   dd 0    ;+0
352
.start_y                dw frame_2.y+14   ;+4
353
.start_x                dw frame_2.x+20   ;+6
354
.font_size_x            dw 6    ;+8     ; 6 - for font 0, 8 - for font 1
355
.area_size_x            dw frame_2.width-35  ;+10
356
.font_number            dd 0    ;+12    ; 0 - monospace, 1 - variable
357
.background_flag        dd 0    ;+16
358
.font_color             dd 0    ;+20
359
.background_color       dd 0    ;+24
360
.text_pointer           dd fname_buf    ;+28
361
.work_area_pointer      dd text_work_area       ;+32
362
.temp_text_length       dd 0    ;+36
363
;---------------------------------------------------------------------
364
OpenDialog_data:
365
.type                   dd 1    ; Save
366
.procinfo               dd procinfo     ;+4
367
.com_area_name          dd communication_area_name      ;+8
368
.com_area               dd 0    ;+12
369
.opendir_path           dd temp_dir_path        ;+16
370
.dir_default_path       dd communication_area_default_path      ;+20
371
.start_path             dd open_dialog_path     ;+24
372
.draw_window            dd draw_window  ;+28
373
.status                 dd 0    ;+32
374
.openfile_pach          dd fname_buf    ;+36
375
.filename_area          dd filename_area        ;+40
376
.filter_area            dd Filter
377
.x:
378
.x_size                 dw 420 ;+48 ; Window X size
379
.x_start                dw 200 ;+50 ; Window X position
380
.y:
381
.y_size                 dw 320 ;+52 ; Window y size
382
.y_start                dw 120 ;+54 ; Window Y position
383
 
384
communication_area_name:
385
        db 'FFFFFFFF_open_dialog',0
386
open_dialog_path:
387
    db '/sys/File Managers/opendial',0
388
communication_area_default_path:
389
        db '/sys',0
390
 
391
Filter:
392
dd      Filter.end - Filter
393
.1:
394
db      'IMG',0
395
db      'IMA',0
396
.end:
397
db      0
398
 
399
start_temp_file_name:   db 'some.garbage',0
400
 
401
start_file_path:  db '/sys/.download', 0
402
;---------------------------------------------------------------------
4158 hidnplayr 403
document_user   db 'http://'
404
;---------------------------------------------------------------------
405
IM_END:
406
;---------------------------------------------------------------------
407
params          rb URLMAXLEN
408
;---------------------------------------------------------------------
409
                sc system_colors
410
;---------------------------------------------------------------------
411
identifier      dd ?
412
;---------------------------------------------------------------------
4243 mario79 413
filename_area:
414
                rb 256
415
;---------------------------------------------------------------------
416
temp_dir_path:
417
                rb 4096
418
;---------------------------------------------------------------------
419
procinfo:
420
                rb 1024
421
;---------------------------------------------------------------------
422
fname_buf:
423
                rb 4096
424
;---------------------------------------------------------------------
425
text_work_area:
426
                rb 1024
427
;---------------------------------------------------------------------
428
                rb 4096
429
stacktop:
430
;---------------------------------------------------------------------
4158 hidnplayr 431
I_END:
4243 mario79 432
;---------------------------------------------------------------------
4158 hidnplayr 433