Linux multi-monitor fullscreen support
[ryzomcore.git] / ryzom / common / src / game_share / bnp_patch.h
blobd6ccff70257654f6b633da9ca4d6a82b7574805d
1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2019 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
6 //
7 // This program is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU Affero General Public License as
9 // published by the Free Software Foundation, either version 3 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU Affero General Public License for more details.
17 // You should have received a copy of the GNU Affero General Public License
18 // along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #ifndef BNP_PATCH_H
21 #define BNP_PATCH_H
23 //-----------------------------------------------------------------------------
24 // includes
25 //-----------------------------------------------------------------------------
27 #include "nel/misc/types_nl.h"
28 #include "nel/misc/common.h"
29 #include "nel/misc/debug.h"
30 #include "nel/misc/sha1.h"
31 #include "persistent_data.h"
34 //-----------------------------------------------------------------------------
35 // class IVersionNumberGenerator
36 //-----------------------------------------------------------------------------
38 class IVersionNumberGenerator
40 public:
41 // reserver the next version number (if we don't already have one)
42 virtual void grabVersionNumber() =0;
44 // get the current reserved version number
45 // return ~0u if none reserved
46 virtual uint32 getPackageVersionNumber() =0;
50 //-----------------------------------------------------------------------------
51 // class CBNPFileVersion
52 //-----------------------------------------------------------------------------
54 class CBNPFileVersion
56 public:
57 DECLARE_PERSISTENCE_METHODS
59 public:
60 // ctor
61 CBNPFileVersion();
63 // setup record contents from a file name and version number
64 // returns false if the file didn't exist
65 bool setup(const std::string &fileName, uint32 versionNumber);
67 void setVersionNumber(uint32 nVersionNumber);
68 void set7ZipFileSize(uint32 n7ZFileSize);
69 void setPatchSize(uint32 nPatchSize);
70 void setTimeStamp(uint32 nTimeStamp);
72 // accessors
73 uint32 getVersionNumber() const;
74 uint32 getTimeStamp() const;
75 uint32 get7ZFileSize() const;
76 uint32 getFileSize() const;
77 uint32 getPatchSize() const;
78 NLMISC::CHashKey getHashKey() const;
80 // == operator
81 bool operator==(const CBNPFileVersion& other) const;
83 // != operator
84 bool operator!=(const CBNPFileVersion& other) const;
86 private:
87 uint32 _VersionNumber;
88 uint32 _FileTime;
89 uint32 _FileSize;
90 uint32 _7ZFileSize;
91 uint32 _PatchSize;
92 std::vector<uint32> _HashKey;
95 //-----------------------------------------------------------------------------
96 // class CBNPFile
97 //-----------------------------------------------------------------------------
99 class CBNPFile
101 public:
102 DECLARE_PERSISTENCE_METHODS
104 public:
105 // ctor
106 CBNPFile();
108 // add a version to the file
109 // returns false if file not found
110 bool addVersion(const std::string& bnpDirectory, const std::string& refDirectory, IVersionNumberGenerator& version);
112 // get the last existing version number less than or equal to parameter in the file's history
113 uint32 getLatestVersionNumber(uint32 max=~0u) const;
115 // get number of versions in the versions vector
116 uint32 versionCount() const;
118 // get the nth version from the version vector
119 const CBNPFileVersion& getVersion(uint32 idx) const;
121 CBNPFileVersion& getVersion(uint32 idx);
123 // _FileName write accessor
124 void setFileName(const std::string& fileName);
126 // _FileName read accessor
127 const std::string& getFileName() const;
129 // _Incrmental flag write accessor
130 void setIncremental(bool value);
132 // _Incrmental flag read accessor
133 bool isIncremental();
135 private:
136 bool _IsIncremental;
137 std::string _FileName;
138 std::vector<CBNPFileVersion> _Versions;
141 //-----------------------------------------------------------------------------
142 // class CBNPFileSet
143 //-----------------------------------------------------------------------------
145 class CBNPFileSet
147 public:
148 DECLARE_PERSISTENCE_METHODS
150 public:
151 // add a version to the file
152 // returns highest version number in files after operation
153 uint32 addVersion(const std::string& bnpDirectory, const std::string& refDirectory, IVersionNumberGenerator& version);
154 // look through the refferenced files for the highest version number
155 uint32 getVersionNumber() const;
157 void clear();
159 uint32 fileCount() const;
160 const CBNPFile& getFile(uint32 idx) const;
161 const CBNPFile* getFileByName(const std::string& fileName) const;
162 CBNPFile& getFile(uint32 idx);
163 CBNPFile* getFileByName(const std::string& fileName);
164 void addFile(const std::string& fileName,bool isIncremental=true);
166 void removeFile(const std::string &filename);
168 private:
169 std::vector<CBNPFile> _Files;
172 //-----------------------------------------------------------------------------
173 // class CBNPCategory
174 //-----------------------------------------------------------------------------
176 class CBNPCategory
178 public:
179 DECLARE_PERSISTENCE_METHODS
181 public:
182 // ctor
183 CBNPCategory();
185 const std::string& getName() const;
186 void setName(const std::string& name);
188 void setOptional(bool value);
189 bool isOptional() const;
191 void setUnpackTo(const std::string &pathName);
192 const std::string &getUnpackTo() const;
194 void setIncremental(bool value);
195 bool isIncremental() const;
197 void setCatRequired(const std::string &cat);
198 const std::string &getCatRequired() const;
200 void setHidden(bool value);
201 bool isHidden() const;
203 uint32 fileCount() const;
204 const std::string& getFile(uint32 idx) const;
205 void addFile(const std::string& fileName);
207 bool hasFile(const std::string &fileName) const;
209 private:
210 std::string _Name;
211 bool _IsOptional;
212 std::string _UnpackTo;
213 bool _IsIncremental;
214 std::string _CatRequired; // Name of the category required
215 bool _Hidden; // If optional but not displayed
216 std::vector<std::string> _Files;
220 //-----------------------------------------------------------------------------
221 // class CBNPCategorySet
222 //-----------------------------------------------------------------------------
224 class CBNPCategorySet
226 public:
227 DECLARE_PERSISTENCE_METHODS
229 public:
230 void clear();
232 // file accessors
233 uint32 fileCount() const;
234 const std::string& getFile(uint32 idx) const;
236 // category accessors
237 uint32 categoryCount() const;
238 CBNPCategory& getCategory(uint32 idx);
239 const CBNPCategory& getCategory(uint32 idx) const;
240 void deleteCategory(uint32 index);
242 // check whether a named category exists and add a new one if need be
243 const CBNPCategory* getCategory(const std::string& categoryName) const;
244 CBNPCategory* getCategory(const std::string& categoryName, bool addIfNotExist);
245 void addFile(const std::string& categoryName,const std::string& fileName);
247 // lookup a file and check whether it's flagged as non-incremental
248 bool isFileIncremental(const std::string& fileName) const;
250 const CBNPCategory* getCategoryFromFile(const std::string &fileName) const;
252 private:
253 std::vector<CBNPCategory> _Category;
257 //-----------------------------------------------------------------------------
258 // class CProductDescriptionForClient
259 //-----------------------------------------------------------------------------
260 // This object is created by the patch generator, stored to a bin file, and
261 // used at patch time on the client to identify the required patch set
263 class CProductDescriptionForClient
265 public:
266 DECLARE_PERSISTENCE_METHODS
268 public:
269 void clear();
271 // a few read and write accessors used for getting and setting parts of the complete data set
272 void setCategories(CPersistentDataRecord &pdr);
273 void setFiles(CPersistentDataRecord &pdr);
274 void getCategories(CPersistentDataRecord &pdr);
275 void getFiles(CPersistentDataRecord &pdr);
277 // load from file
278 bool load(const std::string& filePath);
280 const CBNPCategorySet &getCategories() { return _Categories; }
281 const CBNPFileSet &getFiles() { return _Files; }
283 void serial(NLMISC::IStream &f);
285 private:
286 CBNPCategorySet _Categories;
287 CBNPFileSet _Files;
291 //================================================================================================
292 //================================================================================================
293 //================================================================================================
294 //================================================================================================
296 //#if 0
298 ////-----------------------------------------------------------------------------
299 //// class CBNPPatchDescription
300 ////-----------------------------------------------------------------------------
301 //// a little object used to describe patches in CBNPUnpatcher class
303 //class CBNPPatchDescription
305 //public:
306 // // ctor
307 // CBNPPatchDescription(const std::string& targetFileName,uint32 version,uint32 size,bool requiresDownload);
309 // // read accessors
310 // const std::string& getTargetFileName() const { return _TargetFileName; }
311 // const std::string& getRefFileName() const { return _TargetFileName; }
312 // uint32 getVersion() const { return _Version; }
313 // uint32 getSize() const { return _Size; }
314 // bool getRequiresDownload() const { return _RequiresDownload; }
316 // // accessors for the patcher
317 // std::string getPatchFileName() const;
319 //private:
320 // std::string _TargetFileName;
321 // uint32 _Version;
322 // uint32 _Size;
323 // bool _RequiresDownload;
324 //};
327 ////-----------------------------------------------------------------------------
328 //// class CBNPUnpatcher
329 ////-----------------------------------------------------------------------------
330 //// This class, derived from CProductDescriptionForClient is used on the client
331 //// to read and interpret the index file retrieved from the patch server
333 //class CBNPUnpatcher: public CProductDescriptionForClient
335 //public:
336 // //-------------------------------------------------------------------------
337 // // initialisation
339 // // ctor - initialises paths etc
340 // // also call scanForFiles()
341 // CBNPUnpatcher(const std::string& productName,uint32 version,const std::string& appRootDirectory,const std::string& patchDirectory);
343 // // get the version number for this index file (deduced from the highest
344 // // version number found in the file list that it contains) and compare to
345 // // the version number supplied in the ctor
346 // bool isIndexUpToDate();
348 // // get hold of the download record for the index file
349 // CBNPPatchDescription getIndexFileDownloadDescription();
352 // //-------------------------------------------------------------------------
353 // // accessors for directories
355 // std::string getRootDirectory() const;
356 // std::string getDataDirectory() const;
357 // std::string getPatchDirectory() const;
360 // //-------------------------------------------------------------------------
361 // // accessors for retrieving info on required patches
363 // // return true if the installed product is completely up to date (no new patches exist)
364 // bool isUpToDate();
366 // // return true if mandatory patches exist that have not been applied
367 // bool isPatchMandatory();
369 // // return true if there are no mandatory patches but there are optional patches
370 // bool isPatchOptional();
372 // // return true if patches exist that have not been applied for the
373 // // optional categories that have been flagged as selected
374 // bool isPatchRequired();
376 // // return true if it's necessary to download patches for the selected options
377 // bool isDownloadRequired();
379 // // return true if it's necessary to download the next patch that needs to be applied (in order)
380 // bool isNextPatchDownloadRequired();
383 // //-------------------------------------------------------------------------
384 // // crunching routines
386 // // scan the directories for files - identifies the set of required patches
387 // // and also the set of these patches that is missing from the patch directory
388 // void scanForFiles();
390 // // apply the mandatory and selected optional patches
391 // // nlerror if isDownloadRequired() is not false
392 // void applyPatches();
394 // // apply the next patch (in order)
395 // // nlerror if isNextPatchDownloadRequired() is not false
396 // void applyNextPatch();
399 // //-------------------------------------------------------------------------
400 // // managing the set of selected optional patch categories
402 // // get the names of all optional categories
403 // void getAllOptionalCategories(std::vector<std::string>& result);
405 // // get the names of the optional categories that require patching
406 // void getPatchableOptionalCategories(std::vector<std::string>& result);
408 // // select or unselect an optional package
409 // void setOptionalCategorySelectFlag(const std::string& categoryName, bool value);
411 // // select or unselect all optional packages
412 // void setAllOptionalCategorySelectFlags(bool value);
415 // //-------------------------------------------------------------------------
416 // // getting lists of applicable patches
418 // // get the ordered list of mandatory + optional patches that need to be applied to update selected packages
419 // void getSelectedPatches(std::vector<CBNPPatchDescription>& result);
421 // // get the ordered list of optional patches that need to be applied to update selected packages
422 // void getSelectedOptionalPatches(std::vector<CBNPPatchDescription>& result);
424 // // get the ordered list of patches that need to be applied for a minimum update
425 // void getMandatoryPatches(std::vector<CBNPPatchDescription>& result);
427 // // get an ordered list of the patches that need to be applied for a full update
428 // void getAllPatches(std::vector<CBNPPatchDescription>& result);
430 // // get the name of the next patch that needs to be applied (for progress display)
431 // const std::string& getNextPatchName();
433 // // get the patch description for the next patch to apply
434 // CBNPPatchDescription getNextPatch();
436 // // get the list of patches required for selected options that are not present in the local patch directory
437 // void getSelectedDownloadPatches(std::vector<CBNPPatchDescription>& result);
439 // // get the list of all patches that are not present in the local patch directory
440 // void getAllDownloadPatches(std::vector<CBNPPatchDescription>& result);
443 //private:
445 // //-------------------------------------------------------------------------
446 // // private utility routines
448 // // workhorse routine used by isPatchMandatory(), isPatchOptional() & isPatchRequired()
449 // bool _isPatch(bool isBySelectionFlag,bool isOptionalFlag=false);
452 // //-------------------------------------------------------------------------
453 // // private data
455 // std::string _AppRootDirectory;
456 // std::string _PatchDirectory;
457 // std::string _ProductName;
458 // uint32 _Version;
459 // std::set<std::string> _SelectedCategories;
460 //};
462 //#endif
464 #endif