Subversion Repositories Kolibri OS

Rev

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

  1. //copyf - copy file or folder with content
  2. #define WIN_COPY_W 300
  3. #define WIN_COPY_H 50
  4. :int copyf(dword from1, in1)
  5. {
  6.         dword error;
  7.         BDVK CopyFile_atr1;
  8.         DefineAndDrawWindow(Form.left+Form.width-200,Form.top+90,WIN_COPY_W,GetSkinHeight()+WIN_COPY_H-1,0x34,sc.work,T_PASTE_WINDOW);
  9.         if (!from1) || (!in1)
  10.         {
  11.                 notify("Error: too less copyf params!");
  12.                 notify(from1);
  13.                 notify(in1);
  14.                 return;
  15.         }
  16.         if (error = GetFileInfo(from1, #CopyFile_atr1))
  17.         {
  18.                 debugln("Error: copyf->GetFileInfo");
  19.                 return error;
  20.         }
  21.         if (isdir(from1))
  22.                 return CopyFolder(from1, in1);
  23.         else
  24.         {
  25.                 copyf_Draw_Progress(from1+strchr(from1, '/'));
  26.                 return CopyFile(from1, in1);
  27.         }
  28.         if (CheckEvent()==evButton)
  29.         {
  30.                 notify(T_CANCEL_PASTE);
  31.                 CopyExit();
  32.         }
  33. }
  34.  
  35. :int CopyFile(dword copy_from3, copy_in3)
  36. {
  37.         BDVK CopyFile_atr;
  38.         dword error, cbuf;
  39.         if (error = GetFileInfo(copy_from3, #CopyFile_atr))
  40.         {
  41.                 debugln("Error: CopyFile->GetFileInfo");
  42.         }
  43.         else
  44.         {
  45.                 cbuf = malloc(CopyFile_atr.sizelo);    
  46.                 if (error = ReadFile(0, CopyFile_atr.sizelo, cbuf, copy_from3))
  47.                 {
  48.                         debugln("Error: CopyFile->ReadFile");
  49.                 }
  50.                 else
  51.                 {
  52.                         if (error = WriteFile(CopyFile_atr.sizelo, cbuf, copy_in3)) debugln("Error: CopyFile->WriteFile");
  53.                 }
  54.         }
  55.         free(cbuf);
  56.         if (error) debug_error(copy_from3, error);
  57.         return error;
  58. }
  59.  
  60. :int CopyFolder(dword from2, in2)
  61. {
  62.         dword dirbuf, fcount, i, filename;
  63.         char copy_from2[4096], copy_in2[4096], error;
  64.  
  65.         if (error = GetDir(#dirbuf, #fcount, from2, DIRS_ONLYREAL))
  66.         {
  67.                 debugln("Error: CopyFolder->GetDir");
  68.                 debug_error(from2, error);
  69.                 free(dirbuf);
  70.                 return error;
  71.         }
  72.  
  73.         if (chrnum(in2, '/')>2) && (error = CreateDir(in2))
  74.         {
  75.                 debugln("Error: CopyFolder->CreateDir");
  76.                 debug_error(in2, error);
  77.                 free(dirbuf);
  78.                 return error;
  79.         }
  80.  
  81.         for (i=0; i<fcount; i++)
  82.         {
  83.                 filename = i*304+dirbuf+72;
  84.                 strcpy(#copy_from2, from2);
  85.                 chrcat(#copy_from2, '/');
  86.                 strcat(#copy_from2, filename);
  87.                 strcpy(#copy_in2, in2);
  88.                 chrcat(#copy_in2, '/');
  89.                 strcat(#copy_in2, filename);
  90.  
  91.                 if ( TestBit(ESDWORD[filename-40], 4) ) //isdir?
  92.                 {
  93.                         if ( (!strcmp(filename, ".")) || (!strcmp(filename, "..")) ) continue;
  94.                         CopyFolder(#copy_from2, #copy_in2);
  95.                 }
  96.                 else
  97.                 {
  98.                         copyf_Draw_Progress(filename);
  99.                         if (error=CopyFile(#copy_from2, #copy_in2))
  100.                         {
  101.                                 if (fabs(error)==8) { debugln("Stop copying."); break;} //TODO: may be need grobal var like stop_all
  102.                                 error=CopyFile(#copy_from2, #copy_in2); // #2 :)
  103.                         }
  104.                 }
  105.         }
  106.         free(dirbuf);
  107.         return error;
  108. }
  109.  
  110. #ifdef LANG_RUS
  111.         unsigned char *ERROR_TEXT[]={
  112.         "Š®¤ #0: ãᯥ譮",
  113.         "Žè¨¡ª  #1: ­¥ ®¯à¥¤¥«¥­  ¡ §  ¨/¨«¨ à §¤¥« ¦ñá⪮£® ¤¨áª ",
  114.         "Žè¨¡ª  #2: äã­ªæ¨ï ­¥ ¯®¤¤¥à¦¨¢ ¥âáï ¤«ï í⮩ ä ©«®¢®© á¨á⥬ë",
  115.         "Žè¨¡ª  #3: ­¥¨§¢¥áâ­ ï ä ©«®¢ ï á¨á⥬ ",
  116.         0,
  117.         "Žè¨¡ª  #5: ä ©« ¨«¨ ¯ ¯ª  ­¥ ­ ©¤¥­ë",
  118.         "Žè¨¡ª  #6: ª®­¥æ ä ©« ",
  119.         "Žè¨¡ª  #7: 㪠§ â¥«ì ­ å®¤¨âáï ¢á¥ ¯ ¬ï⨠¯à¨«®¦¥­¨ï",
  120.         "Žè¨¡ª  #8: ­¥¤®áâ â®ç­® ¬¥áâ  ­  ¤¨áª¥",
  121.         "Žè¨¡ª  #9: â ¡«¨æ  FAT à §àã襭 ",
  122.         "Žè¨¡ª  #10: ¤®áâ㯠§ ¯à¥é¥­",
  123.         "Žè¨¡ª  #11: ®è¨¡ª  ãáâனᢠ",
  124.         0, 0, 0, 0, 0, 0, 0, 0, 0,
  125.         0, 0, 0, 0, 0, 0, 0, 0, 0,
  126.         "Žè¨¡ª  #30: ­¥¤®áâ â®ç­® ¯ ¬ïâ¨",
  127.         "Žè¨¡ª  #31: ä ©« ­¥ ï¥âáï ¨á¯®«­ï¥¬ë¬",
  128.         "Žè¨¡ª  #32: ᫨誮¬ ¬­®£® ¯à®æ¥áᮢ", 0};
  129. #else
  130.         unsigned char *ERROR_TEXT[]={
  131.         "Code #0 - No error, compleated successfully",
  132.         "Error #1 - Base or partition of a hard disk is not defined",
  133.         "Error #2 - Function isn't supported for this file system",
  134.         "Error #3 - Unknown file system",
  135.         0,
  136.         "Error #5 - File or folder not found",
  137.         "Error #6 - End of file",
  138.         "Error #7 - Pointer lies outside of application memory",
  139.         "Error #8 - Too less disk space",
  140.         "Error #9 - FAT table is destroyed",
  141.         "Error #10 - Access denied",
  142.         "Error #11 - Device error",
  143.         0, 0, 0, 0, 0, 0, 0, 0, 0,
  144.         0, 0, 0, 0, 0, 0, 0, 0, 0,
  145.         "Error #30 - Not enough memory",
  146.         "Error #31 - File is not executable",
  147.         "Error #32 - Too many processes", 0};
  148. #endif
  149.  
  150. :dword get_error(int N)
  151. {
  152.         char error[256];  
  153.         N = fabs(N);
  154.         if (N<=33)
  155.         {
  156.                 strcpy(#error, ERROR_TEXT[N]);
  157.         }
  158.         else
  159.         {
  160.                 strcpy(#error, itoa(N));
  161.                 strcat(#error, " - Unknown error number O_o");
  162.         }
  163.         return #error;
  164. }
  165.  
  166. :void debug_error(dword path, error_number)
  167. {
  168.         if (path) debugln(path);
  169.         debugln(get_error(error_number));
  170. }