Subversion Repositories spk

Rev

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

Rev 129 Rev 158
Line 67... Line 67...
67
	}
67
	}
68
	else
68
	else
69
		PrintError ( err );
69
		PrintError ( err );
70
}
70
}
71
 
71
 
72
CyStringList *FindFiles(CyString filepattern)
-
 
73
{
-
 
74
	CFileIO File((filepattern.IsIn(":")) ? filepattern : g_dir + "/" + filepattern);
-
 
75
	CyStringList *files = File.GetDirIO().DirList(NullString, File.GetFilename());
-
 
76
	return files;
-
 
77
}
-
 
78
 
-
 
79
bool findFiles(Utils::CStringList &files, const Utils::String &filepattern)
72
bool findFiles(Utils::CStringList &files, const Utils::String &filepattern)
80
{
73
{
81
	CFileIO File((filepattern.contains(":")) ? filepattern : g_dir.ToString() + "/" + filepattern);
74
	CFileIO File((filepattern.contains(":")) ? filepattern : g_dir.ToString() + "/" + filepattern);
82
	return File.GetDirIO().dirList(files, Utils::String::Null(), File.GetFilename().ToString());
75
	return File.GetDirIO().dirList(files, Utils::String::Null(), File.filename());
83
}
76
}
84
 
77
 
85
 
78
 
