# AutoPatcher Class Reference
[Autopatcher]

Autopatcher Subsystem. More...

`#include <Autopatcher.h>`

List of all members.

## Public Member Functions

| AutoPatcher ()
| ~AutoPatcher ()
void | Clear (void)
void | SetOrderingStream (int streamIndex)
void | SetNetworkingSystem (RakPeerInterface *localSystem)
void | SetNetworkingSystem (RakClientInterface *localSystem)
void | SetNetworkingSystem (RakServerInterface *localSystem)
void | SetCompressionBoundary (unsigned boundary)
SetFileDownloadableResult | SetFileDownloadable (char *filename, bool checkFileSignature)
bool | UnsetFileDownloadable (char *filename)
unsigned long | GetDownloadStatus (char *filename, unsigned *fileLength, bool *fileDataIsCompressed, unsigned *compressedFileLength)
void | SetDownloadedFileDirectoryPrefix (char *prefix)
void | RequestDownloadableFileList (PlayerID remoteSystem)
void | SendDownloadableFileList (PlayerID remoteSystem)
void | OnAutopatcherFileList (Packet *packet, bool onlyAcceptFilesIfRequested)
void | OnAutopatcherRequestFiles (Packet *packet)
void | OnAutopatcherSetDownloadList (Packet *packet)
bool | OnAutopatcherWriteFile (Packet *packet)

## Static Public Member Functions

static bool | CreateFileSignature (char *filename)
static bool | GenerateSHA1 (char *filename, char SHA1Code[SHA1_LENGTH])
static int | GetFileLength (char *filename)
static bool | WriteFileWithDirectories (const char *path, char *data, unsigned dataLength)

## Protected Attributes

RakPeerInterface * | rakPeerInterface
| One of these 3 must be set in order to send data.
RakClientInterface * | rakClientInterface
| One of these 3 must be set in order to send data.
RakServerInterface * | rakServerInterface
| One of these 3 must be set in order to send data.
char * | downloadPrefix
| The directory to download into basically.
unsigned | compressionBoundary
| Files of length >= this will be compressed.
bool | downloadableFilesRequested
| true if the downloadableFiles have been requested
int | orderingStream
| The ordering stream to use.
BasicDataStructures::List< DownloadableFileDescriptor * > | downloadableFiles
| Directory of files that are downloadable.
BasicDataStructures::List< DownloadableFileDescriptor * > | downloadingFiles
| Directory of files that are downloadable.

## Detailed Description

Autopatcher Subsystem.

This class define the autopatcher facilities. It provide client and server side features to update file of the server side to the client. Missing files are created while modified files are updated. This mecanism use UDP. It might be more efficient to use TCP for large file.

## Constructor & Destructor Documentation

AutoPatcher::AutoPatcher | ( |  | ) |

| Default Constructor

AutoPatcher::~AutoPatcher | ( |  | ) |

| Destructor

## Member Function Documentation

void AutoPatcher::Clear | ( | void |  | ) |

| Frees all downloadable files. Frees the download directory prefix.

bool AutoPatcher::CreateFileSignature | ( | char * | filename | ) | `[static]`

Creates a .sha file signature for a particular file. This is used by SetFileDownloadable with checkFileSignature as true

Parameters:

  | filename | the name of the file

Returns:
  true on success, false on file does not exist.

bool AutoPatcher::GenerateSHA1 | ( | char * | filename,
|  | char | SHA1Code[SHA1_LENGTH]
| ) | `[static]`

unsigned long AutoPatcher::GetDownloadStatus | ( | char * | filename,
|  | unsigned * | fileLength,
|  | bool * | fileDataIsCompressed,
|  | unsigned * | compressedFileLength
| ) |

Returns how many files are still in the download list. Requires a previous call to OnAutopatcherFileList If returns >=1 filename and fileLength will be filled in to match the current file being downloaded A value of 0 for compressedFileLength indicates unknown

Parameters:

  | filename | the file currently downloaded
  | fileLength | the size of the file currently downloaded
  | fileDataIsCompressed | true if the file is compressed
  | compressedFileLength | the size of the compressed file

Returns:
  the number of file still in the download list.

int AutoPatcher::GetFileLength | ( | char * | filename | ) | `[static]`

void AutoPatcher::OnAutopatcherFileList | ( | Packet * | packet,
|  | bool | onlyAcceptFilesIfRequested
| ) |

If the packet identifier is ID_AUTOPATCHER_FILE_LIST, call this function with the packet. It will parse out all the files on the remote system and request to download the ones we don't have or don't match. The remote system should get a packet with ID ID_AUTOPATCHER_REQUEST_FILES for each file requested

We can specify to only accept files if we previously requested them by a call to RequestDownloadableFileList. Set onlyAcceptFilesIfRequested to true to do this

After this function is called you can call GetDownloadStatus(...) To find out which, if any, files are currently downloading

Parameters:

  | packet | the packet with id ID_AUTOPATCHER_FILE_LIST
  | onlyAcceptFilesIfRequested | true implies we previously ask for the requested file list.

void AutoPatcher::OnAutopatcherRequestFiles | ( | Packet * | packet | ) |

If the packet identifier is ID_AUTOPATCHER_REQUEST_FILES, call this function with the packet. Reads the files from disk and sends them to the specified system

Parameters:

  | packet | the packet with id ID_AUTOPATCHER_REQUEST_FILES

