Subversion Repositories spk

Rev

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

Rev 222 Rev 226
Line 179... Line 179...
179
		else
179
		else
180
			wprintf(L"Error: Unable to add file: %s\n", filename.c_str());
180
			wprintf(L"Error: Unable to add file: %s\n", filename.c_str());
181
	}
181
	}
182
}
182
}
183
 
183
 
184
void RemoveFile ( CyString C_File, CyString remfile )
184
void RemoveFile (const Utils::WString &C_File, const Utils::WString &remfile )
185
{
185
{
186
	// first open the cat file
186
	// first open the cat file
187
	CCatFile cat;
187
	CCatFile cat;
188
	int err = cat.open(C_File.ToString(), "", CATREAD_CATDECRYPT);
188
	int err = cat.open(C_File, L"", CATREAD_CATDECRYPT);
189
	if ( err )
189
	if ( err )
190
	{
190
	{
191
		PrintError ( err );
191
		PrintError ( err );
192
		return;
192
		return;
193
	}
193
	}
194
 
194
 
195
	SInCatFile *f = cat.findData(remfile.ToString());
195
	SInCatFile *f = cat.findData(remfile);
196
	if ( !f )
196
	if ( !f )
197
	{
197
	{
198
		printf ( "Unable to find %s in cat file\n", remfile.c_str() );
198
		wprintf(L"Unable to find %s in cat file\n", remfile.c_str() );
199
		return;
199
		return;
200
	}
200
	}
201
 
201
 
202
	if (cat.removeFile(f))
202
	if (cat.removeFile(f))
203
		printf ( "File has been removed from archive\n" );
203
		printf ( "File has been removed from archive\n" );
204
}
204
}
205
 
205
 
206
void UnpackFile(const Utils::String &file, const Utils::String &tofile )
206
void UnpackFile(const Utils::WString &file, const Utils::WString &tofile )
207
{
207
{
208
	Utils::WStringList list;
208
	Utils::WStringList list;
209
	if(!findFiles(list, file) || !list.size())
209
	if(!findFiles(list, file) || !list.size())
210
	{
210
	{
211
		printf("Error: no files found to unpack: %s\n", file.c_str());
211
		wprintf(L"Error: no files found to unpack: %s\n", file.c_str());
212
		return;
212
		return;
213
	}
213
	}
214
 
214
 
215
	for(auto itr = list.first(); itr; list.next())
215
	for(auto itr = list.first(); itr; list.next())
216
	{
216
	{
Line 223... Line 223...
223
			wprintf(L"Error: unable to open file: %s\n", filename.c_str() );
223
			wprintf(L"Error: unable to open file: %s\n", filename.c_str() );
224
		else
224
		else
225
		{
225
		{
226
			f.UnPCKFile();
226
			f.UnPCKFile();
227
			if ( tofile.empty() )
227
			if ( tofile.empty() )
228
				f.changeFileExt("xml");
228
				f.changeFileExt(L"xml");
229
			else if ( tofile.left(2) == "*." )
229
			else if ( tofile.left(2) == L"*." )
230
				f.changeFileExt(CFileIO(tofile).extension().toString());
230
				f.changeFileExt(CFileIO(tofile).extension().toString());
231
			else
231
			else
232
				f.setFilename(tofile);
232
				f.setFilename(tofile);
233
 
233
 
234
			if ( !f.writeFilePointer() )
234
			if ( !f.writeFilePointer() )
235
				printf("Error: unable to write file: %s\n", tofile.c_str() );
235
				wprintf(L"Error: unable to write file: %s\n", tofile.c_str() );
236
			else
236
			else
237
				wprintf(L"%hs has been unpacked to %s\n", file.c_str(), f.filename().c_str() );
237
				wprintf(L"%s has been unpacked to %s\n", file.c_str(), f.filename().c_str() );
238
		}
238
		}
239
	}
239
	}
240
}
240
}
241
 
241
 
