Subversion Repositories Kolibri OS

Rev

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