Rev 6904 | Rev 7058 | 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' |
||
37 | |||
38 | virtual at 0 |
||
39 | http_msg http_msg |
||
40 | end virtual |
||
41 | |||
42 | ;; Parameters |
||
43 | ;; HTTP URL to download |
||
44 | ;; Target filename |
||
45 | proc get_file_over_http targeturl, targetfilename |
||
46 | pusha |
||
6905 | ashmew2 | 47 | xor eax, eax |
6903 | ashmew2 | 48 | mov [write_to_file.current_offset], eax |
49 | mov [write_to_file.bufsize], eax |
||
50 | mov [write_to_file.bufptr], eax |
||
51 | |||
52 | DEBUGF 1, "---- HTTP : Getting %s\n", [targeturl] |
||
6905 | ashmew2 | 53 | invoke HTTP_get, [targeturl], 0, FLAG_KEEPALIVE or FLAG_BLOCK, 0 |
6903 | ashmew2 | 54 | cmp eax, 0 |
55 | je .http_error |
||
6905 | ashmew2 | 56 | mov [httpstruct], eax |
6903 | ashmew2 | 57 | |
58 | ;; No HTTP errors, create a new file for the download. |
||
6905 | ashmew2 | 59 | DEBUGF 1, "---- Creating new file : %s\n", [targetfilename] |
60 | mcall 70, create_new_file |
||
6903 | ashmew2 | 61 | cmp eax, 0 |
62 | jne .file_error |
||
63 | |||
64 | .http_receive_loop: |
||
6905 | ashmew2 | 65 | DEBUGF 1, "---- Receiving over http.\n" |
6903 | ashmew2 | 66 | invoke HTTP_receive, [httpstruct] |
6905 | ashmew2 | 67 | |
6903 | ashmew2 | 68 | cmp eax, 0 |
69 | je .http_transfer_done |
||
70 | |||
6905 | ashmew2 | 71 | |
72 | mov ebp, [httpstruct] |
||
73 | DEBUGF 1, "---- http flags = 0x%x.\n", [ebp + http_msg.flags] |
||
74 | test [ebp + http_msg.flags], 0xffff0000 |
||
6903 | ashmew2 | 75 | jnz .http_error |
76 | |||
6905 | ashmew2 | 77 | mov ebp, [ebp + http_msg.content_received] |
78 | cmp ebp, [write_to_file.current_offset] |
||
6903 | ashmew2 | 79 | jle .http_receive_loop |
6905 | ashmew2 | 80 | ;; Only proceed if we have more data in HTTP buffer than we have written to file. |
6903 | ashmew2 | 81 | |
82 | ;; Process data we got (write it to the file) |
||
6905 | ashmew2 | 83 | mov ebp, [httpstruct] |
84 | mov ecx, [ebp + http_msg.content_length] |
||
6903 | ashmew2 | 85 | mov edx, [ebp + http_msg.content_received] |
86 | |||
6905 | ashmew2 | 87 | DEBUGF 1, "---- Current file write offset : %u (http got : %u / %u)\n", [write_to_file.current_offset], edx, ecx |
6903 | ashmew2 | 88 | sub edx, [write_to_file.current_offset] |
89 | mov [write_to_file.bufsize], edx |
||
90 | |||
91 | mov ecx, [ebp + http_msg.content_ptr] |
||
92 | add ecx, [write_to_file.current_offset] |
||
93 | mov [write_to_file.bufptr], ecx |
||
94 | |||
6905 | ashmew2 | 95 | DEBUGF 1, "---- ecx + offset = 0x%x\n", ecx |
96 | 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 | 97 | mcall 70, write_to_file |
98 | cmp eax, 0 |
||
99 | jne .file_error |
||
100 | |||
6905 | ashmew2 | 101 | DEBUGF 1, "---- Wrote to file %u bytes.\n", ebx |
6903 | ashmew2 | 102 | add [write_to_file.current_offset], ebx |
6905 | ashmew2 | 103 | DEBUGF 1, "---- File offset updated to : %u\n", [write_to_file.current_offset] |
104 | |||
6903 | ashmew2 | 105 | jmp .http_receive_loop |
106 | |||
107 | .file_error: |
||
6905 | ashmew2 | 108 | DEBUGF 1, "file_erroR with eax = %u!", eax |
6903 | ashmew2 | 109 | mcall -1 |
110 | |||
111 | .http_error: |
||
6905 | ashmew2 | 112 | DEBUGF 1, "http_erroR!" |
6903 | ashmew2 | 113 | mcall -1 |
114 | |||
115 | .http_transfer_done: |
||
6905 | ashmew2 | 116 | ;; Write any remaining bytes from the http buffer into the file |
117 | DEBUGF 1, "---- http flags = 0x%x.\n", [httpstruct + http_msg.flags] |
||
118 | DEBUGF 1, "Got %u bytes in total\n", [httpstruct + http_msg.content_length] |
||
6903 | ashmew2 | 119 | |
6905 | ashmew2 | 120 | mov ebp, [httpstruct] |
6903 | ashmew2 | 121 | mov edx, [ebp + http_msg.content_length] |
122 | |||
123 | sub edx, [write_to_file.current_offset] |
||
124 | mov [write_to_file.bufsize], edx |
||
125 | |||
126 | mov ecx, [ebp + http_msg.content_ptr] |
||
127 | add ecx, [write_to_file.current_offset] |
||
128 | mov [write_to_file.bufptr], ecx |
||
129 | |||
6905 | ashmew2 | 130 | DEBUGF 1, "---- Final ecx + offset = 0x%x\n", ecx |
131 | 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 | 132 | |
133 | mcall 70, write_to_file |
||
134 | cmp eax, 0 |
||
135 | jne .file_error |
||
136 | |||
6905 | ashmew2 | 137 | DEBUGF 1, "-- Wrote to file %u bytes.\n", ebx |
6903 | ashmew2 | 138 | add [write_to_file.current_offset], ebx |
6905 | ashmew2 | 139 | DEBUGF 1, "-- File offset updated to : %u\n", [write_to_file.current_offset] |
140 | mov ebp, [httpstruct] |
||
6903 | ashmew2 | 141 | mov edx, [ebp + http_msg.content_length] |
142 | cmp [write_to_file.current_offset], edx |
||
143 | jne .http_transfer_done |
||
144 | |||
6905 | ashmew2 | 145 | invoke HTTP_free, [httpstruct] |
6903 | ashmew2 | 146 | |
6905 | ashmew2 | 147 | popa |
6903 | ashmew2 | 148 | ret |
149 | endp |
||
150 | |||
151 | proc make_new_folder newfolder |
||
6905 | ashmew2 | 152 | pusha |
6903 | ashmew2 | 153 | |
6905 | ashmew2 | 154 | mov eax, [newfolder] |
6903 | ashmew2 | 155 | mov [create_new_folder.foldername], eax |
6905 | ashmew2 | 156 | mcall 70, create_new_folder |
6903 | ashmew2 | 157 | test eax, eax |
158 | jz .success |
||
6905 | ashmew2 | 159 | |
160 | DEBUGF 1, "Failed to create folder: %s\n", [newfolder] |
||
6903 | ashmew2 | 161 | mcall -1 |
162 | |||
163 | .success: |
||
164 | popa |
||
165 | ret |
||
166 | endp |
||
167 | |||
168 | START: |
||
6905 | ashmew2 | 169 | mcall 68, 11 ; init heap |
6903 | ashmew2 | 170 | |
171 | ; load libraries |
||
172 | stdcall dll.Load, @IMPORT |
||
173 | test eax, eax |
||
174 | jnz .all_files_done_error |
||
175 | |||
6905 | ashmew2 | 176 | DEBUGF 2, "-------------------------\n" |
177 | DEBUGF 2, "NETSURF INSTALLER.\n" |
||
6903 | ashmew2 | 178 | |
6905 | ashmew2 | 179 | stdcall make_new_folder, dirname_res |
180 | stdcall make_new_folder, dirname_res_pointers |
||
181 | stdcall make_new_folder, dirname_res_throbber |
||
182 | stdcall make_new_folder, dirname_res_icons |
||
183 | |||
184 | |||
185 | .get_next_file: |
||
6903 | ashmew2 | 186 | mov edi, current_url |
187 | mov esi, url |
||
188 | |||
189 | @@: |
||
6905 | ashmew2 | 190 | movsb |
6903 | ashmew2 | 191 | cmp byte[esi], 0 |
192 | jne @b |
||
6905 | ashmew2 | 193 | ;; Loaded the base URL into current URL |
6903 | ashmew2 | 194 | |
195 | ;; Move onto the subsequent file. |
||
196 | mov esi, [filelistoffset] |
||
197 | cmp byte[esi], 0 |
||
198 | je .all_files_done |
||
199 | |||
200 | @@: |
||
6905 | ashmew2 | 201 | movsb |
6903 | ashmew2 | 202 | cmp byte[esi], 0 |
203 | jne @b |
||
204 | movsb |
||
205 | |||
6905 | ashmew2 | 206 | ;; DEBUGF 1, "-- Current URL with filename is : %s\n", current_url |
6903 | ashmew2 | 207 | |
208 | ; Create name of file we will download to |
||
6905 | ashmew2 | 209 | mov esi, download_file_path |
6903 | ashmew2 | 210 | mov edi, current_filename |
6905 | ashmew2 | 211 | |
6903 | ashmew2 | 212 | @@: |
213 | movsb |
||
214 | cmp byte[esi], 0 |
||
215 | jne @b |
||
6905 | ashmew2 | 216 | |
6903 | ashmew2 | 217 | mov esi, [filelistoffset] |
218 | @@: |
||
219 | movsb |
||
220 | cmp byte[esi], 0 |
||
221 | jne @b |
||
222 | movsb |
||
223 | mov [filelistoffset], esi |
||
6905 | ashmew2 | 224 | |
6903 | ashmew2 | 225 | ;; current_filename is now set to the name of the file |
226 | ;; current_url is now set to the name of the file we will get after download |
||
6905 | ashmew2 | 227 | DEBUGF 2, "Fetching : %s", current_filename |
228 | stdcall get_file_over_http, current_url, current_filename |
||
229 | DEBUGF 2, "...DONE!\n" |
||
230 | jmp .get_next_file |
||
6903 | ashmew2 | 231 | |
232 | .all_files_done: |
||
6905 | ashmew2 | 233 | DEBUGF 2, "-------------------------\n" |
234 | DEBUGF 2, "NETSURF INSTALLED. Enjoy!\n" |
||
235 | DEBUGF 2, "-------------------------\n" |
||
236 | mcall -1 |
||
6903 | ashmew2 | 237 | ;; Inform user that all files are done |
238 | |||
239 | .all_files_done_error: |
||
6905 | ashmew2 | 240 | DEBUGF 1, "FATAL ERROR: FAILED.\n", eax |
6903 | ashmew2 | 241 | mcall -1 |
242 | |||
243 | ;--------------------------------------------------------------------- |
||
244 | ; Data area |
||
245 | ;----------------------------------------------------------------------------- |
||
246 | align 4 |
||
247 | @IMPORT: |
||
248 | |||
249 | library lib_http, 'http.obj' |
||
250 | import lib_http, \ |
||
251 | HTTP_get, 'get', \ |
||
252 | HTTP_receive, 'receive', \ |
||
253 | HTTP_free, 'free' |
||
254 | |||
255 | include_debug_strings |
||
256 | |||
257 | download_file_path db '/tmp0/1/', 0 |
||
258 | dirname_res db '/tmp0/1/res', 0 |
||
259 | dirname_res_pointers db '/tmp0/1/res/pointers', 0 |
||
260 | dirname_res_throbber db '/tmp0/1/res/throbber', 0 |
||
261 | dirname_res_icons db '/tmp0/1/res/icons', 0 |
||
262 | |||
263 | url db 'www.ashmew2.me/',0 |
||
6904 | ashmew2 | 264 | |
265 | filelist db 'nskolibrios', 0 |
||
266 | db 'res/adblock.css', 0 |
||
6903 | ashmew2 | 267 | db 'res/quirks.css', 0 |
268 | db 'res/Messages', 0 |
||
269 | db 'res/licence.html', 0 |
||
270 | db 'res/default.css', 0 |
||
271 | db 'res/netsurf.png', 0 |
||
272 | db 'res/sans.ttf', 0 |
||
273 | db 'res/welcome.html', 0 |
||
274 | db 'res/internal.css', 0 |
||
275 | db 'res/maps.html', 0 |
||
276 | db 'res/favicon.png', 0 |
||
277 | db 'res/credits.html', 0 |
||
278 | db 'res/throbber/throbber8.png', 0 |
||
279 | db 'res/throbber/throbber3.png', 0 |
||
280 | db 'res/throbber/throbber4.png', 0 |
||
281 | db 'res/throbber/throbber0.png', 0 |
||
282 | db 'res/throbber/throbber6.png', 0 |
||
283 | db 'res/throbber/throbber2.png', 0 |
||
284 | db 'res/throbber/throbber1.png', 0 |
||
285 | db 'res/throbber/throbber7.png', 0 |
||
286 | db 'res/throbber/throbber5.png', 0 |
||
287 | db 'res/pointers/point.png', 0 |
||
288 | db 'res/pointers/no_drop.png', 0 |
||
289 | db 'res/pointers/wait.png', 0 |
||
290 | db 'res/pointers/up-down.png', 0 |
||
291 | db 'res/pointers/help.png', 0 |
||
292 | db 'res/pointers/ru-ld.png', 0 |
||
293 | db 'res/pointers/menu.png', 0 |
||
294 | db 'res/pointers/not_allowed.png', 0 |
||
295 | db 'res/pointers/cross.png', 0 |
||
296 | db 'res/pointers/default.png', 0 |
||
297 | db 'res/pointers/caret.png', 0 |
||
298 | db 'res/pointers/left-right.png', 0 |
||
299 | db 'res/pointers/lu-rd.png', 0 |
||
300 | db 'res/pointers/progress.png', 0 |
||
301 | db 'res/pointers/move.png', 0 |
||
302 | db 'res/icons/back.png', 0 |
||
303 | db 'res/icons/back_g.png', 0 |
||
304 | db 'res/icons/scrollr.png', 0 |
||
305 | db 'res/icons/osk.png', 0 |
||
306 | db 'res/icons/forward_g.png', 0 |
||
307 | db 'res/icons/scrolll.png', 0 |
||
308 | db 'res/icons/history.png', 0 |
||
309 | db 'res/icons/forward.png', 0 |
||
310 | db 'res/icons/home_g.png', 0 |
||
311 | db 'res/icons/history_g.png', 0 |
||
312 | db 'res/icons/reload_g.png', 0 |
||
313 | db 'res/icons/scrollu.png', 0 |
||
314 | db 'res/icons/stop.png', 0 |
||
315 | db 'res/icons/scrolld.png', 0 |
||
316 | db 'res/icons/stop_g.png', 0 |
||
317 | db 'res/icons/home.png', 0 |
||
318 | db 'res/icons/reload.png', 0 |
||
319 | db 0 |
||
320 | |||
321 | filelistoffset dd filelist |
||
322 | httpstruct dd 0 |
||
323 | |||
6905 | ashmew2 | 324 | create_new_file dd 2, 0, 0, 0, 0 |
6903 | ashmew2 | 325 | db 0 |
326 | dd current_filename |
||
327 | |||
328 | create_new_folder dd 9, 0, 0, 0, 0 |
||
329 | db 0 |
||
330 | .foldername dd 0 |
||
331 | |||
332 | write_to_file dd 3 |
||
333 | .current_offset dd 0, 0 |
||
334 | .bufsize dd 0 |
||
335 | .bufptr dd 0 |
||
336 | db 0 |
||
337 | dd current_filename |
||
6905 | ashmew2 | 338 | |
339 | socketdata rb 4096 |
||
340 | current_url rb URLMAXLEN |
||
341 | current_filename rb FILENAMEMAXLEN |
||
6903 | ashmew2 | 342 | I_END: |