Subversion Repositories Kolibri OS

Rev

Rev 7842 | 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 '../../string.inc'
  38.  
  39. include '../../system/notify3/notify.inc'
  40.  
  41. include 'notify.asm'
  42.  
  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
  52.     xor eax, eax
  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]
  58.     invoke  HTTP_get, [targeturl], 0, FLAG_KEEPALIVE or FLAG_BLOCK, 0
  59.     cmp     eax, 0
  60.     je .http_error
  61.     mov [httpstruct], eax
  62.  
  63.     ;; No HTTP errors, create a new file for the download.
  64.     DEBUGF 1, "---- Creating new file : %s\n", [targetfilename]
  65.     mcall 70, create_new_file
  66.     cmp eax, 0
  67.     jne .file_error
  68.  
  69.     .http_receive_loop:
  70.         DEBUGF 1, "---- Receiving over http.\n"
  71.         invoke HTTP_receive, [httpstruct]
  72.  
  73.         cmp eax, 0
  74.         je .http_transfer_done
  75.  
  76.  
  77.         mov ebp, [httpstruct]
  78.         DEBUGF 1, "---- http flags = 0x%x.\n",     [ebp + http_msg.flags]
  79.         test [ebp + http_msg.flags], 0xffff0000
  80.         jnz .http_error
  81.  
  82.         mov ebp, [ebp + http_msg.content_received]
  83.         cmp ebp, [write_to_file.current_offset]
  84.         jle .http_receive_loop
  85.         ;; Only proceed if we have more data in HTTP buffer than we have written to file.
  86.  
  87.         ;; Process data we got (write it to the file)
  88.         mov ebp, [httpstruct]
  89.         mov ecx, [ebp + http_msg.content_length]
  90.         mov edx, [ebp + http_msg.content_received]
  91.  
  92.         DEBUGF 1, "---- Current file write offset : %u (http got : %u / %u)\n", [write_to_file.current_offset], edx, ecx
  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.  
  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
  102.         mcall 70, write_to_file
  103.         cmp eax, 0
  104.         jne .file_error
  105.  
  106.         DEBUGF 1, "---- Wrote to file %u bytes.\n", ebx
  107.         add [write_to_file.current_offset], ebx
  108.         DEBUGF 1, "---- File offset updated to : %u\n", [write_to_file.current_offset]
  109.  
  110.         jmp .http_receive_loop
  111.  
  112.     .file_error:
  113.     DEBUGF 1, "file_erroR with eax = %u!", eax
  114.         call EXIT
  115.  
  116.     .http_error:
  117.     DEBUGF 1, "http_erroR!"
  118.         call EXIT
  119.  
  120.     .http_transfer_done:
  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]
  124.  
  125.         mov ebp, [httpstruct]
  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.  
  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
  137.  
  138.         mcall 70, write_to_file
  139.         cmp eax, 0
  140.         jne .file_error
  141.  
  142.         DEBUGF 1, "-- Wrote to file %u bytes.\n", ebx
  143.         add [write_to_file.current_offset], ebx
  144.         DEBUGF 1, "-- File offset updated to : %u\n", [write_to_file.current_offset]
  145.         mov ebp, [httpstruct]
  146.         mov edx, [ebp + http_msg.content_length]
  147.         cmp [write_to_file.current_offset], edx
  148.         jne .http_transfer_done
  149.  
  150.     invoke HTTP_free, [httpstruct]
  151.  
  152.     popa
  153.     ret
  154. endp
  155.  
  156. proc make_new_folder newfolder
  157.     pusha
  158.  
  159.     mov eax, [newfolder]
  160.     mov [create_new_folder.foldername], eax
  161.     mcall 70, create_new_folder
  162.     test eax, eax
  163.     jz .success
  164.  
  165.     DEBUGF 1, "Failed to create folder: %s\n", [newfolder]
  166.     call EXIT
  167.  
  168. .success:
  169.     popa
  170.     ret
  171. endp
  172.  
  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.  
  186. START:
  187.         stdcall run_if_exists, TMP_netsurf
  188.         stdcall run_if_exists, ISO_netsurf
  189.  
  190.     mcall   68, 11                  ; init heap
  191.         call NOTIFY_RUN
  192.  
  193. ; load libraries
  194.     stdcall dll.Load, @IMPORT
  195.     test    eax, eax
  196.     jnz     .all_files_done_error
  197.  
  198.     DEBUGF 2, "-------------------------\n"
  199.     DEBUGF 2, "NETSURF INSTALLER.\n"
  200.  
  201.     stdcall make_new_folder, dirname_res
  202.     ; stdcall make_new_folder, dirname_res_pointers
  203.     ; stdcall make_new_folder, dirname_res_throbber
  204.     ; stdcall make_new_folder, dirname_res_icons
  205.  
  206.  
  207. .get_next_file:
  208.     mov        edi, current_url
  209.     mov        esi, url
  210.  
  211.     @@:
  212.         movsb
  213.         cmp byte[esi], 0
  214.         jne @b
  215.     ;;  Loaded the base URL into current URL
  216.  
  217.     ;; Move onto the subsequent file.
  218.     mov esi, [filelistoffset]
  219.     cmp byte[esi], 0
  220.     je  .all_files_done
  221.  
  222.     @@:
  223.         movsb
  224.         cmp byte[esi], 0
  225.         jne @b
  226.     movsb
  227.  
  228.     ;; DEBUGF 1, "-- Current URL with filename is : %s\n", current_url
  229.  
  230. ; Create name of file we will download to
  231.     mov esi, download_file_path
  232.     mov edi, current_filename
  233.  
  234.     @@:
  235.         movsb
  236.         cmp byte[esi], 0
  237.         jne @b
  238.  
  239.     mov esi, [filelistoffset]
  240.     @@:
  241.         movsb
  242.         cmp byte[esi], 0
  243.         jne @b
  244.     movsb
  245.     mov [filelistoffset], esi
  246.  
  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
  249.     DEBUGF 2, "Fetching : %s", current_filename
  250.         pusha
  251.         call NOTIFY_CHANGE
  252.         popa
  253.     stdcall get_file_over_http, current_url, current_filename
  254.     DEBUGF 2, "...DONE!\n"
  255.     jmp .get_next_file
  256.  
  257. .all_files_done:
  258.     DEBUGF 2, "-------------------------\n"
  259.     DEBUGF 2, "NETSURF INSTALLED. Enjoy!\n"
  260.     DEBUGF 2, "-------------------------\n"
  261.     call EXIT
  262.     ;; Inform user that all files are done
  263.  
  264. .all_files_done_error:
  265.     DEBUGF 1, "FATAL ERROR: FAILED.\n", eax
  266.     call EXIT
  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.  
  288. url              db 'www.kolibri-n.org/files/netsurf/',0
  289.  
  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
  292. filelist_first db '/tmp0/1/netsurf', 0
  293.  
  294. MAX_FILES = 6
  295.  
  296. filelist db 'netsurf', 0
  297.          ;db 'netsurf-kolibrios.map', 0 ;what this???
  298.          db 'res/adblock.css', 0
  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
  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
  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
  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
  351.          db 0
  352.  
  353. filelistoffset   dd filelist
  354. httpstruct       dd 0
  355.  
  356. create_new_file    dd 2, 0, 0, 0, 0
  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
  370.  
  371. socketdata       rb 4096
  372. current_url      rb URLMAXLEN
  373. current_filename rb FILENAMEMAXLEN
  374.  
  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.  
  386. ;=====================================================================
  387. ; NOTIFY DATA
  388. timer     dd 0
  389. params rb 256
  390. ctrl:
  391.  .name rb 32
  392.  .addr rd 1
  393. rb 2048
  394.  
  395.  sz_text:
  396.     db "Downloading Netsurf                  ",10, 0
  397.  sz_quote:
  398.     db "'", 0
  399.  sz_flags:
  400.     db "Ddcpt", 0
  401.        
  402.  sz_final_text:
  403.     db "Netsurf download complete.",10,"Enjoy!",0
  404.  
  405.  fi_launch:
  406.     dd      7, 0, params, 0, 0
  407.     db      "/sys/@notify", 0
  408.        
  409. fileopen    dd 7
  410.             dd 0,0,0,0
  411.             db 0
  412. .path       dd ?          ; path
  413. ;=====================================================================
  414.  
  415. I_END:
  416.