Rev 7227 | Rev 7362 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 7227 | Rev 7331 | ||
---|---|---|---|
1 | #ifndef INCLUDE_FILESYSTEM_H |
1 | #ifndef INCLUDE_FILESYSTEM_H |
2 | #define INCLUDE_FILESYSTEM_H |
2 | #define INCLUDE_FILESYSTEM_H |
3 | #print "[include |
3 | #print "[include |
4 | 4 | ||
5 | #ifndef INCLUDE_DATE_H |
5 | #ifndef INCLUDE_DATE_H |
6 | #include "../lib/date.h" |
6 | #include "../lib/date.h" |
7 | #endif |
7 | #endif |
8 | 8 | ||
9 | :struct f70{ |
9 | :struct f70{ |
10 | dword func; |
10 | dword func; |
11 | dword param1; |
11 | dword param1; |
12 | dword param2; |
12 | dword param2; |
13 | dword param3; |
13 | dword param3; |
14 | dword param4; |
14 | dword param4; |
15 | char rezerv; |
15 | char rezerv; |
16 | dword name; |
16 | dword name; |
17 | }; |
17 | }; |
18 | 18 | ||
19 | :struct BDVK { |
19 | :struct BDVK { |
20 | dword readonly:1, hidden:1, system:1, volume_label:1, isfolder:1, notarchived:1, :0; |
20 | dword readonly:1, hidden:1, system:1, volume_label:1, isfolder:1, notarchived:1, :0; |
21 | byte type_name; |
21 | byte type_name; |
22 | byte rez1, rez2, selected; |
22 | byte rez1, rez2, selected; |
23 | dword timecreate; |
23 | dword timecreate; |
24 | date datecreate; |
24 | date datecreate; |
25 | dword timelastaccess; |
25 | dword timelastaccess; |
26 | date datelastaccess; |
26 | date datelastaccess; |
27 | dword timelastedit; |
27 | dword timelastedit; |
28 | date datelastedit; |
28 | date datelastedit; |
29 | dword sizelo; |
29 | dword sizelo; |
30 | dword sizehi; |
30 | dword sizehi; |
31 | char name[518]; |
31 | char name[518]; |
32 | }; |
32 | }; |
33 | 33 | ||
34 | 34 | ||
35 | 35 | ||
36 | :f70 getinfo_file_70; |
36 | :f70 getinfo_file_70; |
37 | :dword GetFileInfo(dword file_path, bdvk_struct) |
37 | :dword GetFileInfo(dword file_path, bdvk_struct) |
38 | { |
38 | { |
39 | getinfo_file_70.func = 5; |
39 | getinfo_file_70.func = 5; |
40 | getinfo_file_70.param1 = |
40 | getinfo_file_70.param1 = |
41 | getinfo_file_70.param2 = |
41 | getinfo_file_70.param2 = |
42 | getinfo_file_70.param3 = 0; |
42 | getinfo_file_70.param3 = 0; |
43 | getinfo_file_70.param4 = bdvk_struct; |
43 | getinfo_file_70.param4 = bdvk_struct; |
44 | getinfo_file_70.rezerv = 0; |
44 | getinfo_file_70.rezerv = 0; |
45 | getinfo_file_70.name = file_path; |
45 | getinfo_file_70.name = file_path; |
46 | $mov eax,70 |
46 | $mov eax,70 |
47 | $mov ebx,#getinfo_file_70.func |
47 | $mov ebx,#getinfo_file_70.func |
48 | $int 0x40 |
48 | $int 0x40 |
49 | } |
49 | } |
50 | 50 | ||
51 | :f70 setinfo_file_70; |
51 | :f70 setinfo_file_70; |
52 | :dword SetFileInfo(dword file_path, bdvk_struct) |
52 | :dword SetFileInfo(dword file_path, bdvk_struct) |
53 | { |
53 | { |
54 | setinfo_file_70.func = 6; |
54 | setinfo_file_70.func = 6; |
55 | setinfo_file_70.param1 = |
55 | setinfo_file_70.param1 = |
56 | setinfo_file_70.param2 = |
56 | setinfo_file_70.param2 = |
57 | setinfo_file_70.param3 = 0; |
57 | setinfo_file_70.param3 = 0; |
58 | setinfo_file_70.param4 = bdvk_struct; |
58 | setinfo_file_70.param4 = bdvk_struct; |
59 | setinfo_file_70.rezerv = 0; |
59 | setinfo_file_70.rezerv = 0; |
60 | setinfo_file_70.name = file_path; |
60 | setinfo_file_70.name = file_path; |
61 | $mov eax,70 |
61 | $mov eax,70 |
62 | $mov ebx,#setinfo_file_70.func |
62 | $mov ebx,#setinfo_file_70.func |
63 | $int 0x40 |
63 | $int 0x40 |
64 | } |
64 | } |
65 | 65 | ||
66 | :f70 run_file_70; |
66 | :f70 run_file_70; |
67 | :signed int RunProgram(dword run_path, run_param) |
67 | :signed int RunProgram(dword run_path, run_param) |
68 | { |
68 | { |
69 | run_file_70.func = 7; |
69 | run_file_70.func = 7; |
70 | run_file_70.param1 = |
70 | run_file_70.param1 = |
71 | run_file_70.param3 = |
71 | run_file_70.param3 = |
72 | run_file_70.param4 = |
72 | run_file_70.param4 = |
73 | run_file_70.rezerv = 0; |
73 | run_file_70.rezerv = 0; |
74 | run_file_70.param2 = run_param; |
74 | run_file_70.param2 = run_param; |
75 | run_file_70.name = run_path; |
75 | run_file_70.name = run_path; |
76 | $mov eax,70 |
76 | $mov eax,70 |
77 | $mov ebx,#run_file_70.func |
77 | $mov ebx,#run_file_70.func |
78 | $int 0x40 |
78 | $int 0x40 |
79 | } |
79 | } |
80 | 80 | ||
81 | :f70 create_dir_70; |
81 | :f70 create_dir_70; |
82 | :int CreateDir(dword new_folder_path) |
82 | :int CreateDir(dword new_folder_path) |
83 | { |
83 | { |
84 | create_dir_70.func = 9; |
84 | create_dir_70.func = 9; |
85 | create_dir_70.param1 = |
85 | create_dir_70.param1 = |
86 | create_dir_70.param2 = |
86 | create_dir_70.param2 = |
87 | create_dir_70.param3 = |
87 | create_dir_70.param3 = |
88 | create_dir_70.param4 = |
88 | create_dir_70.param4 = |
89 | create_dir_70.rezerv = 0; |
89 | create_dir_70.rezerv = 0; |
90 | create_dir_70.name = new_folder_path; |
90 | create_dir_70.name = new_folder_path; |
91 | $mov eax,70 |
91 | $mov eax,70 |
92 | $mov ebx,#create_dir_70.func |
92 | $mov ebx,#create_dir_70.func |
93 | $int 0x40 |
93 | $int 0x40 |
94 | } |
94 | } |
95 | 95 | ||
96 | :f70 del_file_70; |
96 | :f70 del_file_70; |
97 | :int DeleteFile(dword del_file_path) |
97 | :int DeleteFile(dword del_file_path) |
98 | { |
98 | { |
99 | del_file_70.func = 8; |
99 | del_file_70.func = 8; |
100 | del_file_70.param1 = |
100 | del_file_70.param1 = |
101 | del_file_70.param2 = |
101 | del_file_70.param2 = |
102 | del_file_70.param3 = |
102 | del_file_70.param3 = |
103 | del_file_70.param4 = |
103 | del_file_70.param4 = |
104 | del_file_70.rezerv = 0; |
104 | del_file_70.rezerv = 0; |
105 | del_file_70.name = del_file_path; |
105 | del_file_70.name = del_file_path; |
106 | $mov eax,70 |
106 | $mov eax,70 |
107 | $mov ebx,#del_file_70.func |
107 | $mov ebx,#del_file_70.func |
108 | $int 0x40 |
108 | $int 0x40 |
109 | } |
109 | } |
110 | 110 | ||
111 | :f70 read_file_70; |
111 | :f70 read_file_70; |
112 | :int ReadFile(dword offset, data_size, buffer, file_path) |
112 | :int ReadFile(dword offset, data_size, buffer, file_path) |
113 | { |
113 | { |
114 | read_file_70.func = 0; |
114 | read_file_70.func = 0; |
115 | read_file_70.param1 = offset; |
115 | read_file_70.param1 = offset; |
116 | read_file_70.param2 = 0; |
116 | read_file_70.param2 = 0; |
117 | read_file_70.param3 = data_size; |
117 | read_file_70.param3 = data_size; |
118 | read_file_70.param4 = buffer; |
118 | read_file_70.param4 = buffer; |
119 | read_file_70.rezerv = 0; |
119 | read_file_70.rezerv = 0; |
120 | read_file_70.name = file_path; |
120 | read_file_70.name = file_path; |
121 | $mov eax,70 |
121 | $mov eax,70 |
122 | $mov ebx,#read_file_70.func |
122 | $mov ebx,#read_file_70.func |
123 | $int 0x40 |
123 | $int 0x40 |
124 | } |
124 | } |
125 | 125 | ||
126 | :f70 write_file_70; |
126 | :f70 write_file_70; |
127 | :int CreateFile(dword data_size, buffer, file_path) |
127 | :int CreateFile(dword data_size, buffer, file_path) |
128 | { |
128 | { |
129 | write_file_70.func = 2; |
129 | write_file_70.func = 2; |
130 | write_file_70.param1 = 0; |
130 | write_file_70.param1 = 0; |
131 | write_file_70.param2 = 0; |
131 | write_file_70.param2 = 0; |
132 | write_file_70.param3 = data_size; |
132 | write_file_70.param3 = data_size; |
133 | write_file_70.param4 = buffer; |
133 | write_file_70.param4 = buffer; |
134 | write_file_70.rezerv = 0; |
134 | write_file_70.rezerv = 0; |
135 | write_file_70.name = file_path; |
135 | write_file_70.name = file_path; |
136 | $mov eax,70 |
136 | $mov eax,70 |
137 | $mov ebx,#write_file_70.func |
137 | $mov ebx,#write_file_70.func |
138 | $int 0x40 |
138 | $int 0x40 |
139 | } |
139 | } |
140 | 140 | ||
141 | //////////////////////////////////////// |
141 | //////////////////////////////////////// |
142 | // WriteInFileThatAlredyExists // |
142 | // WriteInFileThatAlredyExists // |
143 | //////////////////////////////////////// |
143 | //////////////////////////////////////// |
144 | :f70 write_file_offset_70; |
144 | :f70 write_file_offset_70; |
145 | :int WriteFile(dword offset, data_size, buffer, file_path) |
145 | :int WriteFile(dword offset, data_size, buffer, file_path) |
146 | { |
146 | { |
147 | write_file_offset_70.func = 3; |
147 | write_file_offset_70.func = 3; |
148 | write_file_offset_70.param1 = offset; |
148 | write_file_offset_70.param1 = offset; |
149 | write_file_offset_70.param2 = 0; |
149 | write_file_offset_70.param2 = 0; |
150 | write_file_offset_70.param3 = data_size; |
150 | write_file_offset_70.param3 = data_size; |
151 | write_file_offset_70.param4 = buffer; |
151 | write_file_offset_70.param4 = buffer; |
152 | write_file_offset_70.rezerv = 0; |
152 | write_file_offset_70.rezerv = 0; |
153 | write_file_offset_70.name = file_path; |
153 | write_file_offset_70.name = file_path; |
154 | $mov eax,70 |
154 | $mov eax,70 |
155 | $mov ebx,#write_file_offset_70.func |
155 | $mov ebx,#write_file_offset_70.func |
156 | $int 0x40 |
156 | $int 0x40 |
157 | } |
157 | } |
158 | 158 | ||
159 | 159 | ||
160 | :f70 read_dir_70; |
160 | :f70 read_dir_70; |
161 | :int ReadDir(dword file_count, read_buffer, dir_path) |
161 | :int ReadDir(dword file_count, read_buffer, dir_path) |
162 | { |
162 | { |
163 | read_dir_70.func = 1; |
163 | read_dir_70.func = 1; |
164 | read_dir_70.param1 = |
164 | read_dir_70.param1 = |
165 | read_dir_70.param2 = |
165 | read_dir_70.param2 = |
166 | read_dir_70.rezerv = 0; |
166 | read_dir_70.rezerv = 0; |
167 | read_dir_70.param3 = file_count; |
167 | read_dir_70.param3 = file_count; |
168 | read_dir_70.param4 = read_buffer; |
168 | read_dir_70.param4 = read_buffer; |
169 | read_dir_70.name = dir_path; |
169 | read_dir_70.name = dir_path; |
170 | $mov eax,70 |
170 | $mov eax,70 |
171 | $mov ebx,#read_dir_70.func |
171 | $mov ebx,#read_dir_70.func |
172 | $int 0x40 |
172 | $int 0x40 |
173 | } |
173 | } |
174 | 174 | ||
175 | :bool dir_exists(dword fpath) |
175 | :bool dir_exists(dword fpath) |
176 | { |
176 | { |
177 | char buf[32]; |
177 | char buf[32]; |
178 | if (!ReadDir(0, #buf, fpath)) return true; |
178 | if (!ReadDir(0, #buf, fpath)) return true; |
179 | return false; |
179 | return false; |
180 | } |
180 | } |
181 | 181 | ||
182 | /* |
182 | /* |
183 | 183 | ||
184 | // This implementation of dir_exists() is faster than |
184 | // This implementation of dir_exists() is faster than |
185 | // previous but here virtual folders like |
185 | // previous but here virtual folders like |
186 | // '/' and '/tmp' are not recognised as FOLDERS |
186 | // '/' and '/tmp' are not recognised as FOLDERS |
187 | // by GetFileInfo() => BDVK.isfolder attribute :( |
187 | // by GetFileInfo() => BDVK.isfolder attribute :( |
188 | 188 | ||
189 | :bool dir_exists(dword fpath) |
189 | :bool dir_exists(dword fpath) |
190 | { |
190 | { |
191 | BDVK fpath_atr; |
191 | BDVK fpath_atr; |
192 | if (GetFileInfo(fpath, #fpath_atr) != 0) return false; |
192 | if (GetFileInfo(fpath, #fpath_atr) != 0) return false; |
193 | return fpath_atr.isfolder; |
193 | return fpath_atr.isfolder; |
194 | } |
194 | } |
195 | */ |
195 | */ |
196 | 196 | ||
197 | 197 | ||
198 | :bool file_exists(dword fpath) |
198 | :bool file_exists(dword fpath) |
199 | { |
199 | { |
200 | BDVK ReadFile_atr; |
200 | BDVK ReadFile_atr; |
201 | if (! GetFileInfo(fpath, #ReadFile_atr)) return true; |
201 | if (! GetFileInfo(fpath, #ReadFile_atr)) return true; |
202 | return false; |
202 | return false; |
203 | } |
203 | } |
204 | 204 | ||
205 | - | ||
206 | :int GetFile(dword buf, filesize, read_path) |
- | |
207 | { |
- | |
208 | int return_val = 0; |
- | |
209 | BDVK ReadFile_atr; |
- | |
210 | dword rBuf; |
- | |
211 | if (! GetFileInfo(read_path, #ReadFile_atr)) |
- | |
212 | { |
- | |
213 | rBuf = malloc(ReadFile_atr.sizelo); |
- | |
214 | if (! ReadFile(0, ReadFile_atr.sizelo, rBuf, read_path)) |
- | |
215 | { |
- | |
216 | ESDWORD[buf] = rBuf; |
- | |
217 | ESDWORD[filesize] = ReadFile_atr.sizelo; |
- | |
218 | return_val = 1; |
- | |
219 | } |
- | |
220 | } |
- | |
221 | free(rBuf); |
- | |
222 | return return_val; |
- | |
223 | } |
- | |
224 | 205 | ||
225 | enum |
206 | enum |
226 | { |
207 | { |
227 | DIRS_ALL, |
208 | DIRS_ALL, |
228 | DIRS_NOROOT, |
209 | DIRS_NOROOT, |
229 | DIRS_ONLYREAL |
210 | DIRS_ONLYREAL |
230 | }; |
211 | }; |
231 | :int GetDir(dword dir_buf, file_count, path, doptions) |
212 | :int GetDir(dword dir_buf, file_count, path, doptions) |
232 | { |
213 | { |
233 | dword buf, fcount, error; |
214 | dword buf, fcount, error; |
234 | buf = malloc(32); |
215 | buf = malloc(32); |
235 | error = ReadDir(0, buf, path); |
216 | error = ReadDir(0, buf, path); |
236 | if (!error) |
217 | if (!error) |
237 | { |
218 | { |
238 | fcount = ESDWORD[buf+8]; |
219 | fcount = ESDWORD[buf+8]; |
239 | buf = realloc(buf, fcount+1*304+32); |
220 | buf = realloc(buf, fcount+1*304+32); |
240 | ReadDir(fcount, buf, path); |
221 | ReadDir(fcount, buf, path); |
241 | //fcount=EBX; |
222 | //fcount=EBX; |
242 | 223 | ||
243 | if (doptions == DIRS_ONLYREAL) |
224 | if (doptions == DIRS_ONLYREAL) |
244 | { |
225 | { |
245 | if (!strcmp(".",buf+72)) {fcount--; memmov(buf,buf+304,fcount*304);} |
226 | if (!strcmp(".",buf+72)) {fcount--; memmov(buf,buf+304,fcount*304);} |
246 | if (!strcmp("..",buf+72)) {fcount--; memmov(buf,buf+304,fcount*304);} |
227 | if (!strcmp("..",buf+72)) {fcount--; memmov(buf,buf+304,fcount*304);} |
247 | } |
228 | } |
248 | if (doptions == DIRS_NOROOT) |
229 | if (doptions == DIRS_NOROOT) |
249 | { |
230 | { |
250 | if (!strcmp(".",buf+72)) {fcount--; memmov(buf,buf+304,fcount*304);} |
231 | if (!strcmp(".",buf+72)) {fcount--; memmov(buf,buf+304,fcount*304);} |
251 | } |
232 | } |
252 | 233 | ||
253 | ESDWORD[dir_buf] = buf; |
234 | ESDWORD[dir_buf] = buf; |
254 | ESDWORD[file_count] = fcount; |
235 | ESDWORD[file_count] = fcount; |
255 | } |
236 | } |
256 | else |
237 | else |
257 | { |
238 | { |
258 | ESDWORD[file_count] = 0; |
239 | ESDWORD[file_count] = 0; |
259 | ESDWORD[dir_buf] = free(buf); |
240 | ESDWORD[dir_buf] = free(buf); |
260 | } |
241 | } |
261 | return error; |
242 | return error; |
262 | } |
243 | } |
263 | 244 | ||
264 | :dword abspath(dword relative_path) //GetAbsolutePathFromRelative() |
245 | :dword abspath(dword relative_path) //GetAbsolutePathFromRelative() |
265 | { |
246 | { |
266 | char absolute_path[4096]; |
247 | char absolute_path[4096]; |
267 | if (ESBYTE[relative_path]=='/') |
248 | if (ESBYTE[relative_path]=='/') |
268 | { |
249 | { |
269 | strcpy(#absolute_path, relative_path); |
250 | strcpy(#absolute_path, relative_path); |
270 | } |
251 | } |
271 | else |
252 | else |
272 | { |
253 | { |
273 | strcpy(#absolute_path, I_Path); |
254 | strcpy(#absolute_path, I_Path); |
274 | absolute_path[strrchr(#absolute_path, '/')] = '\0'; |
255 | absolute_path[strrchr(#absolute_path, '/')] = '\0'; |
275 | strcat(#absolute_path, relative_path); |
256 | strcat(#absolute_path, relative_path); |
276 | } |
257 | } |
277 | return #absolute_path; |
258 | return #absolute_path; |
278 | } |
259 | } |
279 | 260 | ||
280 | :dword GetIni(dword ini_path, ini_name) //search it on /kolibrios/ then on /sys/ |
261 | :dword GetIni(dword ini_path, ini_name) //search it on /kolibrios/ then on /sys/ |
281 | { |
262 | { |
282 | strcpy(ini_path, "/kolibrios/settings/"); |
263 | strcpy(ini_path, "/kolibrios/settings/"); |
283 | strcat(ini_path, ini_name); |
264 | strcat(ini_path, ini_name); |
284 | if (!file_exists(ini_path)) { |
265 | if (!file_exists(ini_path)) { |
285 | strcpy(ini_path, "/sys/SETTINGS/"); |
266 | strcpy(ini_path, "/sys/SETTINGS/"); |
286 | strcat(ini_path, ini_name); |
267 | strcat(ini_path, ini_name); |
287 | } |
268 | } |
288 | return ini_path; |
269 | return ini_path; |
289 | } |
270 | } |
290 | 271 | ||
291 | :byte ConvertSize_size_prefix[8]; |
272 | :byte ConvertSize_size_prefix[8]; |
292 | :dword ConvertSize(dword bytes) |
273 | :dword ConvertSize(dword bytes) |
293 | { |
274 | { |
294 | byte size_nm[4]; |
275 | byte size_nm[4]; |
295 | if (bytes>=1073741824) strlcpy(#size_nm, "Gb",2); |
276 | if (bytes>=1073741824) strlcpy(#size_nm, "Gb",2); |
296 | else if (bytes>=1048576) strlcpy(#size_nm, "Mb",2); |
277 | else if (bytes>=1048576) strlcpy(#size_nm, "Mb",2); |
297 | else if (bytes>=1024) strlcpy(#size_nm, "Kb",2); |
278 | else if (bytes>=1024) strlcpy(#size_nm, "Kb",2); |
298 | else strlcpy(#size_nm, "b ",2); |
279 | else strlcpy(#size_nm, "b ",2); |
299 | while (bytes>1023) bytes >>= 10; |
280 | while (bytes>1023) bytes >>= 10; |
300 | sprintf(#ConvertSize_size_prefix,"%d %s",bytes,#size_nm); |
281 | sprintf(#ConvertSize_size_prefix,"%d %s",bytes,#size_nm); |
301 | return #ConvertSize_size_prefix; |
282 | return #ConvertSize_size_prefix; |
302 | } |
283 | } |
303 | 284 | ||
304 | :dword ConvertSize64(dword bytes_lo, bytes_hi) |
285 | :dword ConvertSize64(dword bytes_lo, bytes_hi) |
305 | { |
286 | { |
306 | if (bytes_hi > 0) { |
287 | if (bytes_hi > 0) { |
307 | if (bytes_lo>=1073741824) bytes_lo >>= 30; else bytes_lo = 0; |
288 | if (bytes_lo>=1073741824) bytes_lo >>= 30; else bytes_lo = 0; |
308 | sprintf(#ConvertSize_size_prefix,"%d Gb",bytes_hi<<2 + bytes_lo); |
289 | sprintf(#ConvertSize_size_prefix,"%d Gb",bytes_hi<<2 + bytes_lo); |
309 | return #ConvertSize_size_prefix; |
290 | return #ConvertSize_size_prefix; |
310 | } |
291 | } |
311 | else return ConvertSize(bytes_lo); |
292 | else return ConvertSize(bytes_lo); |
312 | } |
293 | } |
313 | 294 | ||
314 | :dword notify(dword notify_param) |
295 | :dword notify(dword notify_param) |
315 | { |
296 | { |
316 | return RunProgram("/sys/@notify", notify_param); |
297 | return RunProgram("/sys/@notify", notify_param); |
317 | } |
298 | } |
318 | 299 | ||
319 | :void die(dword _last_msg) |
300 | :void die(dword _last_msg) |
320 | { |
301 | { |
321 | notify(_last_msg); |
302 | notify(_last_msg); |
322 | ExitProcess(); |
303 | ExitProcess(); |
323 | } |
304 | } |
324 | 305 | ||
325 | :unsigned char size[25]=0; |
306 | :unsigned char size[25]=0; |
326 | :dword ConvertSizeToKb(unsigned int bytes) |
307 | :dword ConvertSizeToKb(unsigned int bytes) |
327 | { |
308 | { |
328 | unsigned int kb; |
309 | unsigned int kb; |
329 | dword kb_line; |
310 | dword kb_line; |
330 | 311 | ||
331 | if (bytes >= 1024) |
312 | if (bytes >= 1024) |
332 | { |
313 | { |
333 | kb_line = itoa(bytes / 1024); |
314 | kb_line = itoa(bytes / 1024); |
334 | strcpy(#size, kb_line); |
315 | strcpy(#size, kb_line); |
335 | strcat(#size, " Kb"); |
316 | strcat(#size, " Kb"); |
336 | } |
317 | } |
337 | else { |
318 | else { |
338 | kb_line = itoa(bytes); |
319 | kb_line = itoa(bytes); |
339 | strcpy(#size, kb_line); |
320 | strcpy(#size, kb_line); |
340 | strcat(#size, " b"); |
321 | strcat(#size, " b"); |
341 | } |
322 | } |
342 | 323 | ||
343 | return #size; |
324 | return #size; |
344 | } |
325 | } |
345 | 326 | ||
346 | :int CopyFileAtOnce(dword size, copyFrom, copyTo) |
327 | :int CopyFileAtOnce(dword size, copyFrom, copyTo) |
347 | dword cbuf; |
328 | dword cbuf; |
348 | int error; |
329 | int error; |
349 | { |
330 | { |
350 | cbuf = malloc(size); |
331 | cbuf = malloc(size); |
351 | if (error = ReadFile(0, size, cbuf, copyFrom)) |
332 | if (error = ReadFile(0, size, cbuf, copyFrom)) |
352 | { |
333 | { |
353 | debugln("Error: CopyFileAtOnce->ReadFile"); |
334 | debugln("Error: CopyFileAtOnce->ReadFile"); |
354 | } |
335 | } |
355 | else |
336 | else |
356 | { |
337 | { |
357 | if (error = CreateFile(size, cbuf, copyTo)) debugln("Error: CopyFileAtOnce->CreateFile"); |
338 | if (error = CreateFile(size, cbuf, copyTo)) debugln("Error: CopyFileAtOnce->CreateFile"); |
358 | } |
339 | } |
359 | free(cbuf); |
340 | free(cbuf); |
360 | return error; |
341 | return error; |
361 | } |
342 | } |
362 | 343 | ||
363 | :int CopyFileByBlocks(dword size, copyFrom, copyTo) |
344 | :int CopyFileByBlocks(dword size, copyFrom, copyTo) |
364 | dword cbuf; |
345 | dword cbuf; |
365 | int error=-1; |
346 | int error=-1; |
366 | dword offpos=0; |
347 | dword offpos=0; |
367 | int block_size=1024*1024*4; //copy by 4 MiB |
348 | int block_size=1024*1024*4; //copy by 4 MiB |
368 | { |
349 | { |
369 | if (GetFreeRAM()>1024*78) { |
350 | if (GetFreeRAM()>1024*78) { |
370 | //Set block size 32 MiB |
351 | //Set block size 32 MiB |
371 | block_size <<= 3; |
352 | block_size <<= 3; |
372 | } |
353 | } |
373 | cbuf = malloc(block_size); |
354 | cbuf = malloc(block_size); |
374 | if (error = CreateFile(0, 0, copyTo)) |
355 | if (error = CreateFile(0, 0, copyTo)) |
375 | { |
356 | { |
376 | debugln("Error: CopyFileByBlocks->CreateFile"); |
357 | debugln("Error: CopyFileByBlocks->CreateFile"); |
377 | size = -1; |
358 | size = -1; |
378 | } |
359 | } |
379 | while(offpos < size) |
360 | while(offpos < size) |
380 | { |
361 | { |
381 | error = ReadFile(offpos, block_size, cbuf, copyFrom); |
362 | error = ReadFile(offpos, block_size, cbuf, copyFrom); |
382 | if (error = 6) { //File ended before last byte was readed |
363 | if (error = 6) { //File ended before last byte was readed |
383 | block_size = EBX; |
364 | block_size = EBX; |
384 | if (block_size+offpos>=size) error=0; |
365 | if (block_size+offpos>=size) error=0; |
385 | } |
366 | } |
386 | else |
367 | else |
387 | if (error!=0) { |
368 | if (error!=0) { |
388 | debugln("Error: CopyFileByBlocks->ReadFile"); |
369 | debugln("Error: CopyFileByBlocks->ReadFile"); |
389 | break; |
370 | break; |
390 | } |
371 | } |
391 | if (error = WriteFile(offpos, block_size, cbuf, copyTo)) { |
372 | if (error = WriteFile(offpos, block_size, cbuf, copyTo)) { |
392 | debugln("Error: CopyFileByBlocks->WriteFile"); |
373 | debugln("Error: CopyFileByBlocks->WriteFile"); |
393 | break; |
374 | break; |
394 | } |
375 | } |
395 | offpos += block_size; |
376 | offpos += block_size; |
396 | } |
377 | } |
397 | free(cbuf); |
378 | free(cbuf); |
398 | return error; |
379 | return error; |
399 | } |
380 | } |
400 | 381 | ||
401 | 382 | ||
402 | #endif>=><=>2><2> |
383 | #endif>=><=>2><2> |