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