86
void ExtractFile ( CyString filename, CyString to, bool preserve )
79
void ExtractFile ( CyString filename, CyString to, bool preserve )
87
{
80
{
88
	if ( !filename.IsIn ( "::" ) ) return;
81
	if ( !filename.IsIn ( "::" ) ) return;
89
 
82
 
90
	Utils::String catfile = filename.GetToken ( "::", 1, 1 ).ToString();
83
	Utils::String catfile = filename.GetToken ( "::", 1, 1 ).ToString();
91
	Utils::String filemask = filename.GetToken ( "::", 2, 2 ).ToString();
84
	Utils::String filemask = filename.GetToken ( "::", 2, 2 ).ToString();
92
 
85
 
93
	CCatFile cat;
86
	CCatFile cat;
94
	int err = cat.open(catfile, "", CATREAD_DAT);
87
	int err = cat.open(catfile, "", CATREAD_DAT);
95
	if ( err )
88
	if ( err )
96
	{
89
	{
97
		PrintError ( err );
90
		PrintError ( err );
98
		return;
91
		return;
99
	}
92
	}
100
 
93
 
101
	// all files
94
	// all files
102
	if ( filemask == "*" )
95
	if ( filemask == "*" )
103
	{
96
	{
104
		for (unsigned int i = 0; i < cat.GetNumFiles(); i++)
97
		for (unsigned int i = 0; i < cat.GetNumFiles(); i++)
105
		{
98
		{
106
			SInCatFile *f = cat.GetFile(i);
99
			SInCatFile *f = cat.GetFile(i);
107
			if ( !cat.ExtractFile ( f, to ) )
100
			if ( !cat.ExtractFile ( f, to ) )
108
				printf ( "Error: %s\n", cat.getErrorString().c_str() );
101
				printf ( "Error: %s\n", cat.getErrorString().c_str() );
109
			else
102
			else
110
				printf ( "File has been written (%s)\n", cat.errorString().c_str() );
103
				printf ( "File has been written (%s)\n", cat.errorString().c_str() );
Line 151... Line 144...
151
	}
144
	}
152
	else
145
	else
153
	{
146
	{
154
		catfile = C_File.GetToken ( "::", 1, 1 ).ToString();
147
		catfile = C_File.GetToken ( "::", 1, 1 ).ToString();
155
		file = C_File.GetToken ( "::", 2, 2 ).ToString();
148
		file = C_File.GetToken ( "::", 2, 2 ).ToString();
156
	}
149
	}
157
 
150
 
-
 
151
	Utils::CStringList list;
158
	CyStringList *list = FindFiles(filepattern);
152
	findFiles(list, filepattern.ToString());
159
	if ( !list || !list->Count() )
153
	if (!list.size())
160
	{
154
	{
161
		printf("Error: no files found to add: %s\n", filepattern.c_str());
155
		printf("Error: no files found to add: %s\n", filepattern.c_str());
162
		return;
156
		return;
163
	}
157
	}
164
 
158
 
165
	CCatFile cat;
159
	CCatFile cat;
166
	int err = cat.open(catfile, "", CATREAD_CATDECRYPT);
160
	int err = cat.open(catfile, "", CATREAD_CATDECRYPT);
167
	if ( err )
161
	if ( err )
168
	{
162
	{
169
		delete list;
-
 
170
		PrintError ( err );
163
		PrintError ( err );
171
		return;
164
		return;
172
	}
165
	}
173
 
166
 
174
	for ( SStringList *fname = list->Head(); fname; fname = fname->;next )
167
	for (auto itr = list.begin(); itr != list.end(); itr++)
175
	{
168
	{
176
		Utils::String filename = fname->str.ToString();
169
		Utils::String filename = (*itr)->str;
177
		if ( doFile )
170
		if (doFile)
178
			file = filename;
171
			file = filename;
179
 
172
 
180
		if (!file.isin('.'))
173
		if (!file.isin('.'))
181
		{
174
		{
182
			if ( file[file.length() - 1] != &apos;/' )
175
			if (file[file.length() - 1] != &apos;/')
183
				file += '/';
176
				file += '/';
184
			file += CFileIO(filename).filename();
177
			file += CFileIO(filename).filename();
185
		}
178
		}
186
 
179
 
187
		if ( cat.AppendFile(filename, file))
180
		if (cat.AppendFile(filename, file))
188
			printf ( "File %s has beed added to: %s::%s\n", filename.c_str(), catfile.c_str(), file.c_str() );
181
			printf("File %s has beed added to: %s::%s\n", filename.c_str(), catfile.c_str(), file.c_str());
189
		else
182
		else
190
			printf ( "Error: Unable to add file: %s\n", filename.c_str());
183
			printf("Error: Unable to add file: %s\n", filename.c_str());
191
	}
184
	}
192
 
-
 
193
	delete list;
-
 
194
}
185
}
195
 
186
 
196
void RemoveFile ( CyString C_File, CyString remfile )
187
void RemoveFile ( CyString C_File, CyString remfile )
197
{
188
{
198
	// first open the cat file
189
	// first open the cat file
Line 244... Line 235...
244
				f.SetFilename(tofile);
235
				f.SetFilename(tofile);
245
 
236
 
246
			if ( !f.writeFilePointer() )
237
			if ( !f.writeFilePointer() )
247
				printf("Error: unable to write file: %s\n", tofile.c_str() );
238
				printf("Error: unable to write file: %s\n", tofile.c_str() );
248
			else
239
			else
249
				printf("%s has been unpacked to %s\n", file.c_str(), f.GetFilename().c_str() );
240
				printf("%s has been unpacked to %s\n", file.c_str(), f.filename().c_str() );
250
		}
241
		}
251
	}
242
	}
252
}
243
}
253
 
244
 
254
void PackFile ( CyString file, CyString tofile )
245
void PackFile ( CyString file, CyString tofile )
Line 288... Line 279...
288
				f.SetFilename(tofile);
279
				f.SetFilename(tofile);
289
 
280
 
290
			if ( !f.writeFilePointer() )
281
			if ( !f.writeFilePointer() )
291
				printf("Error: unable to write file: %s\n", tofile.c_str() );
282
				printf("Error: unable to write file: %s\n", tofile.c_str() );
292
			else
283
			else
293
				printf("%s has been packed to %s\n", file.c_str(), f.GetFilename().c_str() );
284
				printf("%s has been packed to %s\n", file.c_str(), f.filename().c_str() );
294
		}
285
		}
295
	}
286
	}
296
}
287
}
297
 
288
 
298
void PrintSyntax(CyString cmd)
289
void PrintSyntax(CyString cmd)