Subversion Repositories Kolibri OS

Rev

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