2013-04-04 19:07:38 +02:00
|
|
|
|
//copyf - copy file or folder with content
|
2015-07-22 20:32:54 +02:00
|
|
|
|
#ifndef INCLUDE_COPYF_H
|
|
|
|
|
#define INCLUDE_COPYF_H
|
2015-08-04 17:48:36 +02:00
|
|
|
|
#print "[include <copyf.h>]\n"
|
2015-07-22 20:32:54 +02:00
|
|
|
|
|
|
|
|
|
#ifndef INCLUDE_FILESYSTEM_H
|
2018-04-03 15:57:56 +02:00
|
|
|
|
#include "../lib/fs.h"
|
2015-07-22 20:32:54 +02:00
|
|
|
|
#endif
|
2015-03-09 19:51:16 +01:00
|
|
|
|
|
2021-12-25 23:43:50 +01:00
|
|
|
|
enum {
|
|
|
|
|
FILE_DEFAULT=0,
|
|
|
|
|
FILE_EXISTS,
|
|
|
|
|
FILE_REPLACE,
|
|
|
|
|
FILE_SKIP,
|
|
|
|
|
};
|
|
|
|
|
|
2021-12-31 01:03:12 +01:00
|
|
|
|
enum {
|
|
|
|
|
MODE_NORMAL,
|
|
|
|
|
MODE_FORCE
|
|
|
|
|
};
|
|
|
|
|
|
2021-12-27 22:44:46 +01:00
|
|
|
|
#define WRITE_ERROR_DEBUG 0
|
|
|
|
|
#define WRITE_ERROR_NOTIFY 1
|
|
|
|
|
:int writing_error_channel = WRITE_ERROR_DEBUG;
|
|
|
|
|
|
2021-12-25 23:43:50 +01:00
|
|
|
|
int copy_state = FILE_DEFAULT;
|
2021-12-31 01:03:12 +01:00
|
|
|
|
int saved_state = FILE_DEFAULT;
|
|
|
|
|
bool is_remember = false;
|
2021-12-25 23:43:50 +01:00
|
|
|
|
|
2013-04-04 19:07:38 +02:00
|
|
|
|
: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;
|
2015-03-09 19:51:16 +01:00
|
|
|
|
|
2013-04-04 19:07:38 +02:00
|
|
|
|
if (!from1) || (!in1)
|
|
|
|
|
{
|
2018-03-26 16:31:26 +02:00
|
|
|
|
notify("Error: too few copyf() params!");
|
2020-05-06 17:53:34 +02:00
|
|
|
|
return -1;
|
2013-04-04 19:07:38 +02:00
|
|
|
|
}
|
|
|
|
|
if (error = GetFileInfo(from1, #CopyFile_atr1))
|
|
|
|
|
{
|
2014-03-14 20:06:48 +01:00
|
|
|
|
debugln("Error: copyf->GetFileInfo");
|
2013-04-04 19:07:38 +02:00
|
|
|
|
return error;
|
|
|
|
|
}
|
2016-02-19 01:33:21 +01:00
|
|
|
|
if (dir_exists(from1))
|
2013-04-04 19:07:38 +02:00
|
|
|
|
return CopyFolder(from1, in1);
|
2013-04-02 15:33:32 +02:00
|
|
|
|
else
|
2021-12-25 23:43:50 +01:00
|
|
|
|
{
|
|
|
|
|
while(1)
|
|
|
|
|
{
|
|
|
|
|
Operation_Draw_Progress(from1+strrchr(from1, '/'));
|
|
|
|
|
if (copy_state == FILE_DEFAULT) || (copy_state == FILE_REPLACE)
|
|
|
|
|
{
|
|
|
|
|
error = CopyFile(from1, in1);
|
|
|
|
|
if (error != 222)
|
|
|
|
|
{
|
|
|
|
|
return error;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (copy_state == FILE_SKIP)
|
|
|
|
|
{
|
2021-12-31 01:03:12 +01:00
|
|
|
|
error = 0;
|
2021-12-25 23:43:50 +01:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-10-20 14:20:57 +02:00
|
|
|
|
}
|
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;
|
2021-06-17 11:29:39 +02:00
|
|
|
|
dword error;
|
2018-03-26 16:31:26 +02:00
|
|
|
|
|
2013-04-04 19:07:38 +02:00
|
|
|
|
if (error = GetFileInfo(copy_from3, #CopyFile_atr))
|
2013-08-31 20:33:48 +02:00
|
|
|
|
{
|
2014-03-14 20:06:48 +01:00
|
|
|
|
debugln("Error: CopyFile->GetFileInfo");
|
2013-08-31 20:33:48 +02:00
|
|
|
|
}
|
2018-03-26 16:31:26 +02:00
|
|
|
|
else
|
2013-03-11 19:16:24 +01:00
|
|
|
|
{
|
2021-12-25 23:43:50 +01:00
|
|
|
|
if (file_exists(copy_in3)) && (copy_state != FILE_REPLACE)
|
|
|
|
|
{
|
2021-12-31 01:03:12 +01:00
|
|
|
|
if (saved_state == FILE_DEFAULT) {
|
|
|
|
|
copy_state = FILE_EXISTS;
|
|
|
|
|
} else {
|
|
|
|
|
copy_state = saved_state;
|
|
|
|
|
}
|
2021-12-25 23:43:50 +01:00
|
|
|
|
return 222;
|
|
|
|
|
}
|
2018-03-26 16:31:26 +02:00
|
|
|
|
if (GetFreeRAM()-1024*1024 < CopyFile_atr.sizelo) //GetFreeRam-1Mb and convert to bytes
|
2013-04-02 15:33:32 +02:00
|
|
|
|
{
|
2018-03-26 16:31:26 +02:00
|
|
|
|
if (error = CopyFileByBlocks(CopyFile_atr.sizelo, copy_from3, copy_in3))
|
|
|
|
|
debugln("Error: CopyFile->CopyFileByBlocks");
|
2013-04-02 15:33:32 +02:00
|
|
|
|
}
|
2018-03-26 16:31:26 +02:00
|
|
|
|
else {
|
|
|
|
|
if (error = CopyFileAtOnce(CopyFile_atr.sizelo, copy_from3, copy_in3))
|
|
|
|
|
debugln("Error: CopyFile->CopyFileAtOnce");
|
|
|
|
|
}
|
2013-03-11 19:16:24 +01:00
|
|
|
|
}
|
2021-12-27 22:44:46 +01:00
|
|
|
|
if (error) write_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;
|
2021-12-25 23:43:50 +01:00
|
|
|
|
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
|
|
|
|
{
|
2014-03-14 20:06:48 +01:00
|
|
|
|
debugln("Error: CopyFolder->GetDir");
|
2021-12-27 22:44:46 +01:00
|
|
|
|
write_error(from2, error);
|
2013-04-02 15:33:32 +02:00
|
|
|
|
free(dirbuf);
|
2013-04-04 19:07:38 +02:00
|
|
|
|
return error;
|
2013-04-02 15:33:32 +02:00
|
|
|
|
}
|
2013-10-14 00:19:31 +02:00
|
|
|
|
|
2013-04-04 19:07:38 +02:00
|
|
|
|
if (chrnum(in2, '/')>2) && (error = CreateDir(in2))
|
2013-03-11 19:16:24 +01:00
|
|
|
|
{
|
2014-03-14 20:06:48 +01:00
|
|
|
|
debugln("Error: CopyFolder->CreateDir");
|
2021-12-27 22:44:46 +01:00
|
|
|
|
write_error(in2, error);
|
2013-04-04 19:07:38 +02:00
|
|
|
|
free(dirbuf);
|
|
|
|
|
return error;
|
2013-03-11 19:16:24 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (i=0; i<fcount; i++)
|
|
|
|
|
{
|
2021-12-25 23:43:50 +01:00
|
|
|
|
copy_state = FILE_DEFAULT;
|
2013-03-11 19:16:24 +01:00
|
|
|
|
filename = i*304+dirbuf+72;
|
2015-07-22 20:32:54 +02:00
|
|
|
|
sprintf(#copy_from2,"%s/%s",from2,filename);
|
|
|
|
|
sprintf(#copy_in2,"%s/%s",in2,filename);
|
2013-04-04 19:07:38 +02:00
|
|
|
|
|
2021-06-25 15:21:42 +02:00
|
|
|
|
if ( ESDWORD[filename-40] & ATR_FOLDER ) //dir_exists?
|
2013-03-11 19:16:24 +01:00
|
|
|
|
{
|
2015-07-22 20:32:54 +02:00
|
|
|
|
if ( (!strncmp(filename, ".",1)) || (!strncmp(filename, "..",2)) ) continue;
|
2013-04-02 15:33:32 +02:00
|
|
|
|
CopyFolder(#copy_from2, #copy_in2);
|
2013-03-11 19:16:24 +01:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2021-12-25 23:43:50 +01:00
|
|
|
|
while(1)
|
2013-04-04 19:07:38 +02:00
|
|
|
|
{
|
2021-12-25 23:43:50 +01:00
|
|
|
|
Operation_Draw_Progress(filename+strrchr(filename, '/'));
|
|
|
|
|
if (copy_state == FILE_DEFAULT) || (copy_state == FILE_REPLACE)
|
|
|
|
|
{
|
|
|
|
|
error = CopyFile(#copy_from2, #copy_in2);
|
|
|
|
|
if (error != 222)
|
|
|
|
|
{
|
|
|
|
|
if (error)
|
|
|
|
|
{
|
|
|
|
|
if (fabs(error)==8) { debugln("Stop copying."); break;} //TODO: may be need grobal var like stop_all
|
|
|
|
|
error=CopyFile(#copy_from2, #copy_in2); // #2 :)
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (copy_state == FILE_SKIP)
|
|
|
|
|
{
|
2021-12-31 01:03:12 +01:00
|
|
|
|
error = 0;
|
2021-12-25 23:43:50 +01:00
|
|
|
|
break;
|
|
|
|
|
}
|
2013-04-04 19:07:38 +02:00
|
|
|
|
}
|
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-10-14 00:19:31 +02:00
|
|
|
|
#ifdef LANG_RUS
|
2019-05-01 10:56:46 +02:00
|
|
|
|
unsigned char *ERROR_TEXT[]={
|
2013-10-14 00:19:31 +02:00
|
|
|
|
"<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-12 22:43:39 +01:00
|
|
|
|
"<EFBFBD>訡<EFBFBD><EFBFBD> #3: <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>⭠<EFBFBD> 䠩<><E4A0A9><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD>⥬<EFBFBD>",
|
2013-10-14 00:19:31 +02: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 11:48:55 +01: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 00:19:31 +02:00
|
|
|
|
"<EFBFBD>訡<EFBFBD><EFBFBD> #10: <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>饭",
|
2015-08-02 01:21:13 +02:00
|
|
|
|
"<EFBFBD>訡<EFBFBD><EFBFBD> #11: <20>訡<EFBFBD><E8A8A1> <20><><EFBFBD>ன<EFBFBD>⢠",
|
2013-10-14 00:19:31 +02:00
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0,
|
2016-11-08 11:48:55 +01:00
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0,
|
2013-10-14 00:19:31 +02: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
|
2019-05-01 10:56:46 +02:00
|
|
|
|
unsigned char *ERROR_TEXT[]={
|
2021-06-28 12:55:08 +02:00
|
|
|
|
"Code #0 - No error",
|
2013-10-14 00:19:31 +02:00
|
|
|
|
"Error #1 - Base or partition of a hard disk is not defined",
|
2021-12-27 22:44:46 +01:00
|
|
|
|
"Error #2 - Function is not supported for this file system",
|
2013-10-14 00:19:31 +02:00
|
|
|
|
"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 11:48:55 +01:00
|
|
|
|
"Error #8 - Not enough space on partition",
|
|
|
|
|
"Error #9 - File system error",
|
2013-10-14 00:19:31 +02:00
|
|
|
|
"Error #10 - Access denied",
|
|
|
|
|
"Error #11 - Device error",
|
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0,
|
2016-11-08 11:48:55 +01:00
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0,
|
2013-10-14 00:19:31 +02:00
|
|
|
|
"Error #30 - Not enough memory",
|
|
|
|
|
"Error #31 - File is not executable",
|
|
|
|
|
"Error #32 - Too many processes", 0};
|
|
|
|
|
#endif
|
2013-03-11 19:16:24 +01:00
|
|
|
|
|
2021-12-27 22:44:46 +01:00
|
|
|
|
:dword get_error(int error_number)
|
2013-03-11 19:16:24 +01:00
|
|
|
|
{
|
2021-12-27 22:44:46 +01:00
|
|
|
|
char error_message[256];
|
|
|
|
|
error_number = fabs(error_number);
|
|
|
|
|
if (error_number<=33) {
|
|
|
|
|
strcpy(#error_message, ERROR_TEXT[error_number]);
|
|
|
|
|
} else {
|
|
|
|
|
miniprintf(#error_message,"%i - Unknown error number O_o",error_number);
|
|
|
|
|
}
|
|
|
|
|
return #error_message;
|
2013-03-11 19:16:24 +01:00
|
|
|
|
}
|
2013-03-31 22:25:54 +02:00
|
|
|
|
|
2021-12-27 22:44:46 +01:00
|
|
|
|
:void write_error(dword path, error_number)
|
2013-03-31 22:25:54 +02:00
|
|
|
|
{
|
2021-12-27 22:44:46 +01:00
|
|
|
|
char notify_message[100];
|
2014-03-14 20:06:48 +01:00
|
|
|
|
if (path) debugln(path);
|
|
|
|
|
debugln(get_error(error_number));
|
2021-12-27 22:44:46 +01:00
|
|
|
|
if (writing_error_channel == WRITE_ERROR_NOTIFY) {
|
|
|
|
|
miniprintf(#notify_message, "'%s' -E", get_error(error_number));
|
|
|
|
|
notify(#notify_message);
|
|
|
|
|
}
|
2015-07-22 20:32:54 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif
|