Subversion Repositories Kolibri OS

Rev

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

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