Subversion Repositories spk

Rev

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

Rev 320 Rev 322
Line 23... Line 23...
23
		case CATERR_MISMATCH:
23
		case CATERR_MISMATCH:
24
			printf("Dat file size mismatch\n");
24
			printf("Dat file size mismatch\n");
25
			break;
25
			break;
26
		case CATERR_CREATED:
26
		case CATERR_CREATED:
27
			printf("Cat file does not exist\n");
27
			printf("Cat file does not exist\n");
-
 
28
			break;
-
 
29
		default:
-
 
30
			printf("Unknown error code: %d\n", err);
28
			break;
31
			break;
29
	}
32
	}
30
}
33
}
31
 
34
 
32
void ListFiles(const Utils::CommandLine &cmd)
35
void ListFiles(const Utils::CommandLine &cmd)
Line 37... Line 40...
37
	CFileIO File(!filename.contains(L":") ? CDirIO(cmd.cmdDir()).file(filename) : filename);
40
	CFileIO File(!filename.contains(L":") ? CDirIO(cmd.cmdDir()).file(filename) : filename);
38
	if(!File.exists())
41
	if(!File.exists())
39
		File.open(filename);
42
		File.open(filename);
40
	if (!File.exists())
43
	if (!File.exists())
41
	{
44
	{
42
		wprintf(L"Error: Cat file: %s, does not exist", filename.c_str());
45
		wprintf(L"Error: Cat file: %s, does not exist\n", filename.c_str());
43
		return;
46
		return;
44
	}
47
	}
45
	
48
	
46
	wprintf(L"Listing files in %s...", filename.c_str());
49
	wprintf(L"Listing files in %s...", filename.c_str());
47
	if (!searchmask.empty())
50
	if (!searchmask.empty())
Line 52... Line 55...
52
	int err = catfile.open(File.fullFilename(), L"", CATREAD_CATDECRYPT);
55
	int err = catfile.open(File.fullFilename(), L"", CATREAD_CATDECRYPT);
53
 
56
 
54
	int listed = 0;
57
	int listed = 0;
55
	if ( err == CATERR_NONE )
58
	if ( err == CATERR_NONE )
56
	{
59
	{
57
		printf ( "Opened file\n" );
60
		wprintf(L"Opened file\n" );
58
		for (unsigned int i = 0; i < catfile.GetNumFiles(); i++)
61
		for (size_t i = 0; i < catfile.GetNumFiles(); i++)
59
		{
62
		{
60
			SInCatFile *file = catfile.GetFile ( i );
63
			SInCatFile *file = catfile.GetFile ( i );
61
 
-
 
62
			if (!searchmask.empty())
64
			if (file)
63
			{
65
			{
-
 
66
				if (!searchmask.empty())
-
 
67
				{
64
				if (!file->sFile.match(searchmask))
68
					if (!file->sFile.match(searchmask))
65
					continue;
69
						continue;
-
 
70
				}
-
 
71
 
-
 
72
				wprintf(L"[%9s] %s\n", SPK::GetSizeString(static_cast<unsigned long>(file->lSize)).c_str(), file->sFile.c_str());
-
 
73
				++listed;
66
			}
74
			}
67
 
-
 
68
			wprintf(L"[%9s] %s\n", SPK::GetSizeString(static_cast<unsigned long>(file->lSize)).c_str(), file->sFile.c_str() );
-
 
69
			++listed;
-
 
70
		}
75
		}
71
 
76
 
72
		if (!searchmask.empty())
77
		if (!searchmask.empty())
73
			wprintf(L"\nListed Files: [%d/%d]", listed, static_cast<int>(catfile.GetNumFiles()));
78
			wprintf(L"\nListed Files: [%d/%d]", listed, static_cast<int>(catfile.GetNumFiles()));
74
	}
79
	}
Line 79... Line 84...
79
void findAllFiles(const CDirIO &dirIO, const Utils::WString& dir, const Utils::WString& filepattern, Utils::WStringList& list)
84
void findAllFiles(const CDirIO &dirIO, const Utils::WString& dir, const Utils::WString& filepattern, Utils::WStringList& list)
80
{
85
{
81
	Utils::WStringList dirList;
86
	Utils::WStringList dirList;
82
	if (dirIO.dirList(dirList, dir, filepattern, true))
87
	if (dirIO.dirList(dirList, dir, filepattern, true))
83
	{
88
	{
84
		for (auto itr = dirList.begin(); itr != dirList.end(); itr++)
89
		for (const auto& entry : dirList)
85
		{
90
		{
86
			if (dirIO.isDir((*itr)->str))
91
			if (dirIO.isDir(entry->str))
87
				findAllFiles(dirIO, (*itr)->str, filepattern, list);
92
				findAllFiles(dirIO, entry->str, filepattern, list);
88
			else
93
			else
89
				list.pushBack((*itr)->str);
94
				list.pushBack(entry->str);
90
		}
95
		}
91
	}
96
	}
92
}
97
}
93
 
