Subversion Repositories Kolibri OS

Rev

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

Rev 6251 Rev 6278
1
//copyf - copy file or folder with content
1
//copyf - copy file or folder with content
2
#ifndef INCLUDE_COPYF_H
2
#ifndef INCLUDE_COPYF_H
3
#define INCLUDE_COPYF_H
3
#define INCLUDE_COPYF_H
4
#print "[include ]\n"
4
#print "[include ]\n"
5
 
5
 
6
#ifndef INCLUDE_FILESYSTEM_H
6
#ifndef INCLUDE_FILESYSTEM_H
7
#include "../lib/file_system.h"
7
#include "../lib/file_system.h"
8
#endif
8
#endif
9
 
9
 
10
:int copyf(dword from1, in1)
10
:int copyf(dword from1, in1)
11
{
11
{
12
	dword error;
12
	dword error;
13
	BDVK CopyFile_atr1;
13
	BDVK CopyFile_atr1;
14
 
14
 
15
	if (!from1) || (!in1)
15
	if (!from1) || (!in1)
16
	{
16
	{
17
		notify("Error: too less copyf params!");
17
		notify("Error: too less copyf params!");
18
		notify(from1);
18
		notify(from1);
19
		notify(in1);
19
		notify(in1);
20
		return;
20
		return;
21
	}
21
	}
22
	if (error = GetFileInfo(from1, #CopyFile_atr1))
22
	if (error = GetFileInfo(from1, #CopyFile_atr1))
23
	{
23
	{
24
		debugln("Error: copyf->GetFileInfo");
24
		debugln("Error: copyf->GetFileInfo");
25
		return error;
25
		return error;
26
	}
26
	}
27
	if (dir_exists(from1))
27
	if (dir_exists(from1))
28
		return CopyFolder(from1, in1);
28
		return CopyFolder(from1, in1);
29
	else
29
	else
30
	{
30
	{
31
		Operation_Draw_Progress(from1+strchr(from1, '/'));
31
		Operation_Draw_Progress(from1+strchr(from1, '/'));
32
		return CopyFile(from1, in1);
32
		return CopyFile(from1, in1);
33
	}
33
	}
34
}
34
}
35
 
35
 
36
:int CopyFile(dword copy_from3, copy_in3)
36
:int CopyFile(dword copy_from3, copy_in3)
37
{
37
{
38
	BDVK CopyFile_atr;
38
	BDVK CopyFile_atr;
39
	dword error, cbuf;
39
	dword error, cbuf;
40
	if (error = GetFileInfo(copy_from3, #CopyFile_atr))
40
	if (error = GetFileInfo(copy_from3, #CopyFile_atr))
41
	{
41
	{
42
		debugln("Error: CopyFile->GetFileInfo");
42
		debugln("Error: CopyFile->GetFileInfo");
43
	}
43
	}
44
	else
44
	else
45
	{
45
	{
46
		cbuf = malloc(CopyFile_atr.sizelo);	
46
		cbuf = malloc(CopyFile_atr.sizelo);	
47
		if (error = ReadFile(0, CopyFile_atr.sizelo, cbuf, copy_from3))
47
		if (error = ReadFile(0, CopyFile_atr.sizelo, cbuf, copy_from3))
48
		{
48
		{
49
			debugln("Error: CopyFile->ReadFile");
49
			debugln("Error: CopyFile->ReadFile");
50
		}
50
		}
51
		else
51
		else
52
		{
52
		{
53
			if (error = WriteFile(CopyFile_atr.sizelo, cbuf, copy_in3)) debugln("Error: CopyFile->WriteFile");
53
			if (error = WriteFile(CopyFile_atr.sizelo, cbuf, copy_in3)) debugln("Error: CopyFile->WriteFile");
54
		}
54
		}
55
	}
55
	}
56
	free(cbuf);
56
	free(cbuf);
57
	if (error) debug_error(copy_from3, error);
57
	if (error) debug_error(copy_from3, error);
58
	return error;
58
	return error;
59
}
59
}
60
 
60
 
61
:int CopyFolder(dword from2, in2)
61
:int CopyFolder(dword from2, in2)
62
{
62
{
63
	dword dirbuf, fcount, i, filename;
63
	dword dirbuf, fcount, i, filename;
64
	char copy_from2[4096], copy_in2[4096], error;
64
	char copy_from2[4096], copy_in2[4096], error;
65
 
65
 
66
	if (error = GetDir(#dirbuf, #fcount, from2, DIRS_ONLYREAL))
66
	if (error = GetDir(#dirbuf, #fcount, from2, DIRS_ONLYREAL))
67
	{
67
	{
68
		debugln("Error: CopyFolder->GetDir");
68
		debugln("Error: CopyFolder->GetDir");
69
		debug_error(from2, error);
69
		debug_error(from2, error);
70
		free(dirbuf);
70
		free(dirbuf);
71
		return error;
71
		return error;
72
	}
72
	}
73
 
73
 
74
	if (chrnum(in2, '/')>2) && (error = CreateDir(in2))
74
	if (chrnum(in2, '/')>2) && (error = CreateDir(in2))
75
	{
75
	{
76
		debugln("Error: CopyFolder->CreateDir");
76
		debugln("Error: CopyFolder->CreateDir");
77
		debug_error(in2, error);
77
		debug_error(in2, error);
78
		free(dirbuf);
78
		free(dirbuf);
79
		return error;
79
		return error;
80
	}
80
	}
81
 
81
 
82
	for (i=0; i
82
	for (i=0; i
83
	{
83
	{
84
		filename = i*304+dirbuf+72;
84
		filename = i*304+dirbuf+72;
85
		sprintf(#copy_from2,"%s/%s",from2,filename);
85
		sprintf(#copy_from2,"%s/%s",from2,filename);
86
		sprintf(#copy_in2,"%s/%s",in2,filename);
86
		sprintf(#copy_in2,"%s/%s",in2,filename);
87
 
87
 
88
		if ( TestBit(ESDWORD[filename-40], 4) ) //dir_exists?
88
		if ( TestBit(ESDWORD[filename-40], 4) ) //dir_exists?
89
		{
89
		{
90
			if ( (!strncmp(filename, ".",1)) || (!strncmp(filename, "..",2)) ) continue;
90
			if ( (!strncmp(filename, ".",1)) || (!strncmp(filename, "..",2)) ) continue;
91
			CopyFolder(#copy_from2, #copy_in2);
91
			CopyFolder(#copy_from2, #copy_in2);
92
		}
92
		}
93
		else
93
		else
94
		{
94
		{
95
			Operation_Draw_Progress(filename);
95
			Operation_Draw_Progress(filename+strchr(filename, '/'));
96
			if (error=CopyFile(#copy_from2, #copy_in2)) 
96
			if (error=CopyFile(#copy_from2, #copy_in2)) 
97
			{
97
			{
98
				if (fabs(error)==8) { debugln("Stop copying."); break;} //TODO: may be need grobal var like stop_all
98
				if (fabs(error)==8) { debugln("Stop copying."); break;} //TODO: may be need grobal var like stop_all
99
				error=CopyFile(#copy_from2, #copy_in2); // #2 :)
99
				error=CopyFile(#copy_from2, #copy_in2); // #2 :)
100
			}
100
			}
101
		}
101
		}
102
	}
102
	}
103
	free(dirbuf);
103
	free(dirbuf);
104
	return error;
104
	return error;
105
}
105
}
106
 
106
 
107
#ifdef LANG_RUS
107
#ifdef LANG_RUS
108
	unsigned char *ERROR_TEXT[]={
108
	unsigned char *ERROR_TEXT[]={
109
	"Š®¤ #0: ãᯥ譮",
109
	"Š®¤ #0: ãᯥ譮",
110
	"Žè¨¡ª  #1: ­¥ ®¯à¥¤¥«¥­  ¡ §  ¨/¨«¨ à §¤¥« ¦ñá⪮£® ¤¨áª ",
110
	"Žè¨¡ª  #1: ­¥ ®¯à¥¤¥«¥­  ¡ §  ¨/¨«¨ à §¤¥« ¦ñá⪮£® ¤¨áª ",
111
	"Žè¨¡ª  #2: äã­ªæ¨ï ­¥ ¯®¤¤¥à¦¨¢ ¥âáï ¤«ï í⮩ ä ©«®¢®© á¨á⥬ë",
111
	"Žè¨¡ª  #2: äã­ªæ¨ï ­¥ ¯®¤¤¥à¦¨¢ ¥âáï ¤«ï í⮩ ä ©«®¢®© á¨á⥬ë",
112
	"Žè¨¡ª  #3: ­¥¨§¢¥áâ­ ï ä ©«®¢ ï á¨á⥬ ",
112
	"Žè¨¡ª  #3: ­¥¨§¢¥áâ­ ï ä ©«®¢ ï á¨á⥬ ",
113
	0,
113
	0,
114
	"Žè¨¡ª  #5: ä ©« ¨«¨ ¯ ¯ª  ­¥ ­ ©¤¥­ë",
114
	"Žè¨¡ª  #5: ä ©« ¨«¨ ¯ ¯ª  ­¥ ­ ©¤¥­ë",
115
	"Žè¨¡ª  #6: ª®­¥æ ä ©« ",
115
	"Žè¨¡ª  #6: ª®­¥æ ä ©« ",
116
	"Žè¨¡ª  #7: 㪠§ â¥«ì ­ å®¤¨âáï ¢á¥ ¯ ¬ï⨠¯à¨«®¦¥­¨ï",
116
	"Žè¨¡ª  #7: 㪠§ â¥«ì ­ å®¤¨âáï ¢á¥ ¯ ¬ï⨠¯à¨«®¦¥­¨ï",
117
	"Žè¨¡ª  #8: ­¥¤®áâ â®ç­® ¬¥áâ  ­  ¤¨áª¥",
117
	"Žè¨¡ª  #8: ­¥¤®áâ â®ç­® ¬¥áâ  ­  ¤¨áª¥",
118
	"Žè¨¡ª  #9: â ¡«¨æ  FAT à §àã襭 ",
118
	"Žè¨¡ª  #9: â ¡«¨æ  FAT à §àã襭 ",
119
	"Žè¨¡ª  #10: ¤®áâ㯠§ ¯à¥é¥­",
119
	"Žè¨¡ª  #10: ¤®áâ㯠§ ¯à¥é¥­",
120
	"Žè¨¡ª  #11: ®è¨¡ª  ãáâனá⢠",
120
	"Žè¨¡ª  #11: ®è¨¡ª  ãáâனá⢠",
121
	0, 0, 0, 0, 0, 0, 0, 0, 0,
121
	0, 0, 0, 0, 0, 0, 0, 0, 0,
122
	0, 0, 0, 0, 0, 0, 0, 0, 0, 
122
	0, 0, 0, 0, 0, 0, 0, 0, 0, 
123
	"Žè¨¡ª  #30: ­¥¤®áâ â®ç­® ¯ ¬ïâ¨",
123
	"Žè¨¡ª  #30: ­¥¤®áâ â®ç­® ¯ ¬ïâ¨",
124
	"Žè¨¡ª  #31: ä ©« ­¥ ï¥âáï ¨á¯®«­ï¥¬ë¬",
124
	"Žè¨¡ª  #31: ä ©« ­¥ ï¥âáï ¨á¯®«­ï¥¬ë¬",
125
	"Žè¨¡ª  #32: ᫨誮¬ ¬­®£® ¯à®æ¥áᮢ", 0};
125
	"Žè¨¡ª  #32: ᫨誮¬ ¬­®£® ¯à®æ¥áᮢ", 0};
126
#else
126
#else
127
	unsigned char *ERROR_TEXT[]={
127
	unsigned char *ERROR_TEXT[]={
128
	"Code #0 - No error, compleated successfully",
128
	"Code #0 - No error, compleated successfully",
129
	"Error #1 - Base or partition of a hard disk is not defined",
129
	"Error #1 - Base or partition of a hard disk is not defined",
130
	"Error #2 - Function isn't supported for this file system",
130
	"Error #2 - Function isn't supported for this file system",
131
	"Error #3 - Unknown file system",
131
	"Error #3 - Unknown file system",
132
	0,
132
	0,
133
	"Error #5 - File or folder not found",
133
	"Error #5 - File or folder not found",
134
	"Error #6 - End of file",
134
	"Error #6 - End of file",
135
	"Error #7 - Pointer lies outside of application memory",
135
	"Error #7 - Pointer lies outside of application memory",
136
	"Error #8 - Too less disk space",
136
	"Error #8 - Too less disk space",
137
	"Error #9 - FAT table is destroyed",
137
	"Error #9 - FAT table is destroyed",
138
	"Error #10 - Access denied",
138
	"Error #10 - Access denied",
139
	"Error #11 - Device error",
139
	"Error #11 - Device error",
140
	0, 0, 0, 0, 0, 0, 0, 0, 0,
140
	0, 0, 0, 0, 0, 0, 0, 0, 0,
141
	0, 0, 0, 0, 0, 0, 0, 0, 0, 
141
	0, 0, 0, 0, 0, 0, 0, 0, 0, 
142
	"Error #30 - Not enough memory",
142
	"Error #30 - Not enough memory",
143
	"Error #31 - File is not executable",
143
	"Error #31 - File is not executable",
144
	"Error #32 - Too many processes", 0};
144
	"Error #32 - Too many processes", 0};
145
#endif
145
#endif
146
 
146
 
147
:dword get_error(int N)
147
:dword get_error(int N)
148
{
148
{
149
	char error[256];  
149
	char error[256];  
150
	N = fabs(N);
150
	N = fabs(N);
151
	if (N<=33) strcpy(#error, ERROR_TEXT[N]);
151
	if (N<=33) strcpy(#error, ERROR_TEXT[N]);
152
	else sprintf(#error,"%d%s",N," - Unknown error number O_o");
152
	else sprintf(#error,"%d%s",N," - Unknown error number O_o");
153
	return #error;
153
	return #error;
154
}
154
}
155
 
155
 
156
:void debug_error(dword path, error_number)
156
:void debug_error(dword path, error_number)
157
{
157
{
158
	if (path) debugln(path);
158
	if (path) debugln(path);
159
	debugln(get_error(error_number));
159
	debugln(get_error(error_number));
160
}
160
}
161
 
161
 
162
#endif
162
#endif