Subversion Repositories Kolibri OS

Rev

Rev 4078 | Rev 4136 | 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. #ifndef AUTOBUILD
  5. #include "lang.h--"
  6. #endif
  7.  
  8. //libraries
  9. #define MEMSIZE 0xD0000
  10. #include "..\lib\kolibri.h"
  11. #include "..\lib\strings.h"
  12. #include "..\lib\mem.h"
  13. #include "..\lib\dll.h"
  14. #include "..\lib\lib.obj\box_lib.h"
  15. #include "..\lib\file_system.h"
  16. #include "..\lib\figures.h"
  17. #include "..\lib\encoding.h"
  18. #include "..\lib\list_box.h"
  19. #include "..\lib\copyf.h"
  20. //images
  21. #include "imgs\toolbar.txt"
  22. #include "imgs\left_p.txt"
  23.  
  24. #ifdef LANG_RUS
  25.         ?define T_FILE "” ©«"
  26.         ?define T_TYPE "’¨¯"
  27.         ?define T_SIZE " §¬¥à"
  28.         ?define T_NEW_FOLDER "®¢ ï ¯ ¯ª "
  29.         ?define T_NEW_FILE "®¢ë© ä ©«"
  30.         ?define T_DELETE_FILE "‚ë ¤¥©á⢨⥫쭮 å®â¨â¥ 㤠«¨âì"
  31.         ?define T_YES "„ "
  32.         ?define T_NO "¥â"
  33.         ?define T_DEL_ERROR_1 "Žè¨¡ª .  ¯ª  ­¥ ¯ãáâ ï."
  34.         ?define WAIT_DELETING_FOLDER "“¤ «ï¥âáï ¯ ¯ª . ®¤®¦¨â¥..."
  35.         ?define NOT_CREATE_FOLDER "¥ 㤠«®áì ᮧ¤ âì ¯ ¯ªã."
  36.         ?define NOT_CREATE_FILE "¥ 㤠«®áì ᮧ¤ âì ä ©«."
  37.         ?define ERROR_1 "Žè¨¡ª  ¯à¨ § £à㧪¥ ¡¨¡«¨®â¥ª¨ /rd/1/lib/box_lib.obj"
  38.         ?define T_PASTE_WINDOW "Š®¯¨àãî..."
  39.         ?define T_PASTE_WINDOW_TEXT "Š®¯¨àã¥âáï ä ©«:"
  40.         ?define T_CANCEL_PASTE "Š®¯¨à®¢ ­¨¥ ¯à¥ªà é¥­®.  ¯ª  ᪮¯¨à®¢ ­  ­¥ ¯®«­®áâìî."
  41.         ?define T_SELECT_APP_TO_OPEN_WITH "‚ë¡¥à¨â¥ ¯à®£à ¬¬ã ¤«ï ®âªàëâ¨ï ä ©« "
  42. #elif LANG_EST
  43.         ?define T_FILE "Fail"
  44.         ?define T_TYPE "Tüüp"
  45.         ?define T_SIZE "Suurus"
  46.         ?define T_NEW_FOLDER "Uus kataloog"
  47.         ?define T_NEW_FILE "Uus fail"
  48.         ?define T_DELETE_FILE "Kas sa tahad tõesti kustutada"
  49.         ?define T_YES "Jah"
  50.         ?define T_NO "Ei"
  51.         ?define T_DEL_ERROR_1 "Viga. Kataloog ei ole tühi."
  52.         ?define WAIT_DELETING_FOLDER "Deleting folder. Please, wait..."
  53.         ?define NOT_CREATE_FOLDER "Kataloogi ei saa luua."
  54.         ?define NOT_CREATE_FILE "Faili ei saa luua."
  55.         ?define ERROR_1 "Viga teegi laadimisel /rd/1/lib/box_lib.obj"
  56.         ?define T_PASTE_WINDOW "Kopeerin..."
  57.         ?define T_PASTE_WINDOW_TEXT "Kopeerin faili:"
  58.         ?define T_CANCEL_PASTE "Copy process terminated. Folder copied incompletely."
  59.         ?define T_SELECT_APP_TO_OPEN_WITH "Select application to open file"
  60. #else
  61.         ?define T_FILE "File"
  62.         ?define T_TYPE "Type"
  63.         ?define T_SIZE "Size"
  64.         ?define T_NEW_FOLDER "New folder"
  65.         ?define T_NEW_FILE "New file"
  66.         ?define T_DELETE_FILE "Do you really want to delete"
  67.         ?define T_YES "Yes"
  68.         ?define T_NO "No"
  69.         ?define T_DEL_ERROR_1 "Error. Folder isn't empty."
  70.         ?define WAIT_DELETING_FOLDER "Deleting folder. Please, wait..."
  71.         ?define NOT_CREATE_FOLDER "Folder can not be created."
  72.         ?define NOT_CREATE_FILE "File can not be created."
  73.         ?define ERROR_1 "Error while loading library /rd/1/lib/box_lib.obj"
  74.         ?define T_PASTE_WINDOW "Copying..."
  75.         ?define T_PASTE_WINDOW_TEXT "Copying file:"
  76.         ?define T_CANCEL_PASTE "Copy process terminated. Folder copied incompletely."
  77.         ?define T_SELECT_APP_TO_OPEN_WITH "Select application to open file"
  78. #endif
  79.  
  80. enum {ONLY_SHOW, WITH_REDRAW, ONLY_OPEN}; //OpenDir
  81.  
  82. #define TITLE "Eolite File Manager v2.0.3"
  83. #define ABOUT_TITLE "Eolite v2.0.3"
  84. dword col_padding, col_selec, col_lpanel;
  85.  
  86. int toolbar_buttons_x[7]={9,46,85,134,167,203};
  87. char tmp_disk_del_param[3]="d0";
  88. struct path_string { char Item[4096]; };
  89.  
  90. int active_about=0;
  91. word about_window;
  92.  
  93. llist files;
  94.  
  95. byte
  96.         path[4096],
  97.         file_path[4096],
  98.         file_name[256],
  99.         temp[4096];      
  100. byte
  101.         rename_active=0,
  102.         del_active=0,
  103.         show_dev_name=1,
  104.         sort_num=2,
  105.         itdir;
  106.  
  107. proc_info Form;
  108. system_colors sc;
  109. mouse m;
  110. int mouse_dd, scroll_used, scroll_size, sorting_arrow_x, kolibrios_drive;
  111. dword buf, off;
  112. dword file_mas[6898];
  113. int j, i;
  114. int action_buf;
  115.  
  116. edit_box edit2 = {250,213,80,0xFFFFCC,0x94AECE,0xFFFFCC,0xffffff,0,248,#file_name,#mouse_dd,64,6,6};
  117. PathShow_data PathShow = {0, 17,250, 6, 250, 0, 0, 0x0, 0xFFFfff, #path, #temp, 0};
  118. PathShow_data FileShow = {0, 56,215, 6, 100, 0, 0, 0x0, 0xFFFfff, #file_name, #temp, 0};
  119.  
  120. #include "include\copy.h"
  121. #include "include\other.h"
  122. #include "include\sorting.h"
  123. #include "include\icons.h"
  124. #include "include\ini.h"
  125. #include "include\left_panel.h"
  126. #include "include\history.h"
  127. #include "include\menu.h"
  128. #include "include\about.h"
  129. #include "include\open_with.h"
  130.  
  131. void SetAppColors()
  132. {
  133.         sc.work = 0xE4DFE1;
  134.         sc.work_text = 0;
  135.         sc.work_graph  = 0x9098B0; //A0A0B8; //0x819FC5;
  136.         sc.work_button_text = 0x000000;
  137.         col_padding = 0xC8C9C9;
  138.         col_selec   = 0x94AECE;
  139.         col_lpanel  = 0x00699C;
  140.         /*
  141.         sc.get();
  142.         for (i=0; i<=14; i++) col_palette[i] = sc.work;
  143.         toolbar_pal[0]= goto_about_pal[0] = sc.work = sc.work;
  144.         col_lpanel = sc.work_graph;
  145.         for (i=0; i<=99; i++) blue_hl_pal[i] = sc.work_graph;
  146.         */
  147. }
  148.  
  149. void main()
  150. {
  151.         word key, id, can_show, can_select, m_selected;
  152.  
  153.         files.line_h=18;
  154.         mem_Init();
  155.         if (load_dll2(boxlib, #box_lib_init,0)!=0) notify(ERROR_1);
  156.         SystemDiscsGet();
  157.         GetIni(1);
  158.         SetAppColors();
  159.         if (param)
  160.         {
  161.                 strcpy(#path, #param);
  162.                 if (path[strlen(#path)-1]!='/') chrcat(#path, '/'); //add "/" to the end of the string
  163.         }
  164.         else
  165.         {
  166.                 strcpy(#path, "/rd/1/");               
  167.         }
  168.         Open_Dir(#path,ONLY_OPEN);
  169.         SetEventMask(0x27);
  170.         loop() switch(WaitEvent())
  171.         {
  172.                 case evMouse:
  173.                         if (del_active) || (!CheckActiveProcess(Form.ID)) || (Form.status_window>2) break;
  174.                         if (rename_active) { edit_box_mouse stdcall(#edit2); break; }
  175.                        
  176.                         m.get();
  177.  
  178.                         if (files.MouseOver(m.x, m.y)) && (!can_select)
  179.                         {
  180.                                 m_selected = m.y - files.y / files.line_h;
  181.                                 if (m.lkm) can_select = 1;
  182.                                 if (m.pkm)
  183.                                 {
  184.                                         can_show = 1;
  185.                                         if (m.y - files.y / files.line_h != files.current) can_select = 1;
  186.                                 }
  187.                         }
  188.  
  189.                         //select/open file {
  190.                         if (!m.lkm) && (!m.pkm) && (can_select)
  191.                         {
  192.                                 can_select = 0;
  193.                                 if (m.y>=files.y)
  194.                                 {
  195.                                         id = m.y - files.y / files.line_h;
  196.                                         if (id!=m_selected)
  197.                                         {
  198.                                                 can_show=0;
  199.                                                 break;
  200.                                         }
  201.                                         if (files.current!=id)
  202.                                         {
  203.                                                 if (id<files.visible) List_Current(id-files.current);
  204.                                         }
  205.                                         else
  206.                                                 Open();
  207.                                 }
  208.                         };
  209.                         // } select/open file
  210.  
  211.                         //file menu {
  212.                         if (!m.pkm) && (!m.lkm) && (can_show)
  213.                         {
  214.                                 can_show = 0;
  215.                                 if (m.y>=files.y)
  216.                                 {
  217.                                         SwitchToAnotherThread();
  218.                                         CreateThread(#FileMenu,#menu_stak+4092);
  219.                                 }
  220.                                 break;
  221.                         }
  222.                         // } file menu
  223.  
  224.                         if (m.vert)
  225.                         {
  226.                                 if (files.MouseScroll(m.vert)) List_ReDraw();
  227.                                 break;
  228.                         }
  229.  
  230.                         if (m.x>=Form.width-26) && (m.x<=Form.width-6) && (m.y>40) && (m.y<files.y)
  231.                         {
  232.                                 IF (m.lkm==1) DrawRectangle3D(onLeft(26,0),41,14,14,0xC7C7C7,0xFFFFFF);
  233.                                 WHILE (m.lkm==1) && (files.first>0)
  234.                                 {
  235.                                         pause(8);
  236.                                         files.first--;
  237.                                         List_ReDraw();
  238.                                         m.get();
  239.                                 }
  240.                                 DrawRectangle3D(onLeft(26,0),41,14,14,0xFFFFFF,0xC7C7C7);
  241.                         }
  242.  
  243.                         if (m.x>=Form.width-26) && (m.x<=Form.width-6) && (m.y>onTop(22,0)+1) && (m.y<onTop(22,0)+16)
  244.                         {
  245.                                 IF (m.lkm==1) DrawRectangle3D(onLeft(26,0),onTop(21,0),14,14,0xC7C7C7,0xFFFFFF);
  246.                                 while (m.lkm==1) && (files.first<files.count-files.visible)
  247.                                 {
  248.                                         pause(8);
  249.                                         files.first++;
  250.                                         List_ReDraw();
  251.                                         m.get();
  252.                                 }
  253.                                 DrawRectangle3D(onLeft(26,0),onTop(21,0),14,14,0xFFFFFF,0xC7C7C7);
  254.                         }
  255.  
  256.                         //Scrooll
  257.                         if (!m.lkm) && (scroll_used) { scroll_used=NULL; Scroll(); }
  258.                         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();}
  259.                        
  260.                         if (scroll_used)
  261.                         {
  262.                                 IF (scroll_size/2+files.y>m.y) || (m.y<0) || (m.y>4000) m.y=scroll_size/2+files.y; //anee eo?ni? iaa ieiii
  263.                                 id=files.first;
  264.                                 j= scroll_size/2;
  265.                                 files.first = m.y -j -files.y * files.count;
  266.                                 files.first /= onTop(22,files.y);
  267.                                 IF (files.visible+files.first>files.count) files.first=files.count-files.visible;
  268.                                 IF (id!=files.first) List_ReDraw();
  269.                         }
  270.                         break;  
  271. //Button pressed-----------------------------------------------------------------------------
  272.                 case evButton:
  273.                         id=GetButtonID();
  274.                         if (id==1)
  275.                         {
  276.                                 KillProcess(about_window);
  277.                                 ExitProcess();
  278.                         }
  279.                         if (rename_active) break;
  280.                         if (del_active)
  281.                         {
  282.                                 IF (id==301) || (id==302) Del_File(302-id);
  283.                                 break;
  284.                         }
  285.                        
  286.                         switch(id)
  287.                         {
  288.                                 case 21: //Back
  289.                                                 GoBack();
  290.                                                 break;
  291.                                 case 22: //Forward
  292.                                                 if (HistoryPath(GO_FORWARD))
  293.                                                 {
  294.                                                         files.first=files.current=NULL; //aaa?o nienea
  295.                                                         Open_Dir(#path,WITH_REDRAW);
  296.                                                 }
  297.                                                 break;
  298.                                 case 23: //up!
  299.                                                 Dir_Up();
  300.                                                 break;
  301.                                 case 24: //cut
  302.                                                 Copy(#file_path, CUT);
  303.                                                 break;
  304.                                 case 25: //copy
  305.                                                 Copy(#file_path, NOCUT);
  306.                                                 break;
  307.                                 case 26: //paste
  308.                                                 CreateThread(#Paste,#copy_stak+4092);
  309.                                                 break;
  310.                                 case 31...33: //sort
  311.                                                 IF(sort_num==1) DrawFilledBar(sorting_arrow_x,42,6,10);
  312.                                                 IF(sort_num==2) DrawFilledBar(sorting_arrow_x,42,6,10);
  313.                                                 IF(sort_num==3) DrawFilledBar(sorting_arrow_x,42,6,10);
  314.                                                 sort_num=id-30;
  315.                                                 Open_Dir(#path,WITH_REDRAW);
  316.                                                 break;
  317.                                 case 50...60: //Actions
  318.                                                 FnProcess(id-50);
  319.                                                 break;
  320.                                 case 100...120:
  321.                                         DEVICE_MARK:
  322.                                                 DrawRectangle(17,id-100*16+74,159,16, 0); //auaaeaiea
  323.                                                 strcpy(#path, #disk_list[id-100].Item);
  324.                                                 files.first=files.current=0;
  325.                                                 Open_Dir(#path,WITH_REDRAW);
  326.                                                 pause(5);
  327.                                                 DrawRectangle(17,id-100*16+74,159,16, 0xFFFFFF);
  328.                                                 break;
  329.                                 case 130...160:
  330.                                                 tmp_disk_del_param[1]=disk_list[id-130].Item[4];
  331.                                                 RunProgram("/sys/tmpdisk", #tmp_disk_del_param);
  332.                                                 pause(10);
  333.                                                 SystemDiscsGet();
  334.                                                 Open_Dir(#path,WITH_REDRAW);
  335.                                                 DrawLeftPanel();
  336.                                                 break;
  337.                         }
  338.                         break;
  339. //Key pressed-----------------------------------------------------------------------------
  340.                 case evKey:
  341.                         key = GetKey();
  342.                         if (Form.status_window>2) break;
  343.                         IF (del_active)
  344.                         {
  345.                                 IF (key==013) Del_File(true);
  346.                                 IF (key==027) Del_File(false);
  347.                                 break;
  348.                         }
  349.                         IF (edit2.flags!=64) && (key!=13) && (key!=27)
  350.                         {
  351.                                 EAX=key<<8;
  352.                                 edit_box_key stdcall (#edit2);
  353.                                 break;
  354.                         }
  355.                         switch (key)
  356.                         {
  357.                                         case 209...217:
  358.                                                         id=key-110;
  359.                                                         IF (id-100>=disc_num) break;
  360.                                                         GOTO DEVICE_MARK;
  361.                                         case 008:
  362.                                                         //GoBack();
  363.                                                         Dir_Up();
  364.                                                         break;
  365.                                         case 004: //Ctrl+D set as bg
  366.                                                         strcpy(#temp, "\\S__");
  367.                                                         strcat(#temp, #file_path);
  368.                                                         RunProgram("/sys/media/kiv", #temp);
  369.                                                         break;
  370.                                         case 014: //Ctrl+N new window
  371.                                                         IF (Form.left==98) MoveSize(Form.left-20,Form.top-20,OLD,OLD);
  372.                                                         RunProgram("/sys/File Managers/Eolite", #path);
  373.                                                         break;
  374.                                         case 024: //Ctrl+X
  375.                                                         Copy(#file_path, CUT);
  376.                                                         break;
  377.                                         case 003: //Ctrl+C
  378.                                                         Copy(#file_path, NOCUT);
  379.                                                         break;
  380.                                         case 022: //Ctrl+V
  381.                                                         CreateThread(#Paste,#copy_stak+4092);
  382.                                                         break;
  383.                                         case 027: //Esc
  384.                                                         IF (rename_active==1) ReName(false);
  385.                                                         break;
  386.                                         case 013: //Enter
  387.                                                         IF (rename_active==1) {ReName(true); break;}
  388.                                                         Open();
  389.                                                         break;
  390.                                         case 173: //Ctrl+Enter
  391.                                                         if (!itdir)
  392.                                                         {
  393.                                                                 SwitchToAnotherThread();
  394.                                                                 CreateThread(#OpenWith,#open_with_stak+4092);
  395.                                                         }
  396.                                                         break;
  397.                                         case 178: //up
  398.                                                         List_Current(-1);
  399.                                                         break;
  400.                                         case 177: //down
  401.                                                         List_Current(1);
  402.                                                         break;
  403.                                         case 180: //home
  404.                                                         if (files.KeyHome()) List_ReDraw();
  405.                                                         break;
  406.                                         case 181: //end
  407.                                                         if (files.KeyEnd()) List_ReDraw();
  408.                                                         break;
  409.                                         case 183: //Page Down
  410.                                                         List_Current(files.visible-1);
  411.                                                         break;
  412.                                         case 184: //Page Up
  413.                                                         List_Current(-files.visible+1);
  414.                                                         break;
  415.                                         case 182: //del
  416.                                                         Del_Form();
  417.                                                         break;
  418.                                         case 050...059: //F1-F10
  419.                                                         FnProcess(key-49);
  420.                                                         break;
  421.                                         default:    
  422.                                                         for (i=files.current+files.first+1; i<files.count; i++)
  423.                                                         {
  424.                                                                 strcpy(#temp, file_mas[i]*304+buf+72);
  425.                                                                 IF (temp[0]==key) || (temp[0]==key-32)
  426.                                                                 {
  427.                                                                         List_Current(i-files.current-files.first);
  428.                                                                         break;
  429.                                                                 }
  430.                                                         }
  431.                         }                        
  432.                         break;
  433.                 case evReDraw:
  434.                         draw_window();
  435.                         if (action_buf) { menu_action(action_buf); action_buf=0;}
  436.         }
  437. }
  438.  
  439. void menu_action(dword id)
  440. {
  441.         if (id==COPY_PASTE_END)
  442.         {
  443.                 FnProcess(5);
  444.                 SelectFile(#copy_to+strrchr(#copy_to,'/'));
  445.         }
  446.         if (id==100) Open();
  447.         if (id==201)
  448.         {
  449.                 SwitchToAnotherThread();
  450.                 CreateThread(#OpenWith,#open_with_stak+4092);
  451.         }
  452.         if (id==202) FnProcess(3); //F3
  453.         if (id==203) FnProcess(4); //F4
  454.         if (id==104) Copy(#file_path, NOCUT);
  455.         if (id==105) Copy(#file_path, CUT);
  456.         if (id==106) CreateThread(#Paste,#copy_stak+4092);
  457.         if (id==207) FnProcess(2);
  458.         if (id==108) Del_Form();
  459.         if (id==109) FnProcess(5);
  460. }
  461.  
  462.  
  463. void draw_window()
  464. {
  465.         DefineAndDrawWindow(40,20,550,500,0x73,sc.work,TITLE);
  466.         GetProcessInfo(#Form, SelfInfo);
  467.         if (Form.status_window>2) return;
  468.         files.SetSizes(192, 57, onLeft(192,27), onTop(57,6), disc_num*16+195,files.line_h);
  469.         if (Form.height < files.min_h) MoveSize(OLD,OLD,OLD,files.min_h);
  470.         if (Form.width<480) MoveSize(OLD,OLD,480,OLD);
  471.         GetProcessInfo(#Form, SelfInfo); //if win_size changed
  472.  
  473.         PutPaletteImage(#toolbar,246,34,0,0,8,#toolbar_pal);
  474.         DrawBar(127, 8, 1, 25, sc.work_graph);
  475.         for (j=0; j<3; j++) DefineButton(toolbar_buttons_x[j]+2,5+2,31-5,29-5,21+j+BT_HIDE,sc.work);
  476.         for (j=3; j<6; j++) DefineButton(toolbar_buttons_x[j],5,31,29,21+j+BT_HIDE,sc.work);
  477.         DrawBar(246,0,onLeft(246,60),12, sc.work); //upper editbox
  478.         DrawBar(246,29,onLeft(246,60),5,sc.work);  //under editbox
  479.         DrawRectangle(246,12,onLeft(66,246),16,sc.work_graph);
  480.         DefineButton(onLeft(34,0),6,27,28,51+BT_HIDE+BT_NOFRAME,0); //about
  481.         PutPaletteImage(#goto_about,56,34,Form.width-65,0,8,#goto_about_pal);
  482.         //main rectangles
  483.         DrawRectangle(1,40,Form.cwidth-3,onTop(46,0),sc.work_graph);
  484.         DrawRectangle(0,39,Form.cwidth-1,onTop(44,0),col_palette[4]); //bg
  485.         for (i=0; i<5; i++) DrawBar(0, 34+i, Form.cwidth, 1, col_palette[8-i]);
  486.         DrawLeftPanel();
  487.         //ListBox
  488.         DrawFlatButton(files.x,40,onLeft(files.x,168),16,31,sc.work,T_FILE);
  489.         DrawFlatButton(onLeft(168,0),40,73,16,32,sc.work,T_TYPE);
  490.         DrawFlatButton(onLeft(95,0),40,68,16,33,sc.work,T_SIZE);
  491.         DrawBar(files.x+files.w,files.y,1,onTop(22,files.y),sc.work_graph); //line to the left from the scroll
  492.         DrawFlatButton(files.x+files.w,40,16,16,0,sc.work,"\x18");
  493.         DrawFlatButton(files.x+files.w,onTop(22,0),16,16,0,sc.work,"\x19");
  494.         Open_Dir(#path,ONLY_SHOW);
  495.         if (del_active) Del_Form();
  496.         //if (itdir) ShowMessage(WAIT_DELETING_FOLDER, 0);
  497.         if (rename_active) FnProcess(2);
  498. }
  499.  
  500.  
  501. void KEdit()
  502. {
  503.         if (Form.width<480) return;
  504.         PathShow.area_size_x = Form.cwidth-306;
  505.         DrawBar(PathShow.start_x-3, PathShow.start_y-4, PathShow.area_size_x+2, 15, 0xFFFfff);
  506.         PathShow_prepare stdcall(#PathShow);
  507.         PathShow_draw stdcall(#PathShow);
  508. }
  509.  
  510.  
  511. void List_Current(int cur)
  512. {
  513.         if (cur<=0) //up
  514.         {
  515.                 IF (files.first==0) && (files.current<=0) return;
  516.                 IF (-cur-1<files.current)
  517.                 {
  518.                         Line_ReDraw(0xFFFFFF, files.current);
  519.                         files.current+=cur;
  520.                         Line_ReDraw(col_selec, files.current);
  521.                         return;
  522.                 }
  523.                 ELSE
  524.                 {
  525.                         IF (-cur<files.first) files.first+=cur; ELSE files.first=0;
  526.                         files.current=0;
  527.                         List_ReDraw();
  528.                         return;
  529.                 }
  530.         }
  531.         else  //down
  532.         {
  533.                 IF (files.first==files.count-files.visible) && (files.current==files.visible-1) return;
  534.                 IF (files.visible-files.current>cur)
  535.                 {
  536.                         Line_ReDraw(0xFFFFFF, files.current);
  537.                         files.current+=cur;
  538.                         Line_ReDraw(col_selec, files.current);
  539.                         return;
  540.                 }
  541.                 else
  542.                 {
  543.                         IF(files.first+files.current+cur>=files.count)
  544.                         {
  545.                                 files.first=files.count-files.visible;
  546.                                 files.current=cur-files.first+files.current;
  547.                                 }
  548.                         ELSE
  549.                         {
  550.                                 files.first+=cur+files.current-files.visible+1;
  551.                                 files.current=files.visible-1;
  552.                         }
  553.                        
  554.                         IF (files.current<0) || (files.current>files.visible)
  555.                         {
  556.                                 files.current=files.visible-1;
  557.                         }
  558.                         List_ReDraw();
  559.                 }
  560.         }
  561. }
  562.  
  563.  
  564. void List_ReDraw()
  565. {
  566.         int paint_y;
  567.         //we are in the end of the list => maximize window => there will be white lines after the last element
  568.         if (files.count-files.first<files.visible) || (files.current>files.visible-1)
  569.         { files.first=files.count-files.visible; files.current=files.visible-1; }
  570.         for (j=0; j<files.visible; j++) if (files.current!=j) Line_ReDraw(0xFFFFFF, j); else Line_ReDraw(col_selec, files.current);
  571.         //in the bottom
  572.         paint_y = j * files.line_h + files.y;
  573.         DrawBar(files.x,paint_y,files.w,onTop(paint_y,6),0xFFFFFF);
  574.         DrawBar(Form.cwidth-159,paint_y,1,onTop(paint_y,6),sc.work);
  575.         DrawBar(Form.cwidth-86,paint_y,1,onTop(paint_y,6),sc.work);
  576.         Scroll();
  577. }
  578.  
  579.  
  580. void Line_ReDraw(dword color, filenum){
  581.         dword text_col=0,
  582.               name_len=0,
  583.               attr,
  584.               y=filenum*files.line_h+files.y;
  585.         DrawBar(files.x,y,3,files.line_h,color);
  586.         DrawBar(files.x+19,y,files.w-19,files.line_h,color);
  587.         DrawBar(files.x+3,y+17,16,1,color);
  588.         if (files.line_h>18) DrawBar(files.x+3,y+18,16,files.line_h-18,color);
  589.         if (files.line_h>15) DrawBar(files.x+3,y,16,files.line_h-15,color);
  590.  
  591.         off=file_mas[filenum+files.first]*304 + buf+72;
  592.         attr = ESDWORD[off - 40];
  593.  
  594.         if (! TestBit(attr, 4) ) //file or folder?
  595.         {      
  596.                 Put_icon(off+_strrchr(off,'.'), files.x+3, files.line_h/2-7+y, color, 0);
  597.                 WriteText(7-strlen(ConvertMemSize(ESDWORD[off-8]))*6+onLeft(75,0),files.line_h-6/2+y,0x80,0,ConvertMemSize(ESDWORD[off-8])); //size
  598.         }
  599.         else
  600.                 if (!strcmp("..",off))
  601.                         Put_icon("..", files.x+3, files.line_h/2-7+y, color, 0);
  602.                 else
  603.                         Put_icon("<DIR>", files.x+3, files.line_h/2-7+y, color, 0);
  604.         if ( TestBit(attr, 1) ) || ( TestBit(attr, 2) ) text_col=0xA6A6B7; //system or hiden?
  605.         if (color!=0xFFFfff)
  606.         {
  607.                 itdir = TestBit(attr, 4);
  608.                 strcpy(#file_name, off);
  609.                 strcpy(#file_path, #path);
  610.                 strcat(#file_path, #file_name);
  611.                 if (text_col==0xA6A6B7) text_col=0xFFFFFF;
  612.         }
  613.         if (Form.width>=480)
  614.         {
  615.                 FileShow.start_x = files.x + 23;
  616.                 FileShow.font_color = text_col;
  617.                 FileShow.area_size_x = Form.width - 380;
  618.                 FileShow.text_pointer = off;
  619.                 FileShow.start_y = files.line_h/2-3+y;
  620.                 PathShow_prepare stdcall(#FileShow);
  621.                 PathShow_draw stdcall(#FileShow);
  622.         }
  623.         DrawBar(Form.cwidth-159,y,1,files.line_h,sc.work); //gray line 1
  624.         DrawBar(Form.cwidth-86,y,1,files.line_h,sc.work); //gray line 2
  625. }
  626.  
  627.  
  628. void Open_Dir(dword dir_path, redraw){
  629.         int errornum, maxcount;
  630.  
  631.         if (redraw!=ONLY_SHOW)
  632.         {
  633.                 if (ESBYTE[dir_path+1]!='\0') ESBYTE[dir_path+strlen(dir_path)-1] = '\0';
  634.                 if (buf) free(buf);
  635.                 errornum = GetDir(#buf, #files.count, dir_path, DIRS_NOROOT);
  636.                 if (ESBYTE[dir_path+1]!='\0') chrcat(dir_path, '/');
  637.                 if (errornum)
  638.                 {
  639.                         HistoryPath(ADD_NEW_PATH);
  640.                         GoBack();
  641.                         Write_Error(errornum);
  642.                         return;
  643.                 }
  644.                 maxcount = sizeof(file_mas)/sizeof(dword)-1;
  645.                 if (files.count>maxcount) files.count = maxcount;              
  646.         }
  647.         if (files.count!=-1)
  648.         {
  649.                 KEdit();
  650.                 HistoryPath(ADD_NEW_PATH);
  651.                 files.visible = files.h / files.line_h;
  652.                 IF (files.count < files.visible) files.visible = files.count;
  653.                 IF (sort_num==1) sorting_arrow_x = Form.width+60/2;
  654.                 IF (sort_num==2) sorting_arrow_x = Form.width-115;
  655.                 IF (sort_num==3) sorting_arrow_x = strlen(T_SIZE)*3-30+files.x+files.w;
  656.                 WriteText(sorting_arrow_x,45,0x80,sc.work_graph,"\x19");
  657.                 IF (redraw!=ONLY_SHOW) Sorting();
  658.                 IF (redraw!=ONLY_OPEN) List_ReDraw();
  659.         }
  660.         IF (files.count==-1) && (redraw!=ONLY_OPEN) {files.visible=files.count=0; List_ReDraw();}
  661. }
  662.  
  663.  
  664. inline Sorting()
  665. {
  666.         dword k=0, l=1;
  667.         int i;
  668.         if (!strcmp(#path,"/")) //do not sort
  669.         {
  670.                 FOR(k=1;k<files.count;k++;) file_mas[k]=k;
  671.                 return;
  672.         }
  673.         FOR (j=files.count-1, off=files.count-1*304+buf+32; j>=0; j--, off-=304;)  //files | folders
  674.         {
  675.                 strttl(off+40);
  676.                 if (TestBit(ESDWORD[off],4)) //directory?
  677.                 {
  678.                         file_mas[k]=j;
  679.                         k++;
  680.                 }
  681.                 else
  682.                 {
  683.                         file_mas[files.count-l]=j;
  684.                         l++;
  685.                 }
  686.         }
  687.         //sorting: files first, then folders
  688.         Sort_by_Name(0,k-1);
  689.         IF (sort_num==1) Sort_by_Name(k,files.count-1);
  690.         IF (sort_num==2) Sort_by_Type(k,files.count-1);
  691.         IF (sort_num==3) Sort_by_Size(k,files.count-1);
  692.         //".." should be first
  693.         IF (k>0) && (strcmp(file_mas[0]*304+buf+72,"..")!=0)
  694.                 FOR(k--; k>0; k--;) IF (!strcmp(file_mas[k]*304+buf+72,"..")) {file_mas[k]><file_mas[0]; break;}
  695. }
  696.  
  697.  
  698. void Del_Form()
  699. {
  700.         int dform_x=files.w-220/2+files.x;
  701.         if (strcmp(#file_name,".")==0) || (strcmp(#file_name,"..")==0) return;
  702.         if (del_active==2)
  703.         {
  704.                 if (itdir) ShowMessage(WAIT_DELETING_FOLDER, 0);
  705.         }
  706.         else
  707.         {
  708.                 if (!files.count) return;
  709.                 DrawPopup(dform_x,160,220,80,1,sc.work,sc.work_graph);
  710.                 WriteText(-strlen(T_DELETE_FILE)*3+110+dform_x,175,0x80,sc.work_text,T_DELETE_FILE);
  711.                 IF (strlen(#file_name)<28)
  712.                 {
  713.                         WriteText(strlen(#file_name)*3+110+dform_x+2,190,0x80,sc.work_text,"?");
  714.                         WriteText(-strlen(#file_name)*3+110+dform_x,190,0x80,sc.work_text,#file_name);
  715.                 }
  716.                 else
  717.                 {
  718.                         WriteText(164+dform_x,190,0x80,0,"...?");
  719.                         ESI = 24;
  720.                         WriteText(dform_x+20,190,0,0,#file_name);
  721.                 }
  722.                 DrawFlatButton(dform_x+27,208,70,20,301,0xFFB6B5,T_YES);
  723.                 DrawFlatButton(dform_x+120,208,70,20,302,0xC6DFC6,T_NO);               
  724.                 del_active=1;
  725.         }
  726. }
  727.  
  728. int del_error;
  729. int Del_File2(dword way)
  730. {    
  731.         dword dirbuf, fcount, i, filename;
  732.         int error;
  733.         char del_from[4096];
  734.         if (isdir(way))
  735.         {
  736.                 if (error = GetDir(#dirbuf, #fcount, way, DIRS_ONLYREAL)) del_error = error;
  737.                 for (i=0; i<fcount; i++)
  738.                 {
  739.                         if (CheckEvent()==evReDraw) draw_window();
  740.                         filename = i*304+dirbuf+72;
  741.                         strcpy(#del_from, way);
  742.                         chrcat(#del_from, '/');
  743.                         strcat(#del_from, filename);
  744.                         if ( TestBit(ESDWORD[filename-40], 4) )
  745.                                 Del_File2(#del_from);
  746.                         else
  747.                         {
  748.                                 if (error = DeleteFile(#del_from)) del_error = error;
  749.                         }
  750.                 }
  751.         }
  752.         if (error = DeleteFile(way)) del_error = error;
  753. }
  754.  
  755.  
  756. void Del_File(byte dodel)
  757. {  
  758.         if (dodel==true)
  759.         {
  760.                 del_active=2;
  761.                 if (itdir) ShowMessage(WAIT_DELETING_FOLDER, 0);
  762.                 del_error = 0;
  763.                 Del_File2(#file_path);
  764.                 if (del_error) Write_Error(del_error);
  765.         }
  766.         del_active=0;
  767.         DeleteButton(301);
  768.         DeleteButton(302);
  769.         Open_Dir(#path,WITH_REDRAW);
  770. }
  771.  
  772.  
  773. void ReName(byte rename)
  774. {
  775.         int del_rezult, copy_rezult;
  776.         char edit_name[256];
  777.         rename_active=0;
  778.         edit2.flags=64;
  779.         if (rename==true)
  780.         {
  781.                 strcpy(#temp, #path);
  782.                 strcpy(#edit_name, #file_name); //save edit name to select it later
  783.                 strcat(#temp, #file_name);
  784.                 if (strcmp(#file_path,#temp)!=0) && (file_name)
  785.                 if (itdir)
  786.                 {
  787.                         if (del_rezult = DeleteFile(#file_path))
  788.                         {
  789.                                 Write_Error(del_rezult);
  790.                                 ShowMessage(T_DEL_ERROR_1, 150);
  791.                                 return;
  792.                         }
  793.                         if (CreateDir(#temp)) CreateDir(#file_path);
  794.                         Open_Dir(#path,WITH_REDRAW);
  795.                         SelectFile(#edit_name);
  796.                 }
  797.                 else
  798.                 {
  799.                         if (copy_rezult = CopyFile(#file_path,#temp))
  800.                         {
  801.                                 Write_Error(copy_rezult);
  802.                         }
  803.                         else
  804.                         {
  805.                                 Del_File(true);
  806.                                 SelectFile(#edit_name);
  807.                         }
  808.                 }
  809.         }
  810.         Line_ReDraw(col_selec,files.current);
  811. }
  812.  
  813.  
  814. void SelectFile(dword that_file)
  815. {
  816.         files.first=files.current=0;
  817.         Open_Dir(#path,ONLY_OPEN);
  818.         strttl(that_file);
  819.         for (i=files.count-1; i>=0; i--;)
  820.                 if (!strcmp(file_mas[i]*304+buf+72,that_file)) break;
  821.         List_Current(i);
  822.         List_ReDraw();
  823. }
  824.  
  825.  
  826. void Dir_Up()
  827. {
  828.         char cur_folder[4096];
  829.         i=strlen(#path)-1;
  830.         if (i==0) return;
  831.         path[i]=0x00;
  832.         i = strrchr(#path, '/');
  833.         strcpy(#cur_folder, #path+i);
  834.         path[i]=0x00;
  835.         SelectFile(#cur_folder);
  836. }
  837.  
  838. void Open()
  839. {
  840.         if (!files.count) return;
  841.         if (!itdir)
  842.         {
  843.                 GetIni(0);
  844.         }
  845.         else
  846.         {
  847.                 if (!strcmp(#file_name,"..")) { Dir_Up(); return; }
  848.                 strcpy(#path, #file_path);
  849.                 if (path[strlen(#path)-1]!='/') chrcat(#path, '/'); //need "/" in the end
  850.                 files.first=files.current=0;
  851.                 Open_Dir(#path,WITH_REDRAW);
  852.         }
  853. }
  854.  
  855.  
  856. inline fastcall void GoBack()
  857. {
  858.         char cur_folder[4096];
  859.         strcpy(#cur_folder, GetCurrentFolder());
  860.         if (HistoryPath(GO_BACK)) SelectFile(#cur_folder);
  861. }
  862.  
  863. void FnProcess(char N)
  864. {
  865.         switch(N)
  866.         {
  867.                 case 1:
  868.                         SwitchToAnotherThread();
  869.                         about_window=CreateThread(#about_dialog,#about_stak+4092);
  870.                         break;
  871.                 case 2:
  872.                         if (!files.count) break;
  873.                         edit2.flags = 100000000000010b; //set active
  874.                         edit2.left = files.x + 21;
  875.                         edit2.width = files.w - 26;
  876.                         edit2.top=files.current*files.line_h+59;
  877.                         edit2.size=edit2.pos=strlen(#file_name);
  878.                         edit_box_draw  stdcall (#edit2);
  879.                         DrawBar(edit2.left,files.current*files.line_h+58,edit2.width+1,1,0xFFFFCC); //bg
  880.                         rename_active=1;
  881.                         break;
  882.                 case 3:
  883.                         IF (!itdir) RunProgram("/sys/tinypad", #file_path);
  884.                         break;
  885.                 case 4:
  886.                         IF (!itdir) RunProgram("/sys/develop/heed", #file_path);
  887.                         break;
  888.                 case 5: //refresh cur dir & devs
  889.                         Tip(56, T_DEVICES, 55, "-");
  890.                         Open_Dir(#path,WITH_REDRAW);
  891.                         pause(10);
  892.                         GetIni(1);
  893.                         SystemDiscsGet();
  894.                         Open_Dir(#path,WITH_REDRAW);
  895.                         DrawLeftPanel();
  896.                         break;
  897.                 case 6:
  898.                         strcpy(#temp, #path);
  899.                         strcat(#temp, T_NEW_FOLDER);
  900.                         CreateDir(#temp);
  901.                         if (!EAX){
  902.                                 SelectFile(T_NEW_FOLDER);
  903.                                 FnProcess(2);
  904.                         }
  905.                         else
  906.                         {
  907.                                 Write_Error(EAX);
  908.                                 ShowMessage(NOT_CREATE_FOLDER, 150);
  909.                         }
  910.                         break;
  911.                 case 7:
  912.                         strcpy(#temp, #path);
  913.                         strcat(#temp, T_NEW_FILE);
  914.                         WriteFile(0, 0, #temp);
  915.                         if (!EAX){
  916.                                 SelectFile(T_NEW_FILE);
  917.                                 FnProcess(2);
  918.                         }
  919.                         else
  920.                         {
  921.                                 Write_Error(EAX);
  922.                                 ShowMessage(NOT_CREATE_FILE, 150);
  923.                         }
  924.                         break;
  925.                 case 10: //F10
  926.                         RunProgram(EDITOR_PATH, abspath("Eolite.ini"));
  927.                         break;
  928.         }
  929. }
  930.  
  931.  
  932. stop:
  933.  
  934. char menu_stak[4096];
  935. char copy_stak[4096];
  936. char open_with_stak[4096];
  937. char about_stak[4096];