Subversion Repositories spk

Rev

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

Rev 125 Rev 127
Line 72... Line 72...
72
CyStringList *FindFiles(CyString filepattern)
72
CyStringList *FindFiles(CyString filepattern)
73
{
73
{
74
	CFileIO File((filepattern.IsIn(":")) ? filepattern : g_dir + "/" + filepattern);
74
	CFileIO File((filepattern.IsIn(":")) ? filepattern : g_dir + "/" + filepattern);
75
	CyStringList *files = File.GetDirIO().DirList(NullString, File.GetFilename());
75
	CyStringList *files = File.GetDirIO().DirList(NullString, File.GetFilename());
76
	return files;
76
	return files;
-
 
77
}
-
 
78
 
-
 
79
bool findFiles(Utils::CStringList &files, const Utils::String &filepattern)
-
 
80
{
-
 
81
	CFileIO File((filepattern.contains(":")) ? filepattern : g_dir.ToString() + "/" + filepattern);
-
 
82
	return File.GetDirIO().dirList(files, Utils::String::Null(), File.GetFilename().ToString());
77
}
83
}
78
 
84
 
79
 
85
 
80
void ExtractFile ( CyString filename, CyString to, bool preserve )
86
void ExtractFile ( CyString filename, CyString to, bool preserve )
81
{
87
{
Line 148... Line 154...
148
		catfile = C_File.GetToken ( "::", 1, 1 ).ToString();
154
		catfile = C_File.GetToken ( "::", 1, 1 ).ToString();
149
		file = C_File.GetToken ( "::", 2, 2 ).ToString();
155
		file = C_File.GetToken ( "::", 2, 2 ).ToString();
150
	}
156
	}
151
 
157
 
152
	CyStringList *list = FindFiles(filepattern);
158
	CyStringList *list = FindFiles(filepattern);
153
	if ( !list || !list->Count() )
159
	if ( !list || !list->Count() )
154
	{
160
	{
155
		printf("Error: no files found to add: %s\n", filepattern.c_str());
161
		printf("Error: no files found to add: %s\n", filepattern.c_str());
156
		return;
162
		return;
157
	}
163
	}
158
 
164
 
Line 209... Line 215...
209
		printf ( "File has been removed from archive\n" );
215
		printf ( "File has been removed from archive\n" );
210
}
216
}
211
 
217
 
212
void UnpackFile ( CyString file, CyString tofile )
218
void UnpackFile ( CyString file, CyString tofile )
213
{
219
{
214
	CyStringList *list = FindFiles(file);
220
	Utils::CStringList list;
215
	if ( !list || !list->Count() )
221
	if(!findFiles(list, file.ToString()) || !list.size())
216
	{
222
	{
217
		printf("Error: no files found to unpack: %s\n", file.c_str());
223
		printf("Error: no files found to unpack: %s\n", file.c_str());
218
		return;
224
		return;
219
	}
225
	}
220
 
226
 
221
	for ( SStringList *fname = list->Head(); fname; fname = fname->next )
227
	for(auto itr = list.first(); itr; list.next())
222
	{
228
	{
223
		CyString filename = CFileIO(file).dir() + "/" + fname->str.ToString();
229
		Utils::String filename = CFileIO(file).dir() + "/" + itr->str;
224
 
230
 
225
		C_File f(filename);
231
		C_File f(filename);
226
		if ( !f.CheckValidFilePointer() )
232
		if ( !f.CheckValidFilePointer() )
227
			printf("Error: %s doesn't exists\n", filename.c_str() );
233
			printf("Error: %s doesn't exists\n", filename.c_str() );
228
		else if ( !f.ReadFromFile() )
234
		else if ( !f.ReadFromFile() )
Line 241... Line 247...
241
				printf("Error: unable to write file: %s\n", tofile.c_str() );
247
				printf("Error: unable to write file: %s\n", tofile.c_str() );
242
			else
248
			else
243
				printf("%s has been unpacked to %s\n", file.c_str(), f.GetFilename().c_str() );
249
				printf("%s has been unpacked to %s\n", file.c_str(), f.GetFilename().c_str() );
244
		}
250
		}
245
	}
251
	}
246
 
-
 
247
	delete list;
-
 
248
}
252
}
249
 
253
 
250
void PackFile ( CyString file, CyString tofile )
254
void PackFile ( CyString file, CyString tofile )
251
{
255
{
252
	CyStringList *list = FindFiles(file);
256
	Utils::CStringList list;
253
	if ( !list || !list->Count() )
257
	if(!findFiles(list, file.ToString()) || !list.size())
254
	{
258
	{
255
		printf("Error: no files found to pack: %s\n", file.c_str());
259
		printf("Error: no files found to pack: %s\n", file.c_str());
256
		return;
260
		return;
257
	}
261
	}
258
 
262
 
259
	for ( SStringList *fname = list->Head(); fname; fname = fname->next )
263
	for(auto itr = list.first(); itr; itr = list.next())
260
	{
264
	{
261
		CyString filename = CFileIO(file).dir() + "/" + fname->str.ToString();
265
		Utils::String filename = CFileIO(file).dir() + "/" + itr->str;
262
 
266
 
263
		C_File f(filename);
267
		C_File f(filename);
264
		if ( !f.CheckValidFilePointer() )
268
		if ( !f.CheckValidFilePointer() )
265
			printf("Error: %s doesn't exists\n", filename.c_str() );
269
			printf("Error: %s doesn't exists\n", filename.c_str() );
266
		else if ( !f.ReadFromFile() )
270
		else if ( !f.ReadFromFile() )
Line 287... Line 291...
287
				printf("Error: unable to write file: %s\n", tofile.c_str() );
291
				printf("Error: unable to write file: %s\n", tofile.c_str() );
288
			else
292
			else
289
				printf("%s has been packed to %s\n", file.c_str(), f.GetFilename().c_str() );
293
				printf("%s has been packed to %s\n", file.c_str(), f.GetFilename().c_str() );
290
		}
294
		}
291
	}
295
	}
292
 
-
 
293
	delete list;
-
 
294
}
296
}
295
 
297
 
296
void PrintSyntax(CyString cmd)
298
void PrintSyntax(CyString cmd)
297
{
299
{
298
	printf ( "Syntax: %s <flags> [arguments]\n", cmd.c_str() );
300
	printf ( "Syntax: %s <flags> [arguments]\n", cmd.c_str() );