2015-07-22 20:32:54 +02:00
|
|
|
#ifndef INCLUDE_FILESYSTEM_H
|
|
|
|
#define INCLUDE_FILESYSTEM_H
|
2018-04-03 15:57:56 +02:00
|
|
|
#print "[include <fs.h>]\n"
|
2015-07-22 20:32:54 +02:00
|
|
|
|
2015-08-02 00:08:58 +02:00
|
|
|
#ifndef INCLUDE_DATE_H
|
|
|
|
#include "../lib/date.h"
|
2015-07-22 20:32:54 +02:00
|
|
|
#endif
|
|
|
|
|
2020-05-06 17:53:34 +02:00
|
|
|
#ifndef INCLUDE_COLLECTION_H
|
|
|
|
#include "../lib/collection.h"
|
|
|
|
#endif
|
|
|
|
|
2018-09-15 12:48:42 +02:00
|
|
|
//===================================================//
|
|
|
|
// //
|
|
|
|
// Basic System Functions //
|
|
|
|
// //
|
|
|
|
//===================================================//
|
|
|
|
|
2021-05-28 01:40:55 +02:00
|
|
|
:struct F70{
|
2012-11-26 16:26:15 +01:00
|
|
|
dword func;
|
|
|
|
dword param1;
|
|
|
|
dword param2;
|
|
|
|
dword param3;
|
|
|
|
dword param4;
|
|
|
|
char rezerv;
|
|
|
|
dword name;
|
2021-05-28 01:40:55 +02:00
|
|
|
} f70;
|
2012-11-26 16:26:15 +01:00
|
|
|
|
2015-02-27 21:25:28 +01:00
|
|
|
:struct BDVK {
|
|
|
|
dword readonly:1, hidden:1, system:1, volume_label:1, isfolder:1, notarchived:1, :0;
|
2012-11-26 16:26:15 +01:00
|
|
|
byte type_name;
|
2014-04-26 11:52:23 +02:00
|
|
|
byte rez1, rez2, selected;
|
2015-02-27 21:25:28 +01:00
|
|
|
dword timecreate;
|
|
|
|
date datecreate;
|
2012-11-26 16:26:15 +01:00
|
|
|
dword timelastaccess;
|
2015-02-27 21:25:28 +01:00
|
|
|
date datelastaccess;
|
2012-11-26 16:26:15 +01:00
|
|
|
dword timelastedit;
|
2015-02-27 21:25:28 +01:00
|
|
|
date datelastedit;
|
2012-11-26 16:26:15 +01:00
|
|
|
dword sizelo;
|
|
|
|
dword sizehi;
|
|
|
|
char name[518];
|
|
|
|
};
|
2021-06-27 11:28:59 +02:00
|
|
|
#define ATR_READONLY 1
|
|
|
|
#define ATR_HIDDEN 2
|
|
|
|
#define ATR_SYSTEM 4
|
|
|
|
#define ATR_VOL_LABEL 8
|
2021-06-25 15:21:42 +02:00
|
|
|
#define ATR_FOLDER 0x10
|
2021-06-27 11:28:59 +02:00
|
|
|
#define ATR_NONARH 0x20
|
2013-04-02 15:33:32 +02:00
|
|
|
|
2015-02-27 21:25:28 +01:00
|
|
|
|
2013-04-02 15:33:32 +02:00
|
|
|
:dword GetFileInfo(dword file_path, bdvk_struct)
|
|
|
|
{
|
2021-05-28 01:40:55 +02:00
|
|
|
f70.func = 5;
|
|
|
|
f70.param1 =
|
|
|
|
f70.param2 =
|
|
|
|
f70.param3 = 0;
|
|
|
|
f70.param4 = bdvk_struct;
|
|
|
|
f70.rezerv = 0;
|
|
|
|
f70.name = file_path;
|
2013-04-02 15:33:32 +02:00
|
|
|
$mov eax,70
|
2021-05-28 01:40:55 +02:00
|
|
|
$mov ebx,#f70.func
|
2013-04-04 19:07:38 +02:00
|
|
|
$int 0x40
|
2013-04-02 15:33:32 +02:00
|
|
|
}
|
2012-11-26 16:26:15 +01:00
|
|
|
|
2021-11-16 03:05:12 +01:00
|
|
|
:dword GetVolumeLabel(dword _path)
|
|
|
|
{
|
|
|
|
BDVK bdvk;
|
|
|
|
//if (ESBYTE[_path+1]=='k') || (ESBYTE[_path+2]=='y') return NULL;
|
|
|
|
f70.func = 5;
|
|
|
|
f70.param1 = 0;
|
|
|
|
f70.param2 = 1;
|
|
|
|
f70.param3 = 1;
|
|
|
|
f70.param4 = #bdvk;
|
|
|
|
f70.rezerv = 0;
|
|
|
|
f70.name = _path;
|
|
|
|
$mov eax,70
|
|
|
|
$mov ebx,#f70.func
|
|
|
|
$int 0x40
|
|
|
|
return #bdvk.name;
|
|
|
|
}
|
|
|
|
|
2015-05-10 03:12:52 +02:00
|
|
|
:dword SetFileInfo(dword file_path, bdvk_struct)
|
|
|
|
{
|
2021-05-28 01:40:55 +02:00
|
|
|
f70.func = 6;
|
|
|
|
f70.param1 =
|
|
|
|
f70.param2 =
|
|
|
|
f70.param3 = 0;
|
|
|
|
f70.param4 = bdvk_struct;
|
|
|
|
f70.rezerv = 0;
|
|
|
|
f70.name = file_path;
|
2015-05-10 03:12:52 +02:00
|
|
|
$mov eax,70
|
2021-05-28 01:40:55 +02:00
|
|
|
$mov ebx,#f70.func
|
2015-05-10 03:12:52 +02:00
|
|
|
$int 0x40
|
|
|
|
}
|
|
|
|
|
2015-02-25 19:38:01 +01:00
|
|
|
:signed int RunProgram(dword run_path, run_param)
|
2012-11-26 16:26:15 +01:00
|
|
|
{
|
2021-05-28 01:40:55 +02:00
|
|
|
f70.func = 7;
|
|
|
|
f70.param1 =
|
|
|
|
f70.param3 =
|
|
|
|
f70.param4 =
|
|
|
|
f70.rezerv = 0;
|
|
|
|
f70.param2 = run_param;
|
|
|
|
f70.name = run_path;
|
2012-11-26 16:26:15 +01:00
|
|
|
$mov eax,70
|
2021-05-28 01:40:55 +02:00
|
|
|
$mov ebx,#f70.func
|
2012-11-26 16:26:15 +01:00
|
|
|
$int 0x40
|
|
|
|
}
|
|
|
|
|
|
|
|
:int CreateDir(dword new_folder_path)
|
|
|
|
{
|
2021-05-28 01:40:55 +02:00
|
|
|
f70.func = 9;
|
|
|
|
f70.param1 =
|
|
|
|
f70.param2 =
|
|
|
|
f70.param3 =
|
|
|
|
f70.param4 =
|
|
|
|
f70.rezerv = 0;
|
|
|
|
f70.name = new_folder_path;
|
2012-11-26 16:26:15 +01:00
|
|
|
$mov eax,70
|
2021-05-28 01:40:55 +02:00
|
|
|
$mov ebx,#f70.func
|
2012-11-26 16:26:15 +01:00
|
|
|
$int 0x40
|
|
|
|
}
|
|
|
|
|
|
|
|
:int DeleteFile(dword del_file_path)
|
|
|
|
{
|
2021-05-28 01:40:55 +02:00
|
|
|
f70.func = 8;
|
|
|
|
f70.param1 =
|
|
|
|
f70.param2 =
|
|
|
|
f70.param3 =
|
|
|
|
f70.param4 =
|
|
|
|
f70.rezerv = 0;
|
|
|
|
f70.name = del_file_path;
|
2012-11-26 16:26:15 +01:00
|
|
|
$mov eax,70
|
2021-05-28 01:40:55 +02:00
|
|
|
$mov ebx,#f70.func
|
2012-11-26 16:26:15 +01:00
|
|
|
$int 0x40
|
|
|
|
}
|
|
|
|
|
2018-03-26 16:31:26 +02:00
|
|
|
:int ReadFile(dword offset, data_size, buffer, file_path)
|
2012-11-26 16:26:15 +01:00
|
|
|
{
|
2021-05-28 01:40:55 +02:00
|
|
|
f70.func = 0;
|
|
|
|
f70.param1 = offset;
|
|
|
|
f70.param2 = 0;
|
|
|
|
f70.param3 = data_size;
|
|
|
|
f70.param4 = buffer;
|
|
|
|
f70.rezerv = 0;
|
|
|
|
f70.name = file_path;
|
2012-11-26 16:26:15 +01:00
|
|
|
$mov eax,70
|
2021-05-28 01:40:55 +02:00
|
|
|
$mov ebx,#f70.func
|
2012-11-26 16:26:15 +01:00
|
|
|
$int 0x40
|
|
|
|
}
|
|
|
|
|
2018-04-16 00:44:36 +02:00
|
|
|
:int CreateFile(dword data_size, buffer, file_path)
|
2012-11-26 16:26:15 +01:00
|
|
|
{
|
2021-05-28 01:40:55 +02:00
|
|
|
f70.func = 2;
|
|
|
|
f70.param1 = 0;
|
|
|
|
f70.param2 = 0;
|
|
|
|
f70.param3 = data_size;
|
|
|
|
f70.param4 = buffer;
|
|
|
|
f70.rezerv = 0;
|
|
|
|
f70.name = file_path;
|
2012-11-26 16:26:15 +01:00
|
|
|
$mov eax,70
|
2021-05-28 01:40:55 +02:00
|
|
|
$mov ebx,#f70.func
|
2012-11-26 16:26:15 +01:00
|
|
|
$int 0x40
|
2015-03-21 00:40:49 +01:00
|
|
|
}
|
|
|
|
|
2015-08-02 00:08:58 +02:00
|
|
|
////////////////////////////////////////
|
|
|
|
// WriteInFileThatAlredyExists //
|
|
|
|
////////////////////////////////////////
|
2018-04-16 00:44:36 +02:00
|
|
|
:int WriteFile(dword offset, data_size, buffer, file_path)
|
2015-03-21 00:40:49 +01:00
|
|
|
{
|
2021-05-28 01:40:55 +02:00
|
|
|
f70.func = 3;
|
|
|
|
f70.param1 = offset;
|
|
|
|
f70.param2 = 0;
|
|
|
|
f70.param3 = data_size;
|
|
|
|
f70.param4 = buffer;
|
|
|
|
f70.rezerv = 0;
|
|
|
|
f70.name = file_path;
|
|
|
|
$mov eax,70
|
|
|
|
$mov ebx,#f70.func
|
|
|
|
$int 0x40
|
|
|
|
}
|
|
|
|
|
|
|
|
:int RenameMove(dword path_to, path_from)
|
|
|
|
{
|
|
|
|
f70.func = 10;
|
|
|
|
f70.param1 =
|
|
|
|
f70.param2 =
|
|
|
|
f70.param3 = 0;
|
|
|
|
f70.param4 = path_to;
|
|
|
|
f70.rezerv = 0;
|
|
|
|
f70.name = path_from;
|
2015-03-21 00:40:49 +01:00
|
|
|
$mov eax,70
|
2021-05-28 01:40:55 +02:00
|
|
|
$mov ebx,#f70.func
|
2015-03-21 00:40:49 +01:00
|
|
|
$int 0x40
|
2018-03-26 16:31:26 +02:00
|
|
|
}
|
|
|
|
|
2012-11-26 16:26:15 +01:00
|
|
|
:int ReadDir(dword file_count, read_buffer, dir_path)
|
2013-03-11 19:16:24 +01:00
|
|
|
{
|
2021-05-28 01:40:55 +02:00
|
|
|
f70.func = 1;
|
|
|
|
f70.param1 =
|
|
|
|
f70.param2 =
|
|
|
|
f70.rezerv = 0;
|
|
|
|
f70.param3 = file_count;
|
|
|
|
f70.param4 = read_buffer;
|
|
|
|
f70.name = dir_path;
|
2012-11-26 16:26:15 +01:00
|
|
|
$mov eax,70
|
2021-05-28 01:40:55 +02:00
|
|
|
$mov ebx,#f70.func
|
2012-11-26 16:26:15 +01:00
|
|
|
$int 0x40
|
|
|
|
}
|
|
|
|
|
2018-11-06 18:05:54 +01:00
|
|
|
//ECX - buf pointer
|
2018-10-01 18:41:14 +02:00
|
|
|
inline fastcall void SetCurDir( ECX)
|
|
|
|
{
|
|
|
|
EAX=30;
|
|
|
|
EBX=1;
|
|
|
|
$int 0x40
|
|
|
|
}
|
|
|
|
|
2018-11-06 18:05:54 +01:00
|
|
|
//ECX - buf pointer
|
|
|
|
//EDX - buf size
|
|
|
|
inline fastcall void GetCurDir( ECX, EDX)
|
|
|
|
{
|
|
|
|
EAX=30;
|
|
|
|
EBX=2;
|
|
|
|
$int 0x40
|
|
|
|
}
|
|
|
|
|
2021-06-27 11:28:59 +02:00
|
|
|
:void read_file(dword path1, buf, size)
|
2020-12-13 02:21:31 +01:00
|
|
|
{
|
|
|
|
EAX = 68;
|
|
|
|
EBX = 27;
|
|
|
|
ECX = path1;
|
|
|
|
$int 0x40;
|
|
|
|
ESDWORD[size] = EDX;
|
|
|
|
ESDWORD[buf] = EAX;
|
|
|
|
}
|
|
|
|
|
2018-09-15 12:48:42 +02:00
|
|
|
//===================================================//
|
|
|
|
// //
|
|
|
|
// Misc //
|
|
|
|
// //
|
|
|
|
//===================================================//
|
|
|
|
|
2018-04-03 15:57:56 +02:00
|
|
|
:bool dir_exists(dword fpath)
|
|
|
|
{
|
|
|
|
char buf[32];
|
|
|
|
if (!ReadDir(0, #buf, fpath)) return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-12-13 13:31:53 +01:00
|
|
|
:dword get_file_size(dword _path)
|
|
|
|
{
|
|
|
|
BDVK bdvk;
|
|
|
|
if (GetFileInfo(_path, #bdvk)!=0) return 0;
|
|
|
|
else return bdvk.sizelo;
|
|
|
|
}
|
|
|
|
|
2018-04-03 15:57:56 +02:00
|
|
|
/*
|
|
|
|
// This implementation of dir_exists() is faster than
|
|
|
|
// previous but here virtual folders like
|
|
|
|
// '/' and '/tmp' are not recognised as FOLDERS
|
|
|
|
// by GetFileInfo() => BDVK.isfolder attribute :(
|
|
|
|
|
2018-03-22 00:26:31 +01:00
|
|
|
:bool dir_exists(dword fpath)
|
2013-04-02 15:33:32 +02:00
|
|
|
{
|
|
|
|
BDVK fpath_atr;
|
2017-07-04 17:14:51 +02:00
|
|
|
if (GetFileInfo(fpath, #fpath_atr) != 0) return false;
|
2015-02-27 21:25:28 +01:00
|
|
|
return fpath_atr.isfolder;
|
2013-04-02 15:33:32 +02:00
|
|
|
}
|
2018-04-03 15:57:56 +02:00
|
|
|
*/
|
|
|
|
|
2018-03-22 00:26:31 +01:00
|
|
|
:bool file_exists(dword fpath)
|
2016-02-19 01:33:21 +01:00
|
|
|
{
|
|
|
|
BDVK ReadFile_atr;
|
|
|
|
if (! GetFileInfo(fpath, #ReadFile_atr)) return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-04-04 19:07:38 +02:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
DIRS_ALL,
|
|
|
|
DIRS_NOROOT,
|
|
|
|
DIRS_ONLYREAL
|
|
|
|
};
|
|
|
|
:int GetDir(dword dir_buf, file_count, path, doptions)
|
2020-05-06 17:53:34 +02:00
|
|
|
dword buf, fcount, error;
|
|
|
|
char readbuf[32];
|
2013-03-11 19:16:24 +01:00
|
|
|
{
|
2020-05-06 17:53:34 +02:00
|
|
|
error = ReadDir(0, #readbuf, path);
|
2013-03-11 19:16:24 +01:00
|
|
|
if (!error)
|
|
|
|
{
|
2020-05-06 17:53:34 +02:00
|
|
|
fcount = ESDWORD[#readbuf+8];
|
|
|
|
buf = malloc(fcount+1*304+32);
|
2013-03-11 19:16:24 +01:00
|
|
|
ReadDir(fcount, buf, path);
|
2013-04-02 15:33:32 +02:00
|
|
|
//fcount=EBX;
|
2013-04-04 19:07:38 +02:00
|
|
|
|
|
|
|
if (doptions == DIRS_ONLYREAL)
|
|
|
|
{
|
|
|
|
if (!strcmp(".",buf+72)) {fcount--; memmov(buf,buf+304,fcount*304);}
|
|
|
|
if (!strcmp("..",buf+72)) {fcount--; memmov(buf,buf+304,fcount*304);}
|
|
|
|
}
|
|
|
|
if (doptions == DIRS_NOROOT)
|
|
|
|
{
|
|
|
|
if (!strcmp(".",buf+72)) {fcount--; memmov(buf,buf+304,fcount*304);}
|
|
|
|
}
|
|
|
|
|
2013-03-11 19:16:24 +01:00
|
|
|
ESDWORD[dir_buf] = buf;
|
|
|
|
ESDWORD[file_count] = fcount;
|
|
|
|
}
|
2013-04-02 15:33:32 +02:00
|
|
|
else
|
2012-11-26 16:26:15 +01:00
|
|
|
{
|
2020-05-06 17:53:34 +02:00
|
|
|
ESDWORD[dir_buf] = 0;
|
2018-09-14 20:22:11 +02:00
|
|
|
ESDWORD[file_count] = 0;
|
2012-11-26 16:26:15 +01:00
|
|
|
}
|
2013-04-02 15:33:32 +02:00
|
|
|
return error;
|
2012-11-26 16:26:15 +01:00
|
|
|
}
|
|
|
|
|
2013-03-30 01:52:50 +01:00
|
|
|
:dword abspath(dword relative_path) //GetAbsolutePathFromRelative()
|
|
|
|
{
|
|
|
|
char absolute_path[4096];
|
2013-10-30 02:12:01 +01:00
|
|
|
if (ESBYTE[relative_path]=='/')
|
|
|
|
{
|
|
|
|
strcpy(#absolute_path, relative_path);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-11-21 21:25:00 +01:00
|
|
|
strcpy(#absolute_path, I_Path);
|
2013-10-30 02:12:01 +01:00
|
|
|
absolute_path[strrchr(#absolute_path, '/')] = '\0';
|
|
|
|
strcat(#absolute_path, relative_path);
|
|
|
|
}
|
2013-03-30 01:52:50 +01:00
|
|
|
return #absolute_path;
|
|
|
|
}
|
2015-02-27 02:47:38 +01:00
|
|
|
|
2018-03-22 00:26:31 +01:00
|
|
|
:dword GetIni(dword ini_path, ini_name) //search it on /kolibrios/ then on /sys/
|
2018-03-20 18:03:14 +01:00
|
|
|
{
|
2018-03-22 00:26:31 +01:00
|
|
|
strcpy(ini_path, "/kolibrios/settings/");
|
|
|
|
strcat(ini_path, ini_name);
|
|
|
|
if (!file_exists(ini_path)) {
|
2018-04-01 14:34:23 +02:00
|
|
|
strcpy(ini_path, "/sys/SETTINGS/");
|
2018-03-22 00:26:31 +01:00
|
|
|
strcat(ini_path, ini_name);
|
2018-03-20 18:03:14 +01:00
|
|
|
}
|
2018-03-22 00:26:31 +01:00
|
|
|
return ini_path;
|
2018-03-20 18:03:14 +01:00
|
|
|
}
|
|
|
|
|
2018-09-15 12:48:42 +02:00
|
|
|
:dword notify(dword notify_param)
|
|
|
|
{
|
|
|
|
return RunProgram("/sys/@notify", notify_param);
|
|
|
|
}
|
|
|
|
|
|
|
|
:void die(dword _last_msg)
|
|
|
|
{
|
|
|
|
notify(_last_msg);
|
|
|
|
ExitProcess();
|
|
|
|
}
|
|
|
|
|
2021-06-26 09:59:13 +02:00
|
|
|
:bool file_name_is_8_3(dword name)
|
|
|
|
{
|
|
|
|
strlen(name);
|
|
|
|
if (EAX>12) return false;
|
|
|
|
$push eax
|
|
|
|
strrchr(name, '.');
|
|
|
|
$pop ebx
|
|
|
|
|
|
|
|
//EAX = dot pos
|
|
|
|
//EBX = name length
|
|
|
|
|
|
|
|
if (EAX) {
|
|
|
|
if (EBX-EAX>3) return false;
|
|
|
|
} else {
|
|
|
|
if (EBX>8) return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-09-15 12:48:42 +02:00
|
|
|
//===================================================//
|
|
|
|
// //
|
|
|
|
// Convert Size //
|
|
|
|
// //
|
|
|
|
//===================================================//
|
|
|
|
|
2015-07-21 03:10:37 +02:00
|
|
|
:byte ConvertSize_size_prefix[8];
|
2015-07-16 03:44:30 +02:00
|
|
|
:dword ConvertSize(dword bytes)
|
2015-02-27 02:47:38 +01:00
|
|
|
{
|
2015-07-21 03:10:37 +02:00
|
|
|
byte size_nm[4];
|
2015-09-05 16:04:04 +02:00
|
|
|
if (bytes>=1073741824) strlcpy(#size_nm, "Gb",2);
|
|
|
|
else if (bytes>=1048576) strlcpy(#size_nm, "Mb",2);
|
|
|
|
else if (bytes>=1024) strlcpy(#size_nm, "Kb",2);
|
2021-07-06 09:17:41 +02:00
|
|
|
else strlcpy(#size_nm, "B ",2);
|
2017-09-18 11:49:04 +02:00
|
|
|
while (bytes>1023) bytes >>= 10;
|
2015-07-21 03:10:37 +02:00
|
|
|
sprintf(#ConvertSize_size_prefix,"%d %s",bytes,#size_nm);
|
|
|
|
return #ConvertSize_size_prefix;
|
2015-03-01 22:36:17 +01:00
|
|
|
}
|
2018-04-03 15:57:56 +02:00
|
|
|
|
2017-09-18 10:38:34 +02:00
|
|
|
:dword ConvertSize64(dword bytes_lo, bytes_hi)
|
|
|
|
{
|
|
|
|
if (bytes_hi > 0) {
|
2017-09-18 11:49:04 +02:00
|
|
|
if (bytes_lo>=1073741824) bytes_lo >>= 30; else bytes_lo = 0;
|
|
|
|
sprintf(#ConvertSize_size_prefix,"%d Gb",bytes_hi<<2 + bytes_lo);
|
2017-09-18 10:38:34 +02:00
|
|
|
return #ConvertSize_size_prefix;
|
|
|
|
}
|
|
|
|
else return ConvertSize(bytes_lo);
|
|
|
|
}
|
2018-04-03 15:57:56 +02:00
|
|
|
|
2018-09-15 12:48:42 +02:00
|
|
|
:unsigned char size[25];
|
2015-03-01 22:36:17 +01:00
|
|
|
:dword ConvertSizeToKb(unsigned int bytes)
|
|
|
|
{
|
|
|
|
dword kb_line;
|
|
|
|
|
2016-10-05 15:26:19 +02:00
|
|
|
if (bytes >= 1024)
|
|
|
|
{
|
|
|
|
kb_line = itoa(bytes / 1024);
|
|
|
|
strcpy(#size, kb_line);
|
2021-07-06 09:17:41 +02:00
|
|
|
strcat(#size, " Kb");
|
2016-10-05 15:26:19 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
kb_line = itoa(bytes);
|
|
|
|
strcpy(#size, kb_line);
|
2021-07-06 09:17:41 +02:00
|
|
|
strcat(#size, " B");
|
2016-10-05 15:26:19 +02:00
|
|
|
}
|
2015-03-01 22:36:17 +01:00
|
|
|
|
|
|
|
return #size;
|
2015-07-22 20:32:54 +02:00
|
|
|
}
|
2018-03-26 16:31:26 +02:00
|
|
|
|
2018-09-15 12:48:42 +02:00
|
|
|
//===================================================//
|
|
|
|
// //
|
|
|
|
// Copy //
|
|
|
|
// //
|
|
|
|
//===================================================//
|
|
|
|
|
2018-03-26 16:31:26 +02:00
|
|
|
:int CopyFileAtOnce(dword size, copyFrom, copyTo)
|
|
|
|
dword cbuf;
|
|
|
|
int error;
|
|
|
|
{
|
|
|
|
cbuf = malloc(size);
|
|
|
|
if (error = ReadFile(0, size, cbuf, copyFrom))
|
|
|
|
{
|
|
|
|
debugln("Error: CopyFileAtOnce->ReadFile");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-04-16 00:44:36 +02:00
|
|
|
if (error = CreateFile(size, cbuf, copyTo)) debugln("Error: CopyFileAtOnce->CreateFile");
|
2018-03-26 16:31:26 +02:00
|
|
|
}
|
|
|
|
free(cbuf);
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
:int CopyFileByBlocks(dword size, copyFrom, copyTo)
|
|
|
|
dword cbuf;
|
|
|
|
int error=-1;
|
|
|
|
dword offpos=0;
|
2018-04-16 00:44:36 +02:00
|
|
|
int block_size=1024*1024*4; //copy by 4 MiB
|
2018-03-26 16:31:26 +02:00
|
|
|
{
|
2018-04-16 00:44:36 +02:00
|
|
|
if (GetFreeRAM()>1024*78) {
|
|
|
|
//Set block size 32 MiB
|
|
|
|
block_size <<= 3;
|
|
|
|
}
|
2018-03-26 16:31:26 +02:00
|
|
|
cbuf = malloc(block_size);
|
2018-04-16 00:44:36 +02:00
|
|
|
if (error = CreateFile(0, 0, copyTo))
|
|
|
|
{
|
|
|
|
debugln("Error: CopyFileByBlocks->CreateFile");
|
|
|
|
size = -1;
|
|
|
|
}
|
2018-03-26 16:31:26 +02:00
|
|
|
while(offpos < size)
|
|
|
|
{
|
|
|
|
error = ReadFile(offpos, block_size, cbuf, copyFrom);
|
|
|
|
if (error = 6) { //File ended before last byte was readed
|
|
|
|
block_size = EBX;
|
2018-04-16 00:44:36 +02:00
|
|
|
if (block_size+offpos>=size) error=0;
|
2018-03-26 16:31:26 +02:00
|
|
|
}
|
|
|
|
else
|
2018-04-16 00:44:36 +02:00
|
|
|
if (error!=0) {
|
|
|
|
debugln("Error: CopyFileByBlocks->ReadFile");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (error = WriteFile(offpos, block_size, cbuf, copyTo)) {
|
|
|
|
debugln("Error: CopyFileByBlocks->WriteFile");
|
|
|
|
break;
|
|
|
|
}
|
2018-03-26 16:31:26 +02:00
|
|
|
offpos += block_size;
|
|
|
|
}
|
|
|
|
free(cbuf);
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2018-09-15 12:48:42 +02:00
|
|
|
//===================================================//
|
|
|
|
// //
|
|
|
|
// Directory Size //
|
|
|
|
// //
|
|
|
|
//===================================================//
|
|
|
|
|
2020-05-06 17:53:34 +02:00
|
|
|
:struct DIR_SIZE
|
2018-09-15 12:48:42 +02:00
|
|
|
{
|
|
|
|
BDVK dir_info;
|
|
|
|
dword folders;
|
|
|
|
dword files;
|
|
|
|
dword bytes;
|
2020-05-06 17:53:34 +02:00
|
|
|
dword get();
|
|
|
|
dword calculate_loop();
|
|
|
|
};
|
2018-09-15 12:48:42 +02:00
|
|
|
|
2020-05-06 17:53:34 +02:00
|
|
|
:dword DIR_SIZE::get(dword way1)
|
2018-09-15 12:48:42 +02:00
|
|
|
{
|
|
|
|
folders = files = bytes = 0;
|
2020-05-06 17:53:34 +02:00
|
|
|
if (!way1) return 0;
|
|
|
|
calculate_loop(way1);
|
2018-09-15 12:48:42 +02:00
|
|
|
}
|
|
|
|
|
2020-05-06 17:53:34 +02:00
|
|
|
:dword DIR_SIZE::calculate_loop(dword way)
|
2018-09-15 12:48:42 +02:00
|
|
|
{
|
|
|
|
dword dirbuf, fcount, i, filename;
|
|
|
|
dword cur_file;
|
2020-05-06 17:53:34 +02:00
|
|
|
if (!way) return 0;
|
2018-09-15 12:48:42 +02:00
|
|
|
if (dir_exists(way))
|
|
|
|
{
|
|
|
|
cur_file = malloc(4096);
|
|
|
|
// In the process of recursive descent, memory must be allocated dynamically,
|
|
|
|
// because the static memory -> was a bug !!! But unfortunately pass away to sacrifice speed.
|
|
|
|
GetDir(#dirbuf, #fcount, way, DIRS_ONLYREAL);
|
|
|
|
for (i=0; i<fcount; i++)
|
|
|
|
{
|
|
|
|
filename = i*304+dirbuf+72;
|
|
|
|
sprintf(cur_file,"%s/%s",way,filename);
|
|
|
|
|
2021-06-25 15:21:42 +02:00
|
|
|
if (ESDWORD[filename-40] & ATR_FOLDER )
|
2018-09-15 12:48:42 +02:00
|
|
|
{
|
|
|
|
folders++;
|
|
|
|
calculate_loop(cur_file);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
GetFileInfo(cur_file, #dir_info);
|
|
|
|
bytes += dir_info.sizelo;
|
|
|
|
files++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
free(cur_file);
|
|
|
|
free(dirbuf);
|
|
|
|
}
|
2020-05-06 17:53:34 +02:00
|
|
|
return files;
|
2018-09-15 12:48:42 +02:00
|
|
|
}
|
2018-03-26 16:31:26 +02:00
|
|
|
|
2020-05-06 17:53:34 +02:00
|
|
|
|
2015-07-22 20:32:54 +02:00
|
|
|
#endif
|