Subversion Repositories Kolibri OS

Rev

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