Subversion Repositories Kolibri OS

Rev

Rev 3444 | Rev 4023 | 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. :int copyf(dword from1, in1)
  3. {
  4.         dword error;
  5.         BDVK CopyFile_atr1;
  6.         if (!from1) || (!in1)
  7.         {
  8.                 notify("Error: too less copyf params!");
  9.                 notify(from1);
  10.                 notify(in1);
  11.                 return;
  12.         }
  13.         if (error = GetFileInfo(from1, #CopyFile_atr1))
  14.         {
  15.                 debug("Error: copyf->GetFileInfo");
  16.                 return error;
  17.         }
  18.         if (isdir(from1))
  19.                 return CopyFolder(from1, in1);
  20.         else
  21.                 return CopyFile(from1, in1);
  22. }
  23.  
  24. :int CopyFile(dword copy_from3, copy_in3)
  25. {
  26.         BDVK CopyFile_atr;
  27.         dword error, cbuf;
  28.         if (error = GetFileInfo(copy_from3, #CopyFile_atr))
  29.         {
  30.                 debug("Error: CopyFile->GetFileInfo");
  31.         }
  32.         else
  33.         {
  34.                 cbuf = malloc(CopyFile_atr.sizelo);    
  35.                 if (error = ReadFile(0, CopyFile_atr.sizelo, cbuf, copy_from3))
  36.                 {
  37.                         debug("Error: CopyFile->ReadFile");
  38.                 }
  39.                 else
  40.                 {
  41.                         if (error = WriteFile(CopyFile_atr.sizelo, cbuf, copy_in3)) debug("Error: CopyFile->WriteFile");
  42.                 }
  43.         }
  44.         free(cbuf);
  45.         if (error) debug_error(copy_from3, error);
  46.         return error;
  47. }
  48.  
  49. :int CopyFolder(dword from2, in2)
  50. {
  51.         dword dirbuf, fcount, i, filename;
  52.         char copy_from2[4096], copy_in2[4096], error;
  53.  
  54.         if (error = GetDir(#dirbuf, #fcount, from2, DIRS_ONLYREAL))
  55.         {
  56.                 debug("Error: CopyFolder->GetDir");
  57.                 debug_error(from2, error);
  58.                 free(dirbuf);
  59.                 return error;
  60.         }
  61.        
  62.         if (chrnum(in2, '/')>2) && (error = CreateDir(in2))
  63.         {
  64.                 debug("Error: CopyFolder->CreateDir");
  65.                 debug_error(in2, error);
  66.                 free(dirbuf);
  67.                 return error;
  68.         }
  69.  
  70.         for (i=0; i<fcount; i++)
  71.         {
  72.                 filename = i*304+dirbuf+72;
  73.                 strcpy(#copy_from2, from2);
  74.                 chrcat(#copy_from2, '/');
  75.                 strcat(#copy_from2, filename);
  76.                 strcpy(#copy_in2, in2);
  77.                 chrcat(#copy_in2, '/');
  78.                 strcat(#copy_in2, filename);
  79.  
  80.                 if ( TestBit(ESDWORD[filename-40], 4) ) //isdir?
  81.                 {
  82.                         if ( (!strcmp(filename, ".")) || (!strcmp(filename, "..")) ) continue;
  83.                         CopyFolder(#copy_from2, #copy_in2);
  84.                 }
  85.                 else
  86.                 {
  87.                         copyf_Action(filename);
  88.                         if (error=CopyFile(#copy_from2, #copy_in2))
  89.                         {
  90.                                 if (fabs(error)==8) { debug("Stop copying."); break;} //TODO: may be need grobal var like stop_all
  91.                                 error=CopyFile(#copy_from2, #copy_in2); // #2 :)
  92.                         }
  93.                 }
  94.         }
  95.         free(dirbuf);
  96.         return error;
  97. }
  98.  
  99.  
  100. unsigned char *ERROR_TEXT[]={
  101. "Code #0 - No error",
  102. "Error #1 - Base or partition of a hard disk is not defined",
  103. "Error #2 - Function isn't supported for this file system",
  104. "Error #3 - Unknown file system",
  105. "Error #4 - Reserved, is never returned",
  106. "Error #5 - File or folder not found",
  107. "Error #6 - End of file, EOF",
  108. "Error #7 - Pointer lies outside of application memory",
  109. "Error #8 - Too less disk space",
  110. "Error #9 - FAT table is destroyed",
  111. "Error #10 - Access denied",
  112. "Error #11 - Device error",
  113. 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114. 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115. "Error #30 - Not enough memory",
  116. "Error #31 - File is not executable",
  117. "Error #32 - Too many processes",
  118. 0};
  119.  
  120. :dword get_error(int N)
  121. {
  122.         char error[256];  
  123.         N = fabs(N);
  124.         if (N<=33)
  125.         {
  126.                 strcpy(#error, ERROR_TEXT[N]);
  127.         }
  128.         else
  129.         {
  130.                 strcpy(#error, itoa(N));
  131.                 strcat(#error, " - Unknown error number O_o");
  132.         }
  133.         return #error;
  134. }
  135.  
  136. :void debug_error(dword path, error_number)
  137. {
  138.         if (path) debug(path);
  139.         debug(get_error(error_number));
  140. }