Please note that implementing storage is not necessary if you only want to use cloud saves. Cloud saves can be handled by the GOG GALAXY client without the need of adding any special code to your game. The Storage interface of the GOG GALAXY SDK was created to allow users to share files with others.
This class allows you to upload and download files from the cloud storage in GOG GALAXY. Although it’s implemented with no particular purpose in the game, it can be used to experiment with the interface using the methods we created available in the Debug Menu.
Class Initialization and Termination¶
The Storage class is initialized, when the user successfully logs in (in the AuthenticationListener.OnAuthSuccess() callback of the GalaxyManager class). When enabled, the Storage class initializes three listeners:
- FileShareListener, which waits for the result of sharing a file, and adds the
fileNamekey with the
sharedFileIDvalue to the current user data.
- SharedFileDownloadListener – a listener for the
DownloadSharedFileBySharedFileIDmethod for handling downloading of files from the local storage.
- SpecificUserDataListener is used to catch a callback for the
RequestUserDatamethod called inside of the
DownloadSharedFileByUserIdAndFileNamemethod in order to retrieve a
sharedFileIDof a file shared by other user.
All listeners are disposed of when the class is disabled.
Definitions of Listeners¶
When a file was successfully shared, the callback comes to
FileShareListener.OnFileShareSuccess(), where we can get the
sharedFileID parameter provided with the callback (
sharedFileID is necessary for sharing a file with other users), and then we store this value in the user data.
This listener callback will run when a file was downloaded successfully or if it failed in the process. The downloaded file is held in memory and we use this listener to read the data and write it in the local storage. The file will be written to a folder inside of the local storage named either 0, if the file was downloaded from an unspecified user using the
DownloadSharedFileBySharedFileID method, or the owner’s Galaxy ID, if the file was downloaded from a specific user using the
SpecificUserDataListener is a specific listener, which means it will only work for the methods which explicitly register to this listener. This listener is used in pair with the
DownloadSharedFileByUserIdAndFileName method in order to let the user download a file from another user by using theirs GalaxyID and the name of the file.