Subversion Repositories Kolibri OS

Rev

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