File.pkg 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. $#include "File.h"
  2. /// File open mode.
  3. enum FileMode
  4. {
  5. FILE_READ = 0,
  6. FILE_WRITE,
  7. FILE_READWRITE
  8. };
  9. /// %File opened either through the filesystem or from within a package file.
  10. class File : public Deserializer
  11. {
  12. public:
  13. /// Construct.
  14. File(Context* context);
  15. /// Construct and open a filesystem file.
  16. File(Context* context, const String& fileName, FileMode mode = FILE_READ);
  17. /// Construct and open from a package file.
  18. File(Context* context, PackageFile* package, const String& fileName);
  19. /// Destruct. Close the file if open.
  20. virtual ~File();
  21. /// Read bytes from the file. Return number of bytes actually read.
  22. virtual unsigned Read(void* dest, unsigned size);
  23. /// Set position from the beginning of the file.
  24. virtual unsigned Seek(unsigned position);
  25. /// Return the file name.
  26. virtual const String& GetName() const;
  27. /// Return a checksum of the file contents using the SDBM hash algorithm.
  28. virtual unsigned GetChecksum();
  29. /// Open a filesystem file. Return true if successful.
  30. bool Open(const String& fileName, FileMode mode = FILE_READ);
  31. /// Open from within a package file. Return true if successful.
  32. bool Open(PackageFile* package, const String& fileName);
  33. /// Close the file.
  34. void Close();
  35. /// Flush any buffered output to the file.
  36. void Flush();
  37. /// Change the file name. Used by the resource system.
  38. void SetName(const String& name);
  39. /// Return the open mode.
  40. FileMode GetMode() const { return mode_; }
  41. /// Return whether is open.
  42. bool IsOpen() const { return handle_ != 0; }
  43. /// Return the file handle.
  44. void* GetHandle() const { return handle_; }
  45. /// Return whether the file originates from a package.
  46. bool IsPackaged() const { return offset_ != 0; }
  47. };