Subversion Repositories Kolibri OS

Rev

Rev 7842 | 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
 
8418 leency 173
proc run_if_exists file_path
174
    m2m   [fileinfo.path], [file_path]
175
    mcall 70, fileinfo
176
	test eax, eax
177
	jnz   @f
178
	m2m   [fileopen.path], [file_path]
179
	mcall 70, fileopen
180
	mcall -1
181
@@:
182
	ret
183
endp
184
 
185
 
6903 ashmew2 186
START:
8418 leency 187
	stdcall run_if_exists, TMP_netsurf
188
	stdcall run_if_exists, ISO_netsurf
189
 
6905 ashmew2 190
    mcall   68, 11                  ; init heap
7106 leency 191
	call NOTIFY_RUN
6903 ashmew2 192
 
193
; load libraries
194
    stdcall dll.Load, @IMPORT
195
    test    eax, eax
196
    jnz     .all_files_done_error
197
 
6905 ashmew2 198
    DEBUGF 2, "-------------------------\n"
199
    DEBUGF 2, "NETSURF INSTALLER.\n"
6903 ashmew2 200
 
6905 ashmew2 201
    stdcall make_new_folder, dirname_res
8418 leency 202
    ; stdcall make_new_folder, dirname_res_pointers
203
    ; stdcall make_new_folder, dirname_res_throbber
204
    ; stdcall make_new_folder, dirname_res_icons
6905 ashmew2 205
 
206
 
207
.get_next_file:
6903 ashmew2 208
    mov        edi, current_url
209
    mov        esi, url
210
 
211
    @@:
6905 ashmew2 212
        movsb
6903 ashmew2 213
        cmp byte[esi], 0
214
        jne @b
6905 ashmew2 215
    ;;  Loaded the base URL into current URL
6903 ashmew2 216
 
217
    ;; Move onto the subsequent file.
218
    mov esi, [filelistoffset]
219
    cmp byte[esi], 0
220
    je  .all_files_done
221
 
222
    @@:
6905 ashmew2 223
        movsb
6903 ashmew2 224
        cmp byte[esi], 0
225
        jne @b
226
    movsb
227
 
6905 ashmew2 228
    ;; DEBUGF 1, "-- Current URL with filename is : %s\n", current_url
6903 ashmew2 229
 
230
; Create name of file we will download to
6905 ashmew2 231
    mov esi, download_file_path
6903 ashmew2 232
    mov edi, current_filename
6905 ashmew2 233
 
6903 ashmew2 234
    @@:
235
        movsb
236
        cmp byte[esi], 0
237
        jne @b
6905 ashmew2 238
 
6903 ashmew2 239
    mov esi, [filelistoffset]
240
    @@:
241
        movsb
242
        cmp byte[esi], 0
243
        jne @b
244
    movsb
245
    mov [filelistoffset], esi
6905 ashmew2 246
 
6903 ashmew2 247
    ;; current_filename is now set to the name of the file
248
    ;; current_url is now set to the name of the file we will get after download
6905 ashmew2 249
    DEBUGF 2, "Fetching : %s", current_filename
7106 leency 250
	pusha
251
	call NOTIFY_CHANGE
252
	popa
6905 ashmew2 253
    stdcall get_file_over_http, current_url, current_filename
254
    DEBUGF 2, "...DONE!\n"
255
    jmp .get_next_file
6903 ashmew2 256
 
257
.all_files_done:
6905 ashmew2 258
    DEBUGF 2, "-------------------------\n"
259
    DEBUGF 2, "NETSURF INSTALLED. Enjoy!\n"
260
    DEBUGF 2, "-------------------------\n"
7106 leency 261
    call EXIT
6903 ashmew2 262
    ;; Inform user that all files are done
263
 
264
.all_files_done_error:
6905 ashmew2 265
    DEBUGF 1, "FATAL ERROR: FAILED.\n", eax
7106 leency 266
    call EXIT
6903 ashmew2 267
 
268
;---------------------------------------------------------------------
269
; Data area
270
;-----------------------------------------------------------------------------
271
align   4
272
@IMPORT:
273
 
274
library lib_http,       'http.obj'
275
import  lib_http, \
276
        HTTP_get,       'get', \
277
        HTTP_receive,   'receive', \
278
        HTTP_free,      'free'
279
 
280
include_debug_strings
281
 
282
download_file_path db '/tmp0/1/', 0
283
dirname_res db '/tmp0/1/res', 0
284
dirname_res_pointers db '/tmp0/1/res/pointers', 0
285
dirname_res_throbber db '/tmp0/1/res/throbber', 0
286
dirname_res_icons    db '/tmp0/1/res/icons', 0
287
 
7835 leency 288
url              db 'www.kolibri-n.org/files/netsurf/',0
6904 ashmew2 289
 
7106 leency 290
; I don't know why NOTIFY_CHANGE doesn't work for the first file
291
; so I use this small shit to fix it at NOTIFY_RUN phase
7835 leency 292
filelist_first db '/tmp0/1/netsurf', 0
7106 leency 293
 
8418 leency 294
MAX_FILES = 6
295
 
7835 leency 296
filelist db 'netsurf', 0
297
         ;db 'netsurf-kolibrios.map', 0 ;what this???
