Simple class to send changes between directories. In essence, a simple autopatcher that can be used for transmitting levels, skins, etc. More...
#include <DirectoryDeltaTransfer.h>
Inherits PluginInterface2.
Public Member Functions | |
DirectoryDeltaTransfer () | |
virtual | ~DirectoryDeltaTransfer () |
void | SetFileListTransferPlugin (FileListTransfer *flt) |
This plugin has a dependency on the FileListTransfer plugin, which it uses to actually send the files. | |
void | SetApplicationDirectory (const char *pathToApplication) |
Set the local root directory to base all file uploads and downloads off of. | |
void | SetUploadSendParameters (PacketPriority _priority, char _orderingChannel) |
What parameters to use for the RakPeerInterface::Send() call when uploading files. | |
void | AddUploadsFromSubdirectory (const char *subdir) |
Add all files in the specified subdirectory recursively. | |
unsigned short | DownloadFromSubdirectory (const char *subdir, const char *outputSubdir, bool prependAppDirToOutputSubdir, SystemAddress host, FileListTransferCBInterface *onFileCallback, PacketPriority _priority, char _orderingChannel, FileListProgress *cb) |
Downloads files from the matching parameter subdir in AddUploadsFromSubdirectory. | |
void | ClearUploads (void) |
Clear all allowed uploads previously set with AddUploadsFromSubdirectory. | |
unsigned | GetNumberOfFilesForUpload (void) const |
Returns how many files are available for upload. | |
void | SetCompressOutgoingSends (bool compress) |
Set if we should compress outgoing sends or not. | |
void | SetDownloadRequestIncrementalReadInterface (IncrementalReadInterface *_incrementalReadInterface, unsigned int _chunkSize) |
Normally, if a remote system requests files, those files are all loaded into memory and sent immediately. | |
virtual PluginReceiveResult | OnReceive (Packet *packet) |
Protected Member Functions | |
void | OnDownloadRequest (Packet *packet) |
Protected Attributes | |
char | applicationDirectory [512] |
FileListTransfer * | fileListTransfer |
FileList * | availableUploads |
PacketPriority | priority |
char | orderingChannel |
bool | compressOutgoingSends |
IncrementalReadInterface * | incrementalReadInterface |
unsigned int | chunkSize |
Simple class to send changes between directories. In essence, a simple autopatcher that can be used for transmitting levels, skins, etc.
To use, first set the path to your application. For example "C:/Games/MyRPG/"
To allow other systems to download files, call AddUploadsFromSubdirectory, where the parameter is a path relative
to the path to your application. This includes subdirectories.
For example:
SetApplicationDirectory("C:/Games/MyRPG/");
AddUploadsFromSubdirectory("Mods/Skins/");
would allow downloads from
"C:/Games/MyRPG/Mods/Skins/*.*" as well as "C:/Games/MyRPG/Mods/Skins/Level1/*.*"
It would NOT allow downloads from C:/Games/MyRPG/Levels, nor would it allow downloads from C:/Windows
While pathToApplication can be anything you want, applicationSubdirectory must match either partially or fully between systems.
Definition at line 53 of file DirectoryDeltaTransfer.h.
DirectoryDeltaTransfer::DirectoryDeltaTransfer | ( | ) |
Definition at line 65 of file DirectoryDeltaTransfer.cpp.
DirectoryDeltaTransfer::~DirectoryDeltaTransfer | ( | ) | [virtual] |
void DirectoryDeltaTransfer::AddUploadsFromSubdirectory | ( | const char * | subdir | ) |
Add all files in the specified subdirectory recursively.
subdir is appended to pathToApplication in SetApplicationDirectory(). All files in the resultant directory and subdirectories are then hashed so that users can download them.
[in] | subdir | Concatenated with pathToApplication to form the final path from which to allow uploads. |
Definition at line 104 of file DirectoryDeltaTransfer.cpp.
void DirectoryDeltaTransfer::ClearUploads | ( | void | ) |
Clear all allowed uploads previously set with AddUploadsFromSubdirectory.
Definition at line 154 of file DirectoryDeltaTransfer.cpp.
unsigned short DirectoryDeltaTransfer::DownloadFromSubdirectory | ( | const char * | subdir, | |
const char * | outputSubdir, | |||
bool | prependAppDirToOutputSubdir, | |||
SystemAddress | host, | |||
FileListTransferCBInterface * | onFileCallback, | |||
PacketPriority | _priority, | |||
char | _orderingChannel, | |||
FileListProgress * | cb | |||
) |
Downloads files from the matching parameter subdir in AddUploadsFromSubdirectory.
subdir must contain all starting characters in subdir in AddUploadsFromSubdirectory Therefore, AddUploadsFromSubdirectory("Levels/Level1/"); would allow you to download using DownloadFromSubdirectory("Levels/Level1/Textures/"... but it would NOT allow you to download from DownloadFromSubdirectory("Levels/"... or DownloadFromSubdirectory("Levels/Level2/"...
[in] | subdir | A directory passed to AddUploadsFromSubdirectory on the remote system. The passed dir can be more specific than the remote dir. |
[in] | outputSubdir | The directory to write the output to. Usually this will match subdir but it can be different if you want. |
[in] | prependAppDirToOutputSubdir | True to prepend outputSubdir with pathToApplication when determining the final output path. Usually you want this to be true. |
[in] | host | The address of the remote system to send the message to. |
[in] | onFileCallback | Callback to call per-file (optional). When fileIndex+1==setCount in the callback then the download is done |
[in] | _priority | See RakPeerInterface::Send() |
[in] | _orderingChannel | See RakPeerInterface::Send() |
[in] | cb | Callback to get progress updates. Pass 0 to not use. |
Definition at line 108 of file DirectoryDeltaTransfer.cpp.
unsigned DirectoryDeltaTransfer::GetNumberOfFilesForUpload | ( | void | ) | const |
Returns how many files are available for upload.
Definition at line 199 of file DirectoryDeltaTransfer.cpp.
void DirectoryDeltaTransfer::OnDownloadRequest | ( | Packet * | packet | ) | [protected] |
Definition at line 158 of file DirectoryDeltaTransfer.cpp.
PluginReceiveResult DirectoryDeltaTransfer::OnReceive | ( | Packet * | packet | ) | [virtual] |
OnReceive is called for every packet.
[in] | packet | the packet that is being returned to the user |
Reimplemented from PluginInterface2.
Definition at line 187 of file DirectoryDeltaTransfer.cpp.
void DirectoryDeltaTransfer::SetApplicationDirectory | ( | const char * | pathToApplication | ) |
Set the local root directory to base all file uploads and downloads off of.
[in] | pathToApplication | This path will be prepended to applicationSubdirectory in AddUploadsFromSubdirectory to find the actual path on disk. |
Definition at line 87 of file DirectoryDeltaTransfer.cpp.
void DirectoryDeltaTransfer::SetCompressOutgoingSends | ( | bool | compress | ) |
Set if we should compress outgoing sends or not.
Defaults to false, because this results in a noticeable freeze on large requests. You can set this to true if you only send small files though
[in] | compress | True to compress, false to not. |
Definition at line 203 of file DirectoryDeltaTransfer.cpp.
void DirectoryDeltaTransfer::SetDownloadRequestIncrementalReadInterface | ( | IncrementalReadInterface * | _incrementalReadInterface, | |
unsigned int | _chunkSize | |||
) |
Normally, if a remote system requests files, those files are all loaded into memory and sent immediately.
This function allows the files to be read in incremental chunks, saving memory
[in] | _incrementalReadInterface | If a file in fileList has no data, filePullInterface will be used to read the file in chunks of size chunkSize |
[in] | _chunkSize | How large of a block of a file to send at once |
Definition at line 208 of file DirectoryDeltaTransfer.cpp.
void DirectoryDeltaTransfer::SetFileListTransferPlugin | ( | FileListTransfer * | flt | ) |
This plugin has a dependency on the FileListTransfer plugin, which it uses to actually send the files.
So you need an instance of that plugin registered with RakPeerInterface, and a pointer to that interface should be passed here.
[in] | flt | A pointer to a registered instance of FileListTransfer |
Definition at line 79 of file DirectoryDeltaTransfer.cpp.
void DirectoryDeltaTransfer::SetUploadSendParameters | ( | PacketPriority | _priority, | |
char | _orderingChannel | |||
) |
What parameters to use for the RakPeerInterface::Send() call when uploading files.
[in] | _priority | See RakPeerInterface::Send() |
[in] | _orderingChannel | See RakPeerInterface::Send() |
Definition at line 99 of file DirectoryDeltaTransfer.cpp.
char DirectoryDeltaTransfer::applicationDirectory[512] [protected] |
Definition at line 124 of file DirectoryDeltaTransfer.h.
FileList* DirectoryDeltaTransfer::availableUploads [protected] |
Definition at line 126 of file DirectoryDeltaTransfer.h.
unsigned int DirectoryDeltaTransfer::chunkSize [protected] |
Definition at line 131 of file DirectoryDeltaTransfer.h.
bool DirectoryDeltaTransfer::compressOutgoingSends [protected] |
Definition at line 129 of file DirectoryDeltaTransfer.h.
FileListTransfer* DirectoryDeltaTransfer::fileListTransfer [protected] |
Definition at line 125 of file DirectoryDeltaTransfer.h.
Definition at line 130 of file DirectoryDeltaTransfer.h.
char DirectoryDeltaTransfer::orderingChannel [protected] |
Definition at line 128 of file DirectoryDeltaTransfer.h.
PacketPriority DirectoryDeltaTransfer::priority [protected] |
Definition at line 127 of file DirectoryDeltaTransfer.h.