Rev 7878 | Rev 8944 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 7878 | Rev 8868 | ||
---|---|---|---|
1 | //copyf - copy file or folder with content |
1 | //copyf - copy file or folder with content |
2 | #ifndef INCLUDE_COPYF_H |
2 | #ifndef INCLUDE_COPYF_H |
3 | #define INCLUDE_COPYF_H |
3 | #define INCLUDE_COPYF_H |
4 | #print "[include |
4 | #print "[include |
5 | 5 | ||
6 | #ifndef INCLUDE_FILESYSTEM_H |
6 | #ifndef INCLUDE_FILESYSTEM_H |
7 | #include "../lib/fs.h" |
7 | #include "../lib/fs.h" |
8 | #endif |
8 | #endif |
9 | 9 | ||
10 | :int copyf(dword from1, in1) |
10 | :int copyf(dword from1, in1) |
11 | { |
11 | { |
12 | dword error; |
12 | dword error; |
13 | BDVK CopyFile_atr1; |
13 | BDVK CopyFile_atr1; |
14 | 14 | ||
15 | if (!from1) || (!in1) |
15 | if (!from1) || (!in1) |
16 | { |
16 | { |
17 | notify("Error: too few copyf() params!"); |
17 | notify("Error: too few copyf() params!"); |
18 | return -1; |
18 | return -1; |
19 | } |
19 | } |
20 | if (error = GetFileInfo(from1, #CopyFile_atr1)) |
20 | if (error = GetFileInfo(from1, #CopyFile_atr1)) |
21 | { |
21 | { |
22 | debugln("Error: copyf->GetFileInfo"); |
22 | debugln("Error: copyf->GetFileInfo"); |
23 | return error; |
23 | return error; |
24 | } |
24 | } |
25 | if (dir_exists(from1)) |
25 | if (dir_exists(from1)) |
26 | return CopyFolder(from1, in1); |
26 | return CopyFolder(from1, in1); |
27 | else |
27 | else |
28 | { |
28 | { |
29 | Operation_Draw_Progress(from1+strrchr(from1, '/')); |
29 | Operation_Draw_Progress(from1+strrchr(from1, '/')); |
30 | return CopyFile(from1, in1); |
30 | return CopyFile(from1, in1); |
31 | } |
31 | } |
32 | } |
32 | } |
33 | 33 | ||
34 | :int CopyFile(dword copy_from3, copy_in3) |
34 | :int CopyFile(dword copy_from3, copy_in3) |
35 | { |
35 | { |
36 | BDVK CopyFile_atr; |
36 | BDVK CopyFile_atr; |
37 | dword error, cbuf; |
- | |
38 | dword block; |
37 | dword error; |
39 | 38 | ||
40 | if (error = GetFileInfo(copy_from3, #CopyFile_atr)) |
39 | if (error = GetFileInfo(copy_from3, #CopyFile_atr)) |
41 | { |
40 | { |
42 | debugln("Error: CopyFile->GetFileInfo"); |
41 | debugln("Error: CopyFile->GetFileInfo"); |
43 | } |
42 | } |
44 | else |
43 | else |
45 | { |
44 | { |
46 | if (GetFreeRAM()-1024*1024 < CopyFile_atr.sizelo) //GetFreeRam-1Mb and convert to bytes |
45 | if (GetFreeRAM()-1024*1024 < CopyFile_atr.sizelo) //GetFreeRam-1Mb and convert to bytes |
47 | { |
46 | { |
48 | if (error = CopyFileByBlocks(CopyFile_atr.sizelo, copy_from3, copy_in3)) |
47 | if (error = CopyFileByBlocks(CopyFile_atr.sizelo, copy_from3, copy_in3)) |
49 | debugln("Error: CopyFile->CopyFileByBlocks"); |
48 | debugln("Error: CopyFile->CopyFileByBlocks"); |
50 | } |
49 | } |
51 | else { |
50 | else { |
52 | if (error = CopyFileAtOnce(CopyFile_atr.sizelo, copy_from3, copy_in3)) |
51 | if (error = CopyFileAtOnce(CopyFile_atr.sizelo, copy_from3, copy_in3)) |
53 | debugln("Error: CopyFile->CopyFileAtOnce"); |
52 | debugln("Error: CopyFile->CopyFileAtOnce"); |
54 | } |
53 | } |
55 | } |
54 | } |
56 | if (error) debug_error(copy_from3, error); |
55 | if (error) debug_error(copy_from3, error); |
57 | return error; |
56 | return error; |
58 | } |
57 | } |
59 | 58 | ||
60 | :int CopyFolder(dword from2, in2) |
59 | :int CopyFolder(dword from2, in2) |
61 | { |
60 | { |
62 | dword dirbuf, fcount, i, filename; |
61 | dword dirbuf, fcount, i, filename; |
63 | char copy_from2[4096], copy_in2[4096], error; |
62 | char copy_from2[4096], copy_in2[4096], error; |
64 | 63 | ||
65 | if (error = GetDir(#dirbuf, #fcount, from2, DIRS_ONLYREAL)) |
64 | if (error = GetDir(#dirbuf, #fcount, from2, DIRS_ONLYREAL)) |
66 | { |
65 | { |
67 | debugln("Error: CopyFolder->GetDir"); |
66 | debugln("Error: CopyFolder->GetDir"); |
68 | debug_error(from2, error); |
67 | debug_error(from2, error); |
69 | free(dirbuf); |
68 | free(dirbuf); |
70 | return error; |
69 | return error; |
71 | } |
70 | } |
72 | 71 | ||
73 | if (chrnum(in2, '/')>2) && (error = CreateDir(in2)) |
72 | if (chrnum(in2, '/')>2) && (error = CreateDir(in2)) |
74 | { |
73 | { |
75 | debugln("Error: CopyFolder->CreateDir"); |
74 | debugln("Error: CopyFolder->CreateDir"); |
76 | debug_error(in2, error); |
75 | debug_error(in2, error); |
77 | free(dirbuf); |
76 | free(dirbuf); |
78 | return error; |
77 | return error; |
79 | } |
78 | } |
80 | 79 | ||
81 | for (i=0; i |
80 | for (i=0; i |
82 | { |
81 | { |
83 | filename = i*304+dirbuf+72; |
82 | filename = i*304+dirbuf+72; |
84 | sprintf(#copy_from2,"%s/%s",from2,filename); |
83 | sprintf(#copy_from2,"%s/%s",from2,filename); |
85 | sprintf(#copy_in2,"%s/%s",in2,filename); |
84 | sprintf(#copy_in2,"%s/%s",in2,filename); |
86 | 85 | ||
87 | if ( TestBit(ESDWORD[filename-40], 4) ) //dir_exists? |
86 | if ( TestBit(ESDWORD[filename-40], 4) ) //dir_exists? |
88 | { |
87 | { |
89 | if ( (!strncmp(filename, ".",1)) || (!strncmp(filename, "..",2)) ) continue; |
88 | if ( (!strncmp(filename, ".",1)) || (!strncmp(filename, "..",2)) ) continue; |
90 | CopyFolder(#copy_from2, #copy_in2); |
89 | CopyFolder(#copy_from2, #copy_in2); |
91 | } |
90 | } |
92 | else |
91 | else |
93 | { |
92 | { |
94 | Operation_Draw_Progress(filename+strrchr(filename, '/')); |
93 | Operation_Draw_Progress(filename+strrchr(filename, '/')); |
95 | if (error=CopyFile(#copy_from2, #copy_in2)) |
94 | if (error=CopyFile(#copy_from2, #copy_in2)) |
96 | { |
95 | { |
97 | if (fabs(error)==8) { debugln("Stop copying."); break;} //TODO: may be need grobal var like stop_all |
96 | if (fabs(error)==8) { debugln("Stop copying."); break;} //TODO: may be need grobal var like stop_all |
98 | error=CopyFile(#copy_from2, #copy_in2); // #2 :) |
97 | error=CopyFile(#copy_from2, #copy_in2); // #2 :) |
99 | } |
98 | } |
100 | } |
99 | } |
101 | } |
100 | } |
102 | free(dirbuf); |
101 | free(dirbuf); |
103 | return error; |
102 | return error; |
104 | } |
103 | } |
105 | 104 | ||
106 | #ifdef LANG_RUS |
105 | #ifdef LANG_RUS |
107 | unsigned char *ERROR_TEXT[]={ |
106 | unsigned char *ERROR_TEXT[]={ |
108 | "®¤ #0: ãᯥè®", |
107 | "®¤ #0: ãᯥè®", |
109 | "訡ª #1: ¥ ®¯à¥¤¥«¥ ¡ § ¨/¨«¨ à §¤¥« ¦ñá⪮£® ¤¨áª ", |
108 | "訡ª #1: ¥ ®¯à¥¤¥«¥ ¡ § ¨/¨«¨ à §¤¥« ¦ñá⪮£® ¤¨áª ", |
110 | "訡ª #2: äãªæ¨ï ¥ ¯®¤¤¥à¦¨¢ ¥âáï ¤«ï í⮩ ä ©«®¢®© á¨á⥬ë", |
109 | "訡ª #2: äãªæ¨ï ¥ ¯®¤¤¥à¦¨¢ ¥âáï ¤«ï í⮩ ä ©«®¢®© á¨á⥬ë", |
111 | "訡ª #3: ¥¨§¢¥áâ ï ä ©«®¢ ï á¨á⥬ ", |
110 | "訡ª #3: ¥¨§¢¥áâ ï ä ©«®¢ ï á¨á⥬ ", |
112 | 0, |
111 | 0, |
113 | "訡ª #5: ä ©« ¨«¨ ¯ ¯ª ¥ ©¤¥ë", |
112 | "訡ª #5: ä ©« ¨«¨ ¯ ¯ª ¥ ©¤¥ë", |
114 | "訡ª #6: ª®¥æ ä ©« ", |
113 | "訡ª #6: ª®¥æ ä ©« ", |
115 | "訡ª #7: 㪠§ ⥫ì 室¨âáï ¢á¥ ¯ ¬ï⨠¯à¨«®¦¥¨ï", |
114 | "訡ª #7: 㪠§ ⥫ì 室¨âáï ¢á¥ ¯ ¬ï⨠¯à¨«®¦¥¨ï", |
116 | "訡ª #8: ¥¤®áâ â®ç® ¬¥áâ à §¤¥«¥", |
115 | "訡ª #8: ¥¤®áâ â®ç® ¬¥áâ à §¤¥«¥", |
117 | "訡ª #9: ®è¨¡ª ä ©«®¢®© á¨á⥬ë", |
116 | "訡ª #9: ®è¨¡ª ä ©«®¢®© á¨á⥬ë", |
118 | "訡ª #10: ¤®áâ㯠§ ¯à¥é¥", |
117 | "訡ª #10: ¤®áâ㯠§ ¯à¥é¥", |
119 | "訡ª #11: ®è¨¡ª ãáâனá⢠", |
118 | "訡ª #11: ®è¨¡ª ãáâனá⢠", |
120 | 0, 0, 0, 0, 0, 0, 0, 0, 0, |
119 | 0, 0, 0, 0, 0, 0, 0, 0, 0, |
121 | 0, 0, 0, 0, 0, 0, 0, 0, 0, |
120 | 0, 0, 0, 0, 0, 0, 0, 0, 0, |
122 | "訡ª #30: ¥¤®áâ â®ç® ¯ ¬ïâ¨", |
121 | "訡ª #30: ¥¤®áâ â®ç® ¯ ¬ïâ¨", |
123 | "訡ª #31: ä ©« ¥ ï¥âáï ¨á¯®«ï¥¬ë¬", |
122 | "訡ª #31: ä ©« ¥ ï¥âáï ¨á¯®«ï¥¬ë¬", |
124 | "訡ª #32: ᫨誮¬ ¬®£® ¯à®æ¥áᮢ", 0}; |
123 | "訡ª #32: ᫨誮¬ ¬®£® ¯à®æ¥áᮢ", 0}; |
125 | #else |
124 | #else |
126 | unsigned char *ERROR_TEXT[]={ |
125 | unsigned char *ERROR_TEXT[]={ |
127 | "Code #0 - No error, compleated successfully", |
126 | "Code #0 - No error, compleated successfully", |
128 | "Error #1 - Base or partition of a hard disk is not defined", |
127 | "Error #1 - Base or partition of a hard disk is not defined", |
129 | "Error #2 - Function isn't supported for this file system", |
128 | "Error #2 - Function isn't supported for this file system", |
130 | "Error #3 - Unknown file system", |
129 | "Error #3 - Unknown file system", |
131 | 0, |
130 | 0, |
132 | "Error #5 - File or folder not found", |
131 | "Error #5 - File or folder not found", |
133 | "Error #6 - End of file", |
132 | "Error #6 - End of file", |
134 | "Error #7 - Pointer lies outside of application memory", |
133 | "Error #7 - Pointer lies outside of application memory", |
135 | "Error #8 - Not enough space on partition", |
134 | "Error #8 - Not enough space on partition", |
136 | "Error #9 - File system error", |
135 | "Error #9 - File system error", |
137 | "Error #10 - Access denied", |
136 | "Error #10 - Access denied", |
138 | "Error #11 - Device error", |
137 | "Error #11 - Device error", |
139 | 0, 0, 0, 0, 0, 0, 0, 0, 0, |
138 | 0, 0, 0, 0, 0, 0, 0, 0, 0, |
140 | 0, 0, 0, 0, 0, 0, 0, 0, 0, |
139 | 0, 0, 0, 0, 0, 0, 0, 0, 0, |
141 | "Error #30 - Not enough memory", |
140 | "Error #30 - Not enough memory", |
142 | "Error #31 - File is not executable", |
141 | "Error #31 - File is not executable", |
143 | "Error #32 - Too many processes", 0}; |
142 | "Error #32 - Too many processes", 0}; |
144 | #endif |
143 | #endif |
145 | 144 | ||
146 | :dword get_error(int N) |
145 | :dword get_error(int N) |
147 | { |
146 | { |
148 | char error[256]; |
147 | char error[256]; |
149 | N = fabs(N); |
148 | N = fabs(N); |
150 | if (N<=33) strcpy(#error, ERROR_TEXT[N]); |
149 | if (N<=33) strcpy(#error, ERROR_TEXT[N]); |
151 | else sprintf(#error,"%d%s",N," - Unknown error number O_o"); |
150 | else sprintf(#error,"%d%s",N," - Unknown error number O_o"); |
152 | return #error; |
151 | return #error; |
153 | } |
152 | } |
154 | 153 | ||
155 | :void debug_error(dword path, error_number) |
154 | :void debug_error(dword path, error_number) |
156 | { |
155 | { |
157 | if (path) debugln(path); |
156 | if (path) debugln(path); |
158 | debugln(get_error(error_number)); |
157 | debugln(get_error(error_number)); |
159 | } |
158 | } |
160 | 159 | ||
161 | #endif=33)>> |
160 | #endif=33)>> |