Subversion Repositories spk

Rev

Rev 316 | Rev 320 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 316 Rev 317
Line 35... Line 35...
35
			break;
35
			break;
36
		case CATERR_DECRYPT:
36
		case CATERR_DECRYPT:
37
			printf ( "Unable to decrypt cat file\n" );
37
			printf ( "Unable to decrypt cat file\n" );
38
			break;
38
			break;
39
		case CATERR_MISMATCH:
39
		case CATERR_MISMATCH:
40
			printf ( "Dat file size mismatch\n" );
40
			printf("Dat file size mismatch\n");
-
 
41
			break;
-
 
42
		case CATERR_CREATED:
-
 
43
			printf("Cat file does not exist\n");
41
			break;
44
			break;
42
	}
45
	}
43
}
46
}
44
 
47
 
45
void ListFiles(const Utils::CommandLine &cmd)
48
void ListFiles(const Utils::CommandLine &cmd)
Line 109... Line 112...
109
	CFileIO File((filepattern.contains(L":")) ? filepattern : g_dir + L"/" + filepattern);
112
	CFileIO File((filepattern.contains(L":")) ? filepattern : g_dir + L"/" + filepattern);
110
	return File.GetDirIO().dirList(files, Utils::WString::Null(), File.filename(), true);
113
	return File.GetDirIO().dirList(files, Utils::WString::Null(), File.filename(), true);
111
}
114
}
112
 
115
 
113
 
116
 
114
void ExtractFile (const Utils::WString &filename, const Utils::WString &to, bool preserve )
117
void ExtractFile (const Utils::CommandLine& cmd, const Utils::WString& fileMask, bool preserve)
115
{
118
{
-
 
119
	Utils::WString filename = cmd.arg(1) + fileMask;
-
 
120
	Utils::WString to = cmd.argCount() < 2 ? cmd.cmdDir() : cmd.arg(2);
-
 
121
	if (!to.contains(L":")) to = cmd.file()->dirIO().file(to);
-
 
122
	CDirIO destination(to);
-
 
123
 
-
 
124
	if (cmd.hasSwitch("preserve"))
-
 
125
		preserve = true;
-
 
126
		
116
	if ( !filename.contains(L"::") ) return;
127
	if ( !filename.contains(L"::") ) return;
117
 
128
 
118
	Utils::WString catfile = filename.token(L"::", 1);
129
	Utils::WString catfile = filename.token(L"::", 1);
-
 
130
	CFileIO File((catfile.contains(L":")) ? catfile : g_dir + L"/" + catfile);
119
	Utils::WString filemask = filename.token(L"::", 2);
131
	Utils::WString filemask = filename.token(L"::", 2);
120
 
132
 
121
	CCatFile cat;
133
	CCatFile cat;
122
	int err = cat.open(catfile, L"", CATREAD_DAT);
134
	int err = cat.open(File.fullFilename(), L"", CATREAD_DAT);
123
	if ( err )
135
	if ( err )
124
	{
136
	{
125
		PrintError ( err );
137
		PrintError ( err );
126
		return;
138
		return;
127
	}
139
	}
128
 
140
 
129
	// all files
141
	Utils::WStringList fileList;
130
	if ( filemask == L"*" )
142
	if (filemask.containsAny(L"*?"))
131
	{
143
	{
132
		for (unsigned int i = 0; i < cat.GetNumFiles(); i++)
144
		for (unsigned int i = 0; i < cat.GetNumFiles(); i++)
133
		{
145
		{
134
			SInCatFile *f = cat.GetFile(i);
146
			SInCatFile* f = cat.GetFile(i);
135
			if (!cat.extractFile(f, to))
147
			if(f->sFile.match(filemask))
136
				wprintf(L"Error: %s\n", cat.getErrorString().c_str() );
148
				fileList.pushBack(f->sFile);
137
			else
-
 
138
				wprintf(L"File has been written (%s)\n", cat.errorString().c_str() );
-
 
139
		}
149
		}
140
 
-
 
141
		return;
-
 
142
	}
150
	}
-
 
151
	else
-
 
152
		fileList.pushBack(filemask);
143
 
153
 
144
	//TODO: add proper file mask for extracting
-
 
145
	Utils::WStringList fileList;
-
 
146
	fileList.pushBack(filemask);
-
 
147
	if (fileList.empty())
154
	if (fileList.empty())
148
	{
155
	{
149
		wprintf(L"Error: unable to find any files matching: %s\n", filemask.c_str() );
156
		wprintf(L"Error: unable to find any files matching: %s\n", filemask.c_str() );
150
		return;
157
		return;
151
	}
158
	}
Line 154... Line 161...
154
	{
161
	{
155
		Utils::WString file = (*itr)->str;
162
		Utils::WString file = (*itr)->str;
156
		if (!cat.extractFile(file, to, preserve))
163
		if (!cat.extractFile(file, to, preserve))
157
			wprintf(L"Error: %s\n", cat.getErrorString().c_str() );
164
			wprintf(L"Error: %s\n", cat.getErrorString().c_str() );
158
		else
165
		else
159
			wprintf(L"File has been written (%s)\n", cat.errorString().c_str() );
166
			wprintf(L"File has been written: %s\n", preserve ? file.c_str() : CFileIO(file).filename().c_str());
160
	}
167
	}
161
}
168
}
162
 
