Rev 7533 | Rev 7878 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 7533 | Rev 7639 | ||
---|---|---|---|
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 | 179 | ||
180 | //ECX - buf pointer |
180 | //ECX - buf pointer |
181 | inline fastcall void SetCurDir( ECX) |
181 | inline fastcall void SetCurDir( ECX) |
182 | { |
182 | { |
183 | EAX=30; |
183 | EAX=30; |
184 | EBX=1; |
184 | EBX=1; |
185 | $int 0x40 |
185 | $int 0x40 |
186 | } |
186 | } |
187 | 187 | ||
188 | //ECX - buf pointer |
188 | //ECX - buf pointer |
189 | //EDX - buf size |
189 | //EDX - buf size |
190 | inline fastcall void GetCurDir( ECX, EDX) |
190 | inline fastcall void GetCurDir( ECX, EDX) |
191 | { |
191 | { |
192 | EAX=30; |
192 | EAX=30; |
193 | EBX=2; |
193 | EBX=2; |
194 | $int 0x40 |
194 | $int 0x40 |
195 | } |
195 | } |
196 | 196 | ||
197 | //===================================================// |
197 | //===================================================// |
198 | // // |
198 | // // |
199 | // Misc // |
199 | // Misc // |
200 | // // |
200 | // // |
201 | //===================================================// |
201 | //===================================================// |
202 | 202 | ||
203 | :bool dir_exists(dword fpath) |
203 | :bool dir_exists(dword fpath) |
204 | { |
204 | { |
205 | char buf[32]; |
205 | char buf[32]; |
206 | if (!ReadDir(0, #buf, fpath)) return true; |
206 | if (!ReadDir(0, #buf, fpath)) return true; |
207 | return false; |
207 | return false; |
208 | } |
208 | } |
209 | 209 | ||
210 | /* |
210 | /* |
211 | // This implementation of dir_exists() is faster than |
211 | // This implementation of dir_exists() is faster than |
212 | // previous but here virtual folders like |
212 | // previous but here virtual folders like |
213 | // '/' and '/tmp' are not recognised as FOLDERS |
213 | // '/' and '/tmp' are not recognised as FOLDERS |
214 | // by GetFileInfo() => BDVK.isfolder attribute :( |
214 | // by GetFileInfo() => BDVK.isfolder attribute :( |
215 | 215 | ||
216 | :bool dir_exists(dword fpath) |
216 | :bool dir_exists(dword fpath) |
217 | { |
217 | { |
218 | BDVK fpath_atr; |
218 | BDVK fpath_atr; |
219 | if (GetFileInfo(fpath, #fpath_atr) != 0) return false; |
219 | if (GetFileInfo(fpath, #fpath_atr) != 0) return false; |
220 | return fpath_atr.isfolder; |
220 | return fpath_atr.isfolder; |
221 | } |
221 | } |
222 | */ |
222 | */ |
223 | 223 | ||
224 | :bool file_exists(dword fpath) |
224 | :bool file_exists(dword fpath) |
225 | { |
225 | { |
226 | BDVK ReadFile_atr; |
226 | BDVK ReadFile_atr; |
227 | if (! GetFileInfo(fpath, #ReadFile_atr)) return true; |
227 | if (! GetFileInfo(fpath, #ReadFile_atr)) return true; |
228 | return false; |
228 | return false; |
229 | } |
229 | } |
230 | 230 | ||
231 | enum |
231 | enum |
232 | { |
232 | { |
233 | DIRS_ALL, |
233 | DIRS_ALL, |
234 | DIRS_NOROOT, |
234 | DIRS_NOROOT, |
235 | DIRS_ONLYREAL |
235 | DIRS_ONLYREAL |
236 | }; |
236 | }; |
237 | :int GetDir(dword dir_buf, file_count, path, doptions) |
237 | :int GetDir(dword dir_buf, file_count, path, doptions) |
238 | { |
238 | { |
239 | dword buf, fcount, error; |
239 | dword buf, fcount, error; |
240 | buf = malloc(32); |
240 | buf = malloc(32); |
241 | error = ReadDir(0, buf, path); |
241 | error = ReadDir(0, buf, path); |
242 | if (!error) |
242 | if (!error) |
243 | { |
243 | { |
244 | fcount = ESDWORD[buf+8]; |
244 | fcount = ESDWORD[buf+8]; |
245 | buf = realloc(buf, fcount+1*304+32); |
245 | buf = realloc(buf, fcount+1*304+32); |
246 | ReadDir(fcount, buf, path); |
246 | ReadDir(fcount, buf, path); |
247 | //fcount=EBX; |
247 | //fcount=EBX; |
248 | 248 | ||
249 | if (doptions == DIRS_ONLYREAL) |
249 | if (doptions == DIRS_ONLYREAL) |
250 | { |
250 | { |
251 | if (!strcmp(".",buf+72)) {fcount--; memmov(buf,buf+304,fcount*304);} |
251 | if (!strcmp(".",buf+72)) {fcount--; memmov(buf,buf+304,fcount*304);} |
252 | if (!strcmp("..",buf+72)) {fcount--; memmov(buf,buf+304,fcount*304);} |
252 | if (!strcmp("..",buf+72)) {fcount--; memmov(buf,buf+304,fcount*304);} |
253 | } |
253 | } |
254 | if (doptions == DIRS_NOROOT) |
254 | if (doptions == DIRS_NOROOT) |
255 | { |
255 | { |
256 | if (!strcmp(".",buf+72)) {fcount--; memmov(buf,buf+304,fcount*304);} |
256 | if (!strcmp(".",buf+72)) {fcount--; memmov(buf,buf+304,fcount*304);} |
257 | } |
257 | } |
258 | 258 | ||
259 | ESDWORD[dir_buf] = buf; |
259 | ESDWORD[dir_buf] = buf; |
260 | ESDWORD[file_count] = fcount; |
260 | ESDWORD[file_count] = fcount; |
261 | } |
261 | } |
262 | else |
262 | else |
263 | { |
263 | { |
264 | ESDWORD[dir_buf] = free(buf); |
264 | ESDWORD[dir_buf] = free(buf); |
265 | ESDWORD[file_count] = 0; |
265 | ESDWORD[file_count] = 0; |
266 | } |
266 | } |
267 | return error; |
267 | return error; |
268 | } |
268 | } |
269 | 269 | ||
270 | :dword abspath(dword relative_path) //GetAbsolutePathFromRelative() |
270 | :dword abspath(dword relative_path) //GetAbsolutePathFromRelative() |
271 | { |
271 | { |
272 | char absolute_path[4096]; |
272 | char absolute_path[4096]; |
273 | if (ESBYTE[relative_path]=='/') |
273 | if (ESBYTE[relative_path]=='/') |
274 | { |
274 | { |
275 | strcpy(#absolute_path, relative_path); |
275 | strcpy(#absolute_path, relative_path); |
276 | } |
276 | } |
277 | else |
277 | else |
278 | { |
278 | { |
279 | strcpy(#absolute_path, I_Path); |
279 | strcpy(#absolute_path, I_Path); |
280 | absolute_path[strrchr(#absolute_path, '/')] = '\0'; |
280 | absolute_path[strrchr(#absolute_path, '/')] = '\0'; |
281 | strcat(#absolute_path, relative_path); |
281 | strcat(#absolute_path, relative_path); |
282 | } |
282 | } |
283 | return #absolute_path; |
283 | return #absolute_path; |
284 | } |
284 | } |
285 | 285 | ||
286 | :dword GetIni(dword ini_path, ini_name) //search it on /kolibrios/ then on /sys/ |
286 | :dword GetIni(dword ini_path, ini_name) //search it on /kolibrios/ then on /sys/ |
287 | { |
287 | { |
288 | strcpy(ini_path, "/kolibrios/settings/"); |
288 | strcpy(ini_path, "/kolibrios/settings/"); |
289 | strcat(ini_path, ini_name); |
289 | strcat(ini_path, ini_name); |
290 | if (!file_exists(ini_path)) { |
290 | if (!file_exists(ini_path)) { |
291 | strcpy(ini_path, "/sys/SETTINGS/"); |
291 | strcpy(ini_path, "/sys/SETTINGS/"); |
292 | strcat(ini_path, ini_name); |
292 | strcat(ini_path, ini_name); |
293 | } |
293 | } |
294 | return ini_path; |
294 | return ini_path; |
295 | } |
295 | } |
296 | 296 | ||
297 | :dword notify(dword notify_param) |
297 | :dword notify(dword notify_param) |
298 | { |
298 | { |
299 | return RunProgram("/sys/@notify", notify_param); |
299 | return RunProgram("/sys/@notify", notify_param); |
300 | } |
300 | } |
301 | 301 | ||
302 | :void die(dword _last_msg) |
302 | :void die(dword _last_msg) |
303 | { |
303 | { |
304 | notify(_last_msg); |
304 | notify(_last_msg); |
305 | ExitProcess(); |
305 | ExitProcess(); |
306 | } |
306 | } |
307 | 307 | ||
308 | //===================================================// |
308 | //===================================================// |
309 | // // |
309 | // // |
310 | // Convert Size // |
310 | // Convert Size // |
311 | // // |
311 | // // |
312 | //===================================================// |
312 | //===================================================// |
313 | 313 | ||
314 | :byte ConvertSize_size_prefix[8]; |
314 | :byte ConvertSize_size_prefix[8]; |
315 | :dword ConvertSize(dword bytes) |
315 | :dword ConvertSize(dword bytes) |
316 | { |
316 | { |
317 | byte size_nm[4]; |
317 | byte size_nm[4]; |
318 | if (bytes>=1073741824) strlcpy(#size_nm, "Gb",2); |
318 | if (bytes>=1073741824) strlcpy(#size_nm, "Gb",2); |
319 | else if (bytes>=1048576) strlcpy(#size_nm, "Mb",2); |
319 | else if (bytes>=1048576) strlcpy(#size_nm, "Mb",2); |
320 | else if (bytes>=1024) strlcpy(#size_nm, "Kb",2); |
320 | else if (bytes>=1024) strlcpy(#size_nm, "Kb",2); |
321 | else strlcpy(#size_nm, "b ",2); |
321 | else strlcpy(#size_nm, "b ",2); |
322 | while (bytes>1023) bytes >>= 10; |
322 | while (bytes>1023) bytes >>= 10; |
323 | sprintf(#ConvertSize_size_prefix,"%d %s",bytes,#size_nm); |
323 | sprintf(#ConvertSize_size_prefix,"%d %s",bytes,#size_nm); |
324 | return #ConvertSize_size_prefix; |
324 | return #ConvertSize_size_prefix; |
325 | } |
325 | } |
326 | 326 | ||
327 | :dword ConvertSize64(dword bytes_lo, bytes_hi) |
327 | :dword ConvertSize64(dword bytes_lo, bytes_hi) |
328 | { |
328 | { |
329 | if (bytes_hi > 0) { |
329 | if (bytes_hi > 0) { |
330 | if (bytes_lo>=1073741824) bytes_lo >>= 30; else bytes_lo = 0; |
330 | if (bytes_lo>=1073741824) bytes_lo >>= 30; else bytes_lo = 0; |
331 | sprintf(#ConvertSize_size_prefix,"%d Gb",bytes_hi<<2 + bytes_lo); |
331 | sprintf(#ConvertSize_size_prefix,"%d Gb",bytes_hi<<2 + bytes_lo); |
332 | return #ConvertSize_size_prefix; |
332 | return #ConvertSize_size_prefix; |
333 | } |
333 | } |
334 | else return ConvertSize(bytes_lo); |
334 | else return ConvertSize(bytes_lo); |
335 | } |
335 | } |
336 | 336 | ||
337 | :unsigned char size[25]; |
337 | :unsigned char size[25]; |
338 | :dword ConvertSizeToKb(unsigned int bytes) |
338 | :dword ConvertSizeToKb(unsigned int bytes) |
339 | { |
339 | { |
340 | unsigned int kb; |
- | |
341 | dword kb_line; |
340 | dword kb_line; |
342 | 341 | ||
343 | if (bytes >= 1024) |
342 | if (bytes >= 1024) |
344 | { |
343 | { |
345 | kb_line = itoa(bytes / 1024); |
344 | kb_line = itoa(bytes / 1024); |
346 | strcpy(#size, kb_line); |
345 | strcpy(#size, kb_line); |
347 | strcat(#size, " Kb"); |
346 | strcat(#size, " Kb"); |
348 | } |
347 | } |
349 | else { |
348 | else { |
350 | kb_line = itoa(bytes); |
349 | kb_line = itoa(bytes); |
351 | strcpy(#size, kb_line); |
350 | strcpy(#size, kb_line); |
352 | strcat(#size, " b"); |
351 | strcat(#size, " b"); |
353 | } |
352 | } |
354 | 353 | ||
355 | return #size; |
354 | return #size; |
356 | } |
355 | } |
357 | 356 | ||
358 | //===================================================// |
357 | //===================================================// |
359 | // // |
358 | // // |
360 | // Copy // |
359 | // Copy // |
361 | // // |
360 | // // |
362 | //===================================================// |
361 | //===================================================// |
363 | 362 | ||
364 | :int CopyFileAtOnce(dword size, copyFrom, copyTo) |
363 | :int CopyFileAtOnce(dword size, copyFrom, copyTo) |
365 | dword cbuf; |
364 | dword cbuf; |
366 | int error; |
365 | int error; |
367 | { |
366 | { |
368 | cbuf = malloc(size); |
367 | cbuf = malloc(size); |
369 | if (error = ReadFile(0, size, cbuf, copyFrom)) |
368 | if (error = ReadFile(0, size, cbuf, copyFrom)) |
370 | { |
369 | { |
371 | debugln("Error: CopyFileAtOnce->ReadFile"); |
370 | debugln("Error: CopyFileAtOnce->ReadFile"); |
372 | } |
371 | } |
373 | else |
372 | else |
374 | { |
373 | { |
375 | if (error = CreateFile(size, cbuf, copyTo)) debugln("Error: CopyFileAtOnce->CreateFile"); |
374 | if (error = CreateFile(size, cbuf, copyTo)) debugln("Error: CopyFileAtOnce->CreateFile"); |
376 | } |
375 | } |
377 | free(cbuf); |
376 | free(cbuf); |
378 | return error; |
377 | return error; |
379 | } |
378 | } |
380 | 379 | ||
381 | :int CopyFileByBlocks(dword size, copyFrom, copyTo) |
380 | :int CopyFileByBlocks(dword size, copyFrom, copyTo) |
382 | dword cbuf; |
381 | dword cbuf; |
383 | int error=-1; |
382 | int error=-1; |
384 | dword offpos=0; |
383 | dword offpos=0; |
385 | int block_size=1024*1024*4; //copy by 4 MiB |
384 | int block_size=1024*1024*4; //copy by 4 MiB |
386 | { |
385 | { |
387 | if (GetFreeRAM()>1024*78) { |
386 | if (GetFreeRAM()>1024*78) { |
388 | //Set block size 32 MiB |
387 | //Set block size 32 MiB |
389 | block_size <<= 3; |
388 | block_size <<= 3; |
390 | } |
389 | } |
391 | cbuf = malloc(block_size); |
390 | cbuf = malloc(block_size); |
392 | if (error = CreateFile(0, 0, copyTo)) |
391 | if (error = CreateFile(0, 0, copyTo)) |
393 | { |
392 | { |
394 | debugln("Error: CopyFileByBlocks->CreateFile"); |
393 | debugln("Error: CopyFileByBlocks->CreateFile"); |
395 | size = -1; |
394 | size = -1; |
396 | } |
395 | } |
397 | while(offpos < size) |
396 | while(offpos < size) |
398 | { |
397 | { |
399 | error = ReadFile(offpos, block_size, cbuf, copyFrom); |
398 | error = ReadFile(offpos, block_size, cbuf, copyFrom); |
400 | if (error = 6) { //File ended before last byte was readed |
399 | if (error = 6) { //File ended before last byte was readed |
401 | block_size = EBX; |
400 | block_size = EBX; |
402 | if (block_size+offpos>=size) error=0; |
401 | if (block_size+offpos>=size) error=0; |
403 | } |
402 | } |
404 | else |
403 | else |
405 | if (error!=0) { |
404 | if (error!=0) { |
406 | debugln("Error: CopyFileByBlocks->ReadFile"); |
405 | debugln("Error: CopyFileByBlocks->ReadFile"); |
407 | break; |
406 | break; |
408 | } |
407 | } |
409 | if (error = WriteFile(offpos, block_size, cbuf, copyTo)) { |
408 | if (error = WriteFile(offpos, block_size, cbuf, copyTo)) { |
410 | debugln("Error: CopyFileByBlocks->WriteFile"); |
409 | debugln("Error: CopyFileByBlocks->WriteFile"); |
411 | break; |
410 | break; |
412 | } |
411 | } |
413 | offpos += block_size; |
412 | offpos += block_size; |
414 | } |
413 | } |
415 | free(cbuf); |
414 | free(cbuf); |
416 | return error; |
415 | return error; |
417 | } |
416 | } |
418 | 417 | ||
419 | //===================================================// |
418 | //===================================================// |
420 | // // |
419 | // // |
421 | // Directory Size // |
420 | // Directory Size // |
422 | // // |
421 | // // |
423 | //===================================================// |
422 | //===================================================// |
424 | 423 | ||
425 | :struct _dir_size |
424 | :struct _dir_size |
426 | { |
425 | { |
427 | BDVK dir_info; |
426 | BDVK dir_info; |
428 | dword folders; |
427 | dword folders; |
429 | dword files; |
428 | dword files; |
430 | dword bytes; |
429 | dword bytes; |
431 | void get(); |
430 | void get(); |
432 | void calculate_loop(); |
431 | void calculate_loop(); |
433 | } dir_size; |
432 | } dir_size; |
434 | 433 | ||
435 | :void _dir_size::get(dword way) |
434 | :void _dir_size::get(dword way) |
436 | { |
435 | { |
437 | folders = files = bytes = 0; |
436 | folders = files = bytes = 0; |
438 | if (way) calculate_loop(way); |
437 | if (way) calculate_loop(way); |
439 | } |
438 | } |
440 | 439 | ||
441 | :void _dir_size::calculate_loop(dword way) |
440 | :void _dir_size::calculate_loop(dword way) |
442 | { |
441 | { |
443 | dword dirbuf, fcount, i, filename; |
442 | dword dirbuf, fcount, i, filename; |
444 | dword cur_file; |
443 | dword cur_file; |
445 | if (dir_exists(way)) |
444 | if (dir_exists(way)) |
446 | { |
445 | { |
447 | cur_file = malloc(4096); |
446 | cur_file = malloc(4096); |
448 | // In the process of recursive descent, memory must be allocated dynamically, |
447 | // In the process of recursive descent, memory must be allocated dynamically, |
449 | // because the static memory -> was a bug !!! But unfortunately pass away to sacrifice speed. |
448 | // because the static memory -> was a bug !!! But unfortunately pass away to sacrifice speed. |
450 | GetDir(#dirbuf, #fcount, way, DIRS_ONLYREAL); |
449 | GetDir(#dirbuf, #fcount, way, DIRS_ONLYREAL); |
451 | for (i=0; i |
450 | for (i=0; i |
452 | { |
451 | { |
453 | filename = i*304+dirbuf+72; |
452 | filename = i*304+dirbuf+72; |
454 | sprintf(cur_file,"%s/%s",way,filename); |
453 | sprintf(cur_file,"%s/%s",way,filename); |
455 | 454 | ||
456 | if (TestBit(ESDWORD[filename-40], 4) ) |
455 | if (TestBit(ESDWORD[filename-40], 4) ) |
457 | { |
456 | { |
458 | folders++; |
457 | folders++; |
459 | calculate_loop(cur_file); |
458 | calculate_loop(cur_file); |
460 | } |
459 | } |
461 | else |
460 | else |
462 | { |
461 | { |
463 | GetFileInfo(cur_file, #dir_info); |
462 | GetFileInfo(cur_file, #dir_info); |
464 | bytes += dir_info.sizelo; |
463 | bytes += dir_info.sizelo; |
465 | files++; |
464 | files++; |
466 | } |
465 | } |
467 | } |
466 | } |
468 | free(cur_file); |
467 | free(cur_file); |
469 | free(dirbuf); |
468 | free(dirbuf); |
470 | } |
469 | } |
471 | } |
470 | } |
472 | 471 | ||
473 | #endif>=><=>2><2> |
472 | #endif>=><=>2><2> |