Subversion Repositories Kolibri OS

Rev

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

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