コード例 #1
0
ファイル: File.cpp プロジェクト: Ghor/LoveEngineCore
bool File::open(Mode mode)
{
	if (mode == CLOSED)
		return true;

	// File must exist if read mode.
	if ((mode == READ) && !PHYSFS_exists(filename.c_str()))
		throw love::Exception("Could not open file %s. Does not exist.", filename.c_str());

	// Check whether the write directory is set.
	if ((mode == APPEND || mode == WRITE) && (PHYSFS_getWriteDir() == 0) && !hack_setupWriteDirectory())
		throw love::Exception("Could not set write directory.");

	// File already open?
	if (file != 0)
		return false;

	this->mode = mode;

	switch (mode)
	{
	case READ:
		file = PHYSFS_openRead(filename.c_str());
		break;
	case APPEND:
		file = PHYSFS_openAppend(filename.c_str());
		break;
	case WRITE:
		file = PHYSFS_openWrite(filename.c_str());
		break;
	default:
		break;
	}

	if (file != 0 && !setBuffer(bufferMode, bufferSize))
	{
		// Revert to buffer defaults if we don't successfully set the buffer.
		bufferMode = BUFFER_NONE;
		bufferSize = 0;
	}

	return (file != 0);
}
コード例 #2
0
ファイル: File.cpp プロジェクト: leafo/moonscript-love
	bool File::open(Mode mode)
	{
		if(mode == CLOSED)
			return true;

		// File must exist if read mode.
		if((mode == READ) && !PHYSFS_exists(filename.c_str()))
			throw love::Exception("Could not open file %s. Does not exist.", filename.c_str());

		// Check whether the write directory is set.
		if((mode == APPEND || mode == WRITE) && (PHYSFS_getWriteDir() == 0) && !hack_setupWriteDirectory())
			throw love::Exception("Could not set write directory.");

		// File already open?
		if(file != 0)
			return false;

		this->mode = mode;

		switch(mode)
		{
		case READ:
			file = PHYSFS_openRead(filename.c_str());
			break;
		case APPEND:
			file = PHYSFS_openAppend(filename.c_str());
			break;
		case WRITE:
			file = PHYSFS_openWrite(filename.c_str());
			break;
		default:
			break;
		}

		return (file != 0);
	}