Subversion Repositories Kolibri OS

Rev

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