Subversion Repositories Kolibri OS

Rev

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