242
void PackFile(const Utils::String &file, const Utils::String &tofile)
242
void PackFile(const Utils::String &file, const Utils::String &tofile)
Line 354... Line 354...
354
		else if ( (command == "-xa") || (command == "-extractall") )
354
		else if ( (command == "-xa") || (command == "-extractall") )
355
		{
355
		{
356
			if ( argc < 3 )
356
			if ( argc < 3 )
357
				wprintf(L"Syntax: %s %hs <catfile> [dir]\n\tExtracts all files from the cat archive\n", cmd.c_str(), command.c_str() );
357
				wprintf(L"Syntax: %s %hs <catfile> [dir]\n\tExtracts all files from the cat archive\n", cmd.c_str(), command.c_str() );
358
			else if ( argc < 4 )
358
			else if ( argc < 4 )
359
				ExtractFile(Utils::WString(argv[2]) + L"::*", L"", true );
359
				ExtractFile(Utils::WString::FromString(argv[2]) + L"::*", L"", true );
360
			else
360
			else
361
				ExtractFile(Utils::WString(argv[2]) + L"::*", Utils::WString(argv[3]), true );
361
				ExtractFile(Utils::WString::FromString(argv[2]) + L"::*", Utils::WString(argv[3]), true );
362
		}
362
		}
363
		else if ( (command == "-a") || (command == "-append") )
363
		else if ( (command == "-a") || (command == "-append") )
364
		{
364
		{
365
			if ( argc < 4 )
365
			if ( argc < 4 )
366
				wprintf(L"Syntax: %s -a <filename> <catfile::tofile>\n\tAppends a file into the archive\n", cmd.c_str() );
366
				wprintf(L"Syntax: %s -a <filename> <catfile::tofile>\n\tAppends a file into the archive\n", cmd.c_str() );
Line 370... Line 370...
370
		else if ( (command == "-r") || (command == "-remove") )
370
		else if ( (command == "-r") || (command == "-remove") )
371
		{
371
		{
372
			if ( argc < 4 )
372
			if ( argc < 4 )
373
				wprintf(L"Syntax: %s -r <catfile> <filename>\n\tRemoves a file from the archive\n", cmd.c_str() );
373
				wprintf(L"Syntax: %s -r <catfile> <filename>\n\tRemoves a file from the archive\n", cmd.c_str() );
374
			else
374
			else
375
				RemoveFile ( CyString(argv[2]), CyString(argv[3]) );
375
				RemoveFile (Utils::WString::FromString(argv[2]), Utils::WString::FromString(argv[3]));
376
		}
376
		}
377
		else if ( (command == "-u") || (command == "-unpack") )
377
		else if ( (command == "-u") || (command == "-unpack") )
378
		{
378
		{
379
			if ( argc < 3 )
379
			if ( argc < 3 )
380
				wprintf(L"Syntax: %s -u <filename> [to]\n\tUnpacks a file", cmd.c_str() );
380
				wprintf(L"Syntax: %s -u <filename> [to]\n\tUnpacks a file", cmd.c_str() );
381
			else if ( argc < 4 )
381
			else if ( argc < 4 )
382
				UnpackFile(argv[2], "" );
382
				UnpackFile(Utils::WString::FromString(argv[2]), L"");
383
			else
383
			else
384
				UnpackFile(argv[2], argv[3]);
384
				UnpackFile(Utils::WString::FromString(argv[2]), Utils::WString::FromString(argv[3]));
385
		}
385
		}
386
		else if ( (command == "-p") || (command == "-pack") )
386
		else if ( (command == "-p") || (command == "-pack") )
387
		{
387
		{
388
			if ( argc < 3 )
388
			if ( argc < 3 )
389
				wprintf(L"Syntax: %s -p <filename> [to]\n\tPacks a file to .pck", cmd.c_str() );
389
				wprintf(L"Syntax: %s -p <filename> [to]\n\tPacks a file to .pck", cmd.c_str() );