Subversion Repositories spk

Rev

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

Rev 218 Rev 222
Line 75... Line 75...
75
	CFileIO File((filepattern.contains(L":")) ? filepattern : g_dir + L"/" + filepattern);
75
	CFileIO File((filepattern.contains(L":")) ? filepattern : g_dir + L"/" + filepattern);
76
	return File.GetDirIO().dirList(files, Utils::WString::Null(), File.filename());
76
	return File.GetDirIO().dirList(files, Utils::WString::Null(), File.filename());
77
}
77
}
78
 
78
 
79
 
79
 
80
void ExtractFile ( CyString filename, CyString to, bool preserve )
80
void ExtractFile (const Utils::WString &filename, const Utils::WString &to, bool preserve )
81
{
81
{
82
	if ( !filename.IsIn ( "::" ) ) return;
82
	if ( !filename.contains(L"::") ) return;
83
 
83
 
84
	Utils::String catfile = filename.GetToken ( "::", 1, 1 ).ToString();
84
	Utils::WString catfile = filename.token(L"::", 1);
85
	Utils::String filemask = filename.GetToken ( "::", 2, 2 ).ToString();
85
	Utils::WString filemask = filename.token(L"::", 2);
86
 
86
 
87
	CCatFile cat;
87
	CCatFile cat;
88
	int err = cat.open(catfile, "", CATREAD_DAT);
88
	int err = cat.open(catfile, L"", CATREAD_DAT);
89
	if ( err )
89
	if ( err )
90
	{
90
	{
91
		PrintError ( err );
91
		PrintError ( err );
92
		return;
92
		return;
93
	}
93
	}
94
 
94
 
95
	// all files
95
	// all files
96
	if ( filemask == "*" )
96
	if ( filemask == L"*" )
97
	{
97
	{
98
		for (unsigned int i = 0; i < cat.GetNumFiles(); i++)
98
		for (unsigned int i = 0; i < cat.GetNumFiles(); i++)
99
		{
99
		{
100
			SInCatFile *f = cat.GetFile(i);
100
			SInCatFile *f = cat.GetFile(i);
101
			if (!cat.extractFile(f, to.ToString()))
101
			if (!cat.extractFile(f, to))
102
				wprintf(L"Error: %s\n", cat.getErrorString().c_str() );
102
				wprintf(L"Error: %s\n", cat.getErrorString().c_str() );
103
			else
103
			else
104
				wprintf(L"File has been written (%s)\n", cat.errorString().c_str() );
104
				wprintf(L"File has been written (%s)\n", cat.errorString().c_str() );
105
		}
105
		}
106
 
106
 
107
		return;
107
		return;
108
	}
108
	}
109
 
109
 
110
	//TODO: add proper file mask for extracting
110
	//TODO: add proper file mask for extracting
111
	//CyStringList *fileList = FindFiles(filemask);
-
 
112
	CyStringList *fileList = new CyStringList;
111
	Utils::WStringList fileList;
113
	fileList->PushBack(CyString(filemask));
112
	fileList.pushBack(filemask);
114
	if ( !fileList || fileList->Empty() )
113
	if (fileList.empty())
115
	{
114
	{
116
		if ( fileList ) delete fileList;
-
 
117
		printf ( "Error: unable to find any files matching: %s\n", filemask.c_str() );
115
		wprintf(L"Error: unable to find any files matching: %s\n", filemask.c_str() );
118
		return;
116
		return;
119
	}
117
	}
120
 
118
 
121
	for ( SStringList *fl = fileList->Head(); fl; fl = fl->;next )
119
	for (auto itr = fileList.begin(); itr != fileList.end(); itr++)
122
	{
120
	{
123
		Utils::String file = fl->str.ToString();
121
		Utils::WString file = (*itr)->str;
124
		if (!cat.extractFile(file, to.ToString(), preserve))
122
		if (!cat.extractFile(file, to, preserve))
125
			wprintf(L"Error: %s\n", cat.getErrorString().c_str() );
123
			wprintf(L"Error: %s\n", cat.getErrorString().c_str() );
126
		else
124
		else
127
			wprintf(L"File has been written (%s)\n", cat.errorString().c_str() );
125
			wprintf(L"File has been written (%s)\n", cat.errorString().c_str() );
128
	}
126
	}
129
 
-
 
130
	delete fileList;
-
 
131
}
127
}
132
 
128
 
133
void AppendFile ( CyString C_File, const Utils::WString &filepattern )
129
void AppendFile ( CyString C_File, const Utils::WString &filepattern )
134
{
130
{
135
	Utils::WString catfile;
131
	Utils::WString catfile;
Line 349... Line 345...
349
		else if ( (command == "-x") || (command == "-extract") || (command == "-xp") || (command == "-extractpreserve") )
345
		else if ( (command == "-x") || (command == "-extract") || (command == "-xp") || (command == "-extractpreserve") )
350
		{
346
		{
351
			if ( argc < 3 )
347
			if ( argc < 3 )
352
				wprintf(L"Syntax: %s %hs <catfile::filename> [dir]\n\tExtracts a file from the cat archive\n", cmd.c_str(), command.c_str() );
348
				wprintf(L"Syntax: %s %hs <catfile::filename> [dir]\n\tExtracts a file from the cat archive\n", cmd.c_str(), command.c_str() );
353
			else if ( argc < 4 )
349
			else if ( argc < 4 )
354
				ExtractFile ( CyString(argv[2]), CyString(""), (command == "-xp" || command == "-extractpreserve") ? true : false );
350
				ExtractFile (Utils::WString(argv[2]), L"", (command == "-xp" || command == "-extractpreserve") ? true : false );
355
			else
351
			else
356
				ExtractFile ( CyString(argv[2]), CyString(argv[3]), (command == "-xp" || command == "-extractpreserve") ? true : false );
352
				ExtractFile (Utils::WString(argv[2]), Utils::WString(argv[3]), (command == "-xp" || command == "-extractpreserve") ? true : false );
357
		}
353
		}
358
		else if ( (command == "-xa") || (command == "-extractall") )
354
		else if ( (command == "-xa") || (command == "-extractall") )
359
		{
355
		{
360
			if ( argc < 3 )
356
			if ( argc < 3 )
361
				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() );
362
			else if ( argc < 4 )
358
			else if ( argc < 4 )
363
				ExtractFile ( CyString(argv[2]) + "::*&quot;, CyString(""), true );
359
				ExtractFile(Utils::WString(argv[2]) + L"::*&quot;, L"", true );
364
			else
360
			else
365
				ExtractFile ( CyString(argv[2]) + "::*", CyString(argv[3]), true );
361
				ExtractFile(Utils::WString(argv[2]) + L"::*", Utils::WString(argv[3]), true );
366
		}
362
		}
367
		else if ( (command == "-a") || (command == "-append") )
363
		else if ( (command == "-a") || (command == "-append") )
368
		{
364
		{
369
			if ( argc < 4 )
365
			if ( argc < 4 )
370
				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() );