//copyf - copy file or folder with content #ifndef INCLUDE_COPYF_H #define INCLUDE_COPYF_H #print "[include ]\n" #ifndef INCLUDE_FILESYSTEM_H #include "../lib/fs.h" #endif enum { FILE_DEFAULT=0, FILE_EXISTS, FILE_REPLACE, FILE_SKIP, }; enum { MODE_NORMAL, MODE_FORCE }; #define WRITE_ERROR_DEBUG 0 #define WRITE_ERROR_NOTIFY 1 :int writing_error_channel = WRITE_ERROR_DEBUG; int copy_state = FILE_DEFAULT; int saved_state = FILE_DEFAULT; bool is_remember = false; :int copyf(dword from1, in1) { dword error; BDVK CopyFile_atr1; if (!from1) || (!in1) { notify("Error: too few copyf() params!"); return -1; } if (error = GetFileInfo(from1, #CopyFile_atr1)) { debugln("Error: copyf->GetFileInfo"); return error; } if (dir_exists(from1)) return CopyFolder(from1, in1); else { 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) { error = 0; return 0; } } } } :int CopyFile(dword copy_from3, copy_in3) { BDVK CopyFile_atr; dword error; if (error = GetFileInfo(copy_from3, #CopyFile_atr)) { debugln("Error: CopyFile->GetFileInfo"); } else { if (file_exists(copy_in3)) && (copy_state != FILE_REPLACE) { if (saved_state == FILE_DEFAULT) { copy_state = FILE_EXISTS; } else { copy_state = saved_state; } return 222; } if (GetFreeRAM()-1024*1024 < CopyFile_atr.sizelo) //GetFreeRam-1Mb and convert to bytes { if (error = CopyFileByBlocks(CopyFile_atr.sizelo, copy_from3, copy_in3)) debugln("Error: CopyFile->CopyFileByBlocks"); } else { if (error = CopyFileAtOnce(CopyFile_atr.sizelo, copy_from3, copy_in3)) debugln("Error: CopyFile->CopyFileAtOnce"); } } if (error) write_error(copy_from3, error); return error; } :int CopyFolder(dword from2, in2) { dword dirbuf, fcount, i, filename; char copy_from2[4096], copy_in2[4096], error; if (error = GetDir(#dirbuf, #fcount, from2, DIRS_ONLYREAL)) { debugln("Error: CopyFolder->GetDir"); write_error(from2, error); free(dirbuf); return error; } if (chrnum(in2, '/')>2) && (error = CreateDir(in2)) { debugln("Error: CopyFolder->CreateDir"); write_error(in2, error); free(dirbuf); return error; } for (i=0; i