[Scummvm-cvs-logs] SF.net SVN: scummvm:[53244] scummvm/trunk/engines/sword25/package

sev at users.sourceforge.net sev at users.sourceforge.net
Wed Oct 13 00:46:14 CEST 2010


Revision: 53244
          http://scummvm.svn.sourceforge.net/scummvm/?rev=53244&view=rev
Author:   sev
Date:     2010-10-12 22:46:13 +0000 (Tue, 12 Oct 2010)

Log Message:
-----------
SWORD25: Fix package manager. Now scripts run.

Modified Paths:
--------------
    scummvm/trunk/engines/sword25/package/scummvmpackagemanager.cpp
    scummvm/trunk/engines/sword25/package/scummvmpackagemanager.h

Modified: scummvm/trunk/engines/sword25/package/scummvmpackagemanager.cpp
===================================================================
--- scummvm/trunk/engines/sword25/package/scummvmpackagemanager.cpp	2010-10-12 22:45:53 UTC (rev 53243)
+++ scummvm/trunk/engines/sword25/package/scummvmpackagemanager.cpp	2010-10-12 22:46:13 UTC (rev 53244)
@@ -103,7 +103,7 @@
 			// element is ".", so we do nothing
 		} else {
 			// Normal elements get added to the list
-			pathElements.push_back(PathElement(wholePath.begin() + separatorPos + 1, wholePath.begin() + nextseparatorPos));
+			pathElements.push_back(new PathElement(wholePath.begin() + separatorPos + 1, wholePath.begin() + nextseparatorPos));
 		}
 
 		separatorPos = nextseparatorPos;
@@ -124,7 +124,7 @@
 		PathElementArray::const_iterator It = pathElements.begin();
 		while (It != pathElements.end()) {
 			Result += PATH_SEPARATOR;
-			Result += Common::String(It->GetBegin(), It->GetEnd());
+			Result += Common::String((*It)->GetBegin(), (*It)->GetEnd());
 			++It;
 		}
 
@@ -161,48 +161,32 @@
 /**
  * Scans through the archive list for a specified file
  */
