Exemplo n.º 1
0
Common::WriteStream *TestbedConfigManager::getConfigWriteStream() const {
	// Look for config file in game-path
	const Common::String &path = ConfMan.get("path");
	Common::WriteStream *ws;
	Common::FSNode gameRoot(path);
	Common::FSNode config = gameRoot.getChild(_configFileName);
	ws = config.createWriteStream();
	return ws;
}
Exemplo n.º 2
0
Common::OutSaveFile *Ps2SaveFileManager::openForSaving(const Common::String &filename, bool compress) {
	Common::FSNode savePath(ConfMan.get("savepath")); // TODO: is this fast?
	Common::WriteStream *sf;

	printf("openForSaving : %s\n", filename.c_str());

	if (!savePath.exists() || !savePath.isDirectory())
		return NULL;

	_screen->wantAnim(true);

	if (_getDev(savePath) == MC_DEV) {
	// if (strncmp(savePath.getPath().c_str(), "mc0:", 4) == 0) {
		char path[32];

		// FIXME : hack for indy4 iq-points
		if (filename == "iq-points") {
			mcCheck("mc0:ScummVM/indy4");
			sprintf(path, "mc0:ScummVM/indy4/iq-points");
		}
		// FIXME : hack for bs1 saved games
        else if (filename == "SAVEGAME.INF") {
            mcCheck("mc0:ScummVM/sword1");
            sprintf(path, "mc0:ScummVM/sword1/SAVEGAME.INF");
        }
		else {
			char temp[32];
			strcpy(temp, filename.c_str());

			// mcSplit(temp, game, ext);
			char *game = strdup(strtok(temp, "."));
			char *ext = strdup(strtok(NULL, "*"));
			sprintf(path, "mc0:ScummVM/%s", game); // per game path
			mcCheck(path);
			sprintf(path, "mc0:ScummVM/%s/%s.sav", game, ext);

			free(game);
			free(ext);
		}

		Common::FSNode file(path);
		sf = file.createWriteStream();
	} else {
		Common::FSNode file = savePath.getChild(filename);
		sf = file.createWriteStream();
	}

	_screen->wantAnim(false);
	return compress ? Common::wrapCompressedWriteStream(sf) : sf;
}
Exemplo n.º 3
0
Common::OutSaveFile *DefaultSaveFileManager::openForSaving(const Common::String &filename, bool compress) {
	// Ensure that the savepath is valid. If not, generate an appropriate error.
	Common::String savePathName = getSavePath();
	checkPath(Common::FSNode(savePathName));
	if (getError().getCode() != Common::kNoError)
		return 0;

	// recreate FSNode since checkPath may have changed/created the directory
	Common::FSNode savePath(savePathName);

	Common::FSNode file = savePath.getChild(filename);

	// Open the file for saving
	Common::WriteStream *sf = file.createWriteStream();

	return compress ? Common::wrapCompressedWriteStream(sf) : sf;
}
Exemplo n.º 4
0
Common::OutSaveFile *DefaultSaveFileManager::openForSaving(const Common::String &filename, bool compress) {
	// Assure the savefile name cache is up-to-date.
	const Common::String savePathName = getSavePath();
	assureCached(savePathName);
	if (getError().getCode() != Common::kNoError)
		return nullptr;

	for (Common::StringArray::const_iterator i = _lockedFiles.begin(), end = _lockedFiles.end(); i != end; ++i) {
		if (filename == *i) {
			return nullptr; //file is locked, no saving available
		}
	}

#ifdef USE_LIBCURL
	// Update file's timestamp
	Common::HashMap<Common::String, uint32> timestamps = loadTimestamps();
	timestamps[filename] = INVALID_TIMESTAMP;
	saveTimestamps(timestamps);
#endif

	// Obtain node.
	SaveFileCache::const_iterator file = _saveFileCache.find(filename);
	Common::FSNode fileNode;

	// If the file did not exist before, we add it to the cache.
	if (file == _saveFileCache.end()) {
		const Common::FSNode savePath(savePathName);
		fileNode = savePath.getChild(filename);
	} else {
		fileNode = file->_value;
	}

	// Open the file for saving.
	Common::WriteStream *const sf = fileNode.createWriteStream();
	Common::OutSaveFile *const result = new Common::OutSaveFile(compress ? Common::wrapCompressedWriteStream(sf) : sf);

	// Add file to cache now that it exists.
	_saveFileCache[filename] = Common::FSNode(fileNode.getPath());

	return result;
}
Exemplo n.º 5
0
/**
 * This test creates a file testbed.out, writes a sample data and confirms if
 * it is same by reading the file again.
 */
TestExitStatus FStests::testWriteFile() {
	const Common::String &path = ConfMan.get("path");
	Common::FSNode gameRoot(path);
	if (!gameRoot.exists()) {
		Testsuite::logPrintf("Couldn't open the game data directory %s", path.c_str());
		 return kTestFailed;
	}

	Common::FSNode fileToWrite = gameRoot.getChild("testbed.out");

	Common::WriteStream *ws = fileToWrite.createWriteStream();

	if (!ws) {
		Testsuite::logDetailedPrintf("Can't open writable file in game data dir\n");
		 return kTestFailed;
	}

	ws->writeString("ScummVM Rocks!");
	ws->flush();
	delete ws;

	Common::SeekableReadStream *rs = fileToWrite.createReadStream();
	if (!rs) {
		Testsuite::logDetailedPrintf("Can't open recently written file testbed.out in game data dir\n");
		 return kTestFailed;
	}
	Common::String readFromFile = rs->readLine();
	delete rs;

	if (readFromFile.equals("ScummVM Rocks!")) {
		// All good
		Testsuite::logDetailedPrintf("Data written and read correctly\n");
		 return kTestPassed;
	}

	 return kTestFailed;
}