void AutoPatcher::OnAutopatcherSetDownloadList | ( | Packet * | packet | ) |

If the packet identifier is ID_AUTOPATCHER_SET_DOWNLOAD_LIST, call this function with the packet. Finalizes the list of files that will be downloaded.

Parameters:

  | packet | the packet with id ID_AUTOPATCHER_SET_DOWNLOAD_LIST

bool AutoPatcher::OnAutopatcherWriteFile | ( | Packet * | packet | ) |

If the packet identifier is ID_AUTOPATCHER_WRITE_FILE, call this function with the packet. Writes a file to disk. There is security to prevent writing files we didn't ask for

Parameters:

  | packet | the packet with id ID_AUTOPATCHER_WRITE_FILE

Returns:
  true on success

void AutoPatcher::RequestDownloadableFileList | ( | PlayerID | remoteSystem | ) |

Requests that the remote system send the directory of files that are downloadable. The remote system should get ID_AUTOPATCHER_REQUEST_FILE_LIST. When it does, it should call SendDownloadableFileList with the playerID of the sender. For the client, you can put UNASSIGNED_PLAYER_ID for remoteSystem

Parameters:

  | remoteSystem | The remoteSystem to ask for its downloadable file list.

void AutoPatcher::SendDownloadableFileList | ( | PlayerID | remoteSystem | ) |

If the packet identifier is ID_AUTOPATCHER_REQUEST_FILE_LIST, call this function with packet->playerID Sends a list of all downloadable files to the remote system The remote system should get a packet with ID ID_AUTOPATCHER_FILE_LIST. When it does, it should call OnAutopatcherFileList with the packet from the network

Parameters:

  | remoteSystem | the player to send the list to.

void AutoPatcher::SetCompressionBoundary | ( | unsigned | boundary | ) |

Set the value at which files larger than this will be compressed. Files smaller than this will not be compressed. Defaults to 1024. Only changes files later passed to SetFileDownloadable, not files already processed

Parameters:

  | boundary | the new boundary for compression activation.

void AutoPatcher::SetDownloadedFileDirectoryPrefix | ( | char * | prefix | ) |

Sets a base directory to look for and put all downloaded files in. For example, "Downloads"

Parameters:

  | prefix | the path to the source or the destination directory.

SetFileDownloadableResult AutoPatcher::SetFileDownloadable | ( | char * | filename,
|  | bool | checkFileSignature
| ) |

Makes a file downloadable Returns checkFileSignature - if true then check the associated .sha1 to make sure it describes our file. checkFileSignature is useful to make sure a file wasn't externally modified by a hacker or a virus

Parameters:

  | filename | the name of the file
  | checkFileSignature | check if a file was externaly modified

Returns:
  true on success, false on can't open file

void AutoPatcher::SetNetworkingSystem | ( | RakServerInterface * | localSystem | ) |

Call this to use RakServerInterface on sends. Mutually exclusive with the other 2 overloads.

Parameters:

  | localSystem | The local communication end point to use

void AutoPatcher::SetNetworkingSystem | ( | RakClientInterface * | localSystem | ) |

Call this to use RakClientInterface on sends. Mutually exclusive with the other 2 overloads.

Parameters:

  | localSystem | The local communication end point to use

void AutoPatcher::SetNetworkingSystem | ( | RakPeerInterface * | localSystem | ) |

Call this to use RakPeer on sends. Mutually exclusive with the other 2 overloads.

Parameters:

  | localSystem | The local communication end point to use

void AutoPatcher::SetOrderingStream | ( | int | streamIndex | ) |

Set the ordering stream to send data on. Defaults to 0. Set this if you use ordered data for your game and don't want to hold up game data because of autopatcher file data

Parameters:

  | streamIndex | The stream to use for autopatcher file data

bool AutoPatcher::UnsetFileDownloadable | ( | char * | filename | ) |

Removes access to a file previously set as downloadable.

Parameters:

  | filename | the name of the file

Returns:
  true on success, false on failure.

bool AutoPatcher::WriteFileWithDirectories | ( | const char * | path,
|  | char * | data,
|  | unsigned | dataLength
| ) | `[static]`

## Member Data Documentation

unsigned AutoPatcher::compressionBoundary `[protected]`

| Files of length >= this will be compressed.

BasicDataStructures::List<DownloadableFileDescriptor*> AutoPatcher::downloadableFiles `[protected]`

| Directory of files that are downloadable.

bool AutoPatcher::downloadableFilesRequested `[protected]`

| true if the downloadableFiles have been requested

BasicDataStructures::List<DownloadableFileDescriptor*> AutoPatcher::downloadingFiles `[protected]`

| Directory of files that are downloadable.

char* AutoPatcher::downloadPrefix `[protected]`

| The directory to download into basically.

int AutoPatcher::orderingStream `[protected]`

| The ordering stream to use.

RakClientInterface* AutoPatcher::rakClientInterface `[protected]`

| One of these 3 must be set in order to send data.

RakPeerInterface* AutoPatcher::rakPeerInterface `[protected]`

| One of these 3 must be set in order to send data.

RakServerInterface* AutoPatcher::rakServerInterface `[protected]`

| One of these 3 must be set in order to send data.

The documentation for this class was generated from the following files:

- Projects/raknet/include/autopatcher/Autopatcher.h
- Projects/raknet/Source/Autopatcher/Autopatcher.cpp