2013-04-04 19:07:38 +02:00
|
|
|
//copyf - copy file or folder with content
|
|
|
|
:int copyf(dword from1, in1)
|
2013-03-30 01:52:50 +01:00
|
|
|
{
|
2013-04-02 15:33:32 +02:00
|
|
|
dword error;
|
|
|
|
BDVK CopyFile_atr1;
|
2013-04-04 19:07:38 +02:00
|
|
|
if (!from1) || (!in1)
|
|
|
|
{
|
|
|
|
notify("Error: too less copyf params!");
|
|
|
|
notify(from1);
|
|
|
|
notify(in1);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (error = GetFileInfo(from1, #CopyFile_atr1))
|
|
|
|
{
|
2013-04-02 15:33:32 +02:00
|
|
|
debug("Error: copyf->GetFileInfo");
|
2013-04-04 19:07:38 +02:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
if (isdir(from1))
|
|
|
|
return CopyFolder(from1, in1);
|
2013-04-02 15:33:32 +02:00
|
|
|
else
|
2013-04-04 19:07:38 +02:00
|
|
|
return CopyFile(from1, in1);
|
2013-04-02 15:33:32 +02:00
|
|
|
}
|
2013-03-11 19:16:24 +01:00
|
|
|
|
2013-04-02 15:33:32 +02:00
|
|
|
:int CopyFile(dword copy_from3, copy_in3)
|
|
|
|
{
|
|
|
|
BDVK CopyFile_atr;
|
|
|
|
dword error, cbuf;
|
2013-04-04 19:07:38 +02:00
|
|
|
if (error = GetFileInfo(copy_from3, #CopyFile_atr))
|
2013-08-31 20:33:48 +02:00
|
|
|
{
|
2013-04-04 19:07:38 +02:00
|
|
|
debug("Error: CopyFile->GetFileInfo");
|
2013-08-31 20:33:48 +02:00
|
|
|
}
|
2013-03-11 19:16:24 +01:00
|
|
|
else
|
|
|
|
{
|
2013-04-02 15:33:32 +02:00
|
|
|
cbuf = malloc(CopyFile_atr.sizelo);
|
2013-04-04 19:07:38 +02:00
|
|
|
if (error = ReadFile(0, CopyFile_atr.sizelo, cbuf, copy_from3))
|
2013-08-31 20:33:48 +02:00
|
|
|
{
|
2013-04-02 15:33:32 +02:00
|
|
|
debug("Error: CopyFile->ReadFile");
|
2013-08-31 20:33:48 +02:00
|
|
|
}
|
2013-04-02 15:33:32 +02:00
|
|
|
else
|
|
|
|
{
|
2013-04-04 19:07:38 +02:00
|
|
|
if (error = WriteFile(CopyFile_atr.sizelo, cbuf, copy_in3)) debug("Error: CopyFile->WriteFile");
|
2013-04-02 15:33:32 +02:00
|
|
|
}
|
2013-03-11 19:16:24 +01:00
|
|
|
}
|
2013-04-02 15:33:32 +02:00
|
|
|
free(cbuf);
|
2013-04-04 19:07:38 +02:00
|
|
|
if (error) debug_error(copy_from3, error);
|
2013-04-02 15:33:32 +02:00
|
|
|
return error;
|
2013-03-11 19:16:24 +01:00
|
|
|
}
|
|
|
|
|
2013-04-04 19:07:38 +02:00
|
|
|
:int CopyFolder(dword from2, in2)
|
2013-03-11 19:16:24 +01:00
|
|
|
{
|
2013-04-04 19:07:38 +02:00
|
|
|
dword dirbuf, fcount, i, filename;
|
|
|
|
char copy_from2[4096], copy_in2[4096], error;
|
2013-03-11 19:16:24 +01:00
|
|
|
|
2013-04-04 19:07:38 +02:00
|
|
|
if (error = GetDir(#dirbuf, #fcount, from2, DIRS_ONLYREAL))
|
2013-04-02 15:33:32 +02:00
|
|
|
{
|
|
|
|
debug("Error: CopyFolder->GetDir");
|
|
|
|
debug_error(from2, error);
|
|
|
|
free(dirbuf);
|
2013-04-04 19:07:38 +02:00
|
|
|
return error;
|
2013-04-02 15:33:32 +02:00
|
|
|
}
|
2013-03-11 19:16:24 +01:00
|
|
|
|
2013-04-04 19:07:38 +02:00
|
|
|
if (chrnum(in2, '/')>2) && (error = CreateDir(in2))
|
2013-03-11 19:16:24 +01:00
|
|
|
{
|
2013-04-04 19:07:38 +02:00
|
|
|
debug("Error: CopyFolder->CreateDir");
|
|
|
|
debug_error(in2, error);
|
|
|
|
free(dirbuf);
|
|
|
|
return error;
|
2013-03-11 19:16:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
for (i=0; i<fcount; i++)
|
|
|
|
{
|
|
|
|
filename = i*304+dirbuf+72;
|
2013-04-04 19:07:38 +02:00
|
|
|
strcpy(#copy_from2, from2);
|
|
|
|
chrcat(#copy_from2, '/');
|
|
|
|
strcat(#copy_from2, filename);
|
|
|
|
strcpy(#copy_in2, in2);
|
|
|
|
chrcat(#copy_in2, '/');
|
|
|
|
strcat(#copy_in2, filename);
|
|
|
|
|
|
|
|
if ( TestBit(ESDWORD[filename-40], 4) ) //isdir?
|
2013-03-11 19:16:24 +01:00
|
|
|
{
|
|
|
|
if ( (!strcmp(filename, ".")) || (!strcmp(filename, "..")) ) continue;
|
2013-04-02 15:33:32 +02:00
|
|
|
CopyFolder(#copy_from2, #copy_in2);
|
2013-03-11 19:16:24 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-03-31 22:25:54 +02:00
|
|
|
copyf_Action(filename);
|
2013-04-04 19:07:38 +02:00
|
|
|
if (error=CopyFile(#copy_from2, #copy_in2))
|
|
|
|
{
|
|
|
|
if (fabs(error)==8) { debug("Stop copying."); break;} //TODO: may be need grobal var like stop_all
|
|
|
|
error=CopyFile(#copy_from2, #copy_in2); // #2 :)
|
|
|
|
}
|
2013-03-11 19:16:24 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
free(dirbuf);
|
2013-04-04 19:07:38 +02:00
|
|
|
return error;
|
2013-03-11 19:16:24 +01:00
|
|
|
}
|
|
|
|
|
2013-04-02 15:33:32 +02:00
|
|
|
|
2013-03-11 19:16:24 +01:00
|
|
|
unsigned char *ERROR_TEXT[]={
|
|
|
|
"Code #0 - No error",
|
|
|
|
"Error #1 - Base or partition of a hard disk is not defined",
|
|
|
|
"Error #2 - Function isn't supported for this file system",
|
|
|
|
"Error #3 - Unknown file system",
|
|
|
|
"Error #4 - Reserved, is never returned",
|
|
|
|
"Error #5 - File or folder not found",
|
|
|
|
"Error #6 - End of file, EOF",
|
|
|
|
"Error #7 - Pointer lies outside of application memory",
|
2013-03-30 01:52:50 +01:00
|
|
|
"Error #8 - Too less disk space",
|
2013-03-11 19:16:24 +01:00
|
|
|
"Error #9 - FAT table is destroyed",
|
|
|
|
"Error #10 - Access denied",
|
|
|
|
"Error #11 - Device error",
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
"Error #30 - Not enough memory",
|
|
|
|
"Error #31 - File is not executable",
|
|
|
|
"Error #32 - Too many processes",
|
|
|
|
0};
|
|
|
|
|
2013-04-02 15:33:32 +02:00
|
|
|
:dword get_error(int N)
|
2013-03-11 19:16:24 +01:00
|
|
|
{
|
2013-04-02 15:33:32 +02:00
|
|
|
char error[256];
|
|
|
|
N = fabs(N);
|
|
|
|
if (N<=33)
|
2013-03-11 19:16:24 +01:00
|
|
|
{
|
2013-03-31 22:25:54 +02:00
|
|
|
strcpy(#error, ERROR_TEXT[N]);
|
2013-03-11 19:16:24 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-03-31 22:25:54 +02:00
|
|
|
strcpy(#error, itoa(N));
|
2013-03-11 19:16:24 +01:00
|
|
|
strcat(#error, " - Unknown error number O_o");
|
|
|
|
}
|
2013-03-31 22:25:54 +02:00
|
|
|
return #error;
|
2013-03-11 19:16:24 +01:00
|
|
|
}
|
2013-03-31 22:25:54 +02:00
|
|
|
|
2013-04-02 15:33:32 +02:00
|
|
|
:void debug_error(dword path, error_number)
|
2013-03-31 22:25:54 +02:00
|
|
|
{
|
|
|
|
if (path) debug(path);
|
|
|
|
debug(get_error(error_number));
|
|
|
|
}
|