Subversion Repositories Kolibri OS

Rev

Rev 3434 | Rev 3444 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3434 Rev 3440
Line 1... Line 1...
1
// универсальность добавления /
1
// универсальность добавления /
2
// относительный путь относительно программы
-
 
Line 3... Line 2...
3
 
2
 
4
void copyf(dword params)
3
:void copyf(dword from1, in1)
5
{
-
 
6
	//copyf:  /sys/lib|/sys/lib2
4
{
7
	char from[4096], to[4096];
5
	dword error;
8
	BDVK from_atr;
-
 
9
	int border;
-
 
10
 
6
	BDVK CopyFile_atr1;
11
	if (!params) { notify("Error: no copyf params!"); return; }
7
	if (!from1) || (!in1) { notify("Error: too less copyf params!"); notify(from1); notify(in1); return; }
-
 
8
	error = GetFileInfo(from1, #CopyFile_atr1);
12
	//ищем разделитель
9
	if (error) 
-
 
10
		debug("Error: copyf->GetFileInfo");
13
	border = strchr(params, '|');
11
	else
-
 
12
		if (isdir(from1)) CopyFolder(from1, in1); else CopyFile(from1, in1);
Line 14... Line 13...
14
	if (!border) border = strchr(params, ' ');
13
}
15
 
14
 
-
 
15
:int CopyFile(dword copy_from3, copy_in3)
16
	if (ESBYTE[params]<>'/') //абсолютный путь?
16
{
17
	{
17
	BDVK CopyFile_atr;
18
		strcpy(#from, #program_path);
18
	dword error, cbuf;
19
		strcat(#from, params);
19
	debug(copy_from3);
-
 
20
	error = GetFileInfo(copy_from3, #CopyFile_atr);
20
		from[border+strlen(#program_path)-1]=NULL;
21
	if (error)
21
	}
22
		{debug("Error: CopyFile->GetFileInfo"); debug(copy_from3);}
22
	else
-
 
23
	{
-
 
24
		strcat(#from, params);
-
 
25
		from[border-1]=NULL;		
23
	else
26
	}
-
 
27
	strcpy(#to, params+border);
24
	{
28
 
25
		cbuf = malloc(CopyFile_atr.sizelo);	
29
	GetFileInfo(#from, #from_atr);
26
		error = ReadFile(0, CopyFile_atr.sizelo, cbuf, copy_from3);
30
	if (TestBit(from_atr.attr, 4)==1)
27
		if (error)
-
 
28
			debug("Error: CopyFile->ReadFile");
-
 
29
		else
-
 
30
		{
-
 
31
			error = WriteFile(CopyFile_atr.sizelo, cbuf, copy_in3);
-
 
32
			if (error) debug("Error: CopyFile->WriteFile");
-
 
33
		}
31
		CopyFolder(#from, #to);
34
	}
-
 
35
	free(cbuf);
32
	else
36
	if (error) debug(copy_from3);
Line 33... Line -...
33
		CopyFile(#from, #to);
-
 
34
}
37
	return error;
35
 
38
}
36
 
39
 
37
void CopyFolder(dword from, to)
40
:void CopyFolder(dword from2, in2)
38
{
41
{
39
	dword dirbuf, fcount, filename;
-
 
Line 40... Line 42...
40
	int i, error, isdir;
42
	dword dirbuf, fcount, filename;
-
 
43
	int i, error, isdir;
-
 
44
	char copy_from2[4096], copy_in2[4096];
-
 
45
 
41
	char copy_from[4096], copy_in[4096];
46
	error = GetDir(#dirbuf, #fcount, from2);
-
 
47
	if (error)
-
 
48
	{
-
 
49
		debug("Error: CopyFolder->GetDir");
-
 
50
		debug_error(from2, error);
Line 42... Line 51...
42
	char from2[4096], to2[4096];
51
		debug_error(in2, error);
43
 
52
		free(dirbuf);
44
	error = GetDir(#dirbuf, #fcount, from);
53
		return;
45
	if (error) { debug_error(from, error); return; }
54
	}
46
	
55
	
47
	if ((strcmp(to, "/sys")!=0) && (strcmp(to, "/tmp9/1")!=0))
56
	if ((strcmp(in2, "/sys")!=0) && (strcmp(in2, "/tmp9/1")!=0))
48
	{
57
	{
Line 49... Line 58...
49
		error = CreateDir(to);
58
		error = CreateDir(in2);
50
		if (error) debug_error(to, error);
59
		if (error) debug_error(in2, error);
51
	}
60
	}
52
	chrcat(to, '/');
-
 
53
	chrcat(from, '/');
61
	chrcat(in2, '/');
54
 
62
	chrcat(from2, '/');
55
	for (i=0; i
63
 
56
	{
64
	for (i=0; i
57
		filename = i*304+dirbuf+72;
65
	{
58
 
66
		filename = i*304+dirbuf+72;
-
 
67
		isdir = TestBit(ESDWORD[filename-40], 4);
-
 
68
		if (isdir)
Line 59... Line -...
59
		isdir = TestBit(ESDWORD[filename-40], 4);
-
 
60
		if (isdir)
-
 
61
		{
-
 
62
			if ( (!strcmp(filename, ".")) || (!strcmp(filename, "..")) ) continue;
69
		{
63
			strcpy(#from2, from);
70
			if ( (!strcmp(filename, ".")) || (!strcmp(filename, "..")) ) continue;
64
			strcpy(#to2, to);
71
			strcpy(#copy_from2, from2);
65
 
72
			strcpy(#copy_in2, in2);
66
			strcat(#from2, filename);
73
			strcat(#copy_from2, filename);
67
			strcat(#to2, filename);
74
			strcat(#copy_in2, filename);
68
 
75
 
69
			CopyFolder(#from2, #to2);
76
			CopyFolder(#copy_from2, #copy_in2);
Line 70... Line 77...
70
		}
77
		}
Line 71... Line -...
71
		else
-
 
72
		{
78
		else
73
			strcpy(#copy_from, from);
-
 
74
			strcat(#copy_from, filename);
79
		{
75
			strcpy(#copy_in, to);
80
			strcpy(#copy_from2, from2);
76
			strcat(#copy_in, filename);
81
			strcat(#copy_from2, filename);
77
 
82
			strcpy(#copy_in2, in2);
Line -... Line 83...
-
 
83
			strcat(#copy_in2, filename);
78
			copyf_Action(filename);
84
 
79
 
85
			copyf_Action(filename);
80
			error = CopyFile(#copy_from, #copy_in);
86
 
81
			if (error) error = CopyFile(#copy_from, #copy_in); // #2 :)
87
			if (CopyFile(#copy_from2, #copy_in2)!=0) CopyFile(#copy_from2, #copy_in2); // #2 :)
82
			if (error) debug_error(#copy_in, error);
88
		}
Line 103... Line 109...
103
"Error #30 - Not enough memory",
109
"Error #30 - Not enough memory",
104
"Error #31 - File is not executable",
110
"Error #31 - File is not executable",
105
"Error #32 - Too many processes",
111
"Error #32 - Too many processes",
106
0}; 
112
0}; 
Line 107... Line 113...
107
 
113
 
108
dword get_error(int N)
114
:dword get_error(int N)
109
{
115
{
110
	char error[256];
116
	char error[256];  
111
	if (N<0) N*=-1;   
117
	N = fabs(N);
112
	if (N<33)
118
	if (N<=33)
113
	{
119
	{
114
		strcpy(#error, ERROR_TEXT[N]);
120
		strcpy(#error, ERROR_TEXT[N]);
115
	}
121
	}
116
	else
122
	else
Line 119... Line 125...
119
		strcat(#error, " - Unknown error number O_o");
125
		strcat(#error, " - Unknown error number O_o");
120
	}
126
	}
121
	return #error;
127
	return #error;
122
}
128
}
Line 123... Line 129...
123
 
129
 
124
void debug_error(dword path, error_number)
130
:void debug_error(dword path, error_number)
125
{
131
{
126
	if (path) debug(path);
132
	if (path) debug(path);
127
	debug(get_error(error_number));
133
	debug(get_error(error_number));
128
}
134
}