Subversion Repositories Kolibri OS

Rev

Rev 9689 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

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