Subversion Repositories Kolibri OS

Rev

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