Subversion Repositories Kolibri OS

Rev

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

  1. //Leency & Veliant 2008-2013
  2. //GNU GPL licence.
  3.  
  4. //êîïèðîâàòü ÷åðåç ïîòîê
  5.  
  6. //libraries
  7. #define MEMSIZE 0xA0000
  8. #include "..\lib\kolibri.h"
  9. #include "..\lib\strings.h"
  10. #include "..\lib\mem.h"
  11. #include "..\lib\dll.h"
  12. #include "..\lib\lib.obj\box_lib.h"
  13. #include "..\lib\file_system.h"
  14. #include "..\lib\figures.h"
  15. #include "..\lib\encoding.h"
  16. #include "..\lib\list_box.h"
  17. #include "..\lib\copyf.h"
  18. //images
  19. #include "imgs\toolbar.txt"
  20. #include "imgs\left_p.txt"
  21.  
  22.  
  23. enum {ONLY_SHOW, WITH_REDRAW, ONLY_OPEN}; //OpenDir
  24.  
  25. #define TITLE "Eolite File Manager v1.89"
  26. #define ABOUT_TITLE "Eolite v1.89"
  27. dword col_work    = 0xE4DFE1;
  28. dword col_border  = 0x9098B0; //A0A0B8; //0x819FC5;
  29. dword col_padding = 0xC8C9C9;
  30. dword col_selec   = 0x94AECE;
  31. dword col_lpanel  = 0x00699C;
  32.  
  33. int toolbar_buttons_x[7]={9,46,85,134,167,203};
  34. char tmp_disk_del_param[3]="d0";
  35. struct path_string { char Item[4096]; };
  36.  
  37. llist files;
  38.  
  39. byte
  40.         path[4096],
  41.         file_path[4096],
  42.         file_name[256],
  43.         temp[4096];      
  44. byte
  45.         rename_active=0,
  46.         del_active=0,
  47.         show_dev_name=1,
  48.         sort_num=2,
  49.         itdir;
  50.  
  51. proc_info Form;
  52. mouse m;
  53. int mouse_dd, scroll_used, scroll_size;
  54. dword buf, off;
  55. dword file_mas[6898];
  56. int j, i;
  57.  
  58. edit_box edit2= {250,213,80,0xFFFFCC,0x94AECE,0xFFFFCC,0xffffff,0,248,#file_name,#mouse_dd,64,6,6};
  59. PathShow_data PathShow = {0, 17,250, 6, 250, 0, 0, 0x0, 0xFFFfff, #path, #temp, 0};
  60. PathShow_data FileShow = {0, 56,215, 6, 100, 0, 0, 0x0, 0xFFFfff, #file_name, #temp, 0};
  61.  
  62. #include "include\some_code.h"
  63. #include "include\about_dialog.h"
  64. #include "include\sorting.h"
  65. #include "include\icons_f.h"
  66. #include "include\ini.h"
  67. #include "include\left_panel.h"
  68. #include "include\history.h"
  69. #include "include\file_menu.h"
  70. #include "include\copypaste.h"
  71.  
  72. void main()
  73. {
  74.         word key, id, can_show, can_select, m_selected;
  75.  
  76.         files.line_h=18;
  77.         mem_Init();
  78.         if (load_dll2(boxlib, #box_lib_init,0)!=0) notify("Error while loading library /rd/1/lib/box_lib.obj");
  79.         SystemDiscsGet();
  80.         GetIni(1);     
  81.         if (param)
  82.         {
  83.                 strcpy(#path, #param);
  84.                 if (path[strlen(#path)-1]!='/') chrcat(#path, '/'); //add "/" to the end of the string
  85.         }
  86.         else
  87.                 strcpy(#path, "/rd/1/");               
  88.         Open_Dir(#path,ONLY_OPEN);
  89.         SetEventMask(0x27);
  90.         loop() switch(WaitEvent())
  91.         {
  92.                 case evMouse:
  93.                         IF (del_active) break;         
  94.                         id=GetProcessSlot(Form.ID);
  95.                         IF (id!=GetActiveProcess()) || (Form.status_window>2) break;
  96.                         IF (rename_active) { edit_box_mouse stdcall(#edit2); break; }
  97.                        
  98.                         m.get();
  99.  
  100.                         if (m.x > files.x) && (m.x < files.x + files.w) && (m.y > files.y) && (m.y < files.y+files.h) && (!can_select)
  101.                         {
  102.                                 m_selected = m.y - 57 / files.line_h;
  103.                                 if (m.lkm) can_select = 1;
  104.                                 if (m.pkm)
  105.                                 {
  106.                                         can_show = 1;
  107.                                         if (m.y - 57 / files.line_h != files.current) can_select = 1;
  108.                                 }
  109.                         }
  110.  
  111.                         //select/open file {
  112.                         if (!m.lkm) && (!m.pkm) && (can_select)
  113.                         {
  114.                                 can_select = 0;
  115.                                 if (m.y<57) break;
  116.                                 id = m.y - 57 / files.line_h;
  117.                                 if (id!=m_selected) {can_show=0; break;}
  118.                                 if (files.current!=id) List_Current(id-files.current);
  119.                                 else Open();
  120.                         };
  121.                         // } select/open file
  122.  
  123.                         //file menu {
  124.                         if (!m.pkm) && (!m.lkm) && (can_show)
  125.                         {
  126.                                 can_show = 0;
  127.                                 if (m.y<57) break;
  128.                                 SwitchToAnotherThread();
  129.                                 CreateThread(#FileMenu,#menu_stak);
  130.                                 break;
  131.                         }
  132.                         // } file menu
  133.  
  134.  
  135.                         if (m.vert)
  136.                         {
  137.                                 files.MouseScroll(m.vert);
  138.                                 List_ReDraw();
  139.                                 break;
  140.                         }
  141.  
  142.                         if (m.x>=Form.width-26) && (m.x<=Form.width-6) && (m.y>40) && (m.y<57)
  143.                         {
  144.                                 IF (m.lkm==1) DrawRectangle3D(onLeft(26,0),41,14,14,0xC7C7C7,0xFFFFFF);
  145.                                 WHILE (m.lkm==1) && (files.first>0)
  146.                                 {
  147.                                         pause(8);
  148.                                         files.first--;
  149.                                         List_ReDraw();
  150.                                         m.get();
  151.                                 }
  152.                                 DrawRectangle3D(onLeft(26,0),41,14,14,0xFFFFFF,0xC7C7C7);
  153.                         }
  154.  
  155.                         if (m.x>=Form.width-26) && (m.x<=Form.width-6) && (m.y>onTop(22,0)+1) && (m.y<onTop(22,0)+16)
  156.                         {
  157.                                 IF (m.lkm==1) DrawRectangle3D(onLeft(26,0),onTop(21,0),14,14,0xC7C7C7,0xFFFFFF);
  158.                                 while (m.lkm==1) && (files.first<files.count-files.visible)
  159.                                 {
  160.                                         pause(8);
  161.                                         files.first++;
  162.                                         List_ReDraw();
  163.                                         m.get();
  164.                                 }
  165.                                 DrawRectangle3D(onLeft(26,0),onTop(21,0),14,14,0xFFFFFF,0xC7C7C7);
  166.                         }
  167.  
  168.                         //Scrooll
  169.                         if (!m.lkm) && (scroll_used) { scroll_used=NULL; Scroll(); }
  170.                         if (m.x>=Form.width-26) && (m.x<=Form.width-6) && (m.y>56) && (m.y<Form.height) && (m.lkm) && (!scroll_used) {scroll_used=1;Scroll();}
  171.                        
  172.                         if (scroll_used)
  173.                         {
  174.                                 IF (scroll_size/2+57>m.y) || (m.y<0) || (m.y>4000) m.y=scroll_size/2+57; //anee eo?ni? iaa ieiii
  175.                                 id=files.first;
  176.                                 j= scroll_size/2;
  177.                                 files.first = m.y -j -57 * files.count;
  178.                                 files.first /= onTop(22,57);
  179.                                 IF (files.visible+files.first>files.count) files.first=files.count-files.visible;
  180.                                 IF (id!=files.first) List_ReDraw();
  181.                         }
  182.                         break;  
  183. //Button pressed-----------------------------------------------------------------------------
  184.                 case evButton:
  185.                         id=GetButtonID();
  186.                         if (id==1) ExitProcess();
  187.                         if (rename_active) break;
  188.                         if (del_active)
  189.                         {
  190.                                 IF (id==301) || (id==302) Del_File(302-id);
  191.                                 break;
  192.                         }
  193.                        
  194.                         switch(id)
  195.                         {
  196.                                 case 21: //Back
  197.                                                 GoBack();
  198.                                                 break;
  199.                                 case 22: //Forward
  200.                                                 if (HistoryPath(GO_FORWARD))
  201.                                                 {
  202.                                                         files.first=files.current=NULL; //aaa?o nienea
  203.                                                         Open_Dir(#path,WITH_REDRAW);
  204.                                                 }
  205.                                                 break;
  206.                                 case 23: //up!
  207.                                                 Dir_Up();
  208.                                                 break;
  209.                                 case 24: //cut
  210.                                                 Copy(#file_path, NOCUT);
  211.                                                 break;
  212.                                 case 25: //copy
  213.                                                 Copy(#file_path, CUT);
  214.                                                 break;
  215.                                 case 26: //paste
  216.                                                 CreateThread(#Paste,#copy_stak);
  217.                                                 break;
  218.                                 case 31...33: //sort
  219.                                                 IF(sort_num==1) DrawFilledBar(onLeft(192,168)/2+210,42,6,10);
  220.                                                 IF(sort_num==2) DrawFilledBar(onLeft(115,0),42,6,10);
  221.                                                 IF(sort_num==3) DrawFilledBar(onLeft(44,0),42,6,10);
  222.                                                 sort_num=id-30;
  223.                                                 Open_Dir(#path,WITH_REDRAW);
  224.                                                 break;
  225.                                 case 50...60: //Actions
  226.                                                 FnProcess(id-50);
  227.                                                 break;
  228.                                 case 100...120:
  229.                                         DEVICE_MARK:
  230.                                                 DrawRectangle(17,id-100*16+74,159,16, 0); //auaaeaiea
  231.                                                 strcpy(#path, #disk_list[id-100].Item);
  232.                                                 files.first=files.current=0;
  233.                                                 Open_Dir(#path,WITH_REDRAW);
  234.                                                 pause(5);
  235.                                                 DrawRectangle(17,id-100*16+74,159,16, 0xFFFFFF);
  236.                                                 break;
  237.                                 case 130...160:
  238.                                                 tmp_disk_del_param[1]=disk_list[id-130].Item[4];
  239.                                                 RunProgram("/sys/tmpdisk", #tmp_disk_del_param);
  240.                                                 pause(10);
  241.                                                 SystemDiscsGet();
  242.                                                 Open_Dir(#path,WITH_REDRAW);
  243.                                                 DrawLeftPanel();
  244.                                                 break;
  245.                         }
  246.                         break;
  247. //Key pressed-----------------------------------------------------------------------------
  248.                 case evKey:
  249.                         key = GetKey();
  250.                         if (Form.status_window>2) break;
  251.                         IF (del_active)
  252.                         {
  253.                                 IF (key==013) Del_File(true);
  254.                                 IF (key==027) Del_File(false);
  255.                                 break;
  256.                         }
  257.                         IF (edit2.flags!=64) && (key!=13) && (key!=27)
  258.                         {
  259.                                 EAX=key<<8;
  260.                                 edit_box_key stdcall (#edit2);
  261.                                 break;
  262.                         }
  263.                         switch (key)
  264.                         {
  265.                                         case 209...217:
  266.                                                         id=key-110;
  267.                                                         IF (id-100>=disc_num) break;
  268.                                                         GOTO DEVICE_MARK;
  269.                                         case 008:
  270.                                                         //GoBack();
  271.                                                         Dir_Up();
  272.                                                         break;
  273.                                         case 004: //Ctrl+D set as bg
  274.                                                         strcpy(#temp, "\\S__");
  275.                                                         strcat(#temp, #file_path);
  276.                                                         RunProgram("/sys/media/kiv", #temp);
  277.                                                         break;
  278.                                         case 014: //Ctrl+N new window
  279.                                                         IF (Form.left==98) MoveSize(Form.left-20,Form.top-20,OLD,OLD);
  280.                                                         RunProgram("/sys/File Managers/Eolite", #path);
  281.                                                         break;
  282.                                         case 024: //Ctrl+X
  283.                                                         Copy(#file_path, CUT);
  284.                                                         break;
  285.                                         case 003: //Ctrl+C
  286.                                                         Copy(#file_path, NOCUT);
  287.                                                         break;
  288.                                         case 022: //Ctrl+V
  289.                                                         CreateThread(#Paste,#copy_stak);
  290.                                                         break;
  291.                                         case 027: //Esc
  292.                                                         IF (rename_active==1) ReName(false);
  293.                                                         break;
  294.                                         case 013: //Enter
  295.                                                         IF (rename_active==1) {ReName(true); break;}
  296.                                                         Open();
  297.                                                         break;
  298.                                         case 178: //up
  299.                                                         List_Current(-1);
  300.                                                         break;
  301.                                         case 177: //down
  302.                                                         List_Current(1);
  303.                                                         break;
  304.                                         case 180: //home
  305.                                                         files.first=0;
  306.                                                         files.current=0;
  307.                                                         List_ReDraw();
  308.                                                         break;
  309.                                         case 181: //end
  310.                                                         files.first = files.count - files.visible;
  311.                                                         files.current = files.visible - 1;
  312.                                                         List_ReDraw();
  313.                                                         break;
  314.                                         case 183: //Page Down
  315.                                                         List_Current(files.visible-1);
  316.                                                         break;
  317.                                         case 184: //Page Up
  318.                                                         List_Current(-files.visible+1);
  319.                                                         break;
  320.                                         case 182: //del
  321.                                                         Del_Form();
  322.                                                         break;
  323.                                         case 050...059: //F1-F10
  324.                                                         FnProcess(key-49);
  325.                                                         break;
  326.                                         default:    
  327.                                                         for (i=files.current+files.first+1; i<files.count; i++)
  328.                                                         {
  329.                                                                 strcpy(#temp, file_mas[i]*304+buf+72);
  330.                                                                 IF (temp[0]==key) || (temp[0]==key-32)
  331.                                                                 {
  332.                                                                         List_Current(i-files.current-files.first);
  333.                                                                         break;
  334.                                                                 }
  335.                                                         }
  336.                         }                        
  337.                         break;
  338.                 case evReDraw:
  339.                         draw_window();
  340.         }
  341. }
  342.  
  343.  
  344. void draw_window()
  345. {
  346.         DefineAndDrawWindow(40,20,550,500,0x73,col_work,TITLE);
  347.         GetProcessInfo(#Form, SelfInfo);
  348.         if (Form.status_window>2) return;
  349.         files.SetSizes(192, 57, onLeft(192,27), onTop(57,6), disc_num*16+195,files.line_h);
  350.         if (Form.height < files.min_h) MoveSize(OLD,OLD,OLD,files.min_h);
  351.         if (Form.width<480) MoveSize(OLD,OLD,480,OLD);
  352.         GetProcessInfo(#Form, SelfInfo); //if win_size changed
  353.  
  354.         PutPaletteImage(#toolbar,246,34,0,0,8,#toolbar_pal);
  355.         DrawBar(127, 8, 1, 25, col_border);
  356.         for (j=0; j<3; j++) DefineButton(toolbar_buttons_x[j]+2,5+2,31-5,29-5,21+j+BT_HIDE,col_work);
  357.         for (j=3; j<6; j++) DefineButton(toolbar_buttons_x[j],5,31,29,21+j+BT_HIDE,col_work);
  358.         DrawBar(246,0,onLeft(246,60),12, col_work); //upper editbox
  359.         DrawBar(246,29,onLeft(246,60),5,col_work);  //under editbox
  360.         DrawRectangle(246,12,onLeft(66,246),16,col_border);
  361.         DefineButton(onLeft(34,0),6,27,28,51+BT_HIDE+BT_NOFRAME,0); //about
  362.         PutPaletteImage(#goto_about,56,34,Form.width-65,0,8,#goto_about_pal);
  363.         //main rectangles
  364.         DrawRectangle(1,40,Form.cwidth-3,onTop(46,0),col_border);
  365.         DrawRectangle(0,39,Form.cwidth-1,onTop(44,0),col_palette[4]); //bg
  366.         for (i=0; i<5; i++) DrawBar(0, 34+i, Form.cwidth, 1, col_palette[8-i]);
  367.         DrawLeftPanel();
  368.         //ListBox
  369.         DrawFlatButton(files.x,40,onLeft(files.x,168),16,31,col_work,"File");
  370.         DrawFlatButton(onLeft(168,0),40,73,16,32,col_work,"Type");
  371.         DrawFlatButton(onLeft(95,0),40,68,16,33,col_work,"Size");
  372.         DrawBar(onLeft(27,0),57,1,onTop(22,57),col_border); //line to the left from the scroll
  373.         DrawFlatButton(onLeft(27,0),40,16,16,0,col_work,"\x18");
  374.         DrawFlatButton(onLeft(27,0),onTop(22,0),16,16,0,col_work,"\x19");
  375.         Open_Dir(#path,ONLY_SHOW);
  376.         if (del_active) Del_Form();
  377.         if (rename_active) FnProcess(2);
  378. }
  379.  
  380.  
  381. void KEdit()
  382. {
  383.         if (Form.width<480) return;
  384.         PathShow.area_size_x = Form.cwidth-306;
  385.         DrawBar(PathShow.start_x-3, PathShow.start_y-4, PathShow.area_size_x+2, 15, 0xFFFfff);
  386.         PathShow_prepare stdcall(#PathShow);
  387.         PathShow_draw stdcall(#PathShow);
  388. }
  389.  
  390.  
  391. void List_Current(int cur)
  392. {
  393.         if (cur<=0) //up
  394.         {
  395.                 IF (files.first==0) && (files.current<=0) return;
  396.                 IF (-cur-1<files.current)
  397.                 {
  398.                         Line_ReDraw(0xFFFFFF, files.current);
  399.                         files.current+=cur;
  400.                         Line_ReDraw(col_selec, files.current);
  401.                         return;
  402.                 }
  403.                 ELSE
  404.                 {
  405.                         IF (-cur<files.first) files.first+=cur; ELSE files.first=0;
  406.                         files.current=0;
  407.                         List_ReDraw();
  408.                         return;
  409.                 }
  410.         }
  411.         else  //down
  412.         {
  413.                 IF (files.first==files.count-files.visible) && (files.current==files.visible-1) return;
  414.                 IF (files.visible-files.current>cur)
  415.                 {
  416.                         Line_ReDraw(0xFFFFFF, files.current);
  417.                         files.current+=cur;
  418.                         Line_ReDraw(col_selec, files.current);
  419.                         return;
  420.                 }
  421.                 else
  422.                 {
  423.                         IF(files.first+files.current+cur>=files.count)
  424.                         {
  425.                                 files.first=files.count-files.visible;
  426.                                 files.current=cur-files.first+files.current;
  427.                                 }
  428.                         ELSE
  429.                         {
  430.                                 files.first+=cur+files.current-files.visible+1;
  431.                                 files.current=files.visible-1;
  432.                         }
  433.                        
  434.                         IF (files.current<0) || (files.current>files.visible)
  435.                         {
  436.                                 files.current=files.visible-1;
  437.                         }
  438.                         List_ReDraw();
  439.                 }
  440.         }
  441. }
  442.  
  443.  
  444. void List_ReDraw()
  445. {
  446.         int paint_y;
  447.         //åñëè ìû â êîíöå ñïèñêà ôàéëîâ ðàçâåðí¸ì îêíî ïîÿâÿòüñÿ ïóñòÿå áåëûå êíîïêè
  448.         //ýòî åñëè âûäåëåíèå ïîñëå ñõëîïûâàíèÿ îêíà çà êàäðîì
  449.         if (files.count-files.first<files.visible) || (files.current>files.visible-1)
  450.         { files.first=files.count-files.visible; files.current=files.visible-1; }
  451.  
  452.         for (j=0; j<files.visible; j++) if (files.current!=j) Line_ReDraw(0xFFFFFF, j); else Line_ReDraw(col_selec, files.current);
  453.         //in the bottom
  454.         paint_y = j * files.line_h + files.y;
  455.         DrawBar(files.x,paint_y,files.w,onTop(paint_y,6),0xFFFFFF);
  456.         DrawBar(Form.cwidth-159,paint_y,1,onTop(paint_y,6),col_work);
  457.         DrawBar(Form.cwidth-86,paint_y,1,onTop(paint_y,6),col_work);
  458.         Scroll();
  459. }
  460.  
  461.  
  462. void Line_ReDraw(dword color, filenum){
  463.         dword text_col=0, name_len=0, y=filenum*files.line_h+57;
  464.         DrawBar(files.x,y,3,files.line_h,color);
  465.         DrawBar(files.x+19,y,files.w-19,files.line_h,color);
  466.         DrawBar(files.x+3,y+17,16,1,color);
  467.         if (files.line_h>18) DrawBar(files.x+3,y+18,16,files.line_h-18,color);
  468.         if (files.line_h>15) DrawBar(files.x+3,y,16,files.line_h-15,color);
  469.  
  470.         off=file_mas[filenum+files.first]*304 + buf+72;
  471.  
  472.         if (!TestBit(ESDWORD[off-40], 4)) //file or folder?
  473.         {      
  474.                 Put_icon(off+_strrchr(off,'.'), files.line_h/2-7+y, color);
  475.                 WriteText(7-strlen(ConvertMemSize(ESDWORD[off-8]))*6+onLeft(75,0),files.line_h-6/2+y,0x80,0,ConvertMemSize(ESDWORD[off-8])); //size
  476.         }
  477.         else
  478.                 if (!strcmp("..",off))
  479.                         Put_icon("..", files.line_h/2-7+y, color);
  480.                 else
  481.                         Put_icon("<DIR>", files.line_h/2-7+y, color);
  482.         if (TestBit(ESDWORD[off-40],1)) || (TestBit(ESDWORD[off-40],2)) text_col=0xA6A6B7; //system or hiden?
  483.         if (color!=0xFFFfff)
  484.         {
  485.                 itdir=TestBit(ESDWORD[off-40], 4);             
  486.                 strcpy(#file_name, off);
  487.                 strcpy(#file_path, #path);
  488.                 strcat(#file_path, #file_name);
  489.                 if (text_col==0xA6A6B7) text_col=0xFFFFFF;
  490.         }
  491.         if (Form.width>=480)
  492.         {
  493.                 FileShow.start_x = files.x + 23;
  494.                 FileShow.font_color = text_col;
  495.                 FileShow.area_size_x = Form.width - 380;
  496.                 FileShow.text_pointer = off;
  497.                 FileShow.start_y = files.line_h/2-3+y;
  498.                 PathShow_prepare stdcall(#FileShow);
  499.                 PathShow_draw stdcall(#FileShow);
  500.         }
  501.         DrawBar(Form.cwidth-159,y,1,files.line_h,col_work); //gray line 1
  502.         DrawBar(Form.cwidth-86,y,1,files.line_h,col_work); //gray line 2
  503. }
  504.  
  505.  
  506. void Open_Dir(dword dir_path, redraw){
  507.         int errornum, maxcount;
  508.  
  509.         if (redraw!=ONLY_SHOW)
  510.         {
  511.                 if (ESBYTE[dir_path+1]!='\0') ESBYTE[dir_path+strlen(dir_path)-1] = '\0';
  512.                 if (buf) free(buf);
  513.                 errornum = GetDir(#buf, #files.count, dir_path, DIRS_NOROOT);
  514.                 if (ESBYTE[dir_path+1]!='\0') chrcat(dir_path, '/');
  515.                 if (errornum)
  516.                 {
  517.                         HistoryPath(ADD_NEW_PATH);
  518.                         GoBack();
  519.                         Write_Error(errornum);
  520.                         return;
  521.                 }
  522.                 maxcount = sizeof(file_mas)/sizeof(dword)-1;
  523.                 if (files.count>maxcount) files.count = maxcount;              
  524.         }
  525.         if (files.count!=-1)
  526.         {
  527.                 KEdit();
  528.                 HistoryPath(ADD_NEW_PATH);
  529.                 files.visible = files.h / files.line_h;
  530.                 IF (files.count < files.visible) files.visible = files.count;
  531.                 IF (sort_num==1) WriteText(Form.width+60/2,45,0x80,col_border,"\x19");
  532.                 IF (sort_num==2) WriteText(Form.width-115,45,0x80,col_border,"\x19");
  533.                 IF (sort_num==3) WriteText(Form.width-44,45,0x80,col_border,"\x19");
  534.                 IF (redraw!=ONLY_SHOW) Sorting();
  535.                 IF (redraw!=ONLY_OPEN) List_ReDraw();
  536.         }
  537.         IF (files.count==-1) && (redraw!=ONLY_OPEN) {files.visible=files.count=0; List_ReDraw();}
  538. }
  539.  
  540.  
  541. inline Sorting()
  542. {
  543.         dword k=0, l=1;
  544.         int i;
  545.         if (!strcmp(#path,"/")) //do not sort
  546.         {
  547.                 FOR(k=1;k<files.count;k++;) file_mas[k]=k;
  548.                 return;
  549.         }
  550.         FOR (j=files.count-1, off=files.count-1*304+buf+32; j>=0; j--, off-=304;)  //files | folders
  551.         {
  552.                 strttl(off+40);
  553.                 if (TestBit(ESDWORD[off],4)) //directory?
  554.                 {
  555.                         file_mas[k]=j;
  556.                         k++;
  557.                 }
  558.                 else
  559.                 {
  560.                         file_mas[files.count-l]=j;
  561.                         l++;
  562.                 }
  563.         }
  564.         //sorting: files first, then folders
  565.         Sort_by_Name(0,k-1);
  566.         IF (sort_num==1) Sort_by_Name(k,files.count-1);
  567.         IF (sort_num==2) Sort_by_Type(k,files.count-1);
  568.         IF (sort_num==3) Sort_by_Size(k,files.count-1);
  569.         //".." should be first
  570.         IF (k>0) && (strcmp(file_mas[0]*304+buf+72,"..")!=0)
  571.                 FOR(k--; k>0; k--;) IF (!strcmp(file_mas[k]*304+buf+72,"..")) {file_mas[k]><file_mas[0]; break;}
  572. }
  573.  
  574.  
  575. void Del_Form()
  576. {
  577.         int dform_x = files.w - 200 / 2 + files.x;
  578.         //oeia ieii
  579.         if (!files.count) return;
  580.         DrawFlatButton(dform_x,160,200,80,0,col_work, ""); //oi?ia
  581.         WriteText(dform_x+19,175,0x80,0,"Do you really want to delete");
  582.         IF (strlen(#file_name)<28)
  583.                 {
  584.                         WriteText(strlen(#file_name)*6+dform_x+20,190,0x80,0,"?");
  585.                         WriteText(dform_x+20,190,0x80,0,#file_name); //ieoai eiy
  586.                 }
  587.         ELSE
  588.                 {
  589.                         WriteText(164+dform_x,190,0x80,0,"...?");
  590.                         ESI = 24;
  591.                         WriteText(dform_x+20,190,0,0,#file_name); //ieoai eiy
  592.                 }
  593.         DrawFlatButton(dform_x+20,208,70,20,301,0xFFB6B5,"Yes");
  594.         DrawFlatButton(dform_x+111,208,70,20,302,0xC6DFC6,"No");
  595.         del_active=1;
  596. }
  597.  
  598.        
  599. void Del_File(byte dodel)
  600. {    
  601.         int del_rezult;
  602.         IF (dodel==true)
  603.         {
  604.                 del_rezult = DeleteFile(#file_path);
  605.                 IF (del_rezult)
  606.                 {
  607.                         Write_Error(del_rezult);
  608.                         IF ( itdir) ShowMessage("Error. Folder isn't empty.");
  609.                         IF (!itdir) ShowMessage("Error. Filesystem read-only.");
  610.                 }
  611.         }
  612.         del_active=0;
  613.         DeleteButton(301); DeleteButton(302);
  614.         Open_Dir(#path,WITH_REDRAW);
  615. }
  616.  
  617.  
  618. void ReName(byte rename)
  619. {
  620.         int del_rezult, copy_rezult;
  621.         char edit_name[256];
  622.         rename_active=0;
  623.         edit2.flags=64;
  624.         if (rename==true)
  625.         {
  626.                 strcpy(#temp, #path);
  627.                 strcpy(#edit_name, #file_name); //save edit name to select it later
  628.                 strcat(#temp, #file_name);
  629.                 if (strcmp(#file_path,#temp)!=0) && (file_name)
  630.                 if (itdir)
  631.                 {
  632.                         del_rezult = DeleteFile(#file_path);
  633.                         if (del_rezult!=0)
  634.                         {
  635.                                 Write_Error(del_rezult);
  636.                                 ShowMessage("Error. Folder isn't empty.");
  637.                                 return;
  638.                         }
  639.                         ELSE CreateDir(#temp);
  640.                         Open_Dir(#path,WITH_REDRAW);
  641.                 }
  642.                 ELSE
  643.                 {
  644.                         copy_rezult = CopyFile(#file_path,#temp);
  645.                         if (copy_rezult!=0) Write_Error(copy_rezult); else Del_File(true);
  646.                 }
  647.                 SelectFile(#edit_name);
  648.         }
  649.         Line_ReDraw(col_selec,files.current);
  650. }
  651.  
  652.  
  653. void SelectFile(dword that_file)
  654. {
  655.         files.first=files.current=0;
  656.         Open_Dir(#path,ONLY_OPEN);
  657.         strttl(that_file);
  658.         for (i=files.count-1; i>=0; i--;)
  659.                 if (!strcmp(file_mas[i]*304+buf+72,that_file)) break;
  660.         List_Current(i);
  661.         List_ReDraw();
  662. }
  663.  
  664.  
  665. void Dir_Up()
  666. {
  667.         char cur_folder[4096];
  668.         i=strlen(#path)-1;
  669.         if (i==0) return;
  670.         path[i]=0x00;
  671.         i = strrchr(#path, '/');
  672.         strcpy(#cur_folder, #path+i);
  673.         path[i]=0x00;
  674.         SelectFile(#cur_folder);
  675. }
  676.  
  677. void Open()
  678. {
  679.         if (!files.count) return;
  680.         if (!itdir)
  681.         {
  682.                 GetIni(0);
  683.         }
  684.         else
  685.         {
  686.                 if (!strcmp(#file_name,"..")) { Dir_Up(); return; }
  687.                 strcpy(#path, #file_path);
  688.                 if (path[strlen(#path)-1]!='/') chrcat(#path, '/'); //need "/" in the end
  689.                 files.first=files.current=0;
  690.                 Open_Dir(#path,WITH_REDRAW);
  691.         }
  692. }
  693.  
  694.  
  695. inline fastcall void GoBack()
  696. {
  697.         char cur_folder[4096];
  698.         strcpy(#cur_folder, GetCurrentFolder());
  699.         if (HistoryPath(GO_BACK)) SelectFile(#cur_folder);
  700. }
  701.  
  702. void FnProcess(char N)
  703. {
  704.         switch(N)
  705.         {
  706.                 case 1:
  707.                         SwitchToAnotherThread();
  708.                         CreateThread(#about_dialog,#about_stak);
  709.                         break;
  710.                 case 2:
  711.                         if (!files.count) break;
  712.                         edit2.flags = 100000000000010b; //set active
  713.                         edit2.left = files.x + 21;
  714.                         edit2.width = files.w - 26;
  715.                         edit2.top=files.current*files.line_h+59;
  716.                         edit2.size=edit2.pos=strlen(#file_name);
  717.                         edit_box_draw  stdcall (#edit2);
  718.                         DrawBar(edit2.left,files.current*files.line_h+58,edit2.width+1,1,0xFFFFCC); //bg
  719.                         rename_active=1;
  720.                         break;
  721.                 case 3:
  722.                         IF (!itdir) RunProgram("/sys/tinypad", #file_path);
  723.                         break;
  724.                 case 4:
  725.                         IF (!itdir) RunProgram("/sys/develop/heed", #file_path);
  726.                         break;
  727.                 case 5: //refresh cur dir & devs
  728.                         Tip(56, "Devices", 55, "-");
  729.                         Open_Dir(#path,WITH_REDRAW);
  730.                         pause(10);
  731.                         GetIni(1);
  732.                         SystemDiscsGet();
  733.                         Open_Dir(#path,WITH_REDRAW);
  734.                         DrawLeftPanel();
  735.                         break;
  736.                 case 6:
  737.                         strcpy(#temp, #path);
  738.                         strcat(#temp, "New folder");
  739.                         CreateDir(#temp);
  740.                         if (!EAX){
  741.                                 SelectFile("New folder");
  742.                                 FnProcess(2);
  743.                         }
  744.                         else
  745.                         {
  746.                                 Write_Error(EAX);
  747.                                 ShowMessage("Folder can not be created.");
  748.                         }
  749.                         break;
  750.                 case 7:
  751.                         strcpy(#temp, #path);
  752.                         strcat(#temp, "New file");
  753.                         WriteFile(0, 0, #temp);
  754.                         if (!EAX){
  755.                                 SelectFile("New file");
  756.                                 FnProcess(2);
  757.                         }
  758.                         else
  759.                         {
  760.                                 Write_Error(EAX);
  761.                                 ShowMessage("File can not be created.");
  762.                         }
  763.                         break;
  764.                 case 10: //F10
  765.                         RunProgram(EDITOR_PATH, abspath("Eolite.ini"));
  766.                         break;
  767.         }
  768. }
  769.  
  770.  
  771. stop:
  772.  
  773. char about_stak[512];
  774. char menu_stak[512];
  775. char copy_stak[4096];