-Common::FSNode BS_ScummVMPackageManager::GetFSNode(const Common::String &FileName) {
-	// Get the path elements for the file
-	PathElementArray pathElements = SeparatePath(FileName, _currentDirectory);
-
+Common::ArchiveMemberPtr BS_ScummVMPackageManager::GetArchiveMember(const Common::String &FileName) {
 	// Loop through checking each archive
 	Common::List<ArchiveEntry *>::iterator i;
 	for (i = _archiveList.begin(); i != _archiveList.end(); ++i) {
-		if ((*i)->MountPath.size() > pathElements.size())
+		if (!FileName.hasPrefix((*i)->_mountPath)) {
 			// The mount path has more subfolder depth than the search entry, so skip it
 			continue;
-
-		// Check the path against that of the archive
-		PathElementArray::iterator iPath = pathElements.begin();
-		PathElementArray::iterator iEntry = (*i)->MountPath.begin();
-
-		for (; iEntry != (*i)->MountPath.end(); ++iEntry, ++iPath) {
-			if (Common::String(iPath->GetBegin(), iPath->GetEnd()) ==
-			        Common::String(iEntry->GetBegin(), iEntry->GetEnd()))
-				break;
 		}
 
-		if (iEntry == (*i)->MountPath.end()) {
-			// Look into the archive for the desired file
-			Common::Archive *archiveFolder = (*i)->Archive;
+		// Look into the archive for the desired file
+		Common::Archive *archiveFolder = (*i)->Archive;
 
-			if (archiveFolder->hasFile(FileName)) {
-			}
+		// Construct relative path
+		Common::String resPath(&FileName.c_str()[(*i)->_mountPath.size()]);
 
-			// Return the found node
-			return Common::FSNode();
+		if (archiveFolder->hasFile(resPath)) {
+			return archiveFolder->getMember(resPath);
 		}
 	}
 
-	return Common::FSNode();
+	return Common::ArchiveMemberPtr();
 }
 
 // -----------------------------------------------------------------------------
 
 bool BS_ScummVMPackageManager::LoadPackage(const Common::String &FileName, const Common::String &MountPosition) {
-	// Get the path elements for the file
-	PathElementArray pathElements = SeparatePath(MountPosition, _currentDirectory);
-
 	Common::Archive *zipFile = Common::makeZipArchive(FileName);
 	if (zipFile == NULL) {
 		BS_LOG_ERRORLN("Unable to mount file \"%s\" to \"%s\"", FileName.c_str(), MountPosition.c_str());
@@ -213,7 +197,7 @@
 		zipFile->listMembers(files);
 		debug(0, "Capacity %d", files.size());
 
-		_archiveList.push_back(new ArchiveEntry(zipFile, pathElements));
+		_archiveList.push_back(new ArchiveEntry(zipFile, MountPosition));
 
 		return true;
 	}
@@ -222,9 +206,6 @@
 // -----------------------------------------------------------------------------
 
 bool BS_ScummVMPackageManager::LoadDirectoryAsPackage(const Common::String &DirectoryName, const Common::String &MountPosition) {
-	// Get the path elements for the file
-	PathElementArray pathElements = SeparatePath(MountPosition, _currentDirectory);
-
 	Common::FSNode directory(DirectoryName);
 	Common::Archive *folderArchive = new Common::FSDirectory(directory);
 	if (!directory.exists() || (folderArchive == NULL)) {
@@ -232,7 +213,7 @@
 		return false;
 	} else {
 		BS_LOGLN("Directory '%s' mounted as '%s'.", DirectoryName.c_str(), MountPosition.c_str());
-		_archiveList.push_front(new ArchiveEntry(folderArchive, pathElements));
+		_archiveList.push_front(new ArchiveEntry(folderArchive, MountPosition));
 		return true;
 	}
 }
@@ -240,19 +221,24 @@
 // -----------------------------------------------------------------------------
 
 void *BS_ScummVMPackageManager::GetFile(const Common::String &FileName, unsigned int *FileSizePtr) {
-	Common::File f;
-	Common::FSNode fileNode = GetFSNode(FileName);
-	if (!fileNode.exists()) return 0;
-	if (!f.open(fileNode)) return 0;
+	Common::SeekableReadStream *in;
+	Common::ArchiveMemberPtr fileNode = GetArchiveMember(FileName);
+	if (fileNode->getName().empty())
+		return 0;
+	if (!(in = fileNode->createReadStream()))
+		return 0;
 
 	// If the filesize is desired, then output the size
-	if (FileSizePtr) *FileSizePtr = f.size();
+	if (FileSizePtr)
+		*FileSizePtr = in->size();
 
+	if (in->size() > 102400)
+		warning("UGLY: UGLY: Sucking >100kb file into memory (%d bytes)", in->size());
+
 	// Read the file
-	byte *buffer = new byte[f.size()];
-	if (!f.read(buffer, f.size())) return 0;
+	byte *buffer = new byte[in->size()];
+	if (!in->read(buffer, in->size())) return 0;
 
-	f.close();
 	return buffer;
 }
 
@@ -279,31 +265,32 @@
 // -----------------------------------------------------------------------------
 
 unsigned int BS_ScummVMPackageManager::GetFileSize(const Common::String &FileName) {
-	Common::File f;
-	Common::FSNode fileNode = GetFSNode(FileName);
-	if (!fileNode.exists()) return 0;
-	if (!f.open(fileNode)) return 0;
+	Common::SeekableReadStream *in;
+	Common::ArchiveMemberPtr fileNode = GetArchiveMember(FileName);
+	if (fileNode->getName().empty())
+		return 0;
+	if (!(in = fileNode->createReadStream()))
+		return 0;
 
-	uint32 fileSize = f.size();
-	f.close();
+	uint fileSize = in->size();
+
 	return fileSize;
 }
 
 // -----------------------------------------------------------------------------
 
 unsigned int BS_ScummVMPackageManager::GetFileType(const Common::String &FileName) {
-	Common::File f;
-	Common::FSNode fileNode = GetFSNode(FileName);
-	if (!fileNode.exists()) return 0;
+	warning("STUB: BS_ScummVMPackageManager::GetFileType(%s)", FileName.c_str());
 
-	return fileNode.isDirectory() ? BS_PackageManager::FT_DIRECTORY : BS_PackageManager::FT_FILE;
+	//return fileNode.isDirectory() ? BS_PackageManager::FT_DIRECTORY : BS_PackageManager::FT_FILE;
+	return BS_PackageManager::FT_FILE;
 }
 
 // -----------------------------------------------------------------------------
 
 bool BS_ScummVMPackageManager::FileExists(const Common::String &FileName) {
-	Common::FSNode fileNode = GetFSNode(FileName);
-	return fileNode.exists();
+	Common::ArchiveMemberPtr fileNode = GetArchiveMember(FileName);
+	return !fileNode->getName().empty();
 }
 
 // -----------------------------------------------------------------------------
@@ -345,6 +332,7 @@
 
 BS_PackageManager::FileSearch *BS_ScummVMPackageManager::CreateSearch(
     const Common::String &Filter, const Common::String &Path, unsigned int TypeFilter) {
+#if 0
 	Common::String NormalizedPath = NormalizePath(Path, _currentDirectory);
 
 	Common::FSNode folderNode = GetFSNode(Path);
@@ -364,6 +352,11 @@
 
 	// Return a ArchiveFileSearch object that encapsulates the name list
 	return new ArchiveFileSearch(*this, nameList);
+#else
+	warning("STUB: BS_ScummVMPackageManager::CreateSearch(%s, %s, %d)", Filter.c_str(), Path.c_str(), TypeFilter);
+	Common::StringArray nameList;
+	return new ArchiveFileSearch(*this, nameList);
+#endif
 }
 
 } // End of namespace Sword25

Modified: scummvm/trunk/engines/sword25/package/scummvmpackagemanager.h
===================================================================
--- scummvm/trunk/engines/sword25/package/scummvmpackagemanager.h	2010-10-12 22:45:53 UTC (rev 53243)
+++ scummvm/trunk/engines/sword25/package/scummvmpackagemanager.h	2010-10-12 22:46:13 UTC (rev 53244)
@@ -66,17 +66,17 @@
 	Common::String::const_iterator m_End;
 };
 
-typedef Common::Array<PathElement> PathElementArray;
+typedef Common::Array<PathElement *> PathElementArray;
 
 class BS_ScummVMPackageManager : public BS_PackageManager {
 private:
 	class ArchiveEntry {
 	public:
 		Common::Archive *Archive;
-		PathElementArray MountPath;
+		Common::String _mountPath;
 
-		ArchiveEntry(Common::Archive *Archive_, const PathElementArray &MountPath_):
-			Archive(Archive_), MountPath(MountPath_) {
+		ArchiveEntry(Common::Archive *Archive_, const Common::String &MountPath_):
+			Archive(Archive_), _mountPath(MountPath_) {
 		}
 		~ArchiveEntry() {
 			delete Archive;
@@ -87,7 +87,7 @@
 	Common::FSNode _rootFolder;
 	Common::List<ArchiveEntry *> _archiveList;
 
-	Common::FSNode GetFSNode(const Common::String &FileName);
+	Common::ArchiveMemberPtr GetArchiveMember(const Common::String &FileName);
 public:
 	BS_ScummVMPackageManager(BS_Kernel *KernelPtr);
 	virtual ~BS_ScummVMPackageManager();


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