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;
-
 
127
	}
-
 
128
 
-
 
129
	// all files
-
 
130
	if ( filemask == L"*" )
-
 
131
	{
-
 
132
		for (unsigned int i = 0; i < cat.GetNumFiles(); i++)
-
 
133
		{
-
 
134
			SInCatFile *f = cat.GetFile(i);
-
 
135
			if (!cat.extractFile(f, to))
-
 
136
				wprintf(L"Error: %s\n", cat.getErrorString().c_str() );
-
 
137
			else
-
 
138
				wprintf(L"File has been written (%s)\n", cat.errorString().c_str() );
-
 
139
		}
-
 
140
 
-
 
141
		return;
138
		return;
142
	}
139
	}
143
 
140
 
-
 
141
	Utils::WStringList fileList;
-
 
142
	if (filemask.containsAny(L"*?"))
-
 
143
	{
-
 
144
		for (unsigned int i = 0; i < cat.GetNumFiles(); i++)
-
 
145
		{
144
	//TODO: add proper file mask for extracting
146
			SInCatFile* f = cat.GetFile(i);
145
	Utils::WStringList fileList;
147
			if(f->;sFile.match(filemask))
-
 
148
				fileList.pushBack(f->sFile);
-
 
149
		}
-
 
150
	}
-
 
151
	else
146
	fileList.pushBack(filemask);
152
		fileList.pushBack(filemask);
-
 
153
 
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 178... Line 185...
178
	}
185
	}
179
	else
186
	else
180
	{
187
	{
181
		catfile = C_File.token(L"::", 1);
188
		catfile = C_File.token(L"::", 1);
182
		file = C_File.token(L"::", 2);
189
		file = C_File.token(L"::", 2);
183
	}
190
	}
184
 
191
 
185
	if (!catfile.contains(":"))
192
	if (!catfile.contains(":"))
186
		catfile = g_dir + L"/" + catfile;
193
		catfile = g_dir + L"/" + catfile;
187
 
194
 
188
	Utils::WStringList list;
195
	Utils::WStringList list;
189
 
196
 
190
	CFileIO File((filepattern.contains(L":")) ? filepattern : g_dir + L"/" + filepattern);
197
	CFileIO File((filepattern.contains(L":")) ? filepattern : g_dir + L"/" + filepattern);
191
	if (recursive)
198
	if (recursive)
192
		findAllFiles(File.dirIO(), L"", File.filename(), list);
199
		findAllFiles(File.dirIO(), L"", File.filename(), list);
193
	else
200
	else
194
		findFiles(list, filepattern);
201
		findFiles(list, filepattern);
195
	if (!list.size())
202
	if (!list.size())
196
	{
203
	{
197
		wprintf(L"Error: no files found to add: %s\n", filepattern.c_str());
204
		wprintf(L"Error: no files found to add: %s\n", filepattern.c_str());
198
		return;
205
		return;
199
	}
206
	}
200
 
207
 
201
	CCatFile cat;
208
	CCatFile cat;
202
	int err = cat.open(catfile, L"", CATREAD_CATDECRYPT);
209
	int err = cat.open(catfile, L"", CATREAD_CATDECRYPT);
203
	if ( err && err != CATERR_CREATED)
210
	if ( err && err != CATERR_CREATED)
204
	{
211
	{
205
		PrintError ( err );
212
		PrintError ( err );
Line 221... Line 228...
221
		if (!toFile.contains(L"."))
228
		if (!toFile.contains(L"."))
222
		{
229
		{
223
			if (toFile[static_cast<unsigned long>(toFile.length() - 1)] != L'/')
230
			if (toFile[static_cast<unsigned long>(toFile.length() - 1)] != L'/')
224
				toFile += L"/";
231
				toFile += L"/";
225
			toFile += CFileIO(filename).filename();
232
			toFile += CFileIO(filename).filename();
226
		}
233
		}
227
 
234
 
228
		++added;
235
		++added;
229
		if (cat.appendFile(filename, toFile))
236
		if (cat.appendFile(filename, toFile))
230
			wprintf(L"File %s has beed added to: %s::%s\n", filename.c_str(), catfile.c_str(), toFile.c_str());
237
			wprintf(L"File %s has beed added to: %s::%s\n", filename.c_str(), catfile.c_str(), toFile.c_str());
231
		else
238
		else
Line 249... Line 256...
249
 
256
 
250
	SInCatFile *f = cat.findData(remfile);
257
	SInCatFile *f = cat.findData(remfile);
251
	if ( !f )
258
	if ( !f )
252
	{
259
	{
253
		wprintf(L"Unable to find %s in cat file\n", remfile.c_str() );
260
		wprintf(L"Unable to find %s in cat file\n", remfile.c_str() );
254
		return;
261
		return;
255
	}
262
	}
256
 
263
 
257
	if (cat.removeFile(f))
264
	if (cat.removeFile(f))
258
		printf ( "File has been removed from archive\n" );
265
		printf ( "File has been removed from archive\n" );
259
}
266
}
260
 
267
 
261
void UnpackFile(const Utils::WString &file, const Utils::WString &tofile, const Utils::WString &ext)
268
void UnpackFile(const Utils::WString &file, const Utils::WString &tofile, const Utils::WString &ext)
262
{
269
{
263
	Utils::WStringList list;
270
	Utils::WStringList list;
264
	if(!findFiles(list, file) || !list.size())
271
	if(!findFiles(list, file) || !list.size())
265
	{
272
	{
266
		wprintf(L"Error: no files found to unpack: %s\n", file.c_str());
273
		wprintf(L"Error: no files found to unpack: %s\n", file.c_str());
267
		return;
274
		return;
268
	}
275
	}
269
 
276
 
270
	for(auto itr = list.first(); itr; itr = list.next())
277
	for(auto itr = list.first(); itr; itr = list.next())
271
	{
278
	{
272
		Utils::WString filename = itr->str;
279
		Utils::WString filename = itr->str;
273
 
280
 
274
		C_File f(filename);
281
		C_File f(filename);
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&quot;-extractpreserve") )
404
		else if ((command == L"-x";) || (command == L&quot;-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() );