forked from Mdashdotdashn/LittleGPTracker
-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathFileSystem.h
More file actions
117 lines (94 loc) · 2.45 KB
/
FileSystem.h
File metadata and controls
117 lines (94 loc) · 2.45 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
#ifndef _FILESYSTEM_H_
#define _FILESYSTEM_H_
#include "System/System/System.h"
#include "Foundation/T_Factory.h"
#include "Foundation/T_SimpleList.h"
#include "Foundation/Types/Types.h"
#include "System/Errors/Result.h"
#include <stdlib.h>
#include <string.h>
#include <string>
#define MAX_FILENAME_SIZE 256
enum FileType {
FT_UNKNOWN,
FT_FILE,
FT_DIR
} ;
class Path {
public:
Path() ;
Path(const char *path) ;
Path(const std::string &path) ;
Path(const Path &path) ;
virtual ~Path() ;
Path &operator=(const Path &other) ;
Path Descend(const std::string& leaf);
std::string GetPath() const;
std::string GetCanonicalPath() ;
std::string GetName() ;
Path GetParent() ;
int Compare(const Path &other) ;
bool Exists() ;
bool IsFile() ;
bool IsDirectory();
bool Matches(const char *pattern) ;
static void SetAlias(const char *alias,const char *path) ;
protected:
static const char *resolveAlias(const char *alias) ;
void getType() ;
private:
class Alias {
public:
Alias(const char *alias,const char *path) ;
void SetPath(const char* ) ;
const char* GetPath() ;
void SetAliasName(const char *) ;
const char *GetAliasName() ;
private:
std::string path_ ;
std::string alias_ ;
} ;
static T_SimpleList<Alias> aliases_ ;
private:
char *path_ ;
mutable std::string fullPath_ ;
bool gotType_ ;
FileType type_ ;
} ;
class I_File {
public:
virtual ~I_File() {} ;
virtual int Read(void *ptr, int size, int nmemb)=0 ;
virtual int Write(const void *ptr,int size, int nmemb)=0 ;
virtual void Printf(const char *format,...)=0 ;
virtual void Seek(long offset,int whence)=0 ;
virtual long Tell()=0 ;
virtual void Close()=0 ;
} ;
class I_Dir: public T_SimpleList<Path> {
public:
I_Dir(const char *path):T_SimpleList<Path>(true) {
path_=(char *)SYS_MALLOC((int)strlen(path)+1) ;
strcpy(path_,path) ;
} ;
virtual ~I_Dir() { if (path_) free (path_) ; } ;
virtual void GetContent(char *mask)=0 ;
void Compare(Path &p1,Path &p2) ;
protected:
char *path_ ;
} ;
class FileSystem: public T_Factory<FileSystem> {
public:
virtual I_File *Open(const char *path,char *mode)=0 ;
virtual I_Dir *Open(const char *path)=0 ;
virtual Result MakeDir(const char *path)=0 ;
virtual void Delete(const char *)=0 ;
virtual FileType GetFileType(const char *path)=0 ;
} ;
#define FS_FOPEN(a,b) FileSystem::GetInstance()->Open(a,b)
class FileSystemService {
public:
int Copy(const Path &src,const Path &dst);
int Delete(const Path &path);
};
#endif