2017-05-21 19:32:12 +02:00
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;; ;;
|
|
|
|
;; Copyright (C) KolibriOS team 2017. All rights reserved. ;;
|
|
|
|
;; Distributed under terms of the GNU General Public License ;;
|
|
|
|
;; ;;
|
|
|
|
;; netsurf-installer - Set up Netsurf Browser on KolibriOS ;;
|
|
|
|
;; Author: ashmew2. ;;
|
|
|
|
;; ;;
|
|
|
|
;; Inspired from downloader.asm by hidnplayr@kolibrios.org ;;
|
|
|
|
;; GENERAL PUBLIC LICENSE ;;
|
|
|
|
;; Version 2, June 1991 ;;
|
|
|
|
;; ;;
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
|
|
|
URLMAXLEN = 65535
|
|
|
|
FILENAMEMAXLEN = 1024
|
2017-05-23 21:39:26 +02:00
|
|
|
__DEBUG_LEVEL__ = 2
|
|
|
|
__DEBUG__ = 1
|
2017-05-21 19:32:12 +02:00
|
|
|
|
|
|
|
format binary as ""
|
|
|
|
use32
|
|
|
|
org 0x0
|
|
|
|
db 'MENUET01' ; header
|
|
|
|
dd 0x01 ; header version
|
|
|
|
dd START ; entry point
|
|
|
|
dd I_END ; image size
|
|
|
|
dd I_END+0x1000 ; required memory
|
|
|
|
dd I_END+0x1000 ; esp
|
|
|
|
dd 0x0 ; I_Path
|
|
|
|
dd 0x0 ; I_Path
|
|
|
|
|
|
|
|
include '../../macros.inc'
|
|
|
|
include '../../proc32.inc'
|
|
|
|
include '../../dll.inc'
|
|
|
|
include '../../debug-fdo.inc'
|
|
|
|
include '../../develop/libraries/http/http.inc'
|
2017-11-02 13:20:25 +01:00
|
|
|
include '../../string.inc'
|
|
|
|
|
2020-04-14 01:21:48 +02:00
|
|
|
include '../../system/notify3/notify.inc'
|
|
|
|
|
2017-11-02 13:20:25 +01:00
|
|
|
include 'notify.asm'
|
2017-05-21 19:32:12 +02:00
|
|
|
|
|
|
|
virtual at 0
|
|
|
|
http_msg http_msg
|
|
|
|
end virtual
|
|
|
|
|
|
|
|
;; Parameters
|
|
|
|
;; HTTP URL to download
|
|
|
|
;; Target filename
|
|
|
|
proc get_file_over_http targeturl, targetfilename
|
|
|
|
pusha
|
2017-05-25 13:57:57 +02:00
|
|
|
xor eax, eax
|
2017-05-21 19:32:12 +02:00
|
|
|
mov [write_to_file.current_offset], eax
|
|
|
|
mov [write_to_file.bufsize], eax
|
|
|
|
mov [write_to_file.bufptr], eax
|
|
|
|
|
|
|
|
DEBUGF 1, "---- HTTP : Getting %s\n", [targeturl]
|
2017-05-25 13:57:57 +02:00
|
|
|
invoke HTTP_get, [targeturl], 0, FLAG_KEEPALIVE or FLAG_BLOCK, 0
|
2017-05-21 19:32:12 +02:00
|
|
|
cmp eax, 0
|
|
|
|
je .http_error
|
2017-05-25 13:57:57 +02:00
|
|
|
mov [httpstruct], eax
|
2017-05-21 19:32:12 +02:00
|
|
|
|
|
|
|
;; No HTTP errors, create a new file for the download.
|
2017-05-25 13:57:57 +02:00
|
|
|
DEBUGF 1, "---- Creating new file : %s\n", [targetfilename]
|
|
|
|
mcall 70, create_new_file
|
2017-05-21 19:32:12 +02:00
|
|
|
cmp eax, 0
|
|
|
|
jne .file_error
|
|
|
|
|
|
|
|
.http_receive_loop:
|
2017-05-25 13:57:57 +02:00
|
|
|
DEBUGF 1, "---- Receiving over http.\n"
|
2017-05-21 19:32:12 +02:00
|
|
|
invoke HTTP_receive, [httpstruct]
|
2017-05-25 13:57:57 +02:00
|
|
|
|
2017-05-21 19:32:12 +02:00
|
|
|
cmp eax, 0
|
|
|
|
je .http_transfer_done
|
|
|
|
|
2017-05-25 13:57:57 +02:00
|
|
|
|
|
|
|
mov ebp, [httpstruct]
|
|
|
|
DEBUGF 1, "---- http flags = 0x%x.\n", [ebp + http_msg.flags]
|
|
|
|
test [ebp + http_msg.flags], 0xffff0000
|
2017-05-21 19:32:12 +02:00
|
|
|
jnz .http_error
|
|
|
|
|
2017-05-25 13:57:57 +02:00
|
|
|
mov ebp, [ebp + http_msg.content_received]
|
|
|
|
cmp ebp, [write_to_file.current_offset]
|
2017-05-21 19:32:12 +02:00
|
|
|
jle .http_receive_loop
|
2017-05-25 13:57:57 +02:00
|
|
|
;; Only proceed if we have more data in HTTP buffer than we have written to file.
|
2017-05-21 19:32:12 +02:00
|
|
|
|
|
|
|
;; Process data we got (write it to the file)
|
2017-05-25 13:57:57 +02:00
|
|
|
mov ebp, [httpstruct]
|
|
|
|
mov ecx, [ebp + http_msg.content_length]
|
2017-05-21 19:32:12 +02:00
|
|
|
mov edx, [ebp + http_msg.content_received]
|
|
|
|
|
2017-05-25 13:57:57 +02:00
|
|
|
DEBUGF 1, "---- Current file write offset : %u (http got : %u / %u)\n", [write_to_file.current_offset], edx, ecx
|
2017-05-21 19:32:12 +02:00
|
|
|
sub edx, [write_to_file.current_offset]
|
|
|
|
mov [write_to_file.bufsize], edx
|
|
|
|
|
|
|
|
mov ecx, [ebp + http_msg.content_ptr]
|
|
|
|
add ecx, [write_to_file.current_offset]
|
|
|
|
mov [write_to_file.bufptr], ecx
|
|
|
|
|
2017-05-25 13:57:57 +02:00
|
|
|
DEBUGF 1, "---- ecx + offset = 0x%x\n", ecx
|
|
|
|
DEBUGF 1, "---- Writing to file %u bytes at 0x%x to %s\n", [write_to_file.bufsize], [write_to_file.bufptr], current_filename
|
2017-05-21 19:32:12 +02:00
|
|
|
mcall 70, write_to_file
|
|
|
|
cmp eax, 0
|
|
|
|
jne .file_error
|
|
|
|
|
2017-05-25 13:57:57 +02:00
|
|
|
DEBUGF 1, "---- Wrote to file %u bytes.\n", ebx
|
2017-05-21 19:32:12 +02:00
|
|
|
add [write_to_file.current_offset], ebx
|
2017-05-25 13:57:57 +02:00
|
|
|
DEBUGF 1, "---- File offset updated to : %u\n", [write_to_file.current_offset]
|
|
|
|
|
2017-05-21 19:32:12 +02:00
|
|
|
jmp .http_receive_loop
|
|
|
|
|
|
|
|
.file_error:
|
2017-05-25 13:57:57 +02:00
|
|
|
DEBUGF 1, "file_erroR with eax = %u!", eax
|
2017-11-02 13:20:25 +01:00
|
|
|
call EXIT
|
2017-05-21 19:32:12 +02:00
|
|
|
|
|
|
|
.http_error:
|
2017-05-25 13:57:57 +02:00
|
|
|
DEBUGF 1, "http_erroR!"
|
2017-11-02 13:20:25 +01:00
|
|
|
call EXIT
|
2017-05-21 19:32:12 +02:00
|
|
|
|
|
|
|
.http_transfer_done:
|
2017-05-25 13:57:57 +02:00
|
|
|
;; Write any remaining bytes from the http buffer into the file
|
|
|
|
DEBUGF 1, "---- http flags = 0x%x.\n", [httpstruct + http_msg.flags]
|
|
|
|
DEBUGF 1, "Got %u bytes in total\n", [httpstruct + http_msg.content_length]
|
2017-05-21 19:32:12 +02:00
|
|
|
|
2017-05-25 13:57:57 +02:00
|
|
|
mov ebp, [httpstruct]
|
2017-05-21 19:32:12 +02:00
|
|
|
mov edx, [ebp + http_msg.content_length]
|
|
|
|
|
|
|
|
sub edx, [write_to_file.current_offset]
|
|
|
|
mov [write_to_file.bufsize], edx
|
|
|
|
|
|
|
|
mov ecx, [ebp + http_msg.content_ptr]
|
|
|
|
add ecx, [write_to_file.current_offset]
|
|
|
|
mov [write_to_file.bufptr], ecx
|
|
|
|
|
2017-05-25 13:57:57 +02:00
|
|
|
DEBUGF 1, "---- Final ecx + offset = 0x%x\n", ecx
|
|
|
|
DEBUGF 1, "-- Writing to file %u bytes at 0x%x to %s\n", [write_to_file.bufsize], [write_to_file.bufptr], current_filename
|
2017-05-21 19:32:12 +02:00
|
|
|
|
|
|
|
mcall 70, write_to_file
|
|
|
|
cmp eax, 0
|
|
|
|
jne .file_error
|
|
|
|
|
2017-05-25 13:57:57 +02:00
|
|
|
DEBUGF 1, "-- Wrote to file %u bytes.\n", ebx
|
2017-05-21 19:32:12 +02:00
|
|
|
add [write_to_file.current_offset], ebx
|
2017-05-25 13:57:57 +02:00
|
|
|
DEBUGF 1, "-- File offset updated to : %u\n", [write_to_file.current_offset]
|
|
|
|
mov ebp, [httpstruct]
|
2017-05-21 19:32:12 +02:00
|
|
|
mov edx, [ebp + http_msg.content_length]
|
|
|
|
cmp [write_to_file.current_offset], edx
|
|
|
|
jne .http_transfer_done
|
|
|
|
|
2017-05-25 13:57:57 +02:00
|
|
|
invoke HTTP_free, [httpstruct]
|
2017-05-21 19:32:12 +02:00
|
|
|
|
2017-05-25 13:57:57 +02:00
|
|
|
popa
|
2017-05-21 19:32:12 +02:00
|
|
|
ret
|
|
|
|
endp
|
|
|
|
|
|
|
|
proc make_new_folder newfolder
|
2017-05-25 13:57:57 +02:00
|
|
|
pusha
|
2017-05-21 19:32:12 +02:00
|
|
|
|
2017-05-25 13:57:57 +02:00
|
|
|
mov eax, [newfolder]
|
2017-05-21 19:32:12 +02:00
|
|
|
mov [create_new_folder.foldername], eax
|
2017-05-25 13:57:57 +02:00
|
|
|
mcall 70, create_new_folder
|
2017-05-21 19:32:12 +02:00
|
|
|
test eax, eax
|
|
|
|
jz .success
|
2017-05-25 13:57:57 +02:00
|
|
|
|
|
|
|
DEBUGF 1, "Failed to create folder: %s\n", [newfolder]
|
2017-11-02 13:20:25 +01:00
|
|
|
call EXIT
|
2017-05-21 19:32:12 +02:00
|
|
|
|
|
|
|
.success:
|
|
|
|
popa
|
|
|
|
ret
|
|
|
|
endp
|
|
|
|
|
|
|
|
START:
|
2017-05-25 13:57:57 +02:00
|
|
|
mcall 68, 11 ; init heap
|
2017-11-02 13:20:25 +01:00
|
|
|
call NOTIFY_RUN
|
2017-05-21 19:32:12 +02:00
|
|
|
|
|
|
|
; load libraries
|
|
|
|
stdcall dll.Load, @IMPORT
|
|
|
|
test eax, eax
|
|
|
|
jnz .all_files_done_error
|
|
|
|
|
2017-05-25 13:57:57 +02:00
|
|
|
DEBUGF 2, "-------------------------\n"
|
|
|
|
DEBUGF 2, "NETSURF INSTALLER.\n"
|
|
|
|
|
|
|
|
stdcall make_new_folder, dirname_res
|
|
|
|
stdcall make_new_folder, dirname_res_pointers
|
|
|
|
stdcall make_new_folder, dirname_res_throbber
|
|
|
|
stdcall make_new_folder, dirname_res_icons
|
|
|
|
|
2017-05-21 19:32:12 +02:00
|
|
|
|
2017-05-25 13:57:57 +02:00
|
|
|
.get_next_file:
|
2017-05-21 19:32:12 +02:00
|
|
|
mov edi, current_url
|
|
|
|
mov esi, url
|
|
|
|
|
|
|
|
@@:
|
2017-05-25 13:57:57 +02:00
|
|
|
movsb
|
2017-05-21 19:32:12 +02:00
|
|
|
cmp byte[esi], 0
|
|
|
|
jne @b
|
2017-05-25 13:57:57 +02:00
|
|
|
;; Loaded the base URL into current URL
|
2017-05-21 19:32:12 +02:00
|
|
|
|
|
|
|
;; Move onto the subsequent file.
|
|
|
|
mov esi, [filelistoffset]
|
|
|
|
cmp byte[esi], 0
|
|
|
|
je .all_files_done
|
|
|
|
|
|
|
|
@@:
|
2017-05-25 13:57:57 +02:00
|
|
|
movsb
|
2017-05-21 19:32:12 +02:00
|
|
|
cmp byte[esi], 0
|
|
|
|
jne @b
|
|
|
|
movsb
|
|
|
|
|
2017-05-25 13:57:57 +02:00
|
|
|
;; DEBUGF 1, "-- Current URL with filename is : %s\n", current_url
|
2017-05-21 19:32:12 +02:00
|
|
|
|
|
|
|
; Create name of file we will download to
|
2017-05-25 13:57:57 +02:00
|
|
|
mov esi, download_file_path
|
2017-05-21 19:32:12 +02:00
|
|
|
mov edi, current_filename
|
2017-05-25 13:57:57 +02:00
|
|
|
|
2017-05-21 19:32:12 +02:00
|
|
|
@@:
|
|
|
|
movsb
|
|
|
|
cmp byte[esi], 0
|
|
|
|
jne @b
|
2017-05-25 13:57:57 +02:00
|
|
|
|
2017-05-21 19:32:12 +02:00
|
|
|
mov esi, [filelistoffset]
|
|
|
|
@@:
|
|
|
|
movsb
|
|
|
|
cmp byte[esi], 0
|
|
|
|
jne @b
|
|
|
|
movsb
|
|
|
|
mov [filelistoffset], esi
|
2017-05-25 13:57:57 +02:00
|
|
|
|
2017-05-21 19:32:12 +02:00
|
|
|
;; current_filename is now set to the name of the file
|
|
|
|
;; current_url is now set to the name of the file we will get after download
|
2017-05-25 13:57:57 +02:00
|
|
|
DEBUGF 2, "Fetching : %s", current_filename
|
2017-11-02 13:20:25 +01:00
|
|
|
pusha
|
|
|
|
call NOTIFY_CHANGE
|
|
|
|
popa
|
2017-05-25 13:57:57 +02:00
|
|
|
stdcall get_file_over_http, current_url, current_filename
|
|
|
|
DEBUGF 2, "...DONE!\n"
|
|
|
|
jmp .get_next_file
|
2017-05-21 19:32:12 +02:00
|
|
|
|
|
|
|
.all_files_done:
|
2017-05-25 13:57:57 +02:00
|
|
|
DEBUGF 2, "-------------------------\n"
|
|
|
|
DEBUGF 2, "NETSURF INSTALLED. Enjoy!\n"
|
|
|
|
DEBUGF 2, "-------------------------\n"
|
2017-11-02 13:20:25 +01:00
|
|
|
call EXIT
|
2017-05-21 19:32:12 +02:00
|
|
|
;; Inform user that all files are done
|
|
|
|
|
|
|
|
.all_files_done_error:
|
2017-05-25 13:57:57 +02:00
|
|
|
DEBUGF 1, "FATAL ERROR: FAILED.\n", eax
|
2017-11-02 13:20:25 +01:00
|
|
|
call EXIT
|
2017-05-21 19:32:12 +02:00
|
|
|
|
|
|
|
;---------------------------------------------------------------------
|
|
|
|
; Data area
|
|
|
|
;-----------------------------------------------------------------------------
|
|
|
|
align 4
|
|
|
|
@IMPORT:
|
|
|
|
|
|
|
|
library lib_http, 'http.obj'
|
|
|
|
import lib_http, \
|
|
|
|
HTTP_get, 'get', \
|
|
|
|
HTTP_receive, 'receive', \
|
|
|
|
HTTP_free, 'free'
|
|
|
|
|
|
|
|
include_debug_strings
|
|
|
|
|
|
|
|
download_file_path db '/tmp0/1/', 0
|
|
|
|
dirname_res db '/tmp0/1/res', 0
|
|
|
|
dirname_res_pointers db '/tmp0/1/res/pointers', 0
|
|
|
|
dirname_res_throbber db '/tmp0/1/res/throbber', 0
|
|
|
|
dirname_res_icons db '/tmp0/1/res/icons', 0
|
|
|
|
|
2020-04-28 21:56:44 +02:00
|
|
|
url db 'www.kolibri-n.org/files/netsurf/',0
|
2017-05-23 21:39:26 +02:00
|
|
|
|
2017-11-02 13:20:25 +01:00
|
|
|
; I don't know why NOTIFY_CHANGE doesn't work for the first file
|
|
|
|
; so I use this small shit to fix it at NOTIFY_RUN phase
|
2020-04-28 21:56:44 +02:00
|
|
|
filelist_first db '/tmp0/1/netsurf', 0
|
2017-11-02 13:20:25 +01:00
|
|
|
|
2020-04-28 21:56:44 +02:00
|
|
|
filelist db 'netsurf', 0
|
|
|
|
;db 'netsurf-kolibrios.map', 0 ;what this???
|
2017-05-23 21:39:26 +02:00
|
|
|
db 'res/adblock.css', 0
|
2017-05-21 19:32:12 +02:00
|
|
|
db 'res/quirks.css', 0
|
|
|
|
db 'res/Messages', 0
|
|
|
|
db 'res/licence.html', 0
|
|
|
|
db 'res/default.css', 0
|
|
|
|
db 'res/netsurf.png', 0
|
|
|
|
db 'res/sans.ttf', 0
|
|
|
|
db 'res/welcome.html', 0
|
|
|
|
db 'res/internal.css', 0
|
|
|
|
db 'res/maps.html', 0
|
|
|
|
db 'res/favicon.png', 0
|
|
|
|
db 'res/credits.html', 0
|
|
|
|
db 'res/throbber/throbber8.png', 0
|
|
|
|
db 'res/throbber/throbber3.png', 0
|
|
|
|
db 'res/throbber/throbber4.png', 0
|
|
|
|
db 'res/throbber/throbber0.png', 0
|
|
|
|
db 'res/throbber/throbber6.png', 0
|
|
|
|
db 'res/throbber/throbber2.png', 0
|
|
|
|
db 'res/throbber/throbber1.png', 0
|
|
|
|
db 'res/throbber/throbber7.png', 0
|
|
|
|
db 'res/throbber/throbber5.png', 0
|
2020-04-29 02:47:51 +02:00
|
|
|
; db 'res/pointers/point.png', 0
|
|
|
|
; db 'res/pointers/no_drop.png', 0
|
|
|
|
; db 'res/pointers/wait.png', 0
|
|
|
|
; db 'res/pointers/up-down.png', 0
|
|
|
|
; db 'res/pointers/help.png', 0
|
|
|
|
; db 'res/pointers/ru-ld.png', 0
|
|
|
|
; db 'res/pointers/menu.png', 0
|
|
|
|
; db 'res/pointers/not_allowed.png', 0
|
|
|
|
; db 'res/pointers/cross.png', 0
|
|
|
|
; db 'res/pointers/default.png', 0
|
|
|
|
; db 'res/pointers/caret.png', 0
|
|
|
|
; db 'res/pointers/left-right.png', 0
|
|
|
|
; db 'res/pointers/lu-rd.png', 0
|
|
|
|
; db 'res/pointers/progress.png', 0
|
|
|
|
; db 'res/pointers/move.png', 0
|
2017-05-21 19:32:12 +02:00
|
|
|
db 'res/icons/back.png', 0
|
|
|
|
db 'res/icons/back_g.png', 0
|
|
|
|
db 'res/icons/scrollr.png', 0
|
|
|
|
db 'res/icons/osk.png', 0
|
|
|
|
db 'res/icons/forward_g.png', 0
|
|
|
|
db 'res/icons/scrolll.png', 0
|
|
|
|
db 'res/icons/history.png', 0
|
|
|
|
db 'res/icons/forward.png', 0
|
|
|
|
db 'res/icons/home_g.png', 0
|
|
|
|
db 'res/icons/history_g.png', 0
|
|
|
|
db 'res/icons/reload_g.png', 0
|
|
|
|
db 'res/icons/scrollu.png', 0
|
|
|
|
db 'res/icons/stop.png', 0
|
|
|
|
db 'res/icons/scrolld.png', 0
|
|
|
|
db 'res/icons/stop_g.png', 0
|
|
|
|
db 'res/icons/home.png', 0
|
|
|
|
db 'res/icons/reload.png', 0
|
|
|
|
db 0
|
|
|
|
|
|
|
|
filelistoffset dd filelist
|
|
|
|
httpstruct dd 0
|
|
|
|
|
2017-05-25 13:57:57 +02:00
|
|
|
create_new_file dd 2, 0, 0, 0, 0
|
2017-05-21 19:32:12 +02:00
|
|
|
db 0
|
|
|
|
dd current_filename
|
|
|
|
|
|
|
|
create_new_folder dd 9, 0, 0, 0, 0
|
|
|
|
db 0
|
|
|
|
.foldername dd 0
|
|
|
|
|
|
|
|
write_to_file dd 3
|
|
|
|
.current_offset dd 0, 0
|
|
|
|
.bufsize dd 0
|
|
|
|
.bufptr dd 0
|
|
|
|
db 0
|
|
|
|
dd current_filename
|
2017-05-25 13:57:57 +02:00
|
|
|
|
|
|
|
socketdata rb 4096
|
|
|
|
current_url rb URLMAXLEN
|
|
|
|
current_filename rb FILENAMEMAXLEN
|
2017-11-02 13:20:25 +01:00
|
|
|
|
|
|
|
;=====================================================================
|
|
|
|
; NOTIFY DATA
|
|
|
|
timer dd 0
|
|
|
|
params rb 256
|
|
|
|
ctrl:
|
|
|
|
.name rb 32
|
|
|
|
.addr rd 1
|
|
|
|
rb 2048
|
|
|
|
|
|
|
|
sz_text:
|
|
|
|
db "Netsurf installer ", 0
|
|
|
|
sz_quote:
|
|
|
|
db "'", 0
|
|
|
|
sz_sec_line_start:
|
2020-04-29 02:47:51 +02:00
|
|
|
db 10, "Downloading:",10, 0
|
2017-11-02 13:20:25 +01:00
|
|
|
sz_flags:
|
|
|
|
db "Ddcpt", 0
|
|
|
|
|
|
|
|
sz_final_text:
|
|
|
|
db "Netsurf installer",10,"Download complete.",10,"Enjoy!",0
|
|
|
|
|
|
|
|
fi_launch:
|
|
|
|
dd 7, 0, params, 0, 0
|
2020-04-28 21:56:44 +02:00
|
|
|
db "/sys/@notify", 0
|
2017-11-02 13:20:25 +01:00
|
|
|
|
|
|
|
fileopen dd 7
|
|
|
|
dd 0 ; flags
|
|
|
|
dd 0 ; parameters
|
|
|
|
dd 0 ; reserved
|
|
|
|
dd 0 ; reserved
|
2020-04-28 21:56:44 +02:00
|
|
|
db "/tmp0/1/netsurf", 0 ; path
|
2017-11-02 13:20:25 +01:00
|
|
|
;=====================================================================
|
|
|
|
|
2017-05-21 19:32:12 +02:00
|
|
|
I_END:
|