SLikeNet 0.1.3

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
FileList.h
Go to the documentation of this file.
1 /*
2 * Original work: Copyright (c) 2014, Oculus VR, Inc.
3 * All rights reserved.
4 *
5 * This source code is licensed under the BSD-style license found in the
6 * RakNet License.txt file in the licenses directory of this source tree. An additional grant
7 * of patent rights can be found in the RakNet Patents.txt file in the same directory.
8 *
9 *
10 * Modified work: Copyright (c) 2016-2018, SLikeSoft UG (haftungsbeschränkt)
11 *
12 * This source code was modified by SLikeSoft. Modifications are licensed under the MIT-style
13 * license found in the license.txt file in the root directory of this source tree.
14 */
15
18
19
20 #include "NativeFeatureIncludes.h"
21 #if _RAKNET_SUPPORT_FileOperations==1
22
23 #ifndef __FILE_LIST
24 #define __FILE_LIST
25
26 #include "Export.h"
27 #include "DS_List.h"
28 #include "memoryoverride.h"
29 #include "types.h"
30 #include "FileListNodeContext.h"
31 #include "string.h"
32
33 namespace SLNet
34 {
35 class BitStream;
36 }
37
38 namespace SLNet
39 {
41 class RakPeerInterface;
42 class FileList;
43
44
46 struct FileListNode
47 {
49 SLNet::RakString filename;
50
52 SLNet::RakString fullPathToFile;
53
55 char *data;
56
58 BitSize_t dataLengthBytes;
59
61 unsigned fileLengthBytes;
62
64 FileListNodeContext context;
65
67 bool isAReference;
68 };
69
71 class RAK_DLL_EXPORT FileListProgress
72 {
73 public:
74 // GetInstance() and DestroyInstance(instance*)
75 STATIC_FACTORY_DECLARATIONS(FileListProgress)
76
77 FileListProgress() {}
78 virtual ~FileListProgress() {}
79
81 virtual void OnAddFilesFromDirectoryStarted(FileList *fileList, char *dir) {
82 (void) fileList;
83 (void) dir;
84 }
85
87 virtual void OnDirectory(FileList *fileList, char *dir, unsigned int directoriesRemaining) {
88 (void) fileList;
89 (void) dir;
90 (void) directoriesRemaining;
91 }
92
94 virtual void OnFile(FileList *fileList, char *dir, char *fileName, unsigned int fileSize) {
95 (void) fileList;
96 (void) dir;
97 (void) fileName;
98 (void) fileSize;
99 }
100
108 virtual void OnFilePush(const char *fileName, unsigned int fileLengthBytes, unsigned int offset, unsigned int bytesBeingSent, bool done, SystemAddress targetSystem, unsigned short setId)
109 {
110 (void) fileName;
111 (void) fileLengthBytes;
112 (void) offset;
113 (void) bytesBeingSent;
114 (void) done;
115 (void) targetSystem;
116 (void) setId;
117 }
118
120 virtual void OnFilePushesComplete( SystemAddress systemAddress, unsigned short setId )
121 {
122 (void) systemAddress;
123 (void) setId;
124 }
125
127 virtual void OnSendAborted( SystemAddress systemAddress )
128 {
129 (void) systemAddress;
130 }
131 };
132
134 class RAK_DLL_EXPORT FLP_Printf : public FileListProgress
135 {
136 public:
137 // GetInstance() and DestroyInstance(instance*)
138 STATIC_FACTORY_DECLARATIONS(FLP_Printf)
139
140 FLP_Printf() {}
141 virtual ~FLP_Printf() {}
142
144 virtual void OnAddFilesFromDirectoryStarted(FileList *fileList, char *dir);
145
147 virtual void OnDirectory(FileList *fileList, char *dir, unsigned int directoriesRemaining);
148
150 virtual void OnFilePushesComplete( SystemAddress systemAddress, unsigned short setID );
151
153 virtual void OnSendAborted( SystemAddress systemAddress );
154 };
155
156 class RAK_DLL_EXPORT FileList
157 {
158 public:
159 // GetInstance() and DestroyInstance(instance*)
160 STATIC_FACTORY_DECLARATIONS(FileList)
161
162 FileList();
163 ~FileList();
171 void AddFilesFromDirectory(const char *applicationDirectory, const char *subDirectory, bool writeHash, bool writeData, bool recursive, FileListNodeContext context);
172
174 void Clear(void);
175
177 void Serialize(SLNet::BitStream *outBitStream);
178
180 bool Deserialize(SLNet::BitStream *inBitStream);
181
189 void ListMissingOrChangedFiles(const char *applicationDirectory, FileList *missingOrChangedFiles, bool alwaysWriteHash, bool neverWriteHash);
190
198 void GetDeltaToCurrent(FileList *input, FileList *output, const char *dirSubset, const char *remoteSubdir);
199
205 void PopulateDataFromDisk(const char *applicationDirectory, bool writeFileData, bool writeFileHash, bool removeUnknownFiles);
206
209 void FlagFilesAsReferences(void);
210
213 void WriteDataToDisk(const char *applicationDirectory);
214
224 void AddFile(const char *filename, const char *fullPathToFile, const char *data, const unsigned dataLength, const unsigned fileLength, FileListNodeContext context, bool isAReference=false, bool takeDataPointer=false);
225
230 void AddFile(const char *filepath, const char *filename, FileListNodeContext context);
231
234 void DeleteFiles(const char *applicationDirectory);
235
238 void AddCallback(FileListProgress *cb);
239
242 void RemoveCallback(FileListProgress *cb);
243
245 void ClearCallbacks(void);
246
249 void GetCallbacks(DataStructures::List<FileListProgress*> &callbacks);
250
251 // Here so you can read it, but don't modify it
252 DataStructures::List<FileListNode> fileList;
253
254 static bool FixEndingSlash(char *str);
255 static bool FixEndingSlash(char *str, size_t strLength);
256 protected:
257 DataStructures::List<FileListProgress*> fileListProgressCallbacks;
258 };
259
260 } // namespace SLNet
261
262 #endif
263
264 #endif // _RAKNET_SUPPORT_FileOperations