Subversion Repositories Kolibri OS

Rev

Rev 7058 | Rev 7835 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  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
  17. __DEBUG_LEVEL__ = 2
  18. __DEBUG__       = 1
  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. include '../../notify.inc'
  38. include '../../string.inc'
  39.  
  40. include 'notify.asm'
  41.  
  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
  51.     xor eax, eax
  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]
  57.     invoke  HTTP_get, [targeturl], 0, FLAG_KEEPALIVE or FLAG_BLOCK, 0
  58.     cmp     eax, 0
  59.     je .http_error
  60.     mov [httpstruct], eax
  61.  
  62.     ;; No HTTP errors, create a new file for the download.
  63.     DEBUGF 1, "---- Creating new file : %s\n", [targetfilename]
  64.     mcall 70, create_new_file
  65.     cmp eax, 0
  66.     jne .file_error
  67.  
  68.     .http_receive_loop:
  69.         DEBUGF 1, "---- Receiving over http.\n"
  70.         invoke HTTP_receive, [httpstruct]
  71.  
  72.         cmp eax, 0
  73.         je .http_transfer_done
  74.  
  75.  
  76.         mov ebp, [httpstruct]
  77.         DEBUGF 1, "---- http flags = 0x%x.\n",     [ebp + http_msg.flags]
  78.         test [ebp + http_msg.flags], 0xffff0000
  79.         jnz .http_error
  80.  
  81.         mov ebp, [ebp + http_msg.content_received]
  82.         cmp ebp, [write_to_file.current_offset]
  83.         jle .http_receive_loop
  84.         ;; Only proceed if we have more data in HTTP buffer than we have written to file.
  85.  
  86.         ;; Process data we got (write it to the file)
  87.         mov ebp, [httpstruct]
  88.         mov ecx, [ebp + http_msg.content_length]
  89.         mov edx, [ebp + http_msg.content_received]
  90.  
  91.         DEBUGF 1, "---- Current file write offset : %u (http got : %u / %u)\n", [write_to_file.current_offset], edx, ecx
  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.  
  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
  101.         mcall 70, write_to_file
  102.         cmp eax, 0
  103.         jne .file_error
  104.  
  105.         DEBUGF 1, "---- Wrote to file %u bytes.\n", ebx
  106.         add [write_to_file.current_offset], ebx
  107.         DEBUGF 1, "---- File offset updated to : %u\n", [write_to_file.current_offset]
  108.  
  109.         jmp .http_receive_loop
  110.  
  111.     .file_error:
  112.     DEBUGF 1, "file_erroR with eax = %u!", eax
  113.         call EXIT
  114.  
  115.     .http_error:
  116.     DEBUGF 1, "http_erroR!"
  117.         call EXIT
  118.  
  119.     .http_transfer_done:
  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]
  123.  
  124.         mov ebp, [httpstruct]
  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.  
  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
  136.  
  137.         mcall 70, write_to_file
  138.         cmp eax, 0
  139.         jne .file_error
  140.  
  141.         DEBUGF 1, "-- Wrote to file %u bytes.\n", ebx
  142.         add [write_to_file.current_offset], ebx
  143.         DEBUGF 1, "-- File offset updated to : %u\n", [write_to_file.current_offset]
  144.         mov ebp, [httpstruct]
  145.         mov edx, [ebp + http_msg.content_length]
  146.         cmp [write_to_file.current_offset], edx
  147.         jne .http_transfer_done
  148.  
  149.     invoke HTTP_free, [httpstruct]
  150.  
  151.     popa
  152.     ret
  153. endp
  154.  
  155. proc make_new_folder newfolder
  156.     pusha
  157.  
  158.     mov eax, [newfolder]
  159.     mov [create_new_folder.foldername], eax
  160.     mcall 70, create_new_folder
  161.     test eax, eax
  162.     jz .success
  163.  
  164.     DEBUGF 1, "Failed to create folder: %s\n", [newfolder]
  165.     call EXIT
  166.  
  167. .success:
  168.     popa
  169.     ret
  170. endp
  171.  
  172. START:
  173.     mcall   68, 11                  ; init heap
  174.         call NOTIFY_RUN
  175.  
  176. ; load libraries
  177.     stdcall dll.Load, @IMPORT
  178.     test    eax, eax
  179.     jnz     .all_files_done_error
  180.  
  181.     DEBUGF 2, "-------------------------\n"
  182.     DEBUGF 2, "NETSURF INSTALLER.\n"
  183.  
  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:
  191.     mov        edi, current_url
  192.     mov        esi, url
  193.  
  194.     @@:
  195.         movsb
  196.         cmp byte[esi], 0
  197.         jne @b
  198.     ;;  Loaded the base URL into current URL
  199.  
  200.     ;; Move onto the subsequent file.
  201.     mov esi, [filelistoffset]
  202.     cmp byte[esi], 0
  203.     je  .all_files_done
  204.  
  205.     @@:
  206.         movsb
  207.         cmp byte[esi], 0
  208.         jne @b
  209.     movsb
  210.  
  211.     ;; DEBUGF 1, "-- Current URL with filename is : %s\n", current_url
  212.  
  213. ; Create name of file we will download to
  214.     mov esi, download_file_path
  215.     mov edi, current_filename
  216.  
  217.     @@:
  218.         movsb
  219.         cmp byte[esi], 0
  220.         jne @b
  221.  
  222.     mov esi, [filelistoffset]
  223.     @@:
  224.         movsb
  225.         cmp byte[esi], 0
  226.         jne @b
  227.     movsb
  228.     mov [filelistoffset], esi
  229.  
  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
  232.     DEBUGF 2, "Fetching : %s", current_filename
  233.         pusha
  234.         call NOTIFY_CHANGE
  235.         popa
  236.     stdcall get_file_over_http, current_url, current_filename
  237.     DEBUGF 2, "...DONE!\n"
  238.     jmp .get_next_file
  239.  
  240. .all_files_done:
  241.     DEBUGF 2, "-------------------------\n"
  242.     DEBUGF 2, "NETSURF INSTALLED. Enjoy!\n"
  243.     DEBUGF 2, "-------------------------\n"
  244.     call EXIT
  245.     ;; Inform user that all files are done
  246.  
  247. .all_files_done_error:
  248.     DEBUGF 1, "FATAL ERROR: FAILED.\n", eax
  249.     call EXIT
  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
  272.  
  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.  
  277. filelist db 'netsurf-kolibrios', 0
  278.          db 'netsurf-kolibrios.map', 0
  279.          db 'res/adblock.css', 0
  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.  
  337. create_new_file    dd 2, 0, 0, 0, 0
  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
  351.  
  352. socketdata       rb 4096
  353. current_url      rb URLMAXLEN
  354. current_filename rb FILENAMEMAXLEN
  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.        
  389. I_END:
  390.