2007-05-30 21:56:52 +00:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
|
|
|
*
|
|
|
|
* ScummVM is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
|
|
|
* file distributed with this source distribution.
|
2002-08-31 07:43:34 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
2005-10-18 01:30:26 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2002-08-31 07:43:34 +00:00
|
|
|
*
|
2006-02-11 09:53:53 +00:00
|
|
|
* $URL$
|
|
|
|
* $Id$
|
2002-08-31 07:43:34 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2002-09-08 01:08:12 +00:00
|
|
|
#ifndef COMMON_FILE_H
|
|
|
|
#define COMMON_FILE_H
|
|
|
|
|
2003-08-01 12:21:04 +00:00
|
|
|
#include "common/scummsys.h"
|
2008-07-29 16:09:10 +00:00
|
|
|
#include "common/noncopyable.h"
|
2003-10-10 13:55:08 +00:00
|
|
|
#include "common/str.h"
|
2004-04-17 09:57:15 +00:00
|
|
|
#include "common/stream.h"
|
2002-08-31 07:43:34 +00:00
|
|
|
|
2008-09-03 11:22:51 +00:00
|
|
|
namespace Common {
|
|
|
|
|
2008-10-23 07:59:10 +00:00
|
|
|
class Archive;
|
2008-10-02 16:58:59 +00:00
|
|
|
class FSNode;
|
2006-04-30 23:08:37 +00:00
|
|
|
|
2008-07-29 16:09:10 +00:00
|
|
|
/**
|
|
|
|
* TODO: vital to document this core class properly!!! For both users and implementors
|
|
|
|
*/
|
|
|
|
class File : public SeekableReadStream, public NonCopyable {
|
2004-07-23 01:39:05 +00:00
|
|
|
protected:
|
2007-03-08 16:46:02 +00:00
|
|
|
/** File handle to the actual file; 0 if no file is open. */
|
2008-09-06 20:49:48 +00:00
|
|
|
SeekableReadStream *_handle;
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2008-09-30 09:12:02 +00:00
|
|
|
/** The name of this file, kept for debugging purposes. */
|
2005-05-10 22:56:25 +00:00
|
|
|
String _name;
|
2004-06-28 22:34:22 +00:00
|
|
|
|
2002-08-31 07:43:34 +00:00
|
|
|
public:
|
|
|
|
File();
|
2003-06-21 20:21:40 +00:00
|
|
|
virtual ~File();
|
2004-06-28 22:34:22 +00:00
|
|
|
|
2006-07-24 12:10:32 +00:00
|
|
|
/**
|
|
|
|
* Checks if a given file exists in any of the current default paths
|
|
|
|
* (those were/are added by addDefaultDirectory and/or
|
|
|
|
* addDefaultDirectoryRecursive).
|
|
|
|
*
|
2008-09-30 09:12:02 +00:00
|
|
|
* @param filename the file to check for
|
|
|
|
* @return true if the file exists, false otherwise
|
2006-07-24 12:10:32 +00:00
|
|
|
*/
|
|
|
|
static bool exists(const String &filename);
|
2006-05-20 15:10:04 +00:00
|
|
|
|
2008-09-30 09:12:02 +00:00
|
|
|
/**
|
|
|
|
* Try to open the file with the given filename, by searching SearchMan.
|
|
|
|
* @note Must not be called if this file already is open (i.e. if isOpen returns true).
|
|
|
|
*
|
|
|
|
* @param filename the name of the file to open
|
|
|
|
* @return true if file was opened successfully, false otherwise
|
|
|
|
*/
|
2008-07-29 16:09:10 +00:00
|
|
|
virtual bool open(const String &filename);
|
2008-09-30 09:12:02 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Try to open the file with the given filename from within the given archive.
|
|
|
|
* @note Must not be called if this file already is open (i.e. if isOpen returns true).
|
|
|
|
*
|
|
|
|
* @param filename the name of the file to open
|
|
|
|
* @param archive the archive in which to search for the file
|
|
|
|
* @return true if file was opened successfully, false otherwise
|
|
|
|
*/
|
|
|
|
virtual bool open(const String &filename, Archive &archive);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Try to open the file corresponding to the give node. Will check whether the
|
2008-12-22 11:22:15 +00:00
|
|
|
* node actually refers to an existing file (and not a directory), and handle
|
2008-09-30 09:12:02 +00:00
|
|
|
* those cases gracefully.
|
|
|
|
* @note Must not be called if this file already is open (i.e. if isOpen returns true).
|
|
|
|
*
|
|
|
|
* @param filename the name of the file to open
|
|
|
|
* @param archive the archive in which to search for the file
|
|
|
|
* @return true if file was opened successfully, false otherwise
|
|
|
|
*/
|
2008-10-02 16:58:59 +00:00
|
|
|
virtual bool open(const FSNode &node);
|
2004-11-27 15:09:53 +00:00
|
|
|
|
2008-09-30 09:12:02 +00:00
|
|
|
/**
|
|
|
|
* Try to 'open' the given stream. That is, we just wrap around it, and if stream
|
|
|
|
* is a NULL pointer, we gracefully treat this as if opening failed.
|
|
|
|
* @note Must not be called if this file already is open (i.e. if isOpen returns true).
|
|
|
|
*
|
|
|
|
* @param stream a pointer to a SeekableReadStream, or 0
|
|
|
|
* @param name a string describing the 'file' corresponding to stream
|
2008-11-18 14:57:40 +00:00
|
|
|
* @return true if stream was non-zero, false otherwise
|
2008-09-30 09:12:02 +00:00
|
|
|
*/
|
|
|
|
virtual bool open(SeekableReadStream *stream, const Common::String &name);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Close the file, if open.
|
|
|
|
*/
|
2004-07-26 17:06:39 +00:00
|
|
|
virtual void close();
|
2006-07-24 12:10:32 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if the object opened a file successfully.
|
|
|
|
*
|
|
|
|
* @return: true if any file is opened, false otherwise.
|
|
|
|
*/
|
2003-11-30 00:06:27 +00:00
|
|
|
bool isOpen() const;
|
2006-07-24 12:10:32 +00:00
|
|
|
|
|
|
|
/**
|
2008-09-30 09:12:02 +00:00
|
|
|
* Returns the filename of the opened file for debugging purposes.
|
2006-07-24 12:10:32 +00:00
|
|
|
*
|
|
|
|
* @return: the filename
|
|
|
|
*/
|
2008-09-30 09:12:02 +00:00
|
|
|
const char *getName() const { return _name.c_str(); }
|
2006-07-24 12:10:32 +00:00
|
|
|
|
2009-05-19 11:42:14 +00:00
|
|
|
bool err() const; // implement abstract Stream method
|
|
|
|
void clearErr(); // implement abstract Stream method
|
|
|
|
bool eos() const; // implement abstract SeekableReadStream method
|
|
|
|
|
|
|
|
int32 pos() const; // implement abstract SeekableReadStream method
|
|
|
|
int32 size() const; // implement abstract SeekableReadStream method
|
|
|
|
bool seek(int32 offs, int whence = SEEK_SET); // implement abstract SeekableReadStream method
|
|
|
|
uint32 read(void *dataPtr, uint32 dataSize); // implement abstract SeekableReadStream method
|
2008-07-29 16:09:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* TODO: document this class
|
|
|
|
*
|
|
|
|
* Some design ideas:
|
|
|
|
* - automatically drop all files into dumps/ dir? Might not be desired in all cases
|
|
|
|
*/
|
|
|
|
class DumpFile : public WriteStream, public NonCopyable {
|
|
|
|
protected:
|
|
|
|
/** File handle to the actual file; 0 if no file is open. */
|
2008-09-06 20:49:48 +00:00
|
|
|
WriteStream *_handle;
|
2008-07-29 16:09:10 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
DumpFile();
|
|
|
|
virtual ~DumpFile();
|
|
|
|
|
|
|
|
virtual bool open(const String &filename);
|
2008-10-02 16:58:59 +00:00
|
|
|
virtual bool open(const FSNode &node);
|
2008-07-29 16:09:10 +00:00
|
|
|
|
|
|
|
virtual void close();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if the object opened a file successfully.
|
|
|
|
*
|
|
|
|
* @return: true if any file is opened, false otherwise.
|
|
|
|
*/
|
|
|
|
bool isOpen() const;
|
|
|
|
|
2008-09-14 22:28:53 +00:00
|
|
|
bool err() const;
|
|
|
|
void clearErr();
|
2008-07-29 16:09:10 +00:00
|
|
|
|
2008-08-04 11:30:47 +00:00
|
|
|
virtual uint32 write(const void *dataPtr, uint32 dataSize);
|
|
|
|
|
2008-09-13 16:51:46 +00:00
|
|
|
virtual bool flush();
|
2002-08-31 07:43:34 +00:00
|
|
|
};
|
|
|
|
|
2005-05-10 22:56:25 +00:00
|
|
|
} // End of namespace Common
|
|
|
|
|
2002-08-31 07:43:34 +00:00
|
|
|
#endif
|