[Scummvm-cvs-logs] SF.net SVN: scummvm:[44142] scummvm/trunk/tools/create_kyradat/ create_kyradat.cpp

lordhoto at users.sourceforge.net lordhoto at users.sourceforge.net
Thu Sep 17 13:01:08 CEST 2009


Revision: 44142
          http://scummvm.svn.sourceforge.net/scummvm/?rev=44142&view=rev
Author:   lordhoto
Date:     2009-09-17 11:01:08 +0000 (Thu, 17 Sep 2009)

Log Message:
-----------
Cleanup.

Modified Paths:
--------------
    scummvm/trunk/tools/create_kyradat/create_kyradat.cpp

Modified: scummvm/trunk/tools/create_kyradat/create_kyradat.cpp
===================================================================
--- scummvm/trunk/tools/create_kyradat/create_kyradat.cpp	2009-09-17 09:40:39 UTC (rev 44141)
+++ scummvm/trunk/tools/create_kyradat/create_kyradat.cpp	2009-09-17 11:01:08 UTC (rev 44142)
@@ -1043,6 +1043,10 @@
 
 typedef std::list<DataIdEntry> DataIdList;
 
+typedef std::map<int, Search::ResultData> IdMap;
+
+bool getExtractionData(const Game *g, Search &search, IdMap &map);
+
 bool process(PAKFile &out, const Game *g, const byte *data, const uint32 size) {
 	char filename[128];
 
@@ -1051,31 +1055,81 @@
 		return false;
 	}
 
+	Search search(data, size);
+	IdMap ids;
+
+	if (!getExtractionData(g, search, ids))
+		return false;
+
 	const int *needList = getNeedList(g);
 	if (!needList) {
 		fprintf(stderr, "ERROR: No entry need list available\n");
 		return false;
 	}
 
-	DataIdList dataIdList;
-	Search search(data, size);
+	// Compare against need list
+	for (const int *entry = needList; *entry != -1; ++entry) {
+		if (ids.find(*entry) != ids.end())
+			continue;
 
-	bool allDataPresentAlready = true;
-
-	for (const int *entry = needList; *entry != -1; ++entry) {
 		// Try whether the data is present in the kyra.dat file already
 		filename[0] = 0;
 		if (!getFilename(filename, g, *entry))
 			error("couldn't find filename for id %d", *entry);
 
-		// Do not add the entry to the search list, when it's already present
-		// in kyra.dat, that will speed up the creation.
 		PAKFile::cFileList *list = out.getFileList();
+		// If the data wasn't found already, we need to break the extraction here
+		if (!list || !list->findEntry(filename)) {
+			fprintf(stderr, "Couldn't find id %d/%s in executable file", *entry, getIdString(*entry));
+			return false;
+		} else {
+			warning("Id %d/%s is present in kyra.dat but could not be found in the executable", *entry, getIdString(*entry));
+		}
+	}
+
+	for (IdMap::const_iterator i = ids.begin(); i != ids.end(); ++i) {
+		const int id = i->first;
+	
+		filename[0] = 0;
+		if (!getFilename(filename, g, id)) {
+			fprintf(stderr, "ERROR: couldn't get filename for id %d\n", id);
+			return false;
+		}
+
+		const ExtractFilename *fDesc = getFilenameDesc(id);
+
+		if (!fDesc) {
+			fprintf(stderr, "ERROR: couldn't find file description for id %d\n", id);
+			return false;
+		}
+
+		const ExtractType *tDesc = findExtractType(fDesc->type);
+
+		if (!tDesc) {
+			fprintf(stderr, "ERROR: couldn't find type description for id %d\n", id);
+			return false;
+		}
+
+		PAKFile::cFileList *list = out.getFileList();
 		if (list && list->findEntry(filename) != 0)
 			continue;
 
-		allDataPresentAlready = false;
+		if (!tDesc->extract(out, g, data + i->second.offset, i->second.data.size, filename, id, UNK_LANG)) {
+			fprintf(stderr, "ERROR: couldn't extract id %d\n", id);
+			return false;
+		}
+	}
 
+	if (!updateIndex(out, g)) {
+		error("couldn't update INDEX file, stop processing of all files");
+		return false;
+	}
+
+	return true;
+}
+
+bool setupSearch(const int *needList, Search &search, DataIdList &dataIdList) {
+	for (const int *entry = needList; *entry != -1; ++entry) {
 		bool found = false;
 
 		for (const ExtractEntry *p = extractProviders; p->id != -1; ++p) {
@@ -1083,6 +1137,7 @@
 				for (const ExtractEntrySearchData *d = p->providers; d->hint.size != 0; ++d) {
 					found = true;
 
+					// We will add *all* providers here, regardless of the language and platform!
 					search.addData(d->hint);
 					dataIdList.push_back(DataIdEntry(*d, *entry));
 				}
@@ -1092,14 +1147,26 @@
 		}
 
 		if (!found) {
-			fprintf(stderr, "ERROR: No provider for id %d/\"%s\"\n", *entry, getIdString(*entry));
+			fprintf(stderr, "ERROR: No provider for id %d/%s\n", *entry, getIdString(*entry));
 			return false;
 		}
 	}
 
-	if (allDataPresentAlready)
-		return true;
+	return true;
+}
 
