ReplicaNet and RNLobby  1
ProductPatcher.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 _PRODUCTPATCHER_H_
13 #define _PRODUCTPATCHER_H_
14 #include <string>
15 #include <list>
16 #include <stddef.h>
17 // MPi: TODO: Make cross platform
18 #include <windows.h>
19 #include <wininet.h>
20 #include "RNPlatform/Inc/SysTime.h"
21 #include "RNPlatform/Inc/ThreadClass.h"
22 #include "RNPlatform/Inc/Thread.h"
23 
24 namespace RNReplicaNet
25 {
26 
27 namespace RNLobby
28 {
29 
32 class ProductPatcher : private ThreadClass , private Thread
33 {
34 public:
36  virtual ~ProductPatcher();
37 
38  enum Status
39  {
40  kSuccess = 0,
41  kErrorEncountered,
42  kAborted
43  };
44 
50  bool Start(const char *productPath,const char *patchIndexURL,const char *patchDataURL,const bool multiThread = false,const size_t chunkSize = 1024*1024);
51 
54  bool Stop(void);
55 
58  bool GetCompleted(void);
59 
62  virtual bool CallbackUpdateProgressProduct(const size_t fileIndex,const size_t maxFileIndex);
65  virtual bool CallbackUpdateDownloadPatch(const char *patchingFile,const size_t filePosition,const size_t fileLength);
68  virtual bool CallbackUpdateProgressFile(const char *patchingFile,const size_t filePosition,const size_t fileLength);
69 
71  virtual void CallbackComplete(const Status status);
72 
74  virtual void CallbackFailedToReadFile(const char *file);
75 
79  virtual bool CallbackProcessFile(const char *file);
80 
83  void GetDownloadAttemptsAndFailed(size_t &attempts, size_t &failed) const;
84 
86  void GetDownloadSpeed(size_t &totalBytes, float &overTime) const;
87 
88 protected:
89  void Tidy(void);
90 
91 private:
92 
93  void OpenInternet(void);
94 
95  int ThreadEntry(void);
96  int RealThreadEntry(const char *productPath,const char *patchIndexURL,const char *patchDataURL);
97  std::string GetRealFilePath(const char *url,const char *patchingFile,const char *tempName = 0);
98 
99  std::string mProductPath;
100  std::string mPatchIndexURL;
101  std::string mPatchDataURL;
102 
103  HINTERNET mInternet;
104  void *mTempBuffer;
105  size_t mChunkSize;
106  HINTERNET mFile;
107  FILE *mFP;
108  volatile bool mCallCompleteRequired;
109 
110  bool mAborted;
111 
112  size_t mDownloadAttempts;
113  size_t mDownloadAttemptsFailed;
114 
115  size_t mDownloadedBytes;
116  SysTimeType mDownloadedOverTime;
117 };
118 
119 } // namespace RNLobby
120 
121 } // namespace RNReplicaNet
122 
123 #endif
void GetDownloadSpeed(size_t &totalBytes, float &overTime) const
Gets information that can be used to calculate the download speed.
virtual void CallbackFailedToReadFile(const char *file)
A virtual callback that is triggered when there is an error.
Definition: ProductPatcher.h:32
bool Start(const char *productPath, const char *patchIndexURL, const char *patchDataURL, const bool multiThread=false, const size_t chunkSize=1024 *1024)
virtual void CallbackComplete(const Status status)
A virtual callback that is triggered when the patching is complete.
void GetDownloadAttemptsAndFailed(size_t &attempts, size_t &failed) const
virtual bool CallbackUpdateProgressFile(const char *patchingFile, const size_t filePosition, const size_t fileLength)
virtual bool CallbackUpdateDownloadPatch(const char *patchingFile, const size_t filePosition, const size_t fileLength)
virtual bool CallbackProcessFile(const char *file)
virtual bool CallbackUpdateProgressProduct(const size_t fileIndex, const size_t maxFileIndex)
Definition: ThreadClass.h:96
Definition: Thread.h:29