Subversion Repositories Kolibri OS

Rev

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

  1. @use_library_mem mem.Alloc, mem.Free, mem.ReAlloc, dll.Load
  2.  
  3. fn_icon1 db '../../develop/libraries/box_lib/trunk/tl_sys_16_w.bmp', 0
  4. fn_icon2 db '../../develop/libraries/box_lib/trunk/tl_nod_16_w.bmp', 0
  5. bmp_icon dd 0
  6.  
  7. TLIST_SZ = 325+16 ;=341. 16 is x-size of scroll bar
  8. TLIST1_X = 50
  9. TLIST2_X = 409
  10. BT_SZ_X  = 40
  11. SYS_COL  = 0xe6e6e6
  12. BT_COL   = 0xcccccc
  13. STR_COL  = 0x595959 ;0x000000
  14.  
  15. ; TODO: automatic resizing of GUI elements on window resizing
  16.  
  17. align 4
  18. ;;================================================================================================;;
  19. gui: ;////////////////////////////////////////////////////////////////////////////////////////////;;
  20. ;;------------------------------------------------------------------------------------------------;;
  21. ;? GUI-specific functions                                                                         ;;
  22. ;;------------------------------------------------------------------------------------------------;;
  23. ;> none                                                                                           ;;
  24. ;;------------------------------------------------------------------------------------------------;;
  25. ;< none                                                                                           ;;
  26. ;;================================================================================================;;
  27.  
  28.     dd .init
  29.     dd .server_addr
  30.     dd .get_username
  31.     dd .get_cmd
  32.     dd .print
  33.     dd .set_flags
  34.     dd .list
  35.     dd .progress
  36.     dd .error
  37.  
  38.     .init:
  39.         ; load libraries
  40.         stdcall dll.Load, @IMPORT_BOXLIB
  41.         test    eax, eax
  42.         jnz     .exit
  43.  
  44.         mcall   48, 3, sc, sizeof.system_colors
  45.         mcall   40, 0xC0000027 ; set event mask
  46.         ret
  47.  
  48.     .server_addr:
  49.         mov     [auto_list], 1
  50.         jmp     login_gui.server_addr
  51.  
  52.     .get_username:
  53.         jmp     login_gui.get_username
  54.  
  55.  
  56. ;;================================================================================================;;
  57.     .main: ;//////////////////////////////////////////////////////////////////////////////////////;;
  58. ;;------------------------------------------------------------------------------------------------;;
  59. ;? Initialize tree list, editbox and textedit elements                                            ;;
  60. ;;------------------------------------------------------------------------------------------------;;
  61. ;> none                                                                                           ;;
  62. ;;------------------------------------------------------------------------------------------------;;
  63. ;< none                                                                                           ;;
  64. ;;================================================================================================;;
  65.  
  66.         stdcall [ted_init], tedit0
  67.         mov     dword[tedit0.rec.width], 9
  68.         mov     dword[tedit0.rec.height], 16
  69.  
  70.         stdcall dword[edit_box_set_text], edit_volume, root_dir
  71.  
  72.         ; initialize tree list elements
  73.         stdcall dword[tl_data_init], tree1
  74.         stdcall dword[tl_data_init], tree2
  75.  
  76.         ; read *.bmp file system icons
  77.         copy_path fn_icon1,path,filestruct.name, 0
  78.      
  79.         mov     ecx, 3*256*13
  80.         stdcall mem.Alloc, ecx
  81.         mov     [bmp_icon], eax
  82.      
  83.         mov     [filestruct.ptr], eax
  84.         mov     [filestruct.subfn], 0
  85.         mov     [filestruct.offset], 54
  86.         mov     [filestruct.size], ecx
  87.         mcall   70, filestruct
  88.         cmp     ebx, 0
  89.         jl      @f
  90.         m2m     dword[tree1.data_img_sys], dword[bmp_icon]
  91.         m2m     dword[tree2.data_img_sys], dword[bmp_icon]
  92.  
  93.       @@:
  94.         ; read * .bmp file with the icon of nodes
  95.         copy_path fn_icon2, path, filestruct.name, 0
  96.      
  97.         mov     ecx, 3*256*13
  98.         stdcall mem.Alloc, ecx
  99.         mov     [bmp_icon], eax
  100.      
  101.         mov     [filestruct.ptr], eax
  102.         ;mov    [filestruct.subfn], 0
  103.         ;mov    [filestruct.offset], 54
  104.         mov     [filestruct.size], ecx
  105.         mcall   70, filestruct
  106.         cmp     ebx, 0
  107.         jl      @f
  108.         m2m     dword[tree1.data_img], dword[bmp_icon]
  109.         m2m     dword[tree2.data_img], dword[bmp_icon]
  110.    
  111.       @@:
  112.         mcall   67, 35, 20, 830, 555 ; resize to main gui window's coordinates
  113.         call    .draw
  114.         ; create initial tree list for root_dir
  115.         call    populate_local_tree_list
  116.         jmp     arg_handler.connect
  117.  
  118.     .get_cmd:
  119.         dec     [auto_list]
  120.         jnz     .redraw
  121.         call    .clear_remote_tree
  122.         jmp     cmd_list
  123.  
  124.     .redraw:
  125.         call     .draw
  126.  
  127.     align 4
  128.     .still:
  129.         mcall   10
  130.  
  131.         dec     eax
  132.         jz      .redraw
  133.         dec     eax
  134.         jz      .key
  135.         dec     eax
  136.         jz      .button
  137.         sub     eax, 3
  138.         jz      .mouse
  139.  
  140.         jmp     .still
  141.  
  142.     .error:
  143.         jmp     login_gui.error
  144.  
  145.     .exit:
  146.     ;   stdcall mem.Free,[bmp_icon]
  147.         stdcall dword[tl_data_clear], tree1
  148.         stdcall dword[tl_data_clear], tree2
  149.         stdcall [ted_delete], tedit0
  150.         jmp     exit
  151.  
  152.     align 4
  153.     .draw:
  154.         mcall   12, 1
  155.         ; main window
  156.         mcall   0, <35,830>, <20,555>, 0x34000000+SYS_COL, 0x805080DD, hed
  157.  
  158.         ;-------------------------
  159.         ; textedit components
  160.         ;-------------------------
  161.         mcall   9, procinfo, -1
  162.         mov     edi, tedit0
  163.         call    EvSize
  164.  
  165.         movzx   ebx,word[procinfo.client_box.width]
  166.         inc     bx
  167.         mcall   13, , ted_wnd_t
  168.         stdcall [ted_draw], tedit0
  169.  
  170.         ; draw "disconnect" button
  171.         mcall   8, <50,85>, <25,25>, 3, BT_COL
  172.         ; string "disconnect"
  173.         mcall   4, <50+5,25+5>, 0xb0000000+STR_COL, str_disconnect
  174.         ; draw "Copy" button
  175.         mcall   8, <50,40>, <326,25>, 4, BT_COL
  176.         ; string "copy"
  177.         mcall   4, <50+5,326+5>, 0xb0000000+STR_COL, str_copy
  178.         ; draw "Search" button
  179.         mcall   8, <TLIST2_X+TLIST_SZ-55,55>, <20,25>, 5, BT_COL
  180.         ; string "Search"
  181.         mcall   4, <TLIST2_X+TLIST_SZ-55+5,20+5>, 0xb0000000+STR_COL, str_search
  182.  
  183.         ; draw "LIST" button
  184.         mcall   8, <TLIST2_X+TLIST_SZ-4*BT_SZ_X-15,BT_SZ_X>, <50,25>, 12, BT_COL
  185.         ; string "LIST"
  186.         mcall   4, <TLIST2_X+TLIST_SZ-4*BT_SZ_X-15+5,50+5>, 0xb0000000+STR_COL, str_list
  187.         ; draw "DELE" button
  188.         mcall   8, <TLIST2_X+TLIST_SZ-3*BT_SZ_X-10,BT_SZ_X>, <50,25>, 7, BT_COL
  189.         ; string "DELE"
  190.         mcall   4, <TLIST2_X+TLIST_SZ-3*BT_SZ_X-10+5,50+5>, 0xb0000000+STR_COL, str_dele
  191.         ; draw "RDIR" button
  192.         mcall   8, <TLIST2_X+TLIST_SZ-2*BT_SZ_X-5,BT_SZ_X>, <50,25>, 8, BT_COL
  193.         ; string "RDIR"
  194.         mcall   4, <TLIST2_X+TLIST_SZ-2*BT_SZ_X-5+5,50+5>, 0xb0000000+STR_COL, str_rdir
  195.         ; draw "RMD" button
  196.         mcall   8, <TLIST2_X+TLIST_SZ-BT_SZ_X,BT_SZ_X>, <50,25>, 9, BT_COL
  197.         ; string "RMD"
  198.         mcall   4, <TLIST2_X+TLIST_SZ-BT_SZ_X+5,50+5>, 0xb0000000+STR_COL, str_rmd
  199.  
  200.         ; draw "mkd" button
  201.         mcall   8, <TLIST2_X+TLIST_SZ-BT_SZ_X,BT_SZ_X>, <80,20>, 6, BT_COL
  202.         ; string "mkd"
  203.         mcall   4, <TLIST2_X+TLIST_SZ-BT_SZ_X+5,80+5>, 0xb0000000+STR_COL, str_mkd
  204.        
  205.         ; draw "cancel" button
  206.         mcall   8, <555,55>, <308,25>, 10, BT_COL
  207.         ; string "Cancel"
  208.         mcall   4, <555+5,308+5>, 0xb0000000+STR_COL, str_abort
  209.         ; draw "change volume" button
  210.         mcall   8, <TLIST1_X+TLIST_SZ-55,55>, <100-20,22>, 11, BT_COL
  211.         ; string "Change"
  212.         mcall   4, <TLIST1_X+TLIST_SZ-55+5,100-20+5>, 0xb0000000+STR_COL, str_change
  213.  
  214.         ;--------------------------
  215.         ; tree list components
  216.         ;--------------------------
  217.         stdcall dword[tl_draw], tree1
  218.         stdcall dword[tl_draw], tree2
  219.      
  220.         mov     dword[wScr.all_redraw], 1
  221.         stdcall [scrollbar_ver_draw], wScr
  222.  
  223.         mov     dword[wScr2.all_redraw],1
  224.         stdcall [scrollbar_ver_draw], wScr2
  225.  
  226.         stdcall [edit_box_draw], edit_mkd
  227.         stdcall [edit_box_draw], edit_volume
  228.         stdcall [edit_box_draw], edit_search
  229.  
  230.         ; progress bar
  231.         stdcall [progressbar_draw], pb
  232.  
  233.         mcall   12,2
  234.         ret
  235.  
  236.     align 16
  237.     .mouse:
  238.         mcall   37, 1
  239.         cmp     word[tedit0.wnd.top], ax
  240.         jg      .no_edit
  241.  
  242.         shr     eax, 16
  243.         cmp     word[tedit0.wnd.left], ax
  244.         jg      .no_edit
  245.  
  246.         mcall   37, 3
  247.         bt      eax, 24
  248.         jnc     @f
  249.  
  250.         stdcall [ted_but_select_word], tedit0
  251.         jmp     .still
  252.  
  253.       @@:
  254.         stdcall [ted_mouse], tedit0
  255.         jmp     .still
  256.  
  257.       .no_edit:
  258.         stdcall [tl_mouse], tree1
  259.         stdcall [tl_mouse], tree2
  260.         stdcall [edit_box_mouse], edit_mkd
  261.         stdcall [edit_box_mouse], edit_volume
  262.         stdcall [edit_box_mouse], edit_search
  263.         jmp     .still
  264.  
  265.     align 16
  266.     .key:
  267.         mcall   2
  268.         stdcall [tl_key], tree1
  269.         stdcall [tl_key], tree2
  270.         stdcall [edit_box_key], edit_mkd
  271.         stdcall [edit_box_key], edit_volume
  272.         stdcall [edit_box_key], edit_search
  273.         jmp     .still
  274.  
  275.     align 16
  276.     .button:
  277.         mcall   17
  278.  
  279.         cmp     ah, 3
  280.         jne     @f
  281.         ijmp    eax, interface_addr, interface.server_addr
  282.         jmp     .still
  283.  
  284.       @@:
  285.         cmp     ah, 4
  286.         jne     @f
  287.         stdcall [ted_but_copy], tedit0
  288.         jmp     .still
  289.  
  290.       @@:
  291.         cmp     ah, 5
  292.         jne     @f
  293.         je      filter_remote_list
  294.  
  295.       @@:
  296.         cmp     ah, 6
  297.         je      create_remote_dir
  298.  
  299.         cmp     ah, 7
  300.         je      delete_file
  301.  
  302.         cmp     ah, 8
  303.         je      cmd_rdir
  304.  
  305.         cmp     ah, 9
  306.         je      remove_dir
  307.  
  308.         cmp     ah, 10
  309.         je      cmd_abor
  310.  
  311.         cmp     ah, 11
  312.         jne     @f
  313.         call    populate_local_tree_list
  314.  
  315.       @@:
  316.         cmp     ah, 12
  317.         jne     @f
  318.         call    .clear_remote_tree
  319.         je      cmd_list
  320.  
  321.       @@:
  322.         cmp     ah, 1
  323.         je      .exit
  324.      
  325.         jmp     .still
  326.  
  327.     .print:
  328.         pushad
  329.         mov     ebx, ted_opt_ed_change_time + ted_opt_ed_move_cursor
  330.         mov     ecx, 2 ; 0a0d
  331.         mov     esi, [esp+36]
  332.         mov     word[tedit_buffer], 0x0a0d
  333.         lea     edi, [tedit_buffer+2]
  334.  
  335.       @@:
  336.         movsb
  337.         inc     ecx
  338.         cmp     byte[esi], 0
  339.         jne     @b
  340.         stdcall [ted_text_add], tedit0, tedit_buffer, ecx, ebx
  341.         stdcall [ted_draw], tedit0
  342.         ; write to log file
  343.         mov     eax, [esp+36]
  344.         cmp     [logfile_offset], -1 ; disabled logging?
  345.         je      @f
  346.         call    write_to_file
  347.  
  348.       @@:
  349.         popad
  350.         ret     4
  351.  
  352.     .set_flags:
  353.         ret     4
  354.  
  355.  
  356. ;;================================================================================================;;
  357.     .list: ;//////////////////////////////////////////////////////////////////////////////////////;;
  358. ;;------------------------------------------------------------------------------------------------;;
  359. ;? update tree2 with remote directory listing                                                     ;;
  360. ;;------------------------------------------------------------------------------------------------;;
  361. ;> buf_buffer2 = received data buffer                                                             ;;
  362. ;> eax = size of data                                                                             ;;
  363. ;> remote_list_buf = buffer containing last incomplete entry (if any)                             ;;
  364. ;;------------------------------------------------------------------------------------------------;;
  365. ;< none                                                                                           ;;
  366. ;;================================================================================================;;
  367.  
  368.         push    edx
  369.         push    eax
  370.         ; check if any incomplete entry to be parsed
  371.         cmp     byte[remote_list_buf], 0
  372.         je      .no_backlog
  373.         ; find end of remote_list_buf
  374.         mov     edi, remote_list_buf
  375.         mov     al, 0
  376.         repne   scasb
  377.         ; copy rest of the incomplete entry to remote_list_buf
  378.         mov     esi, buf_buffer2
  379.         dec     edi
  380.  
  381.       @@:
  382.         movsb
  383.         cmp     word[esi-2], 0x0a0d
  384.         jne     @b
  385.         mov     byte[edi], 0
  386.         mov     ecx, edi
  387.         sub     ecx, remote_list_buf ; ecx = length of remote_list_buf
  388.         mov     ebx, esi ; ebx = address at which next parse should start
  389.         mov     edi, remote_list_buf
  390.         jmp     .start_parsing
  391.  
  392.       .no_backlog:
  393.         mov     ecx, eax    ; ecx = number of bytes remaining to parse in buf_buffer2
  394.         mov     edi, buf_buffer2
  395.  
  396.       .start_parsing:
  397.         ; find pointer to name
  398.         cmp     byte[edi], 'd' ; file is a directory
  399.         je      @f
  400.         cmp     byte[edi], 'l' ; link
  401.         je      @f
  402.         mov     word[node_entry2], 'fi'
  403.         jmp     .parse
  404.  
  405.       @@:
  406.         mov     word[node_entry2], 'fo'
  407.  
  408.       .parse:
  409.         mov     edx, 8
  410.  
  411.       @@:
  412.         mov     al, ' '
  413.         mov     ecx, [esp]
  414.         add     ecx, buf_buffer2
  415.         sub     ecx, edi
  416.        
  417.         repne   scasb
  418.  
  419.         ; check if the (last) entry is incomplete
  420.         test    ecx, ecx
  421.         jz      .store_last_entry
  422.  
  423.         rep     scasb
  424.         test    ecx, ecx
  425.         jz      .store_last_entry
  426.        
  427.         dec     edx
  428.         jnz     @b
  429.  
  430.         lea     esi, [edi-1]
  431.         lea     edi, [node_entry2+4]
  432.       @@:
  433.         movsb
  434.         cmp     word[esi], 0x0a0d ; end of entry
  435.         jne     @b
  436.         mov     byte[edi], 0
  437.  
  438.         ; add node to tree list
  439.         cmp     word[node_entry2], 'fi'
  440.         jne     @f
  441.         stdcall dword[tl_node_add], tree2, 0, node_entry2
  442.         jmp     .added_remote_node
  443.  
  444.       @@:
  445.         stdcall dword[tl_node_add], tree2, 0x10000, node_entry2
  446.  
  447.       .added_remote_node:
  448.         ; check whether we are parsing remote_list_buf
  449.         cmp     byte[remote_list_buf], 0
  450.         je      @f
  451.         mov     byte[remote_list_buf], 0 ; done parsing remote_list_buf
  452.         mov     edi, ebx
  453.         mov     eax, [esp]
  454.         mov     ecx, buf_buffer2
  455.         add     ecx, eax
  456.         sub     ecx, ebx
  457.         jmp     .start_parsing
  458.  
  459.       @@:
  460.         ; any more entries to parse?
  461.         lea     edi, [esi+2] ; skip 0a0d
  462.         cmp     byte[edi], 0
  463.         jne     .start_parsing
  464.         jmp     .done_parsing
  465.  
  466.       .store_last_entry:
  467.         ; find index of the last incomplete entry
  468.         mov     ecx, -1
  469.         mov     eax, [esp]
  470.         lea     edi, [buf_buffer2+eax-2]
  471.         mov     al, 0x0a
  472.         std
  473.         repne   scasb
  474.         cld
  475.  
  476.         ; copy last (incomplete) entry of buf_buffer2 to remote_list_buf
  477.         lea     esi, [edi+2]
  478.         mov     edi, remote_list_buf
  479.       @@:
  480.         movsb
  481.         cmp     byte[esi-1], 0
  482.         jne     @b
  483.  
  484.       .done_parsing:
  485.         call    .draw ; to update tree list immediately in case of "auto_list"
  486.         pop     eax
  487.         pop     edx
  488.         jmp     data_loop
  489.  
  490.         ; clear tree list and add ".." node before executing "LIST"
  491.       .clear_remote_tree:
  492.         stdcall dword[tl_info_clear], tree2
  493.         mov     dword[node_entry2+4], 0x2E2E
  494.         stdcall dword[tl_node_add], tree2, 0x10000, node_entry2
  495.         ret
  496.  
  497.  
  498. ;;================================================================================================;;
  499.     .progress: ;//////////////////////////////////////////////////////////////////////////////////;;
  500. ;;------------------------------------------------------------------------------------------------;;
  501. ;? Update progress bar every time new data is received from data_loop block                       ;;
  502. ;;------------------------------------------------------------------------------------------------;;
  503. ;> edx = no. of bytes downloaded                                                                  ;;
  504. ;;------------------------------------------------------------------------------------------------;;
  505. ;< none                                                                                           ;;
  506. ;;================================================================================================;;
  507.  
  508.         ; detect abort
  509.         mcall   17
  510.         cmp     ah, 10
  511.         je      cmd_abor
  512.  
  513.         push    eax ebx ecx edx
  514.         mov     ebx, [file_size]
  515.         mov     ecx, 100
  516.         mov     eax, edx
  517.         mul     ecx
  518.         div     ebx
  519.         cmp     eax, 100
  520.         jle     @f
  521.         mov     eax, 100
  522.  
  523.       @@:
  524.         mov     dword[pb], eax
  525.         push    pb
  526.         call    [progressbar_draw]
  527.         pop     edx ecx ebx eax
  528.         ret
  529.  
  530.  
  531. remove_dir:
  532.  
  533.     stdcall dword[tl_node_get_data], tree2
  534.     cmp     word[eax], 'fo'
  535.     jne     gui.still
  536.     lea     esi, [eax+4]
  537.     lea     edi, [buf_cmd+4]
  538.   @@:
  539.     movsb
  540.     cmp     byte[esi], 0
  541.     jne     @b
  542.     mov     word[edi], 0x000a
  543.     jmp     cmd_rmd
  544.  
  545.  
  546. delete_file:
  547.  
  548.     stdcall dword[tl_node_get_data], tree2
  549.     cmp     word[eax], 'fi'
  550.     jne     gui.still
  551.     lea     esi, [eax+4]
  552.     lea     edi, [buf_cmd+5]
  553.   @@:
  554.     movsb
  555.     cmp     byte[esi], 0
  556.     jne     @b
  557.     mov     word[edi], 0x000a
  558.     jmp     cmd_dele
  559.  
  560.  
  561. create_remote_dir:
  562.  
  563.     lea     edi, [buf_cmd+4]
  564.     mov     esi, new_dir_buf
  565.   @@:
  566.     movsb
  567.     cmp     byte[esi], 0
  568.     jne     @b
  569.     mov     word[edi], 0x000a
  570.     jmp     cmd_mkd
  571.  
  572.  
  573. ; Function to call when you press [Enter]
  574. align 4
  575. fun_on_enter:
  576.  
  577.     stdcall dword[tl_node_get_data], tree1
  578.     cmp     word[eax], 'fi'
  579.     je      @f
  580.     lea     ecx, [eax+4] ; discard first 4 bytes
  581.     call    populate_local_tree_list.read_new_dir
  582.     ;stdcall dword[tl_draw], tree1
  583.     ret
  584.  
  585.   @@:
  586.     lea     esi, [eax+4]
  587.     lea     edi, [buf_cmd+5]
  588.   @@:
  589.     movsb
  590.     cmp     byte[esi], 0
  591.     jne     @b
  592.     mov     word[edi], 0x000a
  593.     jmp     cmd_stor
  594.  
  595.  
  596. ; Function to call when you press [Enter]
  597. ; for treelist with remote directory listing
  598. align 4
  599. fun_on_enter2:
  600.  
  601.     stdcall dword[tl_node_get_data], tree2
  602.     lea     esi, [eax+4]
  603.     cmp     dword[esi], 0x2E2E
  604.     jne     @f
  605.     mov     [auto_list], 1
  606.     jmp     cmd_cdup
  607.  
  608.   @@:
  609.     cmp     word[eax], 'fo'
  610.     je      @f
  611.     lea     edi, [buf_cmd+5]
  612.     jmp     .copy
  613.  
  614.   @@:
  615.     lea     edi, [buf_cmd+4]
  616.  
  617.   .copy:
  618.     movsb
  619.     cmp     byte[esi], 0
  620.     jne     .copy
  621.     mov     word[edi], 0x000a ; extra character before 0 to compensate for
  622.                                 ; newline in console code
  623.     cmp     word[eax], 'fo'
  624.     je      @f
  625.     jmp     cmd_retr
  626.  
  627.   @@:
  628.     stdcall dword[tl_info_clear], tree2
  629.     mov     [auto_list], 1
  630.     jmp     cmd_cwd
  631.  
  632.  
  633. ;;================================================================================================;;
  634. populate_local_tree_list: ;///////////////////////////////////////////////////////////////////////;;
  635. ;;------------------------------------------------------------------------------------------------;;
  636. ;? Update tree1 with file names from current working directory                                    ;;
  637. ;;------------------------------------------------------------------------------------------------;;
  638. ;> none                                                                                           ;;
  639. ;;------------------------------------------------------------------------------------------------;;
  640. ;< none                                                                                           ;;
  641. ;;================================================================================================;;
  642.  
  643.     mov     [filestruct.subfn], 1
  644.     mov     [filestruct.size], 32
  645.     mov     [filestruct.ptr], folder_data
  646.     mov     ecx, root_dir
  647.  
  648.   .read_new_dir: ; ecx = pointer to folder name
  649.     ; parse ".."
  650.     cmp     word[ecx], '..'
  651.     jne     @f
  652.     cmp     byte[ecx+2], 0
  653.     jne     @f
  654.  
  655.     ; removes last file name from filestruct.name
  656.     mcall   30, 2, filestruct.name,1024 ; get absolute path for cwd
  657.     lea     edi, [filestruct.name+eax] ; edi = pointer to the tail of file name
  658.     mov     al, '/'
  659.     mov     ecx, -1
  660.     std
  661.     repne   scasb
  662.     cld
  663.     mov     byte[edi+1], 0
  664.     mov     ecx, filestruct.name
  665.  
  666.   @@:
  667.     mcall   30, 1, ; set cwd
  668.     mcall   30, 2, filestruct.name, 1024 ; get absolute path for cwd
  669.     ; clear all nodes in tree list
  670.     stdcall dword[tl_info_clear], tree1
  671.     mov     [filestruct.offset], 0
  672.  
  673.   ; read 32 blocks
  674.   .outer:
  675.     mcall   70, filestruct
  676.     ;int3
  677.     test    eax, eax
  678.     jz      @f
  679.     cmp     eax, 6 ; EOF
  680.     je      @f
  681.     call    error_fs
  682.     jmp     .done
  683.   @@:
  684.     test    ebx, ebx
  685.     je      .done ; when no. of blocks is multiple of 32
  686.     add     [filestruct.offset], ebx
  687.     mov     ecx, ebx
  688.     mov     edx, folder_data+32+40 ; pointer to first file's name in BDFE
  689.  
  690.   .inner:   ; ebx = total number of BDFEs
  691.             ; ecx = number of BDFEs remaining
  692.             ; edx = pointer to file's name in BDFE
  693.     ; ignore "." entry
  694.     cmp     word[edx], 0x002E
  695.     je      .added
  696.     ; copy file/folder name to node_entry
  697.     mov     esi, edx
  698.     mov     edi, node_entry+4
  699.   @@:
  700.     movsb
  701.     cmp     byte [esi-1], 0
  702.     jne     @b
  703.     ; check whether this is a file or a folder
  704.     mov     al, byte[edx-40]
  705.     and     al, 0x10
  706.     jz      @f
  707.     ; add a folder to tree
  708.     mov     word[node_entry], 'fo'
  709.     stdcall dword[tl_node_add], tree1, 0x10000, node_entry
  710.     jmp     .added
  711.  
  712.   @@:
  713.     ; add a file to tree
  714.     mov     word[node_entry], 'fi'
  715.     stdcall dword[tl_node_add], tree1, 0, node_entry
  716.  
  717.   .added:
  718.     add     edx, 304 ; 304 = length of BDFE. jump to next file's name
  719.     loop    .inner
  720.     stdcall dword[tl_draw], tree1
  721.     cmp     ebx, 32
  722.     je      .outer ; more BDFEs to come
  723.  
  724.   .done:
  725.     ret    
  726.  
  727.  
  728. MIN_M_WND_H equ 500 ;
  729. ;input:
  730. ; edi = pointer to tedit struct
  731. align 4
  732. EvSize:
  733.     pushad
  734.     mov     ebx, ted_scr_h
  735.     mov     esi, ted_scr_w
  736.  
  737.     m2m     ted_wnd_w, [procinfo.client_box.width]
  738.     mov     eax, ted_wnd_l
  739.     sub     ted_wnd_w, eax
  740.     sub     ted_wnd_w, 70
  741.     movzx   eax, word[esi+sb_offs_size_x]
  742.     sub     ted_wnd_w, eax
  743.  
  744.     ;m2m    ted_wnd_h,[procinfo.client_box.height] ;
  745.     ;cmp    ted_wnd_h,MIN_M_WND_H
  746.     ;jg     @f
  747.     mov     ted_wnd_h, MIN_M_WND_H
  748.     ;@@:
  749.  
  750.     movzx   eax, word[ebx+sb_offs_size_y]
  751.     sub     ted_wnd_h, eax
  752.     mov     eax, ted_wnd_t
  753.     sub     ted_wnd_h, eax
  754.  
  755.     stdcall [ted_init_scroll_bars], tedit0,2
  756.  
  757.     popad
  758.     ret
  759.  
  760.  
  761. ;;================================================================================================;;
  762. filter_remote_list: ;/////////////////////////////////////////////////////////////////////////////;;
  763. ;;------------------------------------------------------------------------------------------------;;
  764. ;? Filter tree list according to pattern specified in 'filter'                                    ;;
  765. ;;------------------------------------------------------------------------------------------------;;
  766. ;> none                                                                                           ;;
  767. ;;------------------------------------------------------------------------------------------------;;
  768. ;< none                                                                                           ;;
  769. ;;================================================================================================;;
  770.         stdcall dword[tl_cur_beg], tree2
  771.  
  772.     .next_node:
  773.         stdcall dword[tl_node_get_data], tree2
  774.         ; check whether any nodes left
  775.         test    eax, eax
  776.         jnz     @f
  777.         stdcall dword[tl_draw], tree2
  778.         stdcall dword[edit_box_set_text], edit_search, str_null
  779.         je      gui.still
  780.  
  781.     @@:
  782.         cmp     byte[filter], 0
  783.         je      gui.still
  784.  
  785.         ; calculate size of node entry
  786.         lea     esi, [eax+4]
  787.         mov     edi, esi
  788.         mov     ecx, -1
  789.     @@:
  790.         lodsb
  791.         inc     ecx
  792.         test    al, al
  793.         jnz     @b
  794.  
  795.         ; calculate size of pattern
  796.         mov     esi, filter
  797.         mov     edx, -1
  798.     @@:
  799.         lodsb
  800.         inc     edx
  801.         test    al, al
  802.         jnz     @b
  803.  
  804.         mov     esi, filter
  805.  
  806.         call    search
  807.         pop     esi
  808.         test    al, al
  809.  
  810.         jnz     .get_next
  811.         stdcall dword[tl_node_delete], tree2
  812.         jmp     @f
  813.  
  814.     .get_next:
  815.         stdcall dword[tl_cur_next], tree2
  816.  
  817.     @@:
  818.         jmp     .next_node
  819.  
  820.  
  821. ;;================================================================================================;;
  822. search: ;/////////////////////////////////////////////////////////////////////////////////////////;;
  823. ;;------------------------------------------------------------------------------------------------;;
  824. ;? Search for a substring within a string                                                         ;;
  825. ;;------------------------------------------------------------------------------------------------;;
  826. ;> edi = pointer to haystack                                                                      ;;
  827. ;> ecx = size of haystack                                                                         ;;
  828. ;> esi = pointer to needle                                                                        ;;
  829. ;> edx = size of needle                                                                           ;;
  830. ;;------------------------------------------------------------------------------------------------;;
  831. ;< al = 0 (not found) / 1 (found)                                                                 ;;
  832. ;;================================================================================================;;
  833.    
  834.     push    ebx ecx edx esi edi
  835.     ; if length of haystack < length of needle
  836.     cmp     ecx, edx
  837.     jge     @f
  838.     mov     bh, 0
  839.     jmp     .done
  840.   @@:
  841.     mov     bh, 1 ; flag (0 = not found, 1 = found)
  842.     sub     ecx, edx
  843.     dec     edi
  844.  
  845.   .outer:
  846.     cmp     ecx, 0
  847.     jl      .done
  848.     dec     ecx
  849.     inc     edi
  850.     mov     bh, 1 ; flag (0 = not found, 1 = found)
  851.     mov     edx, [esp+8]
  852.     mov     esi, [esp+4]
  853.  
  854.   .inner:
  855.     test    edx, edx
  856.     jz      .done
  857.     dec     edx
  858.  
  859.     mov     eax, esi
  860.     sub     eax, [esp+4]
  861.     mov     al, byte[edi+eax]
  862.     mov     bl, byte[esi]
  863.  
  864.     inc     esi
  865.     cmp     al, bl
  866.     je      .inner
  867.     mov     bh, 0
  868.     jmp     .outer
  869.  
  870.  
  871.   .done:
  872.     mov     al, bh
  873.     pop     edi esi edx ecx ebx
  874.     ret
  875.  
  876. ;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
  877.  
  878. hed             db 'FTP Client - KolibriOS',0
  879. str_change      db 'Change',0
  880. str_disconnect  db 'Disconnect',0
  881. str_copy        db 'Copy',0
  882. str_mkd         db 'MKD',0
  883. str_dele        db 'DELE',0
  884. str_rdir        db 'RDIR',0
  885. str_rmd         db 'RMD',0
  886. str_abort       db 'Cancel',0
  887. str_search      db 'Search',0
  888. str_list        db 'LIST',0
  889. str_null        db 0
  890.  
  891. ;----------------------
  892. ; tree list elements
  893. ;----------------------
  894. tree1 tree_list 64, 500, tl_list_box_mode, 16, 16, \
  895.     0xffffff, BT_COL, 0x000000, TLIST1_X, 105, TLIST_SZ-16, 185, 14, 4,\
  896.     0, el_focus, wScr, fun_on_enter
  897.  
  898. tree2 tree_list 64, 500, tl_list_box_mode, 16, 16, \
  899.     0xffffff, BT_COL, 0x000000, TLIST2_X, 105, TLIST_SZ-16, 185, 14, 4, \
  900.     0, el_focus, wScr2, fun_on_enter2
  901.  
  902. ; editbox for mkd
  903. edit_mkd edit_box TLIST_SZ-45, TLIST2_X, 82, 0xffffff, 0x6a9480, 0, \
  904.     0xAABBCC, 0, 99, new_dir_buf, mouse_dd, 0
  905.  
  906. ; editbox for default volume
  907. edit_volume edit_box TLIST_SZ-60, TLIST1_X, 105-20, 0xffffff, 0x6a9480, 0, \
  908.     0xAABBCC, 0, 99, root_dir, mouse_dd, 0
  909.  
  910. ; editbox for search
  911. edit_search edit_box TLIST_SZ-60, TLIST2_X, 25, 0xffffff, 0x6a9480, 0, \
  912.     0xAABBCC, 0, 99, filter,mouse_dd, 0
  913.  
  914. ; A subsidiary structure for scrolling
  915. align 4
  916. wScr:
  917.     .x:
  918.     .size_x     dw 16 ;+0
  919.     .start_x    dw 250+50-16 ;+2
  920.     .y:
  921.     .size_y     dw 185 ;+4
  922.     .start_y    dw 105 ;+6
  923.     .btn_high   dd 15 ;+8
  924.     .type       dd 1  ;+12
  925.     .max_area   dd 100  ;+16
  926.     .cur_area   dd 30  ;+20
  927.     .position   dd 0  ;+24
  928.     .bckg_col   dd 0xeeeeee ;+28
  929.     .frnt_col   dd 0xbbddff ;+32
  930.     .line_col   dd 0  ;+36
  931.     .redraw     dd 0  ;+40
  932.     .delta      dw 0  ;+44
  933.     .delta2     dw 0  ;+46
  934.     .run_x:
  935.     .r_size_x   dw 0  ;+48
  936.     .r_start_x  dw 0  ;+50
  937.     .run_y:
  938.     .r_size_y   dw 0 ;+52
  939.     .r_start_y  dw 0 ;+54
  940.     .m_pos      dd 0 ;+56
  941.     .m_pos_2    dd 0 ;+60
  942.     .m_keys     dd 0 ;+64
  943.     .run_size   dd 0 ;+68
  944.     .position2  dd 0 ;+72
  945.     .work_size  dd 0 ;+76
  946.     .all_redraw dd 0 ;+80
  947.     .ar_offset  dd 1 ;+84
  948.  
  949. align 4
  950. wScr2:
  951.     .x:
  952.     .size_x     dw 16 ;+0
  953.     .start_x    dw 675+50-16 ;+2
  954.     .y:
  955.     .size_y     dw 185 ;+4
  956.     .start_y    dw 105 ;+6
  957.     .btn_high   dd 15 ;+8
  958.     .type       dd 1  ;+12
  959.     .max_area   dd 100  ;+16
  960.     .cur_area   dd 30  ;+20
  961.     .position   dd 0  ;+24
  962.     .bckg_col   dd 0xeeeeee ;+28
  963.     .frnt_col   dd 0xbbddff ;+32
  964.     .line_col   dd 0  ;+36
  965.     .redraw     dd 0  ;+40
  966.     .delta      dw 0  ;+44
  967.     .delta2     dw 0  ;+46
  968.     .run_x:
  969.     .r_size_x   dw 0  ;+48
  970.     .r_start_x  dw 0  ;+50
  971.     .run_y:
  972.     .r_size_y   dw 0 ;+52
  973.     .r_start_y  dw 0 ;+54
  974.     .m_pos      dd 0 ;+56
  975.     .m_pos_2    dd 0 ;+60
  976.     .m_keys     dd 0 ;+64
  977.     .run_size   dd 0 ;+68
  978.     .position2  dd 0 ;+72
  979.     .work_size  dd 0 ;+76
  980.     .all_redraw dd 0 ;+80
  981.     .ar_offset  dd 1 ;+84
  982. ;----------------------
  983. ; end tree list element
  984. ;----------------------
  985.  
  986. ;----------------------
  987. ; textedit elements
  988. ;----------------------
  989. align 4
  990. tedit0:
  991.     .wnd BOX 50,355,325,240 ;+ 0 195,5+40,325,240
  992.     .rec BOX 30,13,7,10   ;+16
  993.     .drag_m db 0 ;+32
  994.     .drag_k db 0 ;+33
  995.     .sel rb 16 ;+34
  996.     .seln rb 16 ;+50
  997.     .tex      dd 0 ;+66 text memory pointer
  998.     .tex_1    dd 0 ;+70 text first symbol pointer
  999.     .tex_end  dd 0 ;+74 text end memory pointer
  1000.     .cur_x    dd 0 ;+78
  1001.     .cur_y    dd 0 ;+82
  1002.     .max_chars dd 4096 ;+86
  1003.     .count_colors_text dd 1 ;+90
  1004.     .count_key_words   dd 0 ;+94
  1005.     .color_cursor      dd SYS_COL  ;+98
  1006.     .color_wnd_capt    dd BT_COL   ;+102
  1007.     .color_wnd_work    dd 0xffffff ;+106
  1008.     .color_wnd_bord    dd 0x737373 ;+110
  1009.     .color_select      dd 0x0000ff ;+114
  1010.     .color_cur_text    dd 0xffff00 ;+118
  1011.     .color_wnd_text    dd 0x000000 ;+122
  1012.     .syntax_file       dd 0 ;+126
  1013.     .syntax_file_size  dd 500 ;+130
  1014.     .text_colors       dd 0 ;+134
  1015.     .help_text_f1      dd 0 ;+138
  1016.     .help_id       dd -1 ;+142
  1017.     .key_words_data    dd 0 ;+146
  1018.     .tim_ch      dd ? ;+150
  1019.     .tim_undo    dd ? ;+154
  1020.     .tim_ls      dd ? ;+158
  1021.     .tim_co      dd ? ;+162
  1022.     .el_focus    dd el_focus ;+166
  1023.     .err_save    db 0 ;+170
  1024.     .panel_id    db 0 ;+171
  1025.     .key_new     db 0 ;+172
  1026.     .symbol_new_line db 20 ;+173
  1027.     .scr_w       dd scrol_w1 ;+174
  1028.     .scr_h       dd scrol_h1 ;+178
  1029.     .arr_key_pos dd 0 ;+182
  1030.     .buffer      dd ed_buffer ;+186
  1031.     .buffer_find dd 0 ;+190
  1032.     .cur_ins     db 1 ;+194
  1033.     .mode_color  db 1 ;+195
  1034.     .mode_invis  db 0 ;+196
  1035.     .gp_opt      db 0 ;+197
  1036.     dd 0;.fun_on_key_ctrl_o dd but_ctrl_o ;+198
  1037.     .fun_on_key_ctrl_f dd 0 ;+202 ... Ctrl+F
  1038.     dd 0;.fun_on_key_ctrl_n dd but_ctrl_n ;+206 ... Ctrl+N
  1039.     .fun_on_key_ctrl_s dd 0 ;+210 ... Ctrl+S
  1040.     .buffer_size       dd 4096 ;+214
  1041.     .fun_find_err      dd 0 ;+218
  1042.     .fun_init_synt_err dd 0 ;+222
  1043.     .fun_draw_panel_buttons dd 0 ;+226
  1044.     .fun_draw_panel_find    dd 0 ;+230
  1045.     .fun_draw_panel_syntax  dd 0 ;+234
  1046.     .fun_save_err       dd 0 ;+238
  1047.     .increase_size dd 1000 ;+242
  1048.     .ptr_free_symb dd ? ;+246
  1049.     .font_size     dd 16 shl 24 ; +250
  1050.  
  1051. align 4
  1052. scrol_w1:
  1053.     .x:
  1054.     .size_x   dw 16 ;+0
  1055.     .start_x  dw 85 ;+2
  1056.     .y:
  1057.     .size_y   dw 100 ; +4
  1058.     .start_y  dw  15 ; +6
  1059.     .btn_high dd  15 ; +8
  1060.     .type     dd   1 ;+12
  1061.     .max_area dd 100 ;+16
  1062.     rb 4+4
  1063.     .bckg_col dd 0xeeeeee ;+28
  1064.     .frnt_col dd 0xbbddff ;+32
  1065.     .line_col dd 0x808080 ;+36
  1066.     .redraw   dd   0 ;+40
  1067.     .delta    dw   0 ;+44
  1068.     .delta2   dw   0 ;+46
  1069.     .run_x:
  1070.     rb 2*4+4*6
  1071.     .all_redraw dd 0 ;+80
  1072.     .ar_offset  dd 1 ;+84
  1073. ;---------------------------------------------------------------------
  1074. align 4
  1075. scrol_h1:
  1076.     .x:
  1077.     .size_x     dw 85 ;+0
  1078.     .start_x    dw 30 ;+2
  1079.     .y:
  1080.     .size_y     dw 16 ;+4
  1081.     .start_y    dw 100 ;+6
  1082.     .btn_high   dd 15 ;+8
  1083.     .type       dd 1  ;+12
  1084.     .max_area   dd 100 ;+16
  1085.     rb 4+4
  1086.     .bckg_col   dd 0xeeeeee ;+28
  1087.     .frnt_col   dd 0xbbddff ;+32
  1088.     .line_col   dd 0x808080 ;+36
  1089.     .redraw     dd 0  ;+40
  1090.     .delta      dw 0  ;+44
  1091.     .delta2     dw 0  ;+46
  1092.     .run_x:
  1093.     rb 2*4+4*6
  1094.     .all_redraw dd 0 ;+80
  1095.     .ar_offset  dd 1 ;+84
  1096.  
  1097. ;------------
  1098. ;Progress bar
  1099. ;------------
  1100. struc pb
  1101. {
  1102.     dd 0  ; PB_VALUE          equ +0
  1103.     dd (TLIST2_X+TLIST1_X+TLIST_SZ)/2-150 ; PB_LEFT equ +4. 150 = PB_WIDTH/2
  1104.     dd 315; PB_TOP            equ +8
  1105.     dd 300; PB_WIDTH          equ +12
  1106.     dd 15 ; PB_HEIGHT         equ +16
  1107.     dd ?  ; PB_STYLE          equ +20
  1108.     dd 0  ; PB_MIN            equ +24
  1109.     dd 100; PB_MAX            equ +28
  1110.     dd 0xffffff; PB_BACK_COLOR     equ +32
  1111.     dd 0x00ff40; PB_PROGRESS_COLOR equ +36
  1112.     dd 0x808080; PB_FRAME_COLOR    equ +40
  1113. }
  1114. pb pb
  1115.  
  1116.  
  1117. align 4
  1118. @IMPORT_BOXLIB:
  1119.  
  1120. library box_lib, 'box_lib.obj'
  1121.  
  1122. import  box_lib, \
  1123.         edit_box_draw,      'edit_box', \
  1124.         edit_box_key,       'edit_box_key', \
  1125.         edit_box_mouse,     'edit_box_mouse', \
  1126.         edit_box_set_text,  'edit_box_set_text', \
  1127.         version_ed,         'version_ed', \
  1128.         scrollbar_ver_draw ,'scrollbar_v_draw', \
  1129.         scrollbar_ver_mouse,'scrollbar_v_mouse', \
  1130.         scrollbar_hor_draw, 'scrollbar_h_draw', \
  1131.         scrollbar_hor_mouse,'scrollbar_h_mouse', \
  1132.         version_scrollbar,  'version_scrollbar', \
  1133.         tl_data_init,       'tl_data_init', \
  1134.         tl_data_clear,      'tl_data_clear', \
  1135.         tl_info_clear,      'tl_info_clear', \
  1136.         tl_key,             'tl_key', \
  1137.         tl_mouse,           'tl_mouse', \
  1138.         tl_draw,            'tl_draw', \
  1139.         tl_node_add,        'tl_node_add', \
  1140.         tl_node_set_data,   'tl_node_set_data', \
  1141.         tl_node_get_data,   'tl_node_get_data', \
  1142.         tl_node_delete,     'tl_node_delete', \
  1143.         tl_cur_beg,         'tl_cur_beg', \
  1144.         tl_cur_next,        'tl_cur_next', \
  1145.         tl_cur_perv,        'tl_cur_perv', \
  1146.         tl_node_close_open, 'tl_node_close_open', \
  1147.         ted_but_sumb_upper, 'ted_but_sumb_upper', \
  1148.         ted_but_sumb_lover, 'ted_but_sumb_lover', \
  1149.         ted_can_save,       'ted_can_save', \
  1150.         ted_clear,          'ted_clear', \
  1151.         ted_delete,         'ted_delete', \
  1152.         ted_draw,           'ted_draw', \
  1153.         ted_init,           'ted_init', \
  1154.         ted_init_scroll_bars, 'ted_init_scroll_bars', \
  1155.         ted_init_syntax_file, 'ted_init_syntax_file', \
  1156.         ted_is_select,      'ted_is_select', \
  1157.         ted_key,            'ted_key', \
  1158.         ted_mouse,          'ted_mouse', \
  1159.         ted_open_file,      'ted_open_file', \
  1160.         ted_save_file,      'ted_save_file', \
  1161.         ted_text_add,       'ted_text_add', \
  1162.         ted_but_select_word,'ted_but_select_word', \
  1163.         ted_but_cut,        'ted_but_cut', \
  1164.         ted_but_copy,       'ted_but_copy', \
  1165.         ted_but_paste,      'ted_but_paste', \
  1166.         ted_but_undo,       'ted_but_undo', \
  1167.         ted_but_redo,       'ted_but_redo', \
  1168.         ted_but_reverse,    'ted_but_reverse', \
  1169.         ted_but_find_next,  'ted_but_find_next', \
  1170.         ted_text_colored,   'ted_text_colored', \
  1171.         progressbar_draw,   'progressbar_draw'
  1172.  
  1173.  
  1174. auto_list   db 1 ; to run LIST immediately after CWD
  1175. filter      rb 512
  1176. root_dir    db '/rd/1'
  1177.             rb 507
  1178. new_dir_buf rb 512
  1179. folder_data rb 32+32*304
  1180. node_entry  db '1111'
  1181.             rb 512
  1182. node_entry2 db '1111'
  1183.             rb 512
  1184. remote_list_buf rb 1024
  1185. conv_tabl   rb 128
  1186. ed_buffer   rb 100
  1187. tedit_buffer rb 1024
  1188. el_focus    dd 0
  1189. ;-----------------------
  1190.  
  1191. procinfo        process_information