+bool getExtractionData(const Game *g, Search &search, IdMap &ids) {
+	DataIdList dataIdList;
+
+	const int *needList = getNeedList(g);
+	if (!needList) {
+		fprintf(stderr, "ERROR: No entry need list available\n");
+		return false;
+	}
+
+	if (!setupSearch(needList, search, dataIdList))
+		return false;
+
 	// Process the data search
 	Search::ResultList results;
 	search.search(results);
@@ -1109,9 +1176,6 @@
 		return false;
 	}
 
-	typedef std::map<int, Search::ResultData> IdMap;
-
-	IdMap ids;
 	for (const int *entry = needList; *entry != -1; ++entry) {
 		typedef std::list<ExtractData> ExtractList;
 		ExtractList idResults;
@@ -1155,9 +1219,8 @@
 			continue;
 
 		if (idResults.size() > 1)
-			warning("Multiple entries found for id %d/\"%s\"", *entry, getIdString(*entry));
+			warning("Multiple entries found for id %d/%s", *entry, getIdString(*entry));
 
-
 		Search::ResultData result;
 		result.data.size = 0;
 		result.offset = 0xFFFFFFFF;
@@ -1186,62 +1249,6 @@
 	results.clear();
 	dataIdList.clear();
 
-	// Compare against need list
-	for (const int *entry = needList; *entry != -1; ++entry) {
-		if (ids.find(*entry) != ids.end())
-			continue;
-
-		// Try whether the data is present in the kyra.dat file already
-		filename[0] = 0;
-		if (!getFilename(filename, g, *entry))
-			error("couldn't find filename for id %d", *entry);
-
-		PAKFile::cFileList *list = out.getFileList();
-		// If the data wasn't found already, we need to break the extraction here
-		if (!list || !list->findEntry(filename)) {
-			fprintf(stderr, "Couldn't find id %d/\"%s\" in executable file", *entry, getIdString(*entry));
-			return false;
-		}
-	}
-
-	for (IdMap::const_iterator i = ids.begin(); i != ids.end(); ++i) {
-		const int id = i->first;
-	
-		filename[0] = 0;
-		if (!getFilename(filename, g, id)) {
-			fprintf(stderr, "ERROR: couldn't get filename for id %d\n", id);
-			return false;
-		}
-
-		const ExtractFilename *fDesc = getFilenameDesc(id);
-
-		if (!fDesc) {
-			fprintf(stderr, "ERROR: couldn't find file description for id %d\n", id);
-			return false;
-		}
-
-		const ExtractType *tDesc = findExtractType(fDesc->type);
-
-		if (!tDesc) {
-			fprintf(stderr, "ERROR: couldn't find type description for id %d\n", id);
-			return false;
-		}
-
-		PAKFile::cFileList *list = out.getFileList();
-		if (list && list->findEntry(filename) != 0)
-			continue;
-
-		if (!tDesc->extract(out, g, data + i->second.offset, i->second.data.size, filename, id, UNK_LANG)) {
-			fprintf(stderr, "ERROR: couldn't extract id %d\n", id);
-			return false;
-		}
-	}
-
-	if (!updateIndex(out, g)) {
-		error("couldn't update INDEX file, stop processing of all files");
-		return false;
-	}
-
 	return true;
 }
 


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list