Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
4158 | hidnplayr | 1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
2 | ;; ;; |
||
3 | ;; Copyright (C) KolibriOS team 2009-2013. All rights reserved. ;; |
||
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 "" |
||
21 | |||
22 | use32 |
||
23 | org 0x0 |
||
24 | |||
25 | db 'MENUET01' ; header |
||
26 | dd 0x01 ; header version |
||
27 | dd START ; entry point |
||
28 | dd IM_END ; image size |
||
29 | dd I_END+0x1000 ; required memory |
||
30 | dd I_END+0x1000 ; esp |
||
31 | dd params ; I_PARAM |
||
32 | dd 0x0 ; I_Path |
||
33 | |||
4160 | hidnplayr | 34 | include '../../../../macros.inc' |
35 | include '../../../../proc32.inc' |
||
36 | include '../../../../dll.inc' |
||
37 | include '../../../../debug-fdo.inc' |
||
38 | include '../../box_lib/trunk/box_lib.mac' |
||
39 | include '../../http/http.inc' |
||
4158 | hidnplayr | 40 | |
41 | virtual at 0 |
||
42 | http_msg http_msg |
||
43 | end virtual |
||
44 | |||
45 | START: |
||
46 | |||
47 | mcall 68, 11 ; init heap so we can allocate memory dynamically |
||
48 | |||
49 | ; load libraries |
||
50 | stdcall dll.Load, @IMPORT |
||
51 | test eax, eax |
||
52 | jnz exit |
||
53 | |||
54 | ; check parameters |
||
55 | cmp byte[params], 0 ; no parameters ? |
||
56 | je reset_events ; load the GUI |
||
57 | |||
4160 | hidnplayr | 58 | inc [silently] |
59 | |||
4158 | hidnplayr | 60 | download: |
61 | |||
62 | DEBUGF 1, "Starting download\n" |
||
63 | |||
4221 | hidnplayr | 64 | invoke HTTP_get, params, 0 |
4158 | hidnplayr | 65 | test eax, eax |
66 | jz fail |
||
67 | mov [identifier], eax |
||
68 | |||
69 | .loop: |
||
70 | invoke HTTP_process, [identifier] |
||
71 | test eax, eax |
||
72 | jnz .loop |
||
73 | |||
4160 | hidnplayr | 74 | test [silently], 0xff |
75 | jnz save |
||
76 | |||
4158 | hidnplayr | 77 | reset_events: |
78 | DEBUGF 1, "resetting events\n" |
||
79 | |||
80 | ; Report events |
||
81 | ; defaults + mouse |
||
82 | mcall 40,EVM_REDRAW+EVM_KEY+EVM_BUTTON+EVM_MOUSE+EVM_MOUSE_FILTER |
||
83 | |||
84 | redraw: |
||
85 | call draw_window |
||
86 | |||
87 | still: |
||
88 | ;; DEBUGF 1, "waiting for events\n" |
||
89 | |||
90 | mcall 10 ; wait here for event |
||
91 | |||
92 | cmp eax, EV_REDRAW |
||
93 | je redraw |
||
94 | |||
95 | cmp eax, EV_KEY |
||
96 | je key |
||
97 | |||
98 | cmp eax, EV_BUTTON |
||
99 | je button |
||
100 | |||
101 | cmp eax, EV_MOUSE |
||
102 | je mouse |
||
103 | |||
104 | jmp still |
||
105 | |||
106 | key: |
||
107 | mcall 2 ; read key |
||
108 | |||
109 | stdcall [edit_box_key], dword edit1 |
||
110 | |||
111 | cmp ax, 13 shl 8 |
||
112 | je download |
||
113 | |||
114 | jmp still |
||
115 | |||
116 | button: |
||
117 | |||
118 | mcall 17 ; get id |
||
119 | |||
120 | cmp ah, 26 |
||
121 | jne @f |
||
122 | call save |
||
123 | jmp still |
||
124 | @@: |
||
125 | cmp ah, 1 ; button id=1 ? |
||
126 | je exit |
||
127 | |||
128 | jmp download |
||
129 | |||
130 | mouse: |
||
131 | stdcall [edit_box_mouse], edit1 |
||
132 | jmp still |
||
133 | |||
134 | exit: |
||
135 | DEBUGF 1, "Exiting\n" |
||
4205 | hidnplayr | 136 | invoke HTTP_free, [identifier] ; free buffer |
4158 | hidnplayr | 137 | fail: |
138 | or eax, -1 ; close this program |
||
139 | mcall |
||
140 | |||
141 | |||
142 | save: |
||
143 | mov ebp, [identifier] |
||
4220 | hidnplayr | 144 | mov eax, [ebp + http_msg.content_received] |
4158 | hidnplayr | 145 | mov [final_size], eax |
146 | lea ebx, [ebp + http_msg.data] |
||
147 | add ebx, [ebp + http_msg.header_length] |
||
148 | mov [final_buffer], ebx |
||
149 | mcall 70, fileinfo |
||
150 | |||
4160 | hidnplayr | 151 | test [silently], 0xff |
152 | jnz exit |
||
4158 | hidnplayr | 153 | |
154 | mov ecx, [sc.work_text] |
||
155 | or ecx, 0x80000000 |
||
156 | mcall 4, <10, 93>, , download_complete |
||
157 | |||
4160 | hidnplayr | 158 | jmp still |
4158 | hidnplayr | 159 | |
160 | ; ********************************************* |
||
161 | ; ******* WINDOW DEFINITIONS AND DRAW ******** |
||
162 | ; ********************************************* |
||
163 | |||
164 | draw_window: |
||
165 | |||
166 | mcall 12, 1 ; start window draw |
||
167 | |||
168 | ; get system colors |
||
169 | mcall 48, 3, sc, 40 |
||
170 | |||
171 | ; draw window |
||
172 | mov edx, [sc.work] |
||
173 | or edx, 0x34000000 |
||
174 | mcall 0, <50, 370>, <350, 140>, , 0, title |
||
175 | |||
176 | ; draw "url:" text |
||
177 | mov ecx, [sc.work_text] |
||
178 | or ecx, 80000000h |
||
179 | mcall 4, <14, 14>, , type_pls |
||
180 | |||
181 | ; draw editbox |
||
182 | edit_boxes_set_sys_color edit1, editboxes_end, sc |
||
183 | stdcall [edit_box_draw], edit1 |
||
184 | |||
185 | ; draw buttons |
||
186 | mcall 8, <90, 68>, <54, 16>, 22, [sc.work_button] ; reload |
||
187 | mcall , <166, 50>, <54, 16>, 24 ; stop |
||
188 | mcall , <224, 54>, , 26 ; save |
||
189 | |||
190 | ; draw buttons text |
||
191 | mov ecx, [sc.work_button_text] |
||
192 | or ecx, 80000000h |
||
193 | mcall 4, <102, 59>, , button_text |
||
194 | |||
195 | mcall 12, 2 ; end window redraw |
||
196 | |||
197 | ret |
||
198 | |||
199 | |||
200 | ;----------------------------------------------------------------------------- |
||
201 | ; Data area |
||
202 | ;----------------------------------------------------------------------------- |
||
203 | align 4 |
||
204 | @IMPORT: |
||
205 | |||
206 | library lib_http, 'http.obj', \ |
||
207 | box_lib, 'box_lib.obj' |
||
208 | |||
209 | import lib_http, \ |
||
210 | HTTP_get , 'get' , \ |
||
4205 | hidnplayr | 211 | HTTP_process , 'process' ,\ |
212 | HTTP_free , 'free' |
||
4158 | hidnplayr | 213 | |
214 | import box_lib, \ |
||
215 | edit_box_draw, 'edit_box', \ |
||
216 | edit_box_key, 'edit_box_key', \ |
||
217 | edit_box_mouse, 'edit_box_mouse' |
||
218 | |||
219 | ;--------------------------------------------------------------------- |
||
220 | fileinfo dd 2, 0, 0 |
||
221 | final_size dd 0 |
||
222 | final_buffer dd 0 |
||
223 | db '/rd/1/.download', 0 |
||
224 | |||
225 | ;--------------------------------------------------------------------- |
||
226 | |||
227 | mouse_dd dd 0 |
||
228 | edit1 edit_box 295, 48, 10, 0xffffff, 0xff, 0x80ff, 0, 0x8000, URLMAXLEN, document_user, mouse_dd, ed_focus+ed_always_focus, 7, 7 |
||
229 | editboxes_end: |
||
230 | |||
231 | ;--------------------------------------------------------------------- |
||
232 | |||
233 | include_debug_strings |
||
234 | |||
235 | ;--------------------------------------------------------------------- |
||
236 | |||
237 | type_pls db 'URL:', 0 |
||
4160 | hidnplayr | 238 | button_text db 'DOWNLOAD STOP SAVE', 0 |
4158 | hidnplayr | 239 | download_complete db 'File saved as /rd/1/.download', 0 |
240 | title db 'HTTP Downloader', 0 |
||
4160 | hidnplayr | 241 | silently db 0 |
4158 | hidnplayr | 242 | |
243 | ;--------------------------------------------------------------------- |
||
244 | document_user db 'http://' |
||
245 | ;--------------------------------------------------------------------- |
||
246 | IM_END: |
||
247 | ;--------------------------------------------------------------------- |
||
248 | params rb URLMAXLEN |
||
249 | ;--------------------------------------------------------------------- |
||
250 | sc system_colors |
||
251 | ;--------------------------------------------------------------------- |
||
252 | identifier dd ? |
||
253 | ;--------------------------------------------------------------------- |
||
254 | |||
255 | I_END:102,>224,>54,>166,>54,>90,>14,>350,>50,>10,> |
||
256 |