Subversion Repositories Kolibri OS

Rev

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

Rev 3440 Rev 3444
Line 1... Line 1...
1
// универсальность добавления /
1
//copyf - copy file or folder with content
2
 
-
 
3
:void copyf(dword from1, in1)
2
:int copyf(dword from1, in1)
4
{
3
{
5
	dword error;
4
	dword error;
6
	BDVK CopyFile_atr1;
5
	BDVK CopyFile_atr1;
-
 
6
	if (!from1) || (!in1)
-
 
7
	{
7
	if (!from1) || (!in1) { notify("Error: too less copyf params!"); notify(from1); notify(in1); return; }
8
		notify("Error: too less copyf params!");
-
 
9
		notify(from1);
-
 
10
		notify(in1);
-
 
11
		return;
-
 
12
	}
8
	error = GetFileInfo(from1, #CopyFile_atr1);
13
	if (error = GetFileInfo(from1, #CopyFile_atr1))
9
	if (error) 
14
	{
10
		debug("Error: copyf->GetFileInfo");
15
		debug("Error: copyf->GetFileInfo");
-
 
16
		return error;
-
 
17
	}
-
 
18
	if (isdir(from1))
-
 
19
		return CopyFolder(from1, in1);
11
	else
20
	else
12
		if (isdir(from1)) CopyFolder(from1, in1); else CopyFile(from1, in1);
21
		return CopyFile(from1, in1);
13
}
22
}
Line 14... Line 23...
14
 
23
 
15
:int CopyFile(dword copy_from3, copy_in3)
24
:int CopyFile(dword copy_from3, copy_in3)
16
{
25
{
17
	BDVK CopyFile_atr;
26
	BDVK CopyFile_atr;
18
	dword error, cbuf;
-
 
19
	debug(copy_from3);
27
	dword error, cbuf;
20
	error = GetFileInfo(copy_from3, #CopyFile_atr);
-
 
21
	if (error)
28
	if (error = GetFileInfo(copy_from3, #CopyFile_atr))
22
		{debug("Error: CopyFile->GetFileInfo"); debug(copy_from3);}
29
		debug("Error: CopyFile->GetFileInfo");
23
	else
30
	else
24
	{
31
	{
25
		cbuf = malloc(CopyFile_atr.sizelo);	
32
		cbuf = malloc(CopyFile_atr.sizelo);	
26
		error = ReadFile(0, CopyFile_atr.sizelo, cbuf, copy_from3);
-
 
27
		if (error)
33
		if (error = ReadFile(0, CopyFile_atr.sizelo, cbuf, copy_from3))
28
			debug("Error: CopyFile->ReadFile");
34
			debug("Error: CopyFile->ReadFile");
29
		else
35
		else
30
		{
36
		{
31
			error = WriteFile(CopyFile_atr.sizelo, cbuf, copy_in3);
-
 
32
			if (error) debug("Error: CopyFile->WriteFile");
37
			if (error = WriteFile(CopyFile_atr.sizelo, cbuf, copy_in3)) debug("Error: CopyFile->WriteFile");
33
		}
38
		}
34
	}
39
	}
35
	free(cbuf);
40
	free(cbuf);
36
	if (error) debug(copy_from3);
41
	if (error) debug_error(copy_from3, error);
37
	return error;
42
	return error;
Line 38... Line 43...
38
}
43
}
39
 
44
 
40
:void CopyFolder(dword from2, in2)
45
:int CopyFolder(dword from2, in2)
41
{
-
 
42
	dword dirbuf, fcount, filename;
46
{
Line 43... Line 47...
43
	int i, error, isdir;
47
	dword dirbuf, fcount, i, filename;
44
	char copy_from2[4096], copy_in2[4096];
-
 
45
 
48
	char copy_from2[4096], copy_in2[4096], error;
46
	error = GetDir(#dirbuf, #fcount, from2);
49
 
47
	if (error)
50
	if (error = GetDir(#dirbuf, #fcount, from2, DIRS_ONLYREAL))
48
	{
-
 
49
		debug("Error: CopyFolder->GetDir");
51
	{
50
		debug_error(from2, error);
52
		debug("Error: CopyFolder->GetDir");
51
		debug_error(in2, error);
53
		debug_error(from2, error);
Line 52... Line 54...
52
		free(dirbuf);
54
		free(dirbuf);
53
		return;
55
		return error;
54
	}
56
	}
55
	
57
	
-
 
58
	if (chrnum(in2, '/')>2) && (error = CreateDir(in2))
-
 
59
	{
56
	if ((strcmp(in2, "/sys")!=0) && (strcmp(in2, "/tmp9/1")!=0))
60
		debug("Error: CopyFolder->CreateDir");
57
	{
-
 
58
		error = CreateDir(in2);
-
 
Line 59... Line 61...
59
		if (error) debug_error(in2, error);
61
		debug_error(in2, error);
60
	}
62
		free(dirbuf);
61
	chrcat(in2, '/');
63
		return error;
62
	chrcat(from2, '/');
-
 
63
 
-
 
64
	for (i=0; i
-
 
65
	{
-
 
66
		filename = i*304+dirbuf+72;
64
	}
67
		isdir = TestBit(ESDWORD[filename-40], 4);
65
 
68
		if (isdir)
66
	for (i=0; i
-
 
67
	{
-
 
68
		filename = i*304+dirbuf+72;
69
		{
69
		strcpy(#copy_from2, from2);
Line -... Line 70...
-
 
70
		chrcat(#copy_from2, '/');
-
 
71
		strcat(#copy_from2, filename);
-
 
72
		strcpy(#copy_in2, in2);
70
			if ( (!strcmp(filename, ".")) || (!strcmp(filename, "..")) ) continue;
73
		chrcat(#copy_in2, '/');
71
			strcpy(#copy_from2, from2);
74
		strcat(#copy_in2, filename);
72
			strcpy(#copy_in2, in2);
75
 
73
			strcat(#copy_from2, filename);
76
		if ( TestBit(ESDWORD[filename-40], 4) ) //isdir?
74
			strcat(#copy_in2, filename);
-
 
75
 
-
 
76
			CopyFolder(#copy_from2, #copy_in2);
-
 
77
		}
-
 
78
		else
-
 
79
		{
77
		{
-
 
78
			if ( (!strcmp(filename, ".")) || (!strcmp(filename, "..")) ) continue;
80
			strcpy(#copy_from2, from2);
79
			CopyFolder(#copy_from2, #copy_in2);
-
 
80
		}
81
			strcat(#copy_from2, filename);
81
		else
-
 
82
		{
82
			strcpy(#copy_in2, in2);
83
			copyf_Action(filename);
83
			strcat(#copy_in2, filename);
84
			if (error=CopyFile(#copy_from2, #copy_in2)) 
84
 
85
			{
-
 
86
				if (fabs(error)==8) { debug("Stop copying."); break;} //TODO: may be need grobal var like stop_all
85
			copyf_Action(filename);
87
				error=CopyFile(#copy_from2, #copy_in2); // #2 :)
Line 86... Line 88...
86
 
88
			}
87
			if (CopyFile(#copy_from2, #copy_in2)!=0) CopyFile(#copy_from2, #copy_in2); // #2 :)
89
		}