98
 
94
bool findFiles(Utils::WStringList &files, const Utils::WString &filepattern, const Utils::CommandLine &cmd)
99
bool findFiles(Utils::WStringList &files, const Utils::WString &filepattern, const Utils::CommandLine &cmd)
Line 123... Line 128...
123
	}
128
	}
124
 
129
 
125
	Utils::WStringList fileList;
130
	Utils::WStringList fileList;
126
	if (filemask.containsAny(L"*?"))
131
	if (filemask.containsAny(L"*?"))
127
	{
132
	{
128
		for (unsigned int i = 0; i < cat.GetNumFiles(); i++)
133
		for (size_t i = 0; i < cat.GetNumFiles(); i++)
129
		{
134
		{
130
			SInCatFile* f = cat.GetFile(i);
135
			SInCatFile* f = cat.GetFile(i);
131
			if(f->sFile.match(filemask))
136
			if(f && f->sFile.match(filemask))
132
				fileList.pushBack(f->sFile);
137
				fileList.pushBack(f->sFile);
133
		}
138
		}
134
	}
139
	}
135
	else
140
	else
136
		fileList.pushBack(filemask);
141
		fileList.pushBack(filemask);
Line 243... Line 248...
243
	}
248
	}
244
 
249
 
245
	std::vector<Utils::WString> files;
250
	std::vector<Utils::WString> files;
246
	if (remfile.containsAny(L"*?"))
251
	if (remfile.containsAny(L"*?"))
247
	{
252
	{
248
		for (unsigned int i = 0; i < cat.GetNumFiles(); i++)
253
		for (size_t i = 0; i < cat.GetNumFiles(); i++)
249
		{
254
		{
250
			SInCatFile* f = cat.GetFile(i);
255
			SInCatFile* f = cat.GetFile(i);
251
			if (f->sFile.match(remfile))
256
			if (f && f->sFile.match(remfile))
252
				files.push_back(f->sFile);
257
				files.push_back(f->sFile);
253
		}
258
		}
254
	}
259
	}
255
	else
260
	else
256
		files.push_back(remfile);
261
		files.push_back(remfile);
Line 369... Line 374...
369
	wprintf(L"Syntax: %s <flags> [arguments]\n", cmd.c_str() );
374
	wprintf(L"Syntax: %s <flags> [arguments]\n", cmd.c_str() );
370
	wprintf(L"Flags:\n");
375
	wprintf(L"Flags:\n");
371
	wprintf(L"\t-l <filename> [filemask]\n");
376
	wprintf(L"\t-l <filename> [filemask]\n");
372
	wprintf(L"\t\tLists the contents of a cat file, with optional search mask\n");
377
	wprintf(L"\t\tLists the contents of a cat file, with optional search mask\n");
373
	wprintf(L"\t-x [--preserve] <catfile::filemask> [dir]\n");
378
	wprintf(L"\t-x [--preserve] <catfile::filemask> [dir]\n");
374
	wprintf(L"\t\textracts a file from a cat file to the optional directory\n\t--preverve: Preserves directory structure");
379
	wprintf(L"\t\textracts a file from a cat file to the optional directory\n\t--preserve: Preserves directory structure");
375
	wprintf(L"\t-xa <catfile> [dir]\n");
380
	wprintf(L"\t-xa <catfile> [dir]\n");
376
	wprintf(L"\t\textracts all files to optional directory\n");
381
	wprintf(L"\t\textracts all files to optional directory\n");
377
	wprintf(L"\t-a <filename> <catfile::tofile>\n");
382
	wprintf(L"\t-a <filename> <catfile::tofile>\n");
378
	wprintf(L"\t\tAdds the file into a cat archive, saves it as <tofile>\n");
383
	wprintf(L"\t\tAdds the file into a cat archive, saves it as <tofile>\n");
379
	wprintf(L"\t-r <catfile> <file>\n");
384
	wprintf(L"\t-r <catfile> <file>\n");
Line 448... Line 453...
448
			else
453
			else
449
				PackFile(cmd);
454
				PackFile(cmd);
450
		}
455
		}
451
		else
456
		else
452
		{
457
		{
453
			wprintf(L"Invalaid flag: %s\n\n", command.c_str());
458
			wprintf(L"Invalid flag: %s\n\n", command.c_str());
454
			PrintSyntax(cmd.cmdName());
459
			PrintSyntax(cmd.cmdName());
455
		}
460
		}
456
	}
461
	}
457
 
462
 
458
#ifdef _DEBUG
463
#ifdef _DEBUG