Subversion Repositories Kolibri OS

Rev

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

  1.  
  2. //===================================================//
  3. //                                                   //
  4. //                   MASS ACTIONS                    //
  5. //                                                   //
  6. //===================================================//
  7.  
  8. void setElementSelectedFlag(dword n, int state) {
  9.         dword selected_offset = items.get(n)*304 + buf+32 + 7;
  10.         ESBYTE[selected_offset] = state;
  11.         if (n==0) && (strncmp(items.get(n)*304+buf+72,"..",2)==0) {
  12.                 ESBYTE[selected_offset] = false; //do not selec ".." directory
  13.                 return;
  14.         }
  15.         if (state==true) selected_count++;
  16.         if (state==false) selected_count--;
  17.         if (selected_count<0) selected_count=0;
  18. }
  19.  
  20. int getElementSelectedFlag(dword n) {
  21.         dword selected_offset = items.get(n)*304 + buf+32 + 7;
  22.         return ESBYTE[selected_offset];
  23. }
  24.  
  25. dword GetFilesCount(dword _in_path)
  26. {
  27.         BDVK file_info_count;
  28.         DIR_SIZE paste_dir_size;
  29.  
  30.         GetFileInfo(_in_path, #file_info_count);
  31.         if ( file_info_count.isfolder ) {
  32.                 return paste_dir_size.get(_in_path);
  33.         } else {
  34.                 return 1;
  35.         }
  36. }
  37.  
  38. //===================================================//
  39. //                                                   //
  40. //                  COPY AND PASTE                   //
  41. //                                                   //
  42. //===================================================//
  43. byte copy_to[4096];
  44. byte copy_from[4096];
  45. bool cut_active = false;
  46.  
  47. enum {COPY, CUT, DELETE};
  48.  
  49. void CopyFilesListToClipboard(bool _cut_active)
  50. {
  51.         byte copy_t[4096];
  52.         dword buff_data;
  53.         dword path_len = 0;
  54.         dword size_buf = 0;
  55.         dword copy_buf_offset = 0;
  56.         dword i;
  57.  
  58.         if (files.count<=0) return; //no files
  59.  
  60.         if (_cut_active!=DELETE) cut_active = _cut_active;
  61.  
  62.         //if no element selected by "Insert" key, then we copy current element
  63.         if (!selected_count) {
  64.                 setElementSelectedFlag(files.cur_y, true);
  65.         }
  66.  
  67.         if (!selected_count) return;
  68.        
  69.         size_buf = 4;
  70.         for (i=0; i<files.count; i++)
  71.         {
  72.                 if (getElementSelectedFlag(i) == true) {
  73.                         sprintf(#copy_t,"%s/%s",#path,items.get(i)*304+buf+72);
  74.                         path_len = strlen(#copy_t);
  75.                         size_buf += path_len + 1;
  76.                 }
  77.         }
  78.         size_buf += 20;
  79.         buff_data = malloc(size_buf);
  80.         ESDWORD[buff_data] = size_buf;
  81.         ESDWORD[buff_data+4] = SLOT_DATA_TYPE_RAW;
  82.         ESINT[buff_data+8] = selected_count;
  83.         copy_buf_offset = buff_data + 10;
  84.         for (i=0; i<files.count; i++)
  85.         {
  86.                 if (getElementSelectedFlag(i) == true) {
  87.                         sprintf(copy_buf_offset,"%s/%s",#path,items.get(i)*304+buf+72);
  88.                         copy_buf_offset += strlen(copy_buf_offset) + 1;
  89.  
  90.                         if (cut_active) {
  91.                                 if (i>=files.first) && (i<files.first+files.visible)
  92.                                         PutShadow(files.x+4,i-files.first*files.item_h+files.y,16,files.item_h,1,-3);
  93.                         }
  94.                 }
  95.         }
  96.         if (cut_active) {
  97.                 pause(20);
  98.                 List_ReDraw();
  99.         }
  100.         if (selected_count==1) setElementSelectedFlag(files.cur_y, false);
  101.         Clipboard__SetSlotData(size_buf, buff_data);
  102.         free(buff_data);
  103. }
  104.  
  105.  
  106. void PasteThread()
  107. {
  108.         char copy_rezult;
  109.         int j, i, slash_count=0;
  110.         int paste_elements_count = 0;
  111.         dword buf;
  112.         dword path_offset;
  113.        
  114.         buf = Clipboard__GetSlotData(Clipboard__GetSlotCount()-1);
  115.         if (DSDWORD[buf+4] != 3) return;
  116.         paste_elements_count = ESINT[buf+8];
  117.         path_offset = buf + 10;
  118.  
  119.         if (cut_active) {
  120.                 DisplayOperationForm(MOVE_FLAG);
  121.         } else {
  122.                 DisplayOperationForm(COPY_FLAG);       
  123.         }
  124.  
  125.         if (cut_active) {
  126.                 for (j = 0; j < paste_elements_count; j++) {
  127.                         sprintf(#copy_to, "%s/%s", #path, path_offset+strrchr(path_offset,'/'));
  128.                         slash_count = 0;
  129.                         for (i=0; i<=10; i++) {
  130.                                 if (copy_to[i]=='/') slash_count++;
  131.                                 if (slash_count==3) break;
  132.                         }
  133.                         if (strncmp(#copy_to, path_offset, i)!=0) goto _DIFFERENT_DRIVES;
  134.                         RenameMove(#copy_to+i, path_offset);
  135.                         if (EAX!=0) goto _DIFFERENT_DRIVES;
  136.                         path_offset += strlen(path_offset) + 1;
  137.                 }
  138.                 DialogExit();
  139.         }
  140.  
  141. _DIFFERENT_DRIVES:
  142.         path_offset = buf + 10;
  143.         for (j = 0; j < paste_elements_count; j++) {
  144.                 copy_bar.max += GetFilesCount(path_offset);
  145.                 path_offset += strlen(path_offset) + 1;
  146.         }
  147.        
  148.         path_offset = buf + 10;
  149.         for (j = 0; j < paste_elements_count; j++) {
  150.                 strcpy(#copy_from, path_offset);
  151.                 if (!copy_from) DialogExit();
  152.                 sprintf(#copy_to, "%s/%s", #path, #copy_from+strrchr(#copy_from,'/'));
  153.                 if (streq(#copy_from,#copy_to))
  154.                 {
  155.                         if (cut_active) continue;
  156.                         sprintf(#copy_to, "%s/NEW_%s", #path, #copy_from+strrchr(#copy_from,'/'));
  157.                 }
  158.                 if (strstr(#copy_to, #copy_from))
  159.                 {
  160.                         notify("'Not possible to copy directory into itself.\nProcess terminated.' -E");
  161.                         DialogExit();
  162.                 }
  163.  
  164.                 if (copy_rezult = copyf(#copy_from,#copy_to))
  165.                 {
  166.                         Write_Error(copy_rezult);
  167.                         if (copy_rezult==8) DialogExit(); //not enough space
  168.                 }
  169.                 else if (cut_active)
  170.                 {
  171.                         strcpy(#file_path, #copy_from);
  172.                         RecursiveDelete(#copy_from, false);
  173.                        
  174.                 }
  175.                 path_offset += strlen(path_offset) + 1;
  176.         }
  177.         DialogExit();
  178. }
  179.  
  180.  
  181. //===================================================//
  182. //                                                   //
  183. //                     DELETE                        //
  184. //                                                   //
  185. //===================================================//
  186.  
  187. int del_error;
  188. int RecursiveDelete(dword way, bool show_progress)
  189. {    
  190.         dword dirbuf, fcount, i, filename;
  191.         int error;
  192.         char del_from[4096];
  193.         if (dir_exists(way))
  194.         {
  195.                 if (error = GetDir(#dirbuf, #fcount, way, DIRS_ONLYREAL)) del_error = error;
  196.                 for (i=0; i<fcount; i++)
  197.                 {
  198.                         //if (CheckEvent()==evReDraw) draw_window();
  199.                         filename = i*304+dirbuf+72;
  200.                         sprintf(#del_from,"%s/%s",way,filename);
  201.                         if ( TestBit(ESDWORD[filename-40], 4) )
  202.                         {
  203.                                 RecursiveDelete(#del_from, true);
  204.                         }
  205.                         else
  206.                         {
  207.                                 if (show_progress) Operation_Draw_Progress(filename);
  208.                                 if (error = DeleteFile(#del_from)) del_error = error;
  209.                         }
  210.                 }
  211.         }
  212.         if (error = DeleteFile(way)) del_error = error;
  213. }
  214.  
  215. void DeleteThread()
  216. {
  217.         int j;
  218.         int elements_count = 0;
  219.         dword buf;
  220.         dword path_offset;
  221.  
  222.         DisplayOperationForm(DELETE_FLAG);
  223.        
  224.         buf = Clipboard__GetSlotData(Clipboard__GetSlotCount()-1);
  225.         Clipboard__DeleteLastSlot();
  226.         if (DSDWORD[buf+4] != 3) return;
  227.         elements_count = ESINT[buf+8];
  228.  
  229.         path_offset = buf + 10;
  230.         for (j = 0; j < elements_count; j++) {
  231.                 copy_bar.max += GetFilesCount(path_offset);
  232.                 path_offset += strlen(path_offset) + 1;
  233.         }
  234.        
  235.         path_offset = buf + 10;
  236.         for (j = 0; j < elements_count; j++) {
  237.                 RecursiveDelete(path_offset, true);
  238.                 path_offset += strlen(path_offset) + 1;
  239.         }
  240.         if (del_error) Write_Error(del_error);
  241.         DialogExit();
  242. }