Repository navigation
Expand file tree
/
Copy pathFileSystem.h
More file actions
153 lines (112 loc) · 5.52 KB
/
Copy pathFileSystem.h
File metadata and controls
153 lines (112 loc) · 5.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
//////////////////////////////////////////////////////////////////////////////////
// Copyright (C) Inspiration Byte
// 2009-2020
//////////////////////////////////////////////////////////////////////////////////
// Description: Equilibrium Filesystem
//////////////////////////////////////////////////////////////////////////////////
#pragma once
#include "core/IFileSystem.h"
#include "core/platform/OSFile.h"
class CBasePackageReader;
struct FSSearchPathInfo;
//------------------------------------------------------------------------------
// File stream
//------------------------------------------------------------------------------
class COSFileStream : public IFileStream
{
friend class CFileSystem;
public:
COSFileStream(const char* fileName, COSFile&& file);
VSSize Seek(int64 pos, EFileStreamSeek seekType );
VSSize Tell() const;
VSSize Read(void *dest, VSSize count, VSSize size);
VSSize Write(const void *src, VSSize count, VSSize size);
bool Flush();
uint32 GetCRC32() const;
VSSize GetSize() const;
EFileStreamType GetType() const { return FS_TYPE_FILE; }
const char* GetName() const { return m_name; }
protected:
EqString m_name;
mutable COSFile m_osFile;
};
//------------------------------------------------------------------------------
// Filesystem base
//------------------------------------------------------------------------------
class CFileSystem : public IFileSystem
{
friend class COSFileStream;
friend class CDPKFileReader;
friend class CZipFileReader;
public:
CFileSystem();
~CFileSystem();
//Initialization of filesystem
bool Init( bool editorMode );
void Shutdown();
//------------------------------------------------------------
// Directory stuff
//------------------------------------------------------------
// something like working directory
void SetBasePath(const char* path);
const char* GetBasePath() const {return m_basePath.ToCString();}
// Returns current game path
const char* GetCurrentGameDirectory() const;
// Returns current engine data path
const char* GetCurrentDataDirectory() const;
// adds directory for file search
void AddSearchPath(const char* pathId, const char* pszDir);
void RemoveSearchPath(const char* pathId);
bool Rename(const char* oldNameOrPath, const char* newNameOrPath, ESearchPath search) const;
//Directory operations
bool DirExist(const char* dirname, ESearchPath search) const;
bool MakeDir(const char* dirname, ESearchPath search ) const;
bool RemoveDir(const char* dirname, ESearchPath search ) const;
//------------------------------------------------------------
// File operations
//------------------------------------------------------------
IFileStreamPtr Open(const char* filename, int openFlags, int searchFlags = -1 );
EqString FindFilePath(const char* filename, int searchFlags = -1) const;
bool FileCopy(const char* filename, const char* dest_file, bool overWrite, ESearchPath search);
bool FileExist(const char* filename, int searchFlags = -1) const;
bool FileRemove(const char* filename, ESearchPath search ) const;
// The next ones are deprecated and will be removed
ubyte* GetFileBuffer(const char* filename, VSSize* filesize = 0, int searchFlags = -1);
VSSize GetFileSize(const char* filename, int searchFlags = -1);
uint32 GetFileCRC32(const char* filename, int searchFlags = -1);
//------------------------------------------------------------
// Packages
//------------------------------------------------------------
bool SetAccessKey(const char* accessKey);
// adds package to file system as another layer, acts just like AddSearchPath
// NOTE: packageName must be root-level package file
bool AddPackage(const char* packageName, ESearchPath type, const char* mountPath = nullptr);
void RemovePackage(const char* packageName);
// opens package for further reading. Does not add package as FS layer
IPackFileReaderPtr OpenPackage(const char* packageName, int searchFlags = -1);
//------------------------------------------------------------
// Locator
//------------------------------------------------------------
// opens directory for search props
const char* FindFirst(const char* wildcard, FSFindData** findData, int searchPaths = -1, int dirIndex = -1);
const char* FindNext(FSFindData* findData) const;
void FindClose(FSFindData* findData);
bool FindIsDirectory(FSFindData* findData) const;
int FindGetDirIndex(FSFindData* findData) const;
//-------------------------
bool IsInitialized() const { return m_isInit; }
protected:
bool InitNextPath(FSFindData* findData) const;
EqStringRef GetAbsolutePath(ESearchPath search, const char* dirOrFileName) const;
EqStringRef GetAbsoluteFullPath(ESearchPath search, const char* dirOrFileName) const;
EqStringRef GetSearchPath(ESearchPath search, int directoryId = -1) const;
using SPWalkFunc = EqFunction<bool(EqStringRef filePath, ESearchPath searchPath, const FSSearchPathInfo& spInfo, int spFlags)>;
bool WalkOverSearchPaths(int searchFlags, const char* fileName, const SPWalkFunc& func) const;
EqString m_basePath; // base prepended path
EqString m_dataDir; // Used to load engine data
EqString m_accessKey;
Array<FSSearchPathInfo> m_directories{ PP_SL }; // mod data, for fall back
Array<IPackFileReaderPtr> m_fsPackages{ PP_SL }; // package serving as FS layers
Array<FSFindData*> m_findDatas{ PP_SL };
bool m_isInit{ false };
};