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