Subversion Repositories Kolibri OS

Rev

Rev 3440 | Rev 3877 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
3444 leency 1
//copyf - copy file or folder with content
2
:int copyf(dword from1, in1)
3434 leency 3
{
3440 leency 4
	dword error;
5
	BDVK CopyFile_atr1;
3444 leency 6
	if (!from1) || (!in1)
7
	{
8
		notify("Error: too less copyf params!");
9
		notify(from1);
10
		notify(in1);
11
		return;
12
	}
13
	if (error = GetFileInfo(from1, #CopyFile_atr1))
14
	{
3440 leency 15
		debug("Error: copyf->GetFileInfo");
3444 leency 16
		return error;
17
	}
18
	if (isdir(from1))
19
		return CopyFolder(from1, in1);
3440 leency 20
	else
3444 leency 21
		return CopyFile(from1, in1);
3440 leency 22
}
3434 leency 23
 
3440 leency 24
:int CopyFile(dword copy_from3, copy_in3)
25
{
26
	BDVK CopyFile_atr;
27
	dword error, cbuf;
3444 leency 28
	if (error = GetFileInfo(copy_from3, #CopyFile_atr))
29
		debug("Error: CopyFile->GetFileInfo");
3434 leency 30
	else
31
	{
3440 leency 32
		cbuf = malloc(CopyFile_atr.sizelo);
3444 leency 33
		if (error = ReadFile(0, CopyFile_atr.sizelo, cbuf, copy_from3))
3440 leency 34
			debug("Error: CopyFile->ReadFile");
35
		else
36
		{
3444 leency 37
			if (error = WriteFile(CopyFile_atr.sizelo, cbuf, copy_in3)) debug("Error: CopyFile->WriteFile");
3440 leency 38
		}
3434 leency 39
	}
3440 leency 40
	free(cbuf);
3444 leency 41
	if (error) debug_error(copy_from3, error);
3440 leency 42
	return error;
3434 leency 43
}
44
 
3444 leency 45
:int CopyFolder(dword from2, in2)
3434 leency 46
{
3444 leency 47
	dword dirbuf, fcount, i, filename;
48
	char copy_from2[4096], copy_in2[4096], error;
3434 leency 49
 
3444 leency 50
	if (error = GetDir(#dirbuf, #fcount, from2, DIRS_ONLYREAL))
3440 leency 51
	{
52
		debug("Error: CopyFolder->GetDir");
53
		debug_error(from2, error);
54
		free(dirbuf);
3444 leency 55
		return error;
3440 leency 56
	}
3434 leency 57
 
3444 leency 58
	if (chrnum(in2, '/')>2) && (error = CreateDir(in2))
3434 leency 59
	{
3444 leency 60
		debug("Error: CopyFolder->CreateDir");
61
		debug_error(in2, error);
62
		free(dirbuf);
63
		return error;
3434 leency 64
	}
65
 
66
	for (i=0; i
67
	{
68
		filename = i*304+dirbuf+72;
3444 leency 69
		strcpy(#copy_from2, from2);
70
		chrcat(#copy_from2, '/');
71
		strcat(#copy_from2, filename);
72
		strcpy(#copy_in2, in2);
73
		chrcat(#copy_in2, '/');
74
		strcat(#copy_in2, filename);
75
 
76
		if ( TestBit(ESDWORD[filename-40], 4) ) //isdir?
3434 leency 77
		{
78
			if ( (!strcmp(filename, ".")) || (!strcmp(filename, "..")) ) continue;
3440 leency 79
			CopyFolder(#copy_from2, #copy_in2);
3434 leency 80
		}
81
		else
82
		{
83
			copyf_Action(filename);
3444 leency 84
			if (error=CopyFile(#copy_from2, #copy_in2))
85
			{
86
				if (fabs(error)==8) { debug("Stop copying."); break;} //TODO: may be need grobal var like stop_all
87
				error=CopyFile(#copy_from2, #copy_in2); // #2 :)
88
			}
3434 leency 89
		}
90
	}
91
	free(dirbuf);
3444 leency 92
	return error;
3434 leency 93
}
94
 
3440 leency 95
 
3434 leency 96
unsigned char *ERROR_TEXT[]={
97
"Code #0 - No error",
98
"Error #1 - Base or partition of a hard disk is not defined",
99
"Error #2 - Function isn't supported for this file system",
100
"Error #3 - Unknown file system",
101
"Error #4 - Reserved, is never returned",
102
"Error #5 - File or folder not found",
103
"Error #6 - End of file, EOF",
104
"Error #7 - Pointer lies outside of application memory",
105
"Error #8 - Too less disk space",
106
"Error #9 - FAT table is destroyed",
107
"Error #10 - Access denied",
108
"Error #11 - Device error",
109
0, 0, 0, 0, 0, 0, 0, 0, 0,
110
0, 0, 0, 0, 0, 0, 0, 0, 0,
111
"Error #30 - Not enough memory",
112
"Error #31 - File is not executable",
113
"Error #32 - Too many processes",
114
0};
115
 
3440 leency 116
:dword get_error(int N)
3434 leency 117
{
3440 leency 118
	char error[256];
119
	N = fabs(N);
120
	if (N<=33)
3434 leency 121
	{
122
		strcpy(#error, ERROR_TEXT[N]);
123
	}
124
	else
125
	{
126
		strcpy(#error, itoa(N));
127
		strcat(#error, " - Unknown error number O_o");
128
	}
129
	return #error;
130
}
131
 
3440 leency 132
:void debug_error(dword path, error_number)
3434 leency 133
{
134
	if (path) debug(path);
135
	debug(get_error(error_number));
136
}