Rev 7785 | Rev 7841 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
6903 | ashmew2 | 1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
2 | ;; ;; |
||
3 | ;; Copyright (C) KolibriOS team 2017. All rights reserved. ;; |
||
4 | ;; Distributed under terms of the GNU General Public License ;; |
||
5 | ;; ;; |
||
6 | ;; netsurf-installer - Set up Netsurf Browser on KolibriOS ;; |
||
7 | ;; Author: ashmew2. ;; |
||
8 | ;; ;; |
||
9 | ;; Inspired from downloader.asm by hidnplayr@kolibrios.org ;; |
||
10 | ;; GENERAL PUBLIC LICENSE ;; |
||
11 | ;; Version 2, June 1991 ;; |
||
12 | ;; ;; |
||
13 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
||
14 | |||
15 | URLMAXLEN = 65535 |
||
16 | FILENAMEMAXLEN = 1024 |
||
6904 | ashmew2 | 17 | __DEBUG_LEVEL__ = 2 |
18 | __DEBUG__ = 1 |
||
6903 | ashmew2 | 19 | |
20 | format binary as "" |
||
21 | use32 |
||
22 | org 0x0 |
||
23 | db 'MENUET01' ; header |
||
24 | dd 0x01 ; header version |
||
25 | dd START ; entry point |
||
26 | dd I_END ; image size |
||
27 | dd I_END+0x1000 ; required memory |
||
28 | dd I_END+0x1000 ; esp |
||
29 | dd 0x0 ; I_Path |
||
30 | dd 0x0 ; I_Path |
||
31 | |||
32 | include '../../macros.inc' |
||
33 | include '../../proc32.inc' |
||
34 | include '../../dll.inc' |
||
35 | include '../../debug-fdo.inc' |
||
36 | include '../../develop/libraries/http/http.inc' |
||
7106 | leency | 37 | include '../../string.inc' |
6903 | ashmew2 | 38 | |
7785 | leency | 39 | include '../../system/notify3/notify.inc' |
40 | |||
7106 | leency | 41 | include 'notify.asm' |
42 | |||
6903 | ashmew2 | 43 | virtual at 0 |
44 | http_msg http_msg |
||
45 | end virtual |
||
46 | |||
47 | ;; Parameters |
||
48 | ;; HTTP URL to download |
||
49 | ;; Target filename |
||
50 | proc get_file_over_http targeturl, targetfilename |
||
51 | pusha |
||
6905 | ashmew2 | 52 | xor eax, eax |
6903 | ashmew2 | 53 | mov [write_to_file.current_offset], eax |
54 | mov [write_to_file.bufsize], eax |
||
55 | mov [write_to_file.bufptr], eax |
||
56 | |||
57 | DEBUGF 1, "---- HTTP : Getting %s\n", [targeturl] |
||
6905 | ashmew2 | 58 | invoke HTTP_get, [targeturl], 0, FLAG_KEEPALIVE or FLAG_BLOCK, 0 |
6903 | ashmew2 | 59 | cmp eax, 0 |
60 | je .http_error |
||
6905 | ashmew2 | 61 | mov [httpstruct], eax |
6903 | ashmew2 | 62 | |
63 | ;; No HTTP errors, create a new file for the download. |
||
6905 | ashmew2 | 64 | DEBUGF 1, "---- Creating new file : %s\n", [targetfilename] |
65 | mcall 70, create_new_file |
||
6903 | ashmew2 | 66 | cmp eax, 0 |
67 | jne .file_error |
||
68 | |||
69 | .http_receive_loop: |
||
6905 | ashmew2 | 70 | DEBUGF 1, "---- Receiving over http.\n" |
6903 | ashmew2 | 71 | invoke HTTP_receive, [httpstruct] |
6905 | ashmew2 | 72 | |
6903 | ashmew2 | 73 | cmp eax, 0 |
74 | je .http_transfer_done |
||
75 | |||
6905 | ashmew2 | 76 | |
77 | mov ebp, [httpstruct] |
||
78 | DEBUGF 1, "---- http flags = 0x%x.\n", [ebp + http_msg.flags] |
||
79 | test [ebp + http_msg.flags], 0xffff0000 |
||
6903 | ashmew2 | 80 | jnz .http_error |
81 | |||
6905 | ashmew2 | 82 | mov ebp, [ebp + http_msg.content_received] |
83 | cmp ebp, [write_to_file.current_offset] |
||
6903 | ashmew2 | 84 | jle .http_receive_loop |
6905 | ashmew2 | 85 | ;; Only proceed if we have more data in HTTP buffer than we have written to file. |
6903 | ashmew2 | 86 | |
87 | ;; Process data we got (write it to the file) |
||
6905 | ashmew2 | 88 | mov ebp, [httpstruct] |
89 | mov ecx, [ebp + http_msg.content_length] |
||
6903 | ashmew2 | 90 | mov edx, [ebp + http_msg.content_received] |
91 | |||
6905 | ashmew2 | 92 | DEBUGF 1, "---- Current file write offset : %u (http got : %u / %u)\n", [write_to_file.current_offset], edx, ecx |
6903 | ashmew2 | 93 | sub edx, [write_to_file.current_offset] |
94 | mov [write_to_file.bufsize], edx |
||
95 | |||
96 | mov ecx, [ebp + http_msg.content_ptr] |
||
97 | add ecx, [write_to_file.current_offset] |
||
98 | mov [write_to_file.bufptr], ecx |
||
99 | |||
6905 | ashmew2 | 100 | DEBUGF 1, "---- ecx + offset = 0x%x\n", ecx |
101 | DEBUGF 1, "---- Writing to file %u bytes at 0x%x to %s\n", [write_to_file.bufsize], [write_to_file.bufptr], current_filename |
||
6903 | ashmew2 | 102 | mcall 70, write_to_file |
103 | cmp eax, 0 |
||
104 | jne .file_error |
||
105 | |||
6905 | ashmew2 | 106 | DEBUGF 1, "---- Wrote to file %u bytes.\n", ebx |
6903 | ashmew2 | 107 | add [write_to_file.current_offset], ebx |
6905 | ashmew2 | 108 | DEBUGF 1, "---- File offset updated to : %u\n", [write_to_file.current_offset] |
109 | |||
6903 | ashmew2 | 110 | jmp .http_receive_loop |
111 | |||
112 | .file_error: |
||
6905 | ashmew2 | 113 | DEBUGF 1, "file_erroR with eax = %u!", eax |
7106 | leency | 114 | call EXIT |
6903 | ashmew2 | 115 | |
116 | .http_error: |
||
6905 | ashmew2 | 117 | DEBUGF 1, "http_erroR!" |
7106 | leency | 118 | call EXIT |
6903 | ashmew2 | 119 | |
120 | .http_transfer_done: |
||
6905 | ashmew2 | 121 | ;; Write any remaining bytes from the http buffer into the file |
122 | DEBUGF 1, "---- http flags = 0x%x.\n", [httpstruct + http_msg.flags] |
||
123 | DEBUGF 1, "Got %u bytes in total\n", [httpstruct + http_msg.content_length] |
||
6903 | ashmew2 | 124 | |
6905 | ashmew2 | 125 | mov ebp, [httpstruct] |
6903 | ashmew2 | 126 | mov edx, [ebp + http_msg.content_length] |
127 | |||
128 | sub edx, [write_to_file.current_offset] |
||
129 | mov [write_to_file.bufsize], edx |
||
130 | |||
131 | mov ecx, [ebp + http_msg.content_ptr] |
||
132 | add ecx, [write_to_file.current_offset] |
||
133 | mov [write_to_file.bufptr], ecx |
||
134 | |||
6905 | ashmew2 | 135 | DEBUGF 1, "---- Final ecx + offset = 0x%x\n", ecx |
136 | DEBUGF 1, "-- Writing to file %u bytes at 0x%x to %s\n", [write_to_file.bufsize], [write_to_file.bufptr], current_filename |
||
6903 | ashmew2 | 137 | |
138 | mcall 70, write_to_file |
||
139 | cmp eax, 0 |
||
140 | jne .file_error |
||
141 | |||
6905 | ashmew2 | 142 | DEBUGF 1, "-- Wrote to file %u bytes.\n", ebx |
6903 | ashmew2 | 143 | add [write_to_file.current_offset], ebx |
6905 | ashmew2 | 144 | DEBUGF 1, "-- File offset updated to : %u\n", [write_to_file.current_offset] |
145 | mov ebp, [httpstruct] |
||
6903 | ashmew2 | 146 | mov edx, [ebp + http_msg.content_length] |
147 | cmp [write_to_file.current_offset], edx |
||
148 | jne .http_transfer_done |
||
149 | |||
6905 | ashmew2 | 150 | invoke HTTP_free, [httpstruct] |
6903 | ashmew2 | 151 | |
6905 | ashmew2 | 152 | popa |
6903 | ashmew2 | 153 | ret |
154 | endp |
||
155 | |||
156 | proc make_new_folder newfolder |
||
6905 | ashmew2 | 157 | pusha |
6903 | ashmew2 | 158 | |
6905 | ashmew2 | 159 | mov eax, [newfolder] |
6903 | ashmew2 | 160 | mov [create_new_folder.foldername], eax |
6905 | ashmew2 | 161 | mcall 70, create_new_folder |
6903 | ashmew2 | 162 | test eax, eax |
163 | jz .success |
||
6905 | ashmew2 | 164 | |
165 | DEBUGF 1, "Failed to create folder: %s\n", [newfolder] |
||
7106 | leency | 166 | call EXIT |
6903 | ashmew2 | 167 | |
168 | .success: |
||
169 | popa |
||
170 | ret |
||
171 | endp |
||
172 | |||
173 | START: |
||
6905 | ashmew2 | 174 | mcall 68, 11 ; init heap |
7106 | leency | 175 | call NOTIFY_RUN |
6903 | ashmew2 | 176 | |
177 | ; load libraries |
||
178 | stdcall dll.Load, @IMPORT |
||
179 | test eax, eax |
||
180 | jnz .all_files_done_error |
||
181 | |||
6905 | ashmew2 | 182 | DEBUGF 2, "-------------------------\n" |
183 | DEBUGF 2, "NETSURF INSTALLER.\n" |
||
6903 | ashmew2 | 184 | |
6905 | ashmew2 | 185 | stdcall make_new_folder, dirname_res |
186 | stdcall make_new_folder, dirname_res_pointers |
||
187 | stdcall make_new_folder, dirname_res_throbber |
||
188 | stdcall make_new_folder, dirname_res_icons |
||
189 | |||
190 | |||
191 | .get_next_file: |
||
6903 | ashmew2 | 192 | mov edi, current_url |
193 | mov esi, url |
||
194 | |||
195 | @@: |
||
6905 | ashmew2 | 196 | movsb |
6903 | ashmew2 | 197 | cmp byte[esi], 0 |
198 | jne @b |
||
6905 | ashmew2 | 199 | ;; Loaded the base URL into current URL |
6903 | ashmew2 | 200 | |
201 | ;; Move onto the subsequent file. |
||
202 | mov esi, [filelistoffset] |
||
203 | cmp byte[esi], 0 |
||
204 | je .all_files_done |
||
205 | |||
206 | @@: |
||
6905 | ashmew2 | 207 | movsb |
6903 | ashmew2 | 208 | cmp byte[esi], 0 |
209 | jne @b |
||
210 | movsb |
||
211 | |||
6905 | ashmew2 | 212 | ;; DEBUGF 1, "-- Current URL with filename is : %s\n", current_url |
6903 | ashmew2 | 213 | |
214 | ; Create name of file we will download to |
||
6905 | ashmew2 | 215 | mov esi, download_file_path |
6903 | ashmew2 | 216 | mov edi, current_filename |
6905 | ashmew2 | 217 | |
6903 | ashmew2 | 218 | @@: |
219 | movsb |
||
220 | cmp byte[esi], 0 |
||
221 | jne @b |
||
6905 | ashmew2 | 222 | |
6903 | ashmew2 | 223 | mov esi, [filelistoffset] |
224 | @@: |
||
225 | movsb |
||
226 | cmp byte[esi], 0 |
||
227 | jne @b |
||
228 | movsb |
||
229 | mov [filelistoffset], esi |
||
6905 | ashmew2 | 230 | |
6903 | ashmew2 | 231 | ;; current_filename is now set to the name of the file |
232 | ;; current_url is now set to the name of the file we will get after download |
||
6905 | ashmew2 | 233 | DEBUGF 2, "Fetching : %s", current_filename |
7106 | leency | 234 | pusha |
235 | call NOTIFY_CHANGE |
||
236 | popa |
||
6905 | ashmew2 | 237 | stdcall get_file_over_http, current_url, current_filename |
238 | DEBUGF 2, "...DONE!\n" |
||
239 | jmp .get_next_file |
||
6903 | ashmew2 | 240 | |
241 | .all_files_done: |
||
6905 | ashmew2 | 242 | DEBUGF 2, "-------------------------\n" |
243 | DEBUGF 2, "NETSURF INSTALLED. Enjoy!\n" |
||
244 | DEBUGF 2, "-------------------------\n" |
||
7106 | leency | 245 | call EXIT |
6903 | ashmew2 | 246 | ;; Inform user that all files are done |
247 | |||
248 | .all_files_done_error: |
||
6905 | ashmew2 | 249 | DEBUGF 1, "FATAL ERROR: FAILED.\n", eax |
7106 | leency | 250 | call EXIT |
6903 | ashmew2 | 251 | |
252 | ;--------------------------------------------------------------------- |
||
253 | ; Data area |
||
254 | ;----------------------------------------------------------------------------- |
||
255 | align 4 |
||
256 | @IMPORT: |
||
257 | |||
258 | library lib_http, 'http.obj' |
||
259 | import lib_http, \ |
||
260 | HTTP_get, 'get', \ |
||
261 | HTTP_receive, 'receive', \ |
||
262 | HTTP_free, 'free' |
||
263 | |||
264 | include_debug_strings |
||
265 | |||
266 | download_file_path db '/tmp0/1/', 0 |
||
267 | dirname_res db '/tmp0/1/res', 0 |
||
268 | dirname_res_pointers db '/tmp0/1/res/pointers', 0 |
||
269 | dirname_res_throbber db '/tmp0/1/res/throbber', 0 |
||
270 | dirname_res_icons db '/tmp0/1/res/icons', 0 |
||
271 | |||
7835 | leency | 272 | url db 'www.kolibri-n.org/files/netsurf/',0 |
6904 | ashmew2 | 273 | |
7106 | leency | 274 | ; I don't know why NOTIFY_CHANGE doesn't work for the first file |
275 | ; so I use this small shit to fix it at NOTIFY_RUN phase |
||
7835 | leency | 276 | filelist_first db '/tmp0/1/netsurf', 0 |
7106 | leency | 277 | |
7835 | leency | 278 | filelist db 'netsurf', 0 |
279 | ;db 'netsurf-kolibrios.map', 0 ;what this??? |
||
6904 | ashmew2 | 280 | db 'res/adblock.css', 0 |
6903 | ashmew2 | 281 | db 'res/quirks.css', 0 |
282 | db 'res/Messages', 0 |
||
283 | db 'res/licence.html', 0 |
||
284 | db 'res/default.css', 0 |
||
285 | db 'res/netsurf.png', 0 |
||
286 | db 'res/sans.ttf', 0 |
||
287 | db 'res/welcome.html', 0 |
||
288 | db 'res/internal.css', 0 |
||
289 | db 'res/maps.html', 0 |
||
290 | db 'res/favicon.png', 0 |
||
291 | db 'res/credits.html', 0 |
||
292 | db 'res/throbber/throbber8.png', 0 |
||
293 | db 'res/throbber/throbber3.png', 0 |
||
294 | db 'res/throbber/throbber4.png', 0 |
||
295 | db 'res/throbber/throbber0.png', 0 |
||
296 | db 'res/throbber/throbber6.png', 0 |
||
297 | db 'res/throbber/throbber2.png', 0 |
||
298 | db 'res/throbber/throbber1.png', 0 |
||
299 | db 'res/throbber/throbber7.png', 0 |
||
300 | db 'res/throbber/throbber5.png', 0 |
||
301 | db 'res/pointers/point.png', 0 |
||
302 | db 'res/pointers/no_drop.png', 0 |
||
303 | db 'res/pointers/wait.png', 0 |
||
304 | db 'res/pointers/up-down.png', 0 |
||
305 | db 'res/pointers/help.png', 0 |
||
306 | db 'res/pointers/ru-ld.png', 0 |
||
307 | db 'res/pointers/menu.png', 0 |
||
308 | db 'res/pointers/not_allowed.png', 0 |
||
309 | db 'res/pointers/cross.png', 0 |
||
310 | db 'res/pointers/default.png', 0 |
||
311 | db 'res/pointers/caret.png', 0 |
||
312 | db 'res/pointers/left-right.png', 0 |
||
313 | db 'res/pointers/lu-rd.png', 0 |
||
314 | db 'res/pointers/progress.png', 0 |
||
315 | db 'res/pointers/move.png', 0 |
||
316 | db 'res/icons/back.png', 0 |
||
317 | db 'res/icons/back_g.png', 0 |
||
318 | db 'res/icons/scrollr.png', 0 |
||
319 | db 'res/icons/osk.png', 0 |
||
320 | db 'res/icons/forward_g.png', 0 |
||
321 | db 'res/icons/scrolll.png', 0 |
||
322 | db 'res/icons/history.png', 0 |
||
323 | db 'res/icons/forward.png', 0 |
||
324 | db 'res/icons/home_g.png', 0 |
||
325 | db 'res/icons/history_g.png', 0 |
||
326 | db 'res/icons/reload_g.png', 0 |
||
327 | db 'res/icons/scrollu.png', 0 |
||
328 | db 'res/icons/stop.png', 0 |
||
329 | db 'res/icons/scrolld.png', 0 |
||
330 | db 'res/icons/stop_g.png', 0 |
||
331 | db 'res/icons/home.png', 0 |
||
332 | db 'res/icons/reload.png', 0 |
||
333 | db 0 |
||
334 | |||
335 | filelistoffset dd filelist |
||
336 | httpstruct dd 0 |
||
337 | |||
6905 | ashmew2 | 338 | create_new_file dd 2, 0, 0, 0, 0 |
6903 | ashmew2 | 339 | db 0 |
340 | dd current_filename |
||
341 | |||
342 | create_new_folder dd 9, 0, 0, 0, 0 |
||
343 | db 0 |
||
344 | .foldername dd 0 |
||
345 | |||
346 | write_to_file dd 3 |
||
347 | .current_offset dd 0, 0 |
||
348 | .bufsize dd 0 |
||
349 | .bufptr dd 0 |
||
350 | db 0 |
||
351 | dd current_filename |
||
6905 | ashmew2 | 352 | |
353 | socketdata rb 4096 |
||
354 | current_url rb URLMAXLEN |
||
355 | current_filename rb FILENAMEMAXLEN |
||
7106 | leency | 356 | |
357 | ;===================================================================== |
||
358 | ; NOTIFY DATA |
||
359 | timer dd 0 |
||
360 | params rb 256 |
||
361 | ctrl: |
||
362 | .name rb 32 |
||
363 | .addr rd 1 |
||
364 | rb 2048 |
||
365 | |||
366 | sz_text: |
||
367 | db "Netsurf installer ", 0 |
||
368 | sz_quote: |
||
369 | db "'", 0 |
||
370 | sz_sec_line_start: |
||
371 | db 10, "Fetching:",10, 0 |
||
372 | sz_flags: |
||
373 | db "Ddcpt", 0 |
||
374 | |||
375 | sz_final_text: |
||
376 | db "Netsurf installer",10,"Download complete.",10,"Enjoy!",0 |
||
377 | |||
378 | fi_launch: |
||
379 | dd 7, 0, params, 0, 0 |
||
7835 | leency | 380 | db "/sys/@notify", 0 |
7106 | leency | 381 | |
382 | fileopen dd 7 |
||
383 | dd 0 ; flags |
||
384 | dd 0 ; parameters |
||
385 | dd 0 ; reserved |
||
386 | dd 0 ; reserved |
||
7835 | leency | 387 | db "/tmp0/1/netsurf", 0 ; path |
7106 | leency | 388 | ;===================================================================== |
389 | |||
6903 | ashmew2 | 390 | I_END: |