ezEngine  Milestone 7
FileReaderWriterBase.h
1 #pragma once
2 
3 #include <Foundation/IO/Stream.h>
4 #include <Foundation/IO/FileSystem/Implementation/DataDirType.h>
5 #include <Foundation/IO/FileSystem/FileSystem.h>
6 
12 class EZ_FOUNDATION_DLL ezFileReaderBase : public ezStreamReaderBase
13 {
14  EZ_DISALLOW_COPY_AND_ASSIGN(ezFileReaderBase);
15 
16 public:
17  ezFileReaderBase() { m_pDataDirReader = nullptr; }
18 
20  ezString128 GetFilePathAbsolute() const
21  {
22  ezStringBuilder sAbs = m_pDataDirReader->GetDataDirectory()->GetDataDirectoryPath();
23  sAbs.AppendPath(m_pDataDirReader->GetFilePath().GetData());
24  return sAbs;
25  }
26 
28  ezString128 GetFilePathRelative() const { return m_pDataDirReader->GetFilePath(); }
29 
31  ezDataDirectoryType* GetDataDirectory() const { return m_pDataDirReader->GetDataDirectory(); }
32 
34  bool IsOpen() const { return m_pDataDirReader != nullptr; }
35 
37  ezUInt64 GetFileSize() const { return m_pDataDirReader->GetFileSize(); }
38 
39 protected:
40  ezDataDirectoryReader* GetFileReader(const char* szFile, bool bAllowFileEvents)
41  {
42  return ezFileSystem::GetFileReader(szFile, bAllowFileEvents);
43  }
44 
45  ezDataDirectoryReader* m_pDataDirReader;
46 };
47 
48 
54 class EZ_FOUNDATION_DLL ezFileWriterBase : public ezStreamWriterBase
55 {
56  EZ_DISALLOW_COPY_AND_ASSIGN(ezFileWriterBase);
57 
58 public:
59  ezFileWriterBase() { m_pDataDirWriter = nullptr; }
60 
62  ezString128 GetFilePathAbsolute() const
63  {
64  ezStringBuilder sAbs = m_pDataDirWriter->GetDataDirectory()->GetDataDirectoryPath();
65  sAbs.AppendPath(m_pDataDirWriter->GetFilePath().GetData());
66  return sAbs;
67  }
68 
70  ezString128 GetFilePathRelative() const { return m_pDataDirWriter->GetFilePath(); }
71 
73  ezDataDirectoryType* GetDataDirectory() const { return m_pDataDirWriter->GetDataDirectory(); }
74 
76  bool IsOpen() const { return m_pDataDirWriter != nullptr; }
77 
79  ezUInt64 GetFileSize() const { return m_pDataDirWriter->GetFileSize(); } // [tested]
80 
81 protected:
82  ezDataDirectoryWriter* GetFileWriter(const char* szFile, bool bAllowFileEvents)
83  {
84  return ezFileSystem::GetFileWriter(szFile, bAllowFileEvents);
85  }
86 
87  ezDataDirectoryWriter* m_pDataDirWriter;
88 };
89