AutopatcherClient.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /*
  2. * 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. * LICENSE file in the root directory of this source tree. An additional grant
  7. * of patent rights can be found in the PATENTS file in the same directory.
  8. *
  9. */
  10. /// \file
  11. /// \brief Client plugin for the autopatcher
  12. #ifndef __AUTOPATCHER_CLIENT_H
  13. #define __AUTOPATCHER_CLIENT_H
  14. #include "RakNetTypes.h"
  15. #include "Export.h"
  16. #include "PluginInterface2.h"
  17. #include "PacketPriority.h"
  18. #include "FileList.h"
  19. #include "SimpleMutex.h"
  20. #include "FileListTransferCBInterface.h"
  21. #include "AutopatcherPatchContext.h"
  22. namespace RakNet
  23. {
  24. class RakPeerInterface;
  25. struct Packet;
  26. class FileListTransfer;
  27. class RAK_DLL_EXPORT AutopatcherClientCBInterface : public FileListTransferCBInterface
  28. {
  29. public:
  30. virtual PatchContext ApplyPatchBSDiff(const char *oldFilePath, char **newFileContents, unsigned int *newFileSize, char *patchContents, unsigned int patchSize);
  31. virtual PatchContext ApplyPatchBase(const char *oldFilePath, char **newFileContents, unsigned int *newFileSize, char *patchContents, unsigned int patchSize, uint32_t patchAlgorithm);
  32. };
  33. /// \ingroup Autopatcher
  34. class RAK_DLL_EXPORT AutopatcherClient : public PluginInterface2
  35. {
  36. public:
  37. // Constructor
  38. AutopatcherClient();
  39. // Destructor
  40. ~AutopatcherClient();
  41. /// Are we in the middle of patching?
  42. /// \return True if yes, false otherwise.
  43. bool IsPatching(void) const;
  44. /// What parameters to use for the RakPeerInterface::Send() call when uploading files.
  45. /// \param[in] _priority See RakPeerInterface::Send()
  46. /// \param[in] _orderingChannel See RakPeerInterface::Send()
  47. void SetUploadSendParameters(PacketPriority _priority, char _orderingChannel);
  48. /// This plugin has a dependency on the FileListTransfer plugin, which it uses to actually send the files.
  49. /// So you need an instance of that plugin registered with RakPeerInterface, and a pointer to that interface should be passed here.
  50. /// \param[in] flt A pointer to a registered instance of FileListTransfer
  51. void SetFileListTransferPlugin(FileListTransfer *flt);
  52. /// Patches a certain directory associated with a named application to match the same named application on the patch server
  53. /// \param[in] _applicationName The name of the application
  54. /// \param[in] _applicationDirectory The directory to write the output to.
  55. /// \param[in] lastUpdateDate Returned by time() (seconds since EPOCH) on the server, as well as returned in GetServerDate() after you call PatchApplication successfully. When distributing your application, set to the server time() when the distribution was created. You can pass 0 as well, however this will do a full scan of the entire game so is very slow. See 'Optimizing for large games' in the manual under Help/autopatcher.html
  56. /// \param[in] host The address of the remote system to send the message to.
  57. /// \param[in] onFileCallback Callback to call per-file (optional). When fileIndex+1==setCount in the callback then the download is done
  58. /// \param[in] _restartOutputFilename If it is necessary to restart this application, where to write the restart data to. You can include a path in this filename.
  59. /// \param[in] pathToRestartExe What exe to launch from the AutopatcherClientRestarter . argv[0] will work to relaunch this application.
  60. /// \return true on success, false on failure. On failure, ID_AUTOPATCHER_REPOSITORY_FATAL_ERROR is returned, with the error message written using the stringCompressor class starting after the message id.
  61. bool PatchApplication(const char *_applicationName, const char *_applicationDirectory, double lastUpdateDate, SystemAddress host, AutopatcherClientCBInterface *onFileCallback, const char *restartOutputFilename, const char *pathToRestartExe);
  62. /// After getting ID_AUTOPATCHER_FINISHED or ID_AUTOPATCHER_RESTART_APPLICATION, the server date will be internally recorded. You can send this to PatchApplication::lastUpdateDate to only check for files newer than that date.
  63. double GetServerDate(void) const;
  64. /// Stop processing the current download
  65. /// \note The files in progress will continue to transfer. The only way to stop it is to call CloseConnection(true), then reconnect to the server once you get ID_DISCONNECTION_NOTIFICATION
  66. void CancelDownload(void);
  67. /// Free internal memory.
  68. void Clear(void);
  69. /// \internal For plugin handling
  70. virtual void Update(void);
  71. /// \internal For plugin handling
  72. virtual PluginReceiveResult OnReceive(Packet *packet);
  73. void OnClosedConnection(const SystemAddress &systemAddress, RakNetGUID rakNetGUID, PI2_LostConnectionReason lostConnectionReason );
  74. /// \internal For plugin handling
  75. virtual void OnShutdown(void);
  76. void OnThreadCompletion(void);
  77. protected:
  78. PluginReceiveResult OnCreationList(Packet *packet);
  79. void OnDeletionList(Packet *packet);
  80. PluginReceiveResult OnDownloadFinishedInternal(Packet *packet);
  81. PluginReceiveResult OnDownloadFinished(Packet *packet);
  82. friend class AutopatcherClientCallback;
  83. void CopyAndRestart(const char *filePath);
  84. void Redownload(const char *filePath);
  85. char applicationDirectory[512];
  86. char applicationName[512];
  87. char copyOnRestartOut[512];
  88. char restartExe[512];
  89. double serverDate;
  90. FileListTransfer *fileListTransfer;
  91. PacketPriority priority;
  92. SystemAddress serverId;
  93. SystemIndex serverIdIndex;
  94. char orderingChannel;
  95. unsigned short setId;
  96. AutopatcherClientCBInterface *userCB;
  97. bool patchComplete;
  98. FileList redownloadList, copyAndRestartList;
  99. bool processThreadCompletion;
  100. SimpleMutex processThreadCompletionMutex;
  101. };
  102. } // namespace RakNet
  103. #endif
粤ICP备19079148号