Go to the documentation of this file.
1 /*
2  * The ManaPlus Client
3  * Copyright (C) 2013-2019 The ManaPlus Developers
4  * Copyright (C) 2019-2021 Andrei Karas
5  *
6  * This file is part of The ManaPlus Client.
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <>.
20  */
22 #ifndef FS_VIRTFS_H
23 #define FS_VIRTFS_H
25 #include "enums/fs/fsentrytype.h"
29 #include "utils/stringvector.h"
31 #include "localconsts.h"
33 namespace VirtFs
34 {
35  struct File;
36  struct FsEntry;
37  struct List;
39  void init(const std::string &restrict name);
40  void updateDirSeparator();
41  const char *getDirSeparator();
42  const char *getBaseDir();
43  const char *getUserDir();
44  bool exists(std::string name);
45  List *enumerateFiles(std::string dir) RETURNS_NONNULL;
46  bool isDirectory(std::string name);
47  bool isSymbolicLink(const std::string &restrict name);
48  void freeList(List *restrict const handle);
49  File *openRead(std::string filename);
50  File *openWrite(std::string filename);
51  File *openAppend(std::string filename);
52  bool setWriteDir(const std::string &restrict newDir);
53  bool mountDir(std::string newDir,
54  const Append append);
55  bool mountDir2(std::string newDir,
56  std::string subDir,
57  const Append append);
58  bool mountDirSilent(std::string newDir,
59  const Append append);
60  bool mountDirSilent2(std::string newDir,
61  std::string subDir,
62  const Append append);
63  bool unmountDir(std::string oldDir);
64  bool unmountDir2(std::string oldDir,
65  std::string subDir);
66  bool unmountDirSilent(std::string oldDir);
67  bool unmountDirSilent2(std::string oldDir,
68  std::string subDir);
69  bool mountZip(std::string newDir,
70  const Append append);
71  bool mountZip2(std::string newDir,
72  std::string subDir,
73  const Append append);
74  bool unmountZip(std::string oldDir);
75  bool unmountZip2(std::string oldDir,
76  std::string subDir);
77  std::string getRealDir(std::string filename);
78  bool mkdir(const std::string &restrict dirName);
79  bool remove(const std::string &restrict filename);
80  bool deinit();
81  void permitLinks(const bool val);
82  int64_t read(File *restrict const handle,
83  void *restrict const buffer,
84  const uint32_t objSize,
85  const uint32_t objCount);
86  int64_t write(File *restrict const file,
87  const void *restrict const buffer,
88  const uint32_t objSize,
89  const uint32_t objCount);
90  int close(File *restrict const file);
91  int64_t fileLength(File *restrict const file);
92  int64_t tell(File *restrict const file);
93  int seek(File *restrict const file,
94  const uint64_t pos);
95  int eof(File *restrict const file);
97  bool mountDirInternal(const std::string &restrict newDir,
98  std::string subDir,
99  const Append append);
100  bool unmountDirInternal(std::string oldDir,
101  std::string subDir);
102  STD_VECTOR<FsEntry*> &getEntries();
103  FsEntry *searchByRootInternal(const std::string &restrict root,
104  const std::string &restrict subDir);
105  FsEntry *searchByTypeInternal(const std::string &restrict root,
106  const FsEntryTypeT type);
107  void addEntry(FsEntry *const entry,
108  const Append append);
109 #ifdef UNITTESTS
110  bool mountDirSilentTest(std::string newDir,
111  const Append append);
112  bool mountDirSilentTest2(std::string newDir,
113  std::string subDir,
114  const Append append);
115 #endif // UNITTESTS
116  const char *loadFile(std::string filename,
117  int &restrict fileSize);
118  void getFiles(std::string dirName,
119  StringVect &list);
120  void getFilesWithDir(std::string dirName,
121  StringVect &list);
122  void getDirs(std::string dirName,
123  StringVect &list);
124 } // namespace VirtFs
126 extern const char *dirSeparator;
128 #endif // FS_VIRTFS_H
bool Append
Definition: append.h:30
const char * dirSeparator
Definition: fs.cpp:43
FsEntryType ::T FsEntryTypeT
Definition: fsentrytype.h:32
#define restrict
Definition: localconsts.h:165
Definition: localconsts.h:167
File * openRead(std::string filename)
Definition: fs.cpp:274
bool deinit()
Definition: fs.cpp:785
void getDirs(std::string dirName, StringVect &list)
Definition: fs.cpp:217
void init(const std::string &name)
Definition: fs.cpp:58
bool mkdir(const std::string &dirname)
Definition: fs.cpp:775
void updateDirSeparator()
Definition: fs.cpp:65
int64_t fileLength(File *const file)
Definition: fs.cpp:837
bool mountDir2(std::string newDir, std::string subDir, const Append append)
Definition: fs.cpp:406
std::string getRealDir(std::string fileName)
Definition: fs.cpp:746
bool remove(const std::string &filename)
Definition: fs.cpp:780
bool unmountDirSilent2(std::string oldDir, std::string subDir)
Definition: fs.cpp:571
int64_t tell(File *const file)
Definition: fs.cpp:842
bool mountDirSilent2(std::string newDir, std::string subDir, const Append append)
Definition: fs.cpp:434
const char * getBaseDir()
Definition: fs.cpp:79
void freeList(List *const handle)
Definition: fs.cpp:269
bool isSymbolicLink(const std::string &name)
Definition: fs.cpp:264
int64_t write(File *const file, const void *const buffer, const uint32_t objSize, const uint32_t objCount)
Definition: fs.cpp:826
bool mountDirInternal(const std::string &newDir, std::string subDir, const Append append)
Definition: fs.cpp:345
bool unmountDirSilent(std::string oldDir)
Definition: fs.cpp:554
int close(File *const file)
Definition: fs.cpp:808
bool mountZip(std::string newDir, const Append append)
Definition: fs.cpp:590
int seek(File *const file, const uint64_t pos)
Definition: fs.cpp:847
FsEntry * searchByTypeInternal(const std::string &root, const FsEntryTypeT type)
Definition: fs.cpp:109
bool unmountZip(std::string oldDir)
Definition: fs.cpp:675
int64_t read(File *const file, void *const buffer, const uint32_t objSize, const uint32_t objCount)
Definition: fs.cpp:815
bool unmountDir2(std::string oldDir, std::string subDir)
Definition: fs.cpp:535
std::vector< FsEntry * > & getEntries()
Definition: fs.cpp:89
bool isDirectory(std::string name)
Definition: fs.cpp:239
void getFilesWithDir(std::string dirName, StringVect &list)
Definition: fs.cpp:194
const char * loadFile(std::string filename, int &fileSize)
Definition: fs.cpp:859
void addEntry(FsEntry *const entry, const Append append)
Definition: fs.cpp:336
void permitLinks(const bool val)
Definition: fs.cpp:803
FsEntry * searchByRootInternal(const std::string &root, const std::string &subDir)
Definition: fs.cpp:94
List * enumerateFiles(std::string dirName)
Definition: fs.cpp:147
bool setWriteDir(const std::string &newDir)
Definition: fs.cpp:331
const char * getUserDir()
Definition: fs.cpp:84
bool mountDir(std::string newDir, const Append append)
Definition: fs.cpp:393
bool mountDirSilent(std::string newDir, const Append append)
Definition: fs.cpp:421
const char * getDirSeparator()
Definition: fs.cpp:74
bool unmountZip2(std::string oldDir, std::string subDir)
Definition: fs.cpp:704
void getFiles(std::string dirName, StringVect &list)
Definition: fs.cpp:172
File * openWrite(std::string filename)
Definition: fs.cpp:293
bool unmountDir(std::string oldDir)
Definition: fs.cpp:518
bool unmountDirInternal(std::string oldDir, std::string subDir)
Definition: fs.cpp:477
File * openAppend(std::string filename)
Definition: fs.cpp:312
bool mountZip2(std::string newDir, std::string subDir, const Append append)
Definition: fs.cpp:626
int eof(File *const file)
Definition: fs.cpp:854
bool exists(std::string name)
Definition: fs.cpp:124
std::vector< std::string > StringVect
Definition: stringvector.h:29