Subversion Repositories Kolibri OS

Rev

Rev 5598 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

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