Subversion Repositories Kolibri OS

Rev

Rev 5515 | Rev 5642 | 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
5598 pavelyakov 2
#ifndef INCLUDE_COPYF_H
3
#define INCLUDE_COPYF_H
5515 leency 4
 
5598 pavelyakov 5
#ifndef INCLUDE_FILESYSTEM_H
6
#include "../lib/file_system.h"
7
#endif
8
 
3444 leency 9
:int copyf(dword from1, in1)
3434 leency 10
{
3440 leency 11
	dword error;
12
	BDVK CopyFile_atr1;
5515 leency 13
 
3444 leency 14
	if (!from1) || (!in1)
15
	{
16
		notify("Error: too less copyf params!");
17
		notify(from1);
18
		notify(in1);
19
		return;
20
	}
21
	if (error = GetFileInfo(from1, #CopyFile_atr1))
22
	{
4645 leency 23
		debugln("Error: copyf->GetFileInfo");
3444 leency 24
		return error;
25
	}
26
	if (isdir(from1))
27
		return CopyFolder(from1, in1);
3440 leency 28
	else
4059 leency 29
	{
30
		copyf_Draw_Progress(from1+strchr(from1, '/'));
3444 leency 31
		return CopyFile(from1, in1);
4059 leency 32
	}
3440 leency 33
}
3434 leency 34
 
3440 leency 35
:int CopyFile(dword copy_from3, copy_in3)
36
{
37
	BDVK CopyFile_atr;
38
	dword error, cbuf;
3444 leency 39
	if (error = GetFileInfo(copy_from3, #CopyFile_atr))
3877 leency 40
	{
4645 leency 41
		debugln("Error: CopyFile->GetFileInfo");
3877 leency 42
	}
3434 leency 43
	else
44
	{
3440 leency 45
		cbuf = malloc(CopyFile_atr.sizelo);
3444 leency 46
		if (error = ReadFile(0, CopyFile_atr.sizelo, cbuf, copy_from3))
3877 leency 47
		{
4645 leency 48
			debugln("Error: CopyFile->ReadFile");
3877 leency 49
		}
3440 leency 50
		else
51
		{
4645 leency 52
			if (error = WriteFile(CopyFile_atr.sizelo, cbuf, copy_in3)) debugln("Error: CopyFile->WriteFile");
3440 leency 53
		}
3434 leency 54
	}
3440 leency 55
	free(cbuf);
3444 leency 56
	if (error) debug_error(copy_from3, error);
3440 leency 57
	return error;
3434 leency 58
}
59
 
3444 leency 60
:int CopyFolder(dword from2, in2)
3434 leency 61
{
3444 leency 62
	dword dirbuf, fcount, i, filename;
63
	char copy_from2[4096], copy_in2[4096], error;
3434 leency 64
 
3444 leency 65
	if (error = GetDir(#dirbuf, #fcount, from2, DIRS_ONLYREAL))
3440 leency 66
	{
4645 leency 67
		debugln("Error: CopyFolder->GetDir");
3440 leency 68
		debug_error(from2, error);
69
		free(dirbuf);
3444 leency 70
		return error;
3440 leency 71
	}
4023 leency 72
 
3444 leency 73
	if (chrnum(in2, '/')>2) && (error = CreateDir(in2))
3434 leency 74
	{
4645 leency 75
		debugln("Error: CopyFolder->CreateDir");
3444 leency 76
		debug_error(in2, error);
77
		free(dirbuf);
78
		return error;
3434 leency 79
	}
80
 
81
	for (i=0; i
82
	{
83
		filename = i*304+dirbuf+72;
5598 pavelyakov 84
		sprintf(#copy_from2,"%s/%s",from2,filename);
85
		sprintf(#copy_in2,"%s/%s",in2,filename);
3444 leency 86
 
87
		if ( TestBit(ESDWORD[filename-40], 4) ) //isdir?
3434 leency 88
		{
5598 pavelyakov 89
			if ( (!strncmp(filename, ".",1)) || (!strncmp(filename, "..",2)) ) continue;
3440 leency 90
			CopyFolder(#copy_from2, #copy_in2);
3434 leency 91
		}
92
		else
93
		{
4023 leency 94
			copyf_Draw_Progress(filename);
3444 leency 95
			if (error=CopyFile(#copy_from2, #copy_in2))
96
			{
4645 leency 97
				if (fabs(error)==8) { debugln("Stop copying."); break;} //TODO: may be need grobal var like stop_all
3444 leency 98
				error=CopyFile(#copy_from2, #copy_in2); // #2 :)
99
			}
3434 leency 100
		}
101
	}
102
	free(dirbuf);
3444 leency 103
	return error;
3434 leency 104
}
105
 
4023 leency 106
#ifdef LANG_RUS
107
	unsigned char *ERROR_TEXT[]={
108
	"Код #0: успешно",
109
	"Ошибка #1: не определена база и/или раздел жёсткого диска",
110
	"Ошибка #2: функция не поддерживается для этой файловой системы",
4634 Albom 111
	"Ошибка #3: неизвестная файловая система",
4023 leency 112
	0,
113
	"Ошибка #5: файл или папка не найдены",
114
	"Ошибка #6: конец файла",
115
	"Ошибка #7: указатель находится все памяти приложения",
116
	"Ошибка #8: недостаточно места на диске",
117
	"Ошибка #9: таблица FAT разрушена",
118
	"Ошибка #10: доступ запрещен",
119
	"Ошибка #11: ошибка устройсва",
120
	0, 0, 0, 0, 0, 0, 0, 0, 0,
121
	0, 0, 0, 0, 0, 0, 0, 0, 0,
122
	"Ошибка #30: недостаточно памяти",
123
	"Ошибка #31: файл не является исполняемым",
124
	"Ошибка #32: слишком много процессов", 0};
125
#else
126
	unsigned char *ERROR_TEXT[]={
127
	"Code #0 - No error, compleated successfully",
128
	"Error #1 - Base or partition of a hard disk is not defined",
129
	"Error #2 - Function isn't supported for this file system",
130
	"Error #3 - Unknown file system",
131
	0,
132
	"Error #5 - File or folder not found",
133
	"Error #6 - End of file",
134
	"Error #7 - Pointer lies outside of application memory",
135
	"Error #8 - Too less disk space",
136
	"Error #9 - FAT table is destroyed",
137
	"Error #10 - Access denied",
138
	"Error #11 - Device error",
139
	0, 0, 0, 0, 0, 0, 0, 0, 0,
140
	0, 0, 0, 0, 0, 0, 0, 0, 0,
141
	"Error #30 - Not enough memory",
142
	"Error #31 - File is not executable",
143
	"Error #32 - Too many processes", 0};
144
#endif
3440 leency 145
 
146
:dword get_error(int N)
3434 leency 147
{
3440 leency 148
	char error[256];
149
	N = fabs(N);
5598 pavelyakov 150
	if (N<=33) strcpy(#error, ERROR_TEXT[N]);
151
	else sprintf(#error,"%d%s",N," - Unknown error number O_o");
3434 leency 152
	return #error;
153
}
154
 
3440 leency 155
:void debug_error(dword path, error_number)
3434 leency 156
{
4645 leency 157
	if (path) debugln(path);
158
	debugln(get_error(error_number));
5598 pavelyakov 159
}
160
 
161
#endif