Subversion Repositories Kolibri OS

Rev

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