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