ReplicaNet and RNLobby  1
PatchIndexManager.h
1 /* START_LICENSE_HEADER
2 
3 Copyright (C) 2000 Martin Piper, original design and program code
4 Copyright (C) 2001 Replica Software
5 
6 This program file is copyright (C) Replica Software and can only be used under license.
7 For more information visit: http://www.replicanet.com/
8 Or email: info@replicanet.com
9 
10 END_LICENSE_HEADER */
11 #include "RNPlatform/Inc/MemoryTracking.h"
12 #ifndef _PATCHINDEXMANAGER_H_
13 #define _PATCHINDEXMANAGER_H_
14 #include <string>
15 #include <map>
16 #include "RNLobby/Inc/ScanPath.h"
17 
18 namespace RNReplicaNet
19 {
20 
21 class DynamicMessageHelper;
22 
23 namespace RNLobby
24 {
25 
28 {
29 public:
30  // Used by the stl::map
31  struct ltLowerStr
32  {
33  bool operator() (const std::string& a,const std::string& b) const;
34  };
35 
37  virtual ~PatchIndexManager();
38 
39  struct VersionInfo
40  {
41  VersionInfo() : mUniqueID(0) , mProductVersion(0) , mIsPatch(false) , mNewThisIteration(false) , mDataFileSize(0)
42  {
43  }
44 
45  ScanPath::FileChecksum mChecksum;
46  // This unique ID is used to form the filename of the file that is used to contain the patch/compressed data file this index entry.
47  // This means a minimum unique ID can be used to delete old patch/compressed files from the patch data directory when they are no longer needed.
48  unsigned int mUniqueID;
49  unsigned int mProductVersion;
50  bool mIsPatch;
51  bool mNewThisIteration;
52  unsigned int mDataFileSize; // The size of the patch or the compressed file that may be downloaded
53 
54  void Read(DynamicMessageHelper &in);
55 
56  void Write(DynamicMessageHelper &out) const;
57 
58  void Dump(void) const;
59  };
60 
61  // Paired with file path by the std::map
62  struct EntryInfo
63  {
64  EntryInfo()
65  {
66  mNumMaxVersions = 0;
67  mHasBeenHandled = false;
68  }
69  unsigned int mNumMaxVersions; // Custom limit per file if required
70  VersionInfo mScratch;
71  std::list<VersionInfo> mVersions;
72  bool mHasBeenHandled;
73  };
74 
75  void Clear(void);
76  bool ReadIndex(const char *filename);
77  bool WriteIndex(const char *filename,const bool minimalInfo = false);
78  void Dump(void) const;
79 
80  void AddEntryInfo(std::string filename,const EntryInfo &entryInfo);
81  EntryInfo *GetEntryInfo(std::string filename);
82 
83  unsigned int GetUniqueID(void);
84 
85  void RemoveUnhandled(void);
86  void ClearNewThisIteration(void);
87 
88  void SetProductVersion(unsigned int productVersion)
89  {
90  mProductVersion = productVersion;
91  }
92 
93  unsigned int GetProductVersion(void)
94  {
95  return mProductVersion;
96  }
97 
98  unsigned int GetNumEntries(void)
99  {
100  return (int)mIndex.size();
101  }
102 
103  void BeginIterate(void);
104 
105  EntryInfo *Iterate(std::string &index);
106 
107  static unsigned int GetVersion(void);
108 
109 
111  {
112  ModifiedInfo() : mVisited(false)
113  {
114  }
115 
116  bool mVisited;
117  std::string mTimeStamp;
118  };
119 
120  void ClearModified(void);
121  bool ReadModified(const char *filename);
122  bool WriteModified(const char *filename);
123  bool GetIsModified(const char *filename);
124 
125 private:
126  unsigned int mProductVersion;
127  unsigned int mLastUniqueID;
128 
129  std::map<std::string,EntryInfo,ltLowerStr> mIndex;
130  std::map<std::string,EntryInfo,ltLowerStr>::iterator mSt;
131 
132  std::map<std::string,ModifiedInfo,ltLowerStr> mModified;
133 
134 };
135 
136 } // namespace RNLobby
137 
138 } // namespace RNReplicaNet
139 
140 #endif
Definition: PatchIndexManager.h:62
Handles loading and saving of patch index files with various access methods.
Definition: PatchIndexManager.h:27
Definition: MessageHelper.h:211