Subversion Repositories Kolibri OS

Rev

Rev 5598 | Rev 5806 | 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.  
  5. #ifndef INCLUDE_FILESYSTEM_H
  6. #include "../lib/file_system.h"
  7. #endif
  8.  
  9. :int copyf(dword from1, in1)
  10. {
  11.         dword error;
  12.         BDVK CopyFile_atr1;
  13.  
  14.         if (!from1) || (!in1)
  15.         {
  16.                 notify("Error: too less copyf params!");
  17.                 notify(from1);
  18.                 notify(in1);
  19.                 return;
  20.         }
  21.         if (error = GetFileInfo(from1, #CopyFile_atr1))
  22.         {
  23.                 debugln("Error: copyf->GetFileInfo");
  24.                 return error;
  25.         }
  26.         if (isdir(from1))
  27.                 return CopyFolder(from1, in1);
  28.         else
  29.         {
  30.                 copyf_Draw_Progress(from1+strchr(from1, '/'));
  31.                 return CopyFile(from1, in1);
  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.                 sprintf(#copy_from2,"%s/%s",from2,filename);
  85.                 sprintf(#copy_in2,"%s/%s",in2,filename);
  86.  
  87.                 if ( TestBit(ESDWORD[filename-40], 4) ) //isdir?
  88.                 {
  89.                         if ( (!strncmp(filename, ".",1)) || (!strncmp(filename, "..",2)) ) continue;
  90.                         CopyFolder(#copy_from2, #copy_in2);
  91.                 }
  92.                 else
  93.                 {
  94.                         copyf_Draw_Progress(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: â ¡«¨æ  FAT à §àã襭 ",
  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 - Too less disk space",
  136.         "Error #9 - FAT table is destroyed",
  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