Rev 5631 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
5598 | pavelyakov | 1 | #ifndef INCLUDE_FILESYSTEM_H |
2 | #define INCLUDE_FILESYSTEM_H |
||
3 | |||
5640 | pavelyakov | 4 | #ifndef INCLUDE_DATE_H |
5 | #include "../lib/date.h" |
||
5598 | pavelyakov | 6 | #endif |
7 | |||
5487 | leency | 8 | :struct f70{ |
3067 | leency | 9 | dword func; |
10 | dword param1; |
||
11 | dword param2; |
||
12 | dword param3; |
||
13 | dword param4; |
||
14 | char rezerv; |
||
15 | dword name; |
||
16 | }; |
||
17 | |||
5487 | leency | 18 | :struct BDVK { |
19 | dword readonly:1, hidden:1, system:1, volume_label:1, isfolder:1, notarchived:1, :0; |
||
3067 | leency | 20 | byte type_name; |
4898 | leency | 21 | byte rez1, rez2, selected; |
5487 | leency | 22 | dword timecreate; |
23 | date datecreate; |
||
3067 | leency | 24 | dword timelastaccess; |
5487 | leency | 25 | date datelastaccess; |
3067 | leency | 26 | dword timelastedit; |
5487 | leency | 27 | date datelastedit; |
3067 | leency | 28 | dword sizelo; |
29 | dword sizehi; |
||
30 | char name[518]; |
||
31 | }; |
||
32 | |||
33 | |||
5487 | leency | 34 | |
35 | |||
5640 | pavelyakov | 36 | |
37 | /////////////////////////// |
||
38 | // Параметры файла // |
||
3067 | leency | 39 | /////////////////////////// |
5472 | leency | 40 | :f70 getinfo_file_70; |
3440 | leency | 41 | :dword GetFileInfo(dword file_path, bdvk_struct) |
42 | { |
||
43 | getinfo_file_70.func = 5; |
||
44 | getinfo_file_70.param1 = |
||
45 | getinfo_file_70.param2 = |
||
46 | getinfo_file_70.param3 = 0; |
||
47 | getinfo_file_70.param4 = bdvk_struct; |
||
48 | getinfo_file_70.rezerv = 0; |
||
49 | getinfo_file_70.name = file_path; |
||
50 | $mov eax,70 |
||
51 | $mov ebx,#getinfo_file_70.func |
||
3444 | leency | 52 | $int 0x40 |
3440 | leency | 53 | } |
54 | |||
5640 | pavelyakov | 55 | ///////////////////////////////////// |
56 | // Изменение параметров файла // |
||
57 | ///////////////////////////////////// |
||
5554 | punk_joker | 58 | :f70 setinfo_file_70; |
59 | :dword SetFileInfo(dword file_path, bdvk_struct) |
||
60 | { |
||
61 | setinfo_file_70.func = 6; |
||
62 | setinfo_file_70.param1 = |
||
63 | setinfo_file_70.param2 = |
||
64 | setinfo_file_70.param3 = 0; |
||
65 | setinfo_file_70.param4 = bdvk_struct; |
||
66 | setinfo_file_70.rezerv = 0; |
||
67 | setinfo_file_70.name = file_path; |
||
68 | $mov eax,70 |
||
69 | $mov ebx,#setinfo_file_70.func |
||
70 | $int 0x40 |
||
71 | } |
||
72 | |||
5640 | pavelyakov | 73 | /////////////////////////// |
74 | // Запуск программы // |
||
5554 | punk_joker | 75 | /////////////////////////// |
5472 | leency | 76 | :f70 run_file_70; |
77 | :signed int RunProgram(dword run_path, run_param) |
||
3067 | leency | 78 | { |
79 | run_file_70.func = 7; |
||
80 | run_file_70.param1 = |
||
81 | run_file_70.param3 = |
||
82 | run_file_70.param4 = |
||
83 | run_file_70.rezerv = 0; |
||
84 | run_file_70.param2 = run_param; |
||
85 | run_file_70.name = run_path; |
||
86 | $mov eax,70 |
||
87 | $mov ebx,#run_file_70.func |
||
88 | $int 0x40 |
||
89 | } |
||
90 | |||
5640 | pavelyakov | 91 | /////////////////////////// |
92 | // Создание папки // |
||
3067 | leency | 93 | /////////////////////////// |
5472 | leency | 94 | :f70 create_dir_70; |
3067 | leency | 95 | :int CreateDir(dword new_folder_path) |
96 | { |
||
97 | create_dir_70.func = 9; |
||
98 | create_dir_70.param1 = |
||
99 | create_dir_70.param2 = |
||
100 | create_dir_70.param3 = |
||
101 | create_dir_70.param4 = |
||
102 | create_dir_70.rezerv = 0; |
||
103 | create_dir_70.name = new_folder_path; |
||
104 | $mov eax,70 |
||
105 | $mov ebx,#create_dir_70.func |
||
106 | $int 0x40 |
||
107 | } |
||
108 | |||
5640 | pavelyakov | 109 | //////////////////////////// |
110 | // Удаление файла/папки // |
||
3067 | leency | 111 | //////////////////////////// |
5472 | leency | 112 | :f70 del_file_70; |
3067 | leency | 113 | :int DeleteFile(dword del_file_path) |
114 | { |
||
115 | del_file_70.func = 8; |
||
116 | del_file_70.param1 = |
||
117 | del_file_70.param2 = |
||
118 | del_file_70.param3 = |
||
119 | del_file_70.param4 = |
||
120 | del_file_70.rezerv = 0; |
||
121 | del_file_70.name = del_file_path; |
||
122 | $mov eax,70 |
||
123 | $mov ebx,#del_file_70.func |
||
124 | $int 0x40 |
||
125 | } |
||
126 | |||
5640 | pavelyakov | 127 | //////////////////////////// |
128 | // Прочитать файл // |
||
3067 | leency | 129 | //////////////////////////// |
5472 | leency | 130 | :f70 read_file_70; |
3067 | leency | 131 | :int ReadFile(dword read_pos, read_file_size, read_buffer, read_file_path) |
132 | { |
||
133 | read_file_70.func = 0; |
||
134 | read_file_70.param1 = read_pos; |
||
135 | read_file_70.param2 = 0; |
||
136 | read_file_70.param3 = read_file_size; |
||
137 | read_file_70.param4 = read_buffer; |
||
138 | read_file_70.rezerv = 0; |
||
139 | read_file_70.name = read_file_path; |
||
140 | $mov eax,70 |
||
141 | $mov ebx,#read_file_70.func |
||
142 | $int 0x40 |
||
143 | } |
||
144 | |||
5640 | pavelyakov | 145 | /////////////////////////// |
146 | // Записать файл // |
||
147 | /////////////////////////// |
||
5472 | leency | 148 | :f70 write_file_70; |
3067 | leency | 149 | :int WriteFile(dword write_file_size, write_buffer, write_file_path) |
150 | { |
||
151 | write_file_70.func = 2; |
||
152 | write_file_70.param1 = 0; |
||
153 | write_file_70.param2 = 0; |
||
154 | write_file_70.param3 = write_file_size; |
||
155 | write_file_70.param4 = write_buffer; |
||
156 | write_file_70.rezerv = 0; |
||
157 | write_file_70.name = write_file_path; |
||
158 | $mov eax,70 |
||
159 | $mov ebx,#write_file_70.func |
||
160 | $int 0x40 |
||
5542 | leency | 161 | } |
3067 | leency | 162 | |
5640 | pavelyakov | 163 | //////////////////////////////////////// |
164 | // WriteInFileThatAlredyExists // |
||
165 | //////////////////////////////////////// |
||
5542 | leency | 166 | :f70 write_file_offset_70; |
167 | :int WriteFileWithOffset(dword write_data_size, write_buffer, write_file_path, offset) |
||
168 | { |
||
169 | write_file_offset_70.func = 3; |
||
170 | write_file_offset_70.param1 = offset; |
||
171 | write_file_offset_70.param2 = 0; |
||
172 | write_file_offset_70.param3 = write_data_size; |
||
173 | write_file_offset_70.param4 = write_buffer; |
||
174 | write_file_offset_70.rezerv = 0; |
||
175 | write_file_offset_70.name = write_file_path; |
||
176 | $mov eax,70 |
||
177 | $mov ebx,#write_file_offset_70.func |
||
178 | $int 0x40 |
||
179 | } |
||
180 | |||
5640 | pavelyakov | 181 | /////////////////////////// |
182 | // Прочитать папку // |
||
3067 | leency | 183 | /////////////////////////// |
5472 | leency | 184 | :f70 read_dir_70; |
3067 | leency | 185 | :int ReadDir(dword file_count, read_buffer, dir_path) |
3363 | leency | 186 | { |
3067 | leency | 187 | read_dir_70.func = 1; |
188 | read_dir_70.param1 = |
||
189 | read_dir_70.param2 = |
||
190 | read_dir_70.rezerv = 0; |
||
191 | read_dir_70.param3 = file_count; |
||
192 | read_dir_70.param4 = read_buffer; |
||
193 | read_dir_70.name = dir_path; |
||
194 | $mov eax,70 |
||
195 | $mov ebx,#read_dir_70.func |
||
196 | $int 0x40 |
||
197 | } |
||
198 | |||
5472 | leency | 199 | :char isdir(dword fpath) |
3440 | leency | 200 | { |
201 | BDVK fpath_atr; |
||
202 | GetFileInfo(fpath, #fpath_atr); |
||
5487 | leency | 203 | return fpath_atr.isfolder; |
3440 | leency | 204 | } |
3877 | leency | 205 | |
3440 | leency | 206 | :int GetFile(dword buf, filesize, read_path) |
207 | { |
||
208 | BDVK ReadFile_atr; |
||
209 | dword rBuf; |
||
210 | if (! GetFileInfo(read_path, #ReadFile_atr)) |
||
211 | { |
||
212 | rBuf = malloc(ReadFile_atr.sizelo); |
||
213 | if (! ReadFile(0, ReadFile_atr.sizelo, rBuf, read_path)) |
||
214 | { |
||
215 | ESDWORD[buf] = rBuf; |
||
216 | ESDWORD[filesize] = ReadFile_atr.sizelo; |
||
217 | return 1; |
||
218 | } |
||
219 | } |
||
220 | free(rBuf); |
||
221 | return 0; |
||
222 | } |
||
3067 | leency | 223 | |
3444 | leency | 224 | enum |
3363 | leency | 225 | { |
3444 | leency | 226 | DIRS_ALL, |
227 | DIRS_NOROOT, |
||
228 | DIRS_ONLYREAL |
||
229 | }; |
||
230 | :int GetDir(dword dir_buf, file_count, path, doptions) |
||
231 | { |
||
3363 | leency | 232 | dword buf, fcount, error; |
233 | buf = malloc(32); |
||
234 | error = ReadDir(0, buf, path); |
||
235 | if (!error) |
||
236 | { |
||
237 | fcount = ESDWORD[buf+8]; |
||
238 | buf = realloc(buf, fcount+1*304+32); |
||
239 | ReadDir(fcount, buf, path); |
||
3440 | leency | 240 | //fcount=EBX; |
3444 | leency | 241 | |
242 | if (doptions == DIRS_ONLYREAL) |
||
243 | { |
||
244 | if (!strcmp(".",buf+72)) {fcount--; memmov(buf,buf+304,fcount*304);} |
||
245 | if (!strcmp("..",buf+72)) {fcount--; memmov(buf,buf+304,fcount*304);} |
||
246 | } |
||
247 | if (doptions == DIRS_NOROOT) |
||
248 | { |
||
249 | if (!strcmp(".",buf+72)) {fcount--; memmov(buf,buf+304,fcount*304);} |
||
250 | } |
||
251 | |||
3363 | leency | 252 | ESDWORD[dir_buf] = buf; |
253 | ESDWORD[file_count] = fcount; |
||
254 | } |
||
3440 | leency | 255 | else |
3067 | leency | 256 | { |
3440 | leency | 257 | ESDWORD[file_count] = 0; |
258 | ESDWORD[dir_buf] = free(buf); |
||
3067 | leency | 259 | } |
3440 | leency | 260 | return error; |
3067 | leency | 261 | } |
262 | |||
3432 | leency | 263 | :dword abspath(dword relative_path) //GetAbsolutePathFromRelative() |
264 | { |
||
265 | char absolute_path[4096]; |
||
4137 | leency | 266 | if (ESBYTE[relative_path]=='/') |
267 | { |
||
268 | strcpy(#absolute_path, relative_path); |
||
269 | } |
||
270 | else |
||
271 | { |
||
272 | strcpy(#absolute_path, #program_path); |
||
273 | absolute_path[strrchr(#absolute_path, '/')] = '\0'; |
||
274 | strcat(#absolute_path, relative_path); |
||
275 | } |
||
3432 | leency | 276 | return #absolute_path; |
277 | } |
||
5483 | leency | 278 | |
5591 | pavelyakov | 279 | :byte ConvertSize_size_prefix[8]; |
5576 | pavelyakov | 280 | :dword ConvertSize(dword bytes) |
5483 | leency | 281 | { |
5591 | pavelyakov | 282 | byte size_nm[4]; |
283 | if (bytes>=1073741824) strncpy(#size_nm, "Gb",2); |
||
284 | else if (bytes>=1048576) strncpy(#size_nm, "Mb",2); |
||
285 | else if (bytes>=1024) strncpy(#size_nm, "Kb",2); |
||
286 | else strncpy(#size_nm, "b ",2); |
||
5483 | leency | 287 | while (bytes>1023) bytes/=1024; |
5591 | pavelyakov | 288 | sprintf(#ConvertSize_size_prefix,"%d %s",bytes,#size_nm); |
289 | return #ConvertSize_size_prefix; |
||
5493 | leency | 290 | } |
5631 | pavelyakov | 291 | :dword notify(dword notify_param) |
292 | { |
||
293 | return RunProgram("@notify", notify_param); |
||
294 | } |
||
5493 | leency | 295 | :dword ConvertSizeToKb(unsigned int bytes) |
296 | { |
||
297 | unsigned char size[25]=0; |
||
298 | unsigned int kb; |
||
299 | dword kb_line; |
||
300 | |||
301 | kb_line = itoa(bytes / 1024); |
||
302 | strcpy(#size, kb_line); |
||
303 | strcat(#size, " Kb"); |
||
304 | |||
305 | return #size; |
||
5598 | pavelyakov | 306 | } |
307 | #endif |