169
 
163
void AppendFile (const Utils::CommandLine& cmd)
170
void AppendFile (const Utils::CommandLine& cmd)
164
{
171
{
Line 355... Line 362...
355
{
362
{
356
	wprintf(L"Syntax: %s <flags> [arguments]\n", cmd.c_str() );
363
	wprintf(L"Syntax: %s <flags> [arguments]\n", cmd.c_str() );
357
	wprintf(L"Flags:\n");
364
	wprintf(L"Flags:\n");
358
	wprintf(L"\t-l <filename> [filemask]\n");
365
	wprintf(L"\t-l <filename> [filemask]\n");
359
	wprintf(L"\t\tLists the contents of a cat file, with optional search mask\n");
366
	wprintf(L"\t\tLists the contents of a cat file, with optional search mask\n");
360
	wprintf(L"\t-x <catfile::filename> [dir]\n");
-
 
361
	wprintf(L"\t\textracts a file from a cat file to the optional directory\n");
-
 
362
	wprintf(L"\t-xp <catfile::filename> [dir]\n");
367
	wprintf(L"\t-x [--preserve] <catfile::filemask> [dir]\n");
363
	wprintf(L"\t\textracts a file from a cat file to the optional directory, preserves directory structure\n");
368
	wprintf(L"\t\textracts a file from a cat file to the optional directory\n\t--preverve: Preserves directory structure");
364
	wprintf(L"\t-xa <catfile> [dir]\n");
369
	wprintf(L"\t-xa <catfile> [dir]\n");
365
	wprintf(L"\t\textracts all files to optional directory\n");
370
	wprintf(L"\t\textracts all files to optional directory\n");
366
	wprintf(L"\t-a <filename> <catfile::tofile>\n");
371
	wprintf(L"\t-a <filename> <catfile::tofile>\n");
367
	wprintf(L"\t\tAdds the file into a cat archive, saves it as <tofile>\n");
372
	wprintf(L"\t\tAdds the file into a cat archive, saves it as <tofile>\n");
368
	wprintf(L"\t-r <catfile> <file>\n");
373
	wprintf(L"\t-r <catfile> <file>\n");
Line 394... Line 399...
394
			if (cmd.argCount() < 2)
399
			if (cmd.argCount() < 2)
395
				wprintf(L"Syntax: %s -l <filename> [filemask]\n\tLists the contents of the cat file\n", cmd.cmdName().c_str());
400
				wprintf(L"Syntax: %s -l <filename> [filemask]\n\tLists the contents of the cat file\n", cmd.cmdName().c_str());
396
			else
401
			else
397
				ListFiles(cmd);
402
				ListFiles(cmd);
398
		}
403
		}
399
		else if ( (command == L"-x") || (command == L"-extract") || (command == L"-xp") || (command == L"-extractpreserve") )
404
		else if ((command == L"-x") || (command == L"-extract"))
400
		{
405
		{
401
			if ( args.size() < 2 )
406
			if (cmd.argCount() < 2 )
402
				wprintf(L"Syntax: %s %s <catfile::filename> [dir]\n\tExtracts a file from the cat archive\n", cmd.cmdName().c_str(), command.c_str() );
407
				wprintf(L"Syntax: %s %s [--preserve] <catfile::filemask> [dir]\n\tExtracts a file from the cat archive\n", cmd.cmdName().c_str(), command.c_str() );
403
			else if ( args.size() < 3)
-
 
404
				ExtractFile (args[1], L"", (command == L"-xp" || command == L"-extractpreserve") ? true : false );
-
 
405
			else
408
			else
406
				ExtractFile (args[1], args[2], (command == L"-xp" || command == L"-extractpreserve") ? true : false );
409
				ExtractFile (cmd, L"", false);
407
		}
410
		}
408
		else if ( (command == L"-xa") || (command == L"-extractall") )
411
		else if ( (command == L"-xa") || (command == L"-extractall") )
409
		{
412
		{
410
			if ( args.size() < 2)
413
			if (cmd.argCount() < 2)
411
				wprintf(L"Syntax: %s %s <catfile> [dir]\n\tExtracts all files from the cat archive\n", cmd.cmdName().c_str(), command.c_str() );
414
				wprintf(L"Syntax: %s %s <catfile> [dir]\n\tExtracts all files from the cat archive\n", cmd.cmdName().c_str(), command.c_str() );
412
			else if ( args.size() < 3)
-
 
413
				ExtractFile(args[1] + L"::*", L"", true );
-
 
414
			else
415
			else
415
				ExtractFile(args[1] + L"::*", args[2], true );
416
				ExtractFile(cmd, L"::*", true);
416
		}
417
		}
417
		else if ( (command == L"-a") || (command == L"-append") )
418
		else if ( (command == L"-a") || (command == L"-append") )
418
		{
419
		{
419
			if (args.size() < 3 )
420
			if (args.size() < 3 )
420
				wprintf(L"Syntax: %s -a <filename> <catfile::tofile>\n\tAppends a file into the archive\n", cmd.cmdName().c_str() );
421
				wprintf(L"Syntax: %s -a <filename> <catfile::tofile>\n\tAppends a file into the archive\n", cmd.cmdName().c_str() );