22
#include "SDL_internal.h"
24
#include "../SDL_sysstorage.h"
29
#define STEAM_PROC(ret, func, parms) \
30
typedef ret (*steamfntype_##func) parms;
31
#include "SDL_steamstorage_proc.h"
33
typedef struct STEAM_RemoteStorage
36
#define STEAM_PROC(ret, func, parms) \
37
steamfntype_##func func;
38
#include "SDL_steamstorage_proc.h"
41
static SDL_bool STEAM_CloseStorage(void *userdata)
44
STEAM_RemoteStorage *steam = (STEAM_RemoteStorage*) userdata;
45
void *steamremotestorage = steam->SteamAPI_SteamRemoteStorage_v016();
46
if (steamremotestorage == NULL) {
47
result = SDL_SetError("SteamRemoteStorage unavailable");
48
} else if (!steam->SteamAPI_ISteamRemoteStorage_EndFileWriteBatch(steamremotestorage)) {
49
result = SDL_SetError("SteamRemoteStorage()->EndFileWriteBatch() failed");
51
SDL_UnloadObject(steam->libsteam_api);
56
static SDL_bool STEAM_StorageReady(void *userdata)
61
static SDL_bool STEAM_GetStoragePathInfo(void *userdata, const char *path, SDL_PathInfo *info)
63
STEAM_RemoteStorage *steam = (STEAM_RemoteStorage*) userdata;
64
void *steamremotestorage = steam->SteamAPI_SteamRemoteStorage_v016();
65
if (steamremotestorage == NULL) {
66
return SDL_SetError("SteamRemoteStorage unavailable");
71
info->type = SDL_PATHTYPE_FILE;
72
info->size = steam->SteamAPI_ISteamRemoteStorage_GetFileSize(steamremotestorage, path);
77
static SDL_bool STEAM_ReadStorageFile(void *userdata, const char *path, void *destination, Uint64 length)
80
STEAM_RemoteStorage *steam = (STEAM_RemoteStorage*) userdata;
81
void *steamremotestorage = steam->SteamAPI_SteamRemoteStorage_v016();
82
if (steamremotestorage == NULL) {
83
return SDL_SetError("SteamRemoteStorage unavailable");
85
if (length > SDL_MAX_SINT32) {
86
return SDL_SetError("SteamRemoteStorage only supports INT32_MAX read size");
88
if (steam->SteamAPI_ISteamRemoteStorage_FileRead(steamremotestorage, path, destination, (Sint32) length) == length) {
91
SDL_SetError("SteamAPI_ISteamRemoteStorage_FileRead() failed");
96
static SDL_bool STEAM_WriteStorageFile(void *userdata, const char *path, const void *source, Uint64 length)
99
STEAM_RemoteStorage *steam = (STEAM_RemoteStorage*) userdata;
100
void *steamremotestorage = steam->SteamAPI_SteamRemoteStorage_v016();
101
if (steamremotestorage == NULL) {
102
return SDL_SetError("SteamRemoteStorage unavailable");
104
if (length > SDL_MAX_SINT32) {
105
return SDL_SetError("SteamRemoteStorage only supports INT32_MAX write size");
107
if (steam->SteamAPI_ISteamRemoteStorage_FileWrite(steamremotestorage, path, source, (Sint32) length) == length) {
110
SDL_SetError("SteamAPI_ISteamRemoteStorage_FileRead() failed");
115
static Uint64 STEAM_GetStorageSpaceRemaining(void *userdata)
117
Uint64 total, remaining;
118
STEAM_RemoteStorage *steam = (STEAM_RemoteStorage*) userdata;
119
void *steamremotestorage = steam->SteamAPI_SteamRemoteStorage_v016();
120
if (steamremotestorage == NULL) {
121
SDL_SetError("SteamRemoteStorage unavailable");
124
if (!steam->SteamAPI_ISteamRemoteStorage_GetQuota(steamremotestorage, &total, &remaining)) {
125
SDL_SetError("SteamRemoteStorage()->GetQuota failed");
131
static const SDL_StorageInterface STEAM_user_iface = {
135
STEAM_GetStoragePathInfo,
136
STEAM_ReadStorageFile,
137
STEAM_WriteStorageFile,
142
STEAM_GetStorageSpaceRemaining
145
static SDL_Storage *STEAM_User_Create(const char *org, const char *app, SDL_PropertiesID props)
148
STEAM_RemoteStorage *steam;
149
void *steamremotestorage;
151
steam = (STEAM_RemoteStorage*) SDL_malloc(sizeof(STEAM_RemoteStorage));
156
steam->libsteam_api = SDL_LoadObject(
161
#elif defined(__APPLE__)
167
if (steam->libsteam_api == NULL) {
172
#define STEAM_PROC(ret, func, parms) \
173
steam->func = (steamfntype_##func) SDL_LoadFunction(steam->libsteam_api, #func); \
174
if (steam->func == NULL) { \
175
SDL_SetError("Could not load function " #func); \
178
#include "SDL_steamstorage_proc.h"
180
steamremotestorage = steam->SteamAPI_SteamRemoteStorage_v016();
181
if (steamremotestorage == NULL) {
182
SDL_SetError("SteamRemoteStorage unavailable");
185
if (!steam->SteamAPI_ISteamRemoteStorage_IsCloudEnabledForAccount(steamremotestorage)) {
186
SDL_SetError("Steam cloud is disabled for this user");
189
if (!steam->SteamAPI_ISteamRemoteStorage_IsCloudEnabledForApp(steamremotestorage)) {
190
SDL_SetError("Steam cloud is disabled for this application");
193
if (!steam->SteamAPI_ISteamRemoteStorage_BeginFileWriteBatch(steamremotestorage)) {
194
SDL_SetError("SteamRemoteStorage()->BeginFileWriteBatch failed");
198
result = SDL_OpenStorage(&STEAM_user_iface, steam);
199
if (result == NULL) {
205
SDL_UnloadObject(steam->libsteam_api);
210
UserStorageBootStrap STEAM_userbootstrap = {
212
"SDL Steam user storage driver",