2013-04-04 21:07:38 +04:00
|
|
|
|
//copyf - copy file or folder with content
|
2015-07-22 21:32:54 +03:00
|
|
|
|
#ifndef INCLUDE_COPYF_H
|
|
|
|
|
#define INCLUDE_COPYF_H
|
2015-08-04 18:48:36 +03:00
|
|
|
|
#print "[include <copyf.h>]\n"
|
2015-07-22 21:32:54 +03:00
|
|
|
|
|
|
|
|
|
#ifndef INCLUDE_FILESYSTEM_H
|
|
|
|
|
#include "../lib/file_system.h"
|
|
|
|
|
#endif
|
2015-03-09 21:51:16 +03:00
|
|
|
|
|
2013-04-04 21:07:38 +04:00
|
|
|
|
:int copyf(dword from1, in1)
|
2013-03-30 04:52:50 +04:00
|
|
|
|
{
|
2013-04-02 17:33:32 +04:00
|
|
|
|
dword error;
|
|
|
|
|
BDVK CopyFile_atr1;
|
2015-03-09 21:51:16 +03:00
|
|
|
|
|
2013-04-04 21:07:38 +04:00
|
|
|
|
if (!from1) || (!in1)
|
|
|
|
|
{
|
|
|
|
|
notify("Error: too less copyf params!");
|
|
|
|
|
notify(from1);
|
|
|
|
|
notify(in1);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (error = GetFileInfo(from1, #CopyFile_atr1))
|
|
|
|
|
{
|
2014-03-14 23:06:48 +04:00
|
|
|
|
debugln("Error: copyf->GetFileInfo");
|
2013-04-04 21:07:38 +04:00
|
|
|
|
return error;
|
|
|
|
|
}
|
2016-02-19 03:33:21 +03:00
|
|
|
|
if (dir_exists(from1))
|
2013-04-04 21:07:38 +04:00
|
|
|
|
return CopyFolder(from1, in1);
|
2013-04-02 17:33:32 +04:00
|
|
|
|
else
|
2013-10-20 16:20:57 +04:00
|
|
|
|
{
|
2015-09-05 20:55:13 +03:00
|
|
|
|
Operation_Draw_Progress(from1+strchr(from1, '/'));
|
2013-04-04 21:07:38 +04:00
|
|
|
|
return CopyFile(from1, in1);
|
2013-10-20 16:20:57 +04:00
|
|
|
|
}
|
2013-04-02 17:33:32 +04:00
|
|
|
|
}
|
2013-03-11 22:16:24 +04:00
|
|
|
|
|
2013-04-02 17:33:32 +04:00
|
|
|
|
:int CopyFile(dword copy_from3, copy_in3)
|
|
|
|
|
{
|
|
|
|
|
BDVK CopyFile_atr;
|
|
|
|
|
dword error, cbuf;
|
2013-04-04 21:07:38 +04:00
|
|
|
|
if (error = GetFileInfo(copy_from3, #CopyFile_atr))
|
2013-08-31 22:33:48 +04:00
|
|
|
|
{
|
2014-03-14 23:06:48 +04:00
|
|
|
|
debugln("Error: CopyFile->GetFileInfo");
|
2013-08-31 22:33:48 +04:00
|
|
|
|
}
|
2013-03-11 22:16:24 +04:00
|
|
|
|
else
|
|
|
|
|
{
|
2016-11-08 13:48:55 +03:00
|
|
|
|
cbuf = malloc(CopyFile_atr.sizelo);
|
2013-04-04 21:07:38 +04:00
|
|
|
|
if (error = ReadFile(0, CopyFile_atr.sizelo, cbuf, copy_from3))
|
2013-08-31 22:33:48 +04:00
|
|
|
|
{
|
2014-03-14 23:06:48 +04:00
|
|
|
|
debugln("Error: CopyFile->ReadFile");
|
2013-08-31 22:33:48 +04:00
|
|
|
|
}
|
2013-04-02 17:33:32 +04:00
|
|
|
|
else
|
|
|
|
|
{
|
2014-03-14 23:06:48 +04:00
|
|
|
|
if (error = WriteFile(CopyFile_atr.sizelo, cbuf, copy_in3)) debugln("Error: CopyFile->WriteFile");
|
2013-04-02 17:33:32 +04:00
|
|
|
|
}
|
2013-03-11 22:16:24 +04:00
|
|
|
|
}
|
2013-04-02 17:33:32 +04:00
|
|
|
|
free(cbuf);
|
2013-04-04 21:07:38 +04:00
|
|
|
|
if (error) debug_error(copy_from3, error);
|
2013-04-02 17:33:32 +04:00
|
|
|
|
return error;
|
2013-03-11 22:16:24 +04:00
|
|
|
|
}
|
|
|
|
|
|
2013-04-04 21:07:38 +04:00
|
|
|
|
:int CopyFolder(dword from2, in2)
|
2013-03-11 22:16:24 +04:00
|
|
|
|
{
|
2013-04-04 21:07:38 +04:00
|
|
|
|
dword dirbuf, fcount, i, filename;
|
|
|
|
|
char copy_from2[4096], copy_in2[4096], error;
|
2013-03-11 22:16:24 +04:00
|
|
|
|
|
2013-04-04 21:07:38 +04:00
|
|
|
|
if (error = GetDir(#dirbuf, #fcount, from2, DIRS_ONLYREAL))
|
2013-04-02 17:33:32 +04:00
|
|
|
|
{
|
2014-03-14 23:06:48 +04:00
|
|
|
|
debugln("Error: CopyFolder->GetDir");
|
2013-04-02 17:33:32 +04:00
|
|
|
|
debug_error(from2, error);
|
|
|
|
|
free(dirbuf);
|
2013-04-04 21:07:38 +04:00
|
|
|
|
return error;
|
2013-04-02 17:33:32 +04:00
|
|
|
|
}
|
2013-10-14 02:19:31 +04:00
|
|
|
|
|
2013-04-04 21:07:38 +04:00
|
|
|
|
if (chrnum(in2, '/')>2) && (error = CreateDir(in2))
|
2013-03-11 22:16:24 +04:00
|
|
|
|
{
|
2014-03-14 23:06:48 +04:00
|
|
|
|
debugln("Error: CopyFolder->CreateDir");
|
2013-04-04 21:07:38 +04:00
|
|
|
|
debug_error(in2, error);
|
|
|
|
|
free(dirbuf);
|
|
|
|
|
return error;
|
2013-03-11 22:16:24 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (i=0; i<fcount; i++)
|
|
|
|
|
{
|
|
|
|
|
filename = i*304+dirbuf+72;
|
2015-07-22 21:32:54 +03:00
|
|
|
|
sprintf(#copy_from2,"%s/%s",from2,filename);
|
|
|
|
|
sprintf(#copy_in2,"%s/%s",in2,filename);
|
2013-04-04 21:07:38 +04:00
|
|
|
|
|
2016-02-19 03:33:21 +03:00
|
|
|
|
if ( TestBit(ESDWORD[filename-40], 4) ) //dir_exists?
|
2013-03-11 22:16:24 +04:00
|
|
|
|
{
|
2015-07-22 21:32:54 +03:00
|
|
|
|
if ( (!strncmp(filename, ".",1)) || (!strncmp(filename, "..",2)) ) continue;
|
2013-04-02 17:33:32 +04:00
|
|
|
|
CopyFolder(#copy_from2, #copy_in2);
|
2013-03-11 22:16:24 +04:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2016-02-22 00:57:22 +03:00
|
|
|
|
Operation_Draw_Progress(filename+strchr(filename, '/'));
|
2016-11-08 13:48:55 +03:00
|
|
|
|
if (error=CopyFile(#copy_from2, #copy_in2))
|
2013-04-04 21:07:38 +04:00
|
|
|
|
{
|
2014-03-14 23:06:48 +04:00
|
|
|
|
if (fabs(error)==8) { debugln("Stop copying."); break;} //TODO: may be need grobal var like stop_all
|
2013-04-04 21:07:38 +04:00
|
|
|
|
error=CopyFile(#copy_from2, #copy_in2); // #2 :)
|
|
|
|
|
}
|
2013-03-11 22:16:24 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
free(dirbuf);
|
2013-04-04 21:07:38 +04:00
|
|
|
|
return error;
|
2013-03-11 22:16:24 +04:00
|
|
|
|
}
|
|
|
|
|
|
2013-10-14 02:19:31 +04:00
|
|
|
|
#ifdef LANG_RUS
|
|
|
|
|
unsigned char *ERROR_TEXT[]={
|
|
|
|
|
"<EFBFBD><EFBFBD><EFBFBD> #0: <20>ᯥ譮",
|
|
|
|
|
"<EFBFBD>訡<EFBFBD><EFBFBD> #1: <20><> <20><>।<EFBFBD><E0A5A4><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20>/<2F><><EFBFBD> ࠧ<><E0A0A7><EFBFBD> <20><><EFBFBD>⪮<EFBFBD><E2AAAE> <20><>᪠",
|
|
|
|
|
"<EFBFBD>訡<EFBFBD><EFBFBD> #2: <20>㭪<EFBFBD><E3ADAA><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD>ন<EFBFBD><E0A6A8><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20>⮩ 䠩<><E4A0A9><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD>⥬<EFBFBD>",
|
2014-03-13 01:43:39 +04:00
|
|
|
|
"<EFBFBD>訡<EFBFBD><EFBFBD> #3: <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>⭠<EFBFBD> 䠩<><E4A0A9><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD>⥬<EFBFBD>",
|
2013-10-14 02:19:31 +04:00
|
|
|
|
0,
|
|
|
|
|
"<EFBFBD>訡<EFBFBD><EFBFBD> #5: 䠩<> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>",
|
|
|
|
|
"<EFBFBD>訡<EFBFBD><EFBFBD> #6: <20><><EFBFBD><EFBFBD><EFBFBD> 䠩<><E4A0A9>",
|
|
|
|
|
"<EFBFBD>訡<EFBFBD><EFBFBD> #7: 㪠<><E3AAA0>⥫<EFBFBD> <20><>室<EFBFBD><E5AEA4><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>ਫ<EFBFBD><E0A8AB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>",
|
2016-11-08 13:48:55 +03:00
|
|
|
|
"<EFBFBD>訡<EFBFBD><EFBFBD> #8: <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>筮 <20><><EFBFBD><EFBFBD><EFBFBD> <20><> ࠧ<><E0A0A7><EFBFBD><EFBFBD>",
|
|
|
|
|
"<EFBFBD>訡<EFBFBD><EFBFBD> #9: <20>訡<EFBFBD><E8A8A1> 䠩<><E4A0A9><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD>⥬<EFBFBD>",
|
2013-10-14 02:19:31 +04:00
|
|
|
|
"<EFBFBD>訡<EFBFBD><EFBFBD> #10: <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>饭",
|
2015-08-02 02:21:13 +03:00
|
|
|
|
"<EFBFBD>訡<EFBFBD><EFBFBD> #11: <20>訡<EFBFBD><E8A8A1> <20><><EFBFBD>ன<EFBFBD>⢠",
|
2013-10-14 02:19:31 +04:00
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0,
|
2016-11-08 13:48:55 +03:00
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0,
|
2013-10-14 02:19:31 +04:00
|
|
|
|
"<EFBFBD>訡<EFBFBD><EFBFBD> #30: <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>筮 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>",
|
|
|
|
|
"<EFBFBD>訡<EFBFBD><EFBFBD> #31: 䠩<> <20><> <><EFA2AB><EFBFBD><EFBFBD><EFBFBD> <20>ᯮ<EFBFBD><E1AFAE>塞<EFBFBD><EFA5AC>",
|
|
|
|
|
"<EFBFBD>訡<EFBFBD><EFBFBD> #32: 誮<E1ABA8> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ᮢ", 0};
|
|
|
|
|
#else
|
|
|
|
|
unsigned char *ERROR_TEXT[]={
|
|
|
|
|
"Code #0 - No error, compleated successfully",
|
|
|
|
|
"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",
|
|
|
|
|
0,
|
|
|
|
|
"Error #5 - File or folder not found",
|
|
|
|
|
"Error #6 - End of file",
|
|
|
|
|
"Error #7 - Pointer lies outside of application memory",
|
2016-11-08 13:48:55 +03:00
|
|
|
|
"Error #8 - Not enough space on partition",
|
|
|
|
|
"Error #9 - File system error",
|
2013-10-14 02:19:31 +04:00
|
|
|
|
"Error #10 - Access denied",
|
|
|
|
|
"Error #11 - Device error",
|
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0,
|
2016-11-08 13:48:55 +03:00
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0,
|
2013-10-14 02:19:31 +04:00
|
|
|
|
"Error #30 - Not enough memory",
|
|
|
|
|
"Error #31 - File is not executable",
|
|
|
|
|
"Error #32 - Too many processes", 0};
|
|
|
|
|
#endif
|
2013-03-11 22:16:24 +04:00
|
|
|
|
|
2013-04-02 17:33:32 +04:00
|
|
|
|
:dword get_error(int N)
|
2013-03-11 22:16:24 +04:00
|
|
|
|
{
|
2016-11-08 13:48:55 +03:00
|
|
|
|
char error[256];
|
2013-04-02 17:33:32 +04:00
|
|
|
|
N = fabs(N);
|
2015-07-22 21:32:54 +03:00
|
|
|
|
if (N<=33) strcpy(#error, ERROR_TEXT[N]);
|
|
|
|
|
else sprintf(#error,"%d%s",N," - Unknown error number O_o");
|
2013-04-01 00:25:54 +04:00
|
|
|
|
return #error;
|
2013-03-11 22:16:24 +04:00
|
|
|
|
}
|
2013-04-01 00:25:54 +04:00
|
|
|
|
|
2013-04-02 17:33:32 +04:00
|
|
|
|
:void debug_error(dword path, error_number)
|
2013-04-01 00:25:54 +04:00
|
|
|
|
{
|
2014-03-14 23:06:48 +04:00
|
|
|
|
if (path) debugln(path);
|
|
|
|
|
debugln(get_error(error_number));
|
2015-07-22 21:32:54 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif
|