AutopatcherMySQLRepository.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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 An implementation of the AutopatcherRepositoryInterface to use MySQL to store the relevant data
  12. ///
  13. #ifndef __MYSQL_REPOSITORY_H
  14. #define __MYSQL_REPOSITORY_H
  15. #include "AutopatcherRepositoryInterface.h"
  16. #include "MySQLInterface.h"
  17. #include "Export.h"
  18. namespace RakNet
  19. {
  20. class FileListProgress;
  21. /// \ingroup Autopatcher
  22. /// An implementation of the AutopatcherRepositoryInterface to use MySQL to store the relevant data
  23. class RAK_DLL_EXPORT AutopatcherMySQLRepository : public AutopatcherRepositoryInterface, public MySQLInterface
  24. {
  25. public:
  26. AutopatcherMySQLRepository();
  27. ~AutopatcherMySQLRepository();
  28. /// Create the tables used by the autopatcher, for all applications. Call this first.
  29. /// \return True on success, false on failure.
  30. bool CreateAutopatcherTables(void);
  31. /// Destroy the tables used by the autopatcher. Don't call this unless you don't want to use the autopatcher anymore, or are testing.
  32. /// \return True on success, false on failure.
  33. bool DestroyAutopatcherTables(void);
  34. /// Add an application for use by files. Call this second.
  35. /// \param[in] applicationName A null terminated string.
  36. /// \param[in] userName Stored in the database, but otherwise unused. Useful to track who added this application.
  37. /// \return True on success, false on failure.
  38. bool AddApplication(const char *applicationName, const char *userName);
  39. /// Remove an application and files used by that application.
  40. /// \param[in] applicationName A null terminated string previously passed to AddApplication
  41. /// \return True on success, false on failure.
  42. bool RemoveApplication(const char *applicationName);
  43. /// Update all the files for an application to match what is at the specified directory. Call this third.
  44. /// Be careful not to call this with the wrong directory.
  45. /// This is implemented in a Begin and Rollback block so you won't a messed up database from get partial updates.
  46. /// \param[in] applicationName A null terminated string previously passed to AddApplication
  47. /// \param[in] applicationDirectory The base directory of your application. All files in this directory and subdirectories are added.
  48. /// \param[in] userName Stored in the database, but otherwise unused. Useful to track who added this revision
  49. /// \param[in] cb Callback to get progress updates. Pass 0 to not use.
  50. /// \return True on success, false on failure.
  51. bool UpdateApplicationFiles(const char *applicationName, const char *applicationDirectory, const char *userName, FileListProgress *cb);
  52. /// Get list of files added and deleted since a certain date. This is used by AutopatcherServer and not usually explicitly called.
  53. /// \param[in] applicationName A null terminated string previously passed to AddApplication
  54. /// \param[out] addedFiles A list of the current versions of filenames with SHA1_LENGTH byte hashes as their data that were created after \a sinceData
  55. /// \param[out] deletedFiles A list of the current versions of filenames that were deleted after \a sinceData
  56. /// \param[in] An input date, in the string format of a timestamp.
  57. /// \return True on success, false on failure.
  58. virtual bool GetChangelistSinceDate(const char *applicationName, FileList *addedOrModifiedFilesWithHashData, FileList *deletedFiles, double sinceDate);
  59. /// Get patches (or files) for every file in input, assuming that input has a hash for each of those files. This is used by AutopatcherServer and not usually explicitly called.
  60. /// \param[in] applicationName A null terminated string previously passed to AddApplication
  61. /// \param[in] input A list of files with hashes to get from the database. If this hash exists, a patch to the current version is returned if this file is not the current version. Otherwise the current version is returned.
  62. /// \param[out] patchList A list of files with either the filedata or the patch. This is a subset of \a input. The context data for each file will be either PC_WRITE_FILE (to just write the file) or PC_HASH_WITH_PATCH (to patch). If PC_HASH_WITH_PATCH, then the file contains a SHA1_LENGTH byte patch followed by the hash. The datalength is patchlength + SHA1_LENGTH
  63. /// \return 1 on success, 0 on database failure, -1 on tried to download original unmodified file
  64. virtual int GetPatches(const char *applicationName, FileList *input, bool allowDownloadOfOriginalUnmodifiedFiles, FileList *patchList);
  65. // Not yet implemented
  66. virtual bool GetMostRecentChangelistWithPatches(RakNet::RakString &applicationName, FileList *patchedFiles, FileList *addedFiles, FileList *addedOrModifiedFileHashes, FileList *deletedFiles, double *priorRowPatchTime, double *mostRecentRowPatchTime);
  67. /// If any of the above functions fail, the error string is stored internally. Call this to get it.
  68. virtual const char *GetLastError(void) const;
  69. /// Read part of a file into \a destination
  70. /// Return the number of bytes written. Return 0 when file is done.
  71. /// \param[in] filename Filename to read
  72. /// \param[in] startReadBytes What offset from the start of the file to read from
  73. /// \param[in] numBytesToRead How many bytes to read. This is also how many bytes have been allocated to preallocatedDestination
  74. /// \param[out] preallocatedDestination Write your data here
  75. /// \return The number of bytes read, or 0 if none
  76. virtual unsigned int GetFilePart( const char *filename, unsigned int startReadBytes, unsigned int numBytesToRead, void *preallocatedDestination, FileListNodeContext context);
  77. /// \return Passed to FileListTransfer::Send() as the _chunkSize parameter.
  78. virtual const int GetIncrementalReadChunkSize(void) const;
  79. st_mysql *filePartConnection;
  80. SimpleMutex filePartConnectionMutex;
  81. };
  82. } // namespace RakNet
  83. #endif
粤ICP备19079148号