6904 ashmew2 298
         db 'res/adblock.css', 0
6903 ashmew2 299
         db 'res/quirks.css', 0
300
         db 'res/Messages', 0
301
         db 'res/default.css', 0
302
         db 'res/sans.ttf', 0
303
         db 'res/internal.css', 0
8418 leency 304
         ; db 'res/welcome.html', 0
305
         ; db 'res/licence.html', 0
306
         ; db 'res/maps.html', 0
307
         ; db 'res/credits.html', 0
308
         ; db 'res/favicon.png', 0
309
         ; db 'res/netsurf.png', 0
310
         ; db 'res/throbber/throbber8.png', 0
311
         ; db 'res/throbber/throbber3.png', 0
312
         ; db 'res/throbber/throbber4.png', 0
313
         ; db 'res/throbber/throbber0.png', 0
314
         ; db 'res/throbber/throbber6.png', 0
315
         ; db 'res/throbber/throbber2.png', 0
316
         ; db 'res/throbber/throbber1.png', 0
317
         ; db 'res/throbber/throbber7.png', 0
318
         ; db 'res/throbber/throbber5.png', 0
7841 leency 319
         ; db 'res/pointers/point.png', 0
320
         ; db 'res/pointers/no_drop.png', 0
321
         ; db 'res/pointers/wait.png', 0
322
         ; db 'res/pointers/up-down.png', 0
323
         ; db 'res/pointers/help.png', 0
324
         ; db 'res/pointers/ru-ld.png', 0
325
         ; db 'res/pointers/menu.png', 0
326
         ; db 'res/pointers/not_allowed.png', 0
327
         ; db 'res/pointers/cross.png', 0
328
         ; db 'res/pointers/default.png', 0
329
         ; db 'res/pointers/caret.png', 0
330
         ; db 'res/pointers/left-right.png', 0
331
         ; db 'res/pointers/lu-rd.png', 0
332
         ; db 'res/pointers/progress.png', 0
333
         ; db 'res/pointers/move.png', 0
8418 leency 334
         ; db 'res/icons/back.png', 0
335
         ; db 'res/icons/back_g.png', 0
336
         ; db 'res/icons/scrollr.png', 0
337
         ; db 'res/icons/osk.png', 0
338
         ; db 'res/icons/forward_g.png', 0
339
         ; db 'res/icons/scrolll.png', 0
340
         ; db 'res/icons/history.png', 0
341
         ; db 'res/icons/forward.png', 0
342
         ; db 'res/icons/home_g.png', 0
343
         ; db 'res/icons/history_g.png', 0
344
         ; db 'res/icons/reload_g.png', 0
345
         ; db 'res/icons/scrollu.png', 0
346
         ; db 'res/icons/stop.png', 0
347
         ; db 'res/icons/scrolld.png', 0
348
         ; db 'res/icons/stop_g.png', 0
349
         ; db 'res/icons/home.png', 0
350
         ; db 'res/icons/reload.png', 0
6903 ashmew2 351
         db 0
352
 
353
filelistoffset   dd filelist
354
httpstruct       dd 0
355
 
6905 ashmew2 356
create_new_file    dd 2, 0, 0, 0, 0
6903 ashmew2 357
    db 0
358
    dd current_filename
359
 
360
create_new_folder dd 9, 0, 0, 0, 0
361
                  db 0
362
 .foldername dd 0
363
 
364
write_to_file    dd 3
365
 .current_offset dd 0, 0
366
 .bufsize        dd 0
367
 .bufptr         dd 0
368
                 db 0
369
                 dd current_filename
6905 ashmew2 370
 
371
socketdata       rb 4096
372
current_url      rb URLMAXLEN
373
current_filename rb FILENAMEMAXLEN
7106 leency 374
 
8418 leency 375
ISO_netsurf db "/kolibrios/netsurf/netsurf", 0
376
TMP_netsurf db "/tmp0/1/netsurf", 0
377
 
378
bdvk_buf rb 560
379
 
380
fileinfo    dd 5
381
            dd 0,0,0
382
            dd bdvk_buf
383
            db 0
384
.path       dd ?          ; path
385
 
7106 leency 386
;=====================================================================
387
; NOTIFY DATA
8418 leency 388
timer     dd 0
7106 leency 389
params rb 256
390
ctrl:
391
 .name rb 32
392
 .addr rd 1
393
rb 2048
394
 
395
 sz_text:
7842 leency 396
    db "Downloading Netsurf                  ",10, 0
7106 leency 397
 sz_quote:
398
    db "'", 0
399
 sz_flags:
400
    db "Ddcpt", 0
401
 
402
 sz_final_text:
7842 leency 403
    db "Netsurf download complete.",10,"Enjoy!",0
7106 leency 404
 
405
 fi_launch:
406
    dd	    7, 0, params, 0, 0
7835 leency 407
    db	    "/sys/@notify", 0
7106 leency 408
 
409
fileopen    dd 7
8418 leency 410
            dd 0,0,0,0
411
            db 0
412
.path       dd ?          ; path
7106 leency 413
;=====================================================================
8418 leency 414
 
6903 ashmew2 415
I_END: