Subversion Repositories Kolibri OS

Rev

Rev 7491 | Rev 8868 | 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. #ifndef INCLUDE_COPYF_H
  3. #define INCLUDE_COPYF_H
  4. #print "[include <copyf.h>]\n"
  5.  
  6. #ifndef INCLUDE_FILESYSTEM_H
  7. #include "../lib/fs.h"
  8. #endif
  9.  
  10. :int copyf(dword from1, in1)
  11. {
  12.         dword error;
  13.         BDVK CopyFile_atr1;
  14.  
  15.         if (!from1) || (!in1)
  16.         {
  17.                 notify("Error: too few copyf() params!");
  18.                 return;
  19.         }
  20.         if (error = GetFileInfo(from1, #CopyFile_atr1))
  21.         {
  22.                 debugln("Error: copyf->GetFileInfo");
  23.                 return error;
  24.         }
  25.         if (dir_exists(from1))
  26.                 return CopyFolder(from1, in1);
  27.         else
  28.         {
  29.                 Operation_Draw_Progress(from1+strrchr(from1, '/'));
  30.                 return CopyFile(from1, in1);
  31.         }
  32. }
  33.  
  34. :int CopyFile(dword copy_from3, copy_in3)
  35. {
  36.         BDVK CopyFile_atr;
  37.         dword error, cbuf;
  38.         dword block;
  39.  
  40.         if (error = GetFileInfo(copy_from3, #CopyFile_atr))
  41.         {
  42.                 debugln("Error: CopyFile->GetFileInfo");
  43.         }
  44.         else
  45.         {
  46.                 if (GetFreeRAM()-1024*1024 < CopyFile_atr.sizelo) //GetFreeRam-1Mb and convert to bytes
  47.                 {
  48.                         if (error = CopyFileByBlocks(CopyFile_atr.sizelo, copy_from3, copy_in3))
  49.                                 debugln("Error: CopyFile->CopyFileByBlocks");
  50.                 }
  51.                 else {
  52.                         if (error = CopyFileAtOnce(CopyFile_atr.sizelo, copy_from3, copy_in3))
  53.                                 debugln("Error: CopyFile->CopyFileAtOnce");
  54.                 }              
  55.         }
  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.                 sprintf(#copy_from2,"%s/%s",from2,filename);
  85.                 sprintf(#copy_in2,"%s/%s",in2,filename);
  86.  
  87.                 if ( TestBit(ESDWORD[filename-40], 4) ) //dir_exists?
  88.                 {
  89.                         if ( (!strncmp(filename, ".",1)) || (!strncmp(filename, "..",2)) ) continue;
  90.                         CopyFolder(#copy_from2, #copy_in2);
  91.                 }
  92.                 else
  93.                 {
  94.                         Operation_Draw_Progress(filename+strrchr(filename, '/'));
  95.                         if (error=CopyFile(#copy_from2, #copy_in2))
  96.                         {
  97.                                 if (fabs(error)==8) { debugln("Stop copying."); break;} //TODO: may be need grobal var like stop_all
  98.                                 error=CopyFile(#copy_from2, #copy_in2); // #2 :)
  99.                         }
  100.                 }
  101.         }
  102.         free(dirbuf);
  103.         return error;
  104. }
  105.  
  106. #ifdef LANG_RUS
  107.         unsigned char *ERROR_TEXT[]={
  108.         "Š®¤ #0: ãᯥ譮",
  109.         "Žè¨¡ª  #1: ­¥ ®¯à¥¤¥«¥­  ¡ §  ¨/¨«¨ à §¤¥« ¦ñá⪮£® ¤¨áª ",
  110.         "Žè¨¡ª  #2: äã­ªæ¨ï ­¥ ¯®¤¤¥à¦¨¢ ¥âáï ¤«ï í⮩ ä ©«®¢®© á¨á⥬ë",
  111.         "Žè¨¡ª  #3: ­¥¨§¢¥áâ­ ï ä ©«®¢ ï á¨á⥬ ",
  112.         0,
  113.         "Žè¨¡ª  #5: ä ©« ¨«¨ ¯ ¯ª  ­¥ ­ ©¤¥­ë",
  114.         "Žè¨¡ª  #6: ª®­¥æ ä ©« ",
  115.         "Žè¨¡ª  #7: 㪠§ â¥«ì ­ å®¤¨âáï ¢á¥ ¯ ¬ï⨠¯à¨«®¦¥­¨ï",
  116.         "Žè¨¡ª  #8: ­¥¤®áâ â®ç­® ¬¥áâ  ­  à §¤¥«¥",
  117.         "Žè¨¡ª  #9: ®è¨¡ª  ä ©«®¢®© á¨á⥬ë",
  118.         "Žè¨¡ª  #10: ¤®áâ㯠§ ¯à¥é¥­",
  119.         "Žè¨¡ª  #11: ®è¨¡ª  ãáâனá⢠",
  120.         0, 0, 0, 0, 0, 0, 0, 0, 0,
  121.         0, 0, 0, 0, 0, 0, 0, 0, 0,
  122.         "Žè¨¡ª  #30: ­¥¤®áâ â®ç­® ¯ ¬ïâ¨",
  123.         "Žè¨¡ª  #31: ä ©« ­¥ ï¥âáï ¨á¯®«­ï¥¬ë¬",
  124.         "Žè¨¡ª  #32: ᫨誮¬ ¬­®£® ¯à®æ¥áᮢ", 0};
  125. #else
  126.         unsigned char *ERROR_TEXT[]={
  127.         "Code #0 - No error, compleated successfully",
  128.         "Error #1 - Base or partition of a hard disk is not defined",
  129.         "Error #2 - Function isn't supported for this file system",
  130.         "Error #3 - Unknown file system",
  131.         0,
  132.         "Error #5 - File or folder not found",
  133.         "Error #6 - End of file",
  134.         "Error #7 - Pointer lies outside of application memory",
  135.         "Error #8 - Not enough space on partition",
  136.         "Error #9 - File system error",
  137.         "Error #10 - Access denied",
  138.         "Error #11 - Device error",
  139.         0, 0, 0, 0, 0, 0, 0, 0, 0,
  140.         0, 0, 0, 0, 0, 0, 0, 0, 0,
  141.         "Error #30 - Not enough memory",
  142.         "Error #31 - File is not executable",
  143.         "Error #32 - Too many processes", 0};
  144. #endif
  145.  
  146. :dword get_error(int N)
  147. {
  148.         char error[256];
  149.         N = fabs(N);
  150.         if (N<=33) strcpy(#error, ERROR_TEXT[N]);
  151.         else sprintf(#error,"%d%s",N," - Unknown error number O_o");
  152.         return #error;
  153. }
  154.  
  155. :void debug_error(dword path, error_number)
  156. {
  157.         if (path) debugln(path);
  158.         debugln(get_error(error_number));
  159. }
  160.  
  161. #endif