Subversion Repositories Kolibri OS

Rev

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