update SDL3 from 3.2.20 to 3.4.2
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2026 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
@@ -49,12 +49,12 @@ struct SDL_Storage
|
||||
};
|
||||
|
||||
#define CHECK_STORAGE_MAGIC() \
|
||||
if (!storage) { \
|
||||
CHECK_PARAM(!storage) { \
|
||||
return SDL_SetError("Invalid storage container"); \
|
||||
}
|
||||
|
||||
#define CHECK_STORAGE_MAGIC_RET(result) \
|
||||
if (!storage) { \
|
||||
CHECK_PARAM(!storage) { \
|
||||
SDL_SetError("Invalid storage container"); \
|
||||
return result; \
|
||||
}
|
||||
@@ -118,7 +118,9 @@ SDL_Storage *SDL_OpenTitleStorage(const char *override, SDL_PropertiesID props)
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!storage) {
|
||||
if (storage) {
|
||||
SDL_DebugLogBackend("title_storage", titlebootstrap[i]->name);
|
||||
} else {
|
||||
if (driver_name) {
|
||||
SDL_SetError("%s not available", driver_name);
|
||||
} else {
|
||||
@@ -160,7 +162,9 @@ SDL_Storage *SDL_OpenUserStorage(const char *org, const char *app, SDL_Propertie
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!storage) {
|
||||
if (storage) {
|
||||
SDL_DebugLogBackend("user_storage", userbootstrap[i]->name);
|
||||
} else {
|
||||
if (driver_name) {
|
||||
SDL_SetError("%s not available", driver_name);
|
||||
} else {
|
||||
@@ -179,11 +183,11 @@ SDL_Storage *SDL_OpenStorage(const SDL_StorageInterface *iface, void *userdata)
|
||||
{
|
||||
SDL_Storage *storage;
|
||||
|
||||
if (!iface) {
|
||||
CHECK_PARAM(!iface) {
|
||||
SDL_InvalidParamError("iface");
|
||||
return NULL;
|
||||
}
|
||||
if (iface->version < sizeof(*iface)) {
|
||||
CHECK_PARAM(iface->version < sizeof(*iface)) {
|
||||
// Update this to handle older versions of this interface
|
||||
SDL_SetError("Invalid interface, should be initialized with SDL_INIT_INTERFACE()");
|
||||
return NULL;
|
||||
@@ -241,11 +245,17 @@ bool SDL_ReadStorageFile(SDL_Storage *storage, const char *path, void *destinati
|
||||
{
|
||||
CHECK_STORAGE_MAGIC()
|
||||
|
||||
if (!path) {
|
||||
CHECK_PARAM(!path) {
|
||||
return SDL_InvalidParamError("path");
|
||||
} else if (!ValidateStoragePath(path)) {
|
||||
}
|
||||
CHECK_PARAM(!ValidateStoragePath(path)) {
|
||||
return false;
|
||||
} else if (!storage->iface.read_file) {
|
||||
}
|
||||
CHECK_PARAM(length > 0 && !destination) {
|
||||
return SDL_InvalidParamError("destination");
|
||||
}
|
||||
|
||||
if (!storage->iface.read_file) {
|
||||
return SDL_Unsupported();
|
||||
}
|
||||
|
||||
@@ -256,11 +266,17 @@ bool SDL_WriteStorageFile(SDL_Storage *storage, const char *path, const void *so
|
||||
{
|
||||
CHECK_STORAGE_MAGIC()
|
||||
|
||||
if (!path) {
|
||||
CHECK_PARAM(!path) {
|
||||
return SDL_InvalidParamError("path");
|
||||
} else if (!ValidateStoragePath(path)) {
|
||||
}
|
||||
CHECK_PARAM(!ValidateStoragePath(path)) {
|
||||
return false;
|
||||
} else if (!storage->iface.write_file) {
|
||||
}
|
||||
CHECK_PARAM(length > 0 && !source) {
|
||||
return SDL_InvalidParamError("source");
|
||||
}
|
||||
|
||||
if (!storage->iface.write_file) {
|
||||
return SDL_Unsupported();
|
||||
}
|
||||
|
||||
@@ -271,11 +287,14 @@ bool SDL_CreateStorageDirectory(SDL_Storage *storage, const char *path)
|
||||
{
|
||||
CHECK_STORAGE_MAGIC()
|
||||
|
||||
if (!path) {
|
||||
CHECK_PARAM(!path) {
|
||||
return SDL_InvalidParamError("path");
|
||||
} else if (!ValidateStoragePath(path)) {
|
||||
}
|
||||
CHECK_PARAM(!ValidateStoragePath(path)) {
|
||||
return false;
|
||||
} else if (!storage->iface.mkdir) {
|
||||
}
|
||||
|
||||
if (!storage->iface.mkdir) {
|
||||
return SDL_Unsupported();
|
||||
}
|
||||
|
||||
@@ -303,11 +322,14 @@ bool SDL_RemoveStoragePath(SDL_Storage *storage, const char *path)
|
||||
{
|
||||
CHECK_STORAGE_MAGIC()
|
||||
|
||||
if (!path) {
|
||||
CHECK_PARAM(!path) {
|
||||
return SDL_InvalidParamError("path");
|
||||
} else if (!ValidateStoragePath(path)) {
|
||||
}
|
||||
CHECK_PARAM(!ValidateStoragePath(path)) {
|
||||
return false;
|
||||
} else if (!storage->iface.remove) {
|
||||
}
|
||||
|
||||
if (!storage->iface.remove) {
|
||||
return SDL_Unsupported();
|
||||
}
|
||||
|
||||
@@ -318,15 +340,20 @@ bool SDL_RenameStoragePath(SDL_Storage *storage, const char *oldpath, const char
|
||||
{
|
||||
CHECK_STORAGE_MAGIC()
|
||||
|
||||
if (!oldpath) {
|
||||
CHECK_PARAM(!oldpath) {
|
||||
return SDL_InvalidParamError("oldpath");
|
||||
} else if (!newpath) {
|
||||
}
|
||||
CHECK_PARAM(!newpath) {
|
||||
return SDL_InvalidParamError("newpath");
|
||||
} else if (!ValidateStoragePath(oldpath)) {
|
||||
}
|
||||
|
||||
if (!ValidateStoragePath(oldpath)) {
|
||||
return false;
|
||||
} else if (!ValidateStoragePath(newpath)) {
|
||||
}
|
||||
if (!ValidateStoragePath(newpath)) {
|
||||
return false;
|
||||
} else if (!storage->iface.rename) {
|
||||
}
|
||||
if (!storage->iface.rename) {
|
||||
return SDL_Unsupported();
|
||||
}
|
||||
|
||||
@@ -337,15 +364,20 @@ bool SDL_CopyStorageFile(SDL_Storage *storage, const char *oldpath, const char *
|
||||
{
|
||||
CHECK_STORAGE_MAGIC()
|
||||
|
||||
if (!oldpath) {
|
||||
CHECK_PARAM(!oldpath) {
|
||||
return SDL_InvalidParamError("oldpath");
|
||||
} else if (!newpath) {
|
||||
}
|
||||
CHECK_PARAM(!newpath) {
|
||||
return SDL_InvalidParamError("newpath");
|
||||
} else if (!ValidateStoragePath(oldpath)) {
|
||||
}
|
||||
|
||||
if (!ValidateStoragePath(oldpath)) {
|
||||
return false;
|
||||
} else if (!ValidateStoragePath(newpath)) {
|
||||
}
|
||||
if (!ValidateStoragePath(newpath)) {
|
||||
return false;
|
||||
} else if (!storage->iface.copy) {
|
||||
}
|
||||
if (!storage->iface.copy) {
|
||||
return SDL_Unsupported();
|
||||
}
|
||||
|
||||
@@ -363,11 +395,14 @@ bool SDL_GetStoragePathInfo(SDL_Storage *storage, const char *path, SDL_PathInfo
|
||||
|
||||
CHECK_STORAGE_MAGIC()
|
||||
|
||||
if (!path) {
|
||||
CHECK_PARAM(!path) {
|
||||
return SDL_InvalidParamError("path");
|
||||
} else if (!ValidateStoragePath(path)) {
|
||||
}
|
||||
CHECK_PARAM(!ValidateStoragePath(path)) {
|
||||
return false;
|
||||
} else if (!storage->iface.info) {
|
||||
}
|
||||
|
||||
if (!storage->iface.info) {
|
||||
return SDL_Unsupported();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2026 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
@@ -28,14 +28,14 @@ typedef struct TitleStorageBootStrap
|
||||
{
|
||||
const char *name;
|
||||
const char *desc;
|
||||
SDL_Storage *(*create)(const char*, SDL_PropertiesID);
|
||||
SDL_Storage *(*create)(const char *, SDL_PropertiesID);
|
||||
} TitleStorageBootStrap;
|
||||
|
||||
typedef struct UserStorageBootStrap
|
||||
{
|
||||
const char *name;
|
||||
const char *desc;
|
||||
SDL_Storage *(*create)(const char*, const char*, SDL_PropertiesID);
|
||||
SDL_Storage *(*create)(const char *, const char *, SDL_PropertiesID);
|
||||
} UserStorageBootStrap;
|
||||
|
||||
// Not all of these are available in a given build. Use #ifdefs, etc.
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2026 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
@@ -26,8 +26,19 @@
|
||||
|
||||
static char *GENERIC_INTERNAL_CreateFullPath(const char *base, const char *relative)
|
||||
{
|
||||
const char *rel = relative;
|
||||
|
||||
#ifdef SDL_PLATFORM_ANDROID
|
||||
if (rel) {
|
||||
// Removes any leading slash
|
||||
if (rel[0] == '/' || rel[0] == '\\') {
|
||||
rel += 1;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
char *result = NULL;
|
||||
SDL_asprintf(&result, "%s%s", base ? base : "", relative);
|
||||
SDL_asprintf(&result, "%s%s", base ? base : "", rel ? rel : "");
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -79,7 +90,7 @@ static bool GENERIC_EnumerateStorageDirectory(void *userdata, const char *path,
|
||||
|
||||
char *fullpath = GENERIC_INTERNAL_CreateFullPath((char *)userdata, path);
|
||||
if (fullpath) {
|
||||
wrap_data.base_len = SDL_strlen((char *)userdata);
|
||||
wrap_data.base_len = userdata ? SDL_strlen((char *)userdata) : 0;
|
||||
wrap_data.real_callback = callback;
|
||||
wrap_data.real_userdata = callback_userdata;
|
||||
|
||||
@@ -239,11 +250,16 @@ static SDL_Storage *GENERIC_Title_Create(const char *override, SDL_PropertiesID
|
||||
char *basepath = NULL;
|
||||
|
||||
if (override != NULL) {
|
||||
// make sure override has a path separator at the end. If you're not on Windows and used '\\', that's on you.
|
||||
const size_t slen = SDL_strlen(override);
|
||||
const bool need_sep = (!slen || ((override[slen-1] != '/') && (override[slen-1] != '\\')));
|
||||
if (SDL_asprintf(&basepath, "%s%s", override, need_sep ? "/" : "") == -1) {
|
||||
return NULL;
|
||||
if (slen > 0) {
|
||||
// make sure override has a path separator at the end. If you're not on Windows and used '\\', that's on you.
|
||||
const bool need_sep = ((override[slen - 1] != '/') && (override[slen - 1] != '\\'));
|
||||
if (SDL_asprintf(&basepath, "%s%s", override, need_sep ? "/" : "") == -1) {
|
||||
return NULL;
|
||||
}
|
||||
} else {
|
||||
// override == "" -> empty base (not "/")
|
||||
basepath = SDL_strdup("");
|
||||
}
|
||||
} else {
|
||||
const char *base = SDL_GetBasePath();
|
||||
@@ -320,29 +336,57 @@ static const SDL_StorageInterface GENERIC_file_iface = {
|
||||
SDL_Storage *GENERIC_OpenFileStorage(const char *path)
|
||||
{
|
||||
SDL_Storage *result;
|
||||
size_t len = 0;
|
||||
char *basepath = NULL;
|
||||
char *prepend = NULL;
|
||||
|
||||
if (path) {
|
||||
len += SDL_strlen(path);
|
||||
#ifdef SDL_PLATFORM_ANDROID
|
||||
// Use a base path of "." so the filesystem operations fall back to internal storage and the asset system
|
||||
if (!path || !*path) {
|
||||
path = "./";
|
||||
}
|
||||
if (len > 0) {
|
||||
#ifdef SDL_PLATFORM_WINDOWS
|
||||
const bool appended_separator = (path[len-1] == '/') || (path[len-1] == '\\');
|
||||
#else
|
||||
const bool appended_separator = (path[len-1] == '/');
|
||||
#endif
|
||||
if (appended_separator) {
|
||||
basepath = SDL_strdup(path);
|
||||
if (!basepath) {
|
||||
return NULL;
|
||||
}
|
||||
} else {
|
||||
if (SDL_asprintf(&basepath, "%s/", path) < 0) {
|
||||
return NULL;
|
||||
}
|
||||
#else
|
||||
if (!path || !*path) {
|
||||
#ifdef SDL_PLATFORM_WINDOWS
|
||||
path = "C:/";
|
||||
#else
|
||||
path = "/";
|
||||
#endif
|
||||
}
|
||||
|
||||
bool is_absolute = false;
|
||||
#ifdef SDL_PLATFORM_WINDOWS
|
||||
const char ch = (char) SDL_toupper(path[0]);
|
||||
is_absolute = (ch == '/') || // some sort of absolute Unix-style path.
|
||||
(ch == '\\') || // some sort of absolute Windows-style path.
|
||||
(((ch >= 'A') && (ch <= 'Z')) && (path[1] == ':') && ((path[2] == '\\') || (path[2] == '/'))); // an absolute path with a drive letter.
|
||||
#else
|
||||
is_absolute = (path[0] == '/'); // some sort of absolute Unix-style path.
|
||||
#endif
|
||||
if (!is_absolute) {
|
||||
prepend = SDL_GetCurrentDirectory();
|
||||
if (!prepend) {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
#endif // SDL_PLATFORM_ANDROID
|
||||
|
||||
const size_t len = SDL_strlen(path);
|
||||
const char *appended_separator = "";
|
||||
#ifdef SDL_PLATFORM_WINDOWS
|
||||
if ((path[len-1] != '/') && (path[len-1] != '\\')) {
|
||||
appended_separator = "/";
|
||||
}
|
||||
#else
|
||||
if (path[len-1] != '/') {
|
||||
appended_separator = "/";
|
||||
}
|
||||
#endif
|
||||
const int rc = SDL_asprintf(&basepath, "%s%s%s", prepend ? prepend : "", path, appended_separator);
|
||||
SDL_free(prepend);
|
||||
if (rc < 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
result = SDL_OpenStorage(&GENERIC_file_iface, basepath);
|
||||
if (result == NULL) {
|
||||
SDL_free(basepath);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2026 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
@@ -23,6 +23,23 @@
|
||||
|
||||
#include "../SDL_sysstorage.h"
|
||||
|
||||
#if defined(_WIN64)
|
||||
#define SDL_DRIVER_STEAMAPI_DYNAMIC "steam_api64.dll"
|
||||
#elif defined(_WIN32)
|
||||
#define SDL_DRIVER_STEAMAPI_DYNAMIC "steam_api.dll"
|
||||
#elif defined(__APPLE__)
|
||||
#define SDL_DRIVER_STEAMAPI_DYNAMIC "libsteam_api.dylib"
|
||||
#else
|
||||
#define SDL_DRIVER_STEAMAPI_DYNAMIC "libsteam_api.so"
|
||||
#endif
|
||||
|
||||
SDL_ELF_NOTE_DLOPEN(
|
||||
"storage-steam",
|
||||
"Support for Steam user storage",
|
||||
SDL_ELF_NOTE_DLOPEN_PRIORITY_SUGGESTED,
|
||||
SDL_DRIVER_STEAMAPI_DYNAMIC
|
||||
)
|
||||
|
||||
// !!! FIXME: Async API can use SteamRemoteStorage_ReadFileAsync
|
||||
// !!! FIXME: Async API can use SteamRemoteStorage_WriteFileAsync
|
||||
|
||||
@@ -38,15 +55,20 @@ typedef struct STEAM_RemoteStorage
|
||||
#include "SDL_steamstorage_proc.h"
|
||||
} STEAM_RemoteStorage;
|
||||
|
||||
static SDL_AtomicInt SDL_steam_storage_refcount;
|
||||
|
||||
static bool STEAM_CloseStorage(void *userdata)
|
||||
{
|
||||
bool result = true;
|
||||
STEAM_RemoteStorage *steam = (STEAM_RemoteStorage*) userdata;
|
||||
STEAM_RemoteStorage *steam = (STEAM_RemoteStorage *)userdata;
|
||||
void *steamremotestorage = steam->SteamAPI_SteamRemoteStorage_v016();
|
||||
bool end_batch = SDL_AtomicDecRef(&SDL_steam_storage_refcount);
|
||||
if (steamremotestorage == NULL) {
|
||||
result = SDL_SetError("SteamRemoteStorage unavailable");
|
||||
} else if (!steam->SteamAPI_ISteamRemoteStorage_EndFileWriteBatch(steamremotestorage)) {
|
||||
result = SDL_SetError("SteamRemoteStorage()->EndFileWriteBatch() failed");
|
||||
} else if (end_batch) {
|
||||
if (!steam->SteamAPI_ISteamRemoteStorage_EndFileWriteBatch(steamremotestorage)) {
|
||||
result = SDL_SetError("SteamRemoteStorage()->EndFileWriteBatch() failed");
|
||||
}
|
||||
}
|
||||
SDL_UnloadObject(steam->libsteam_api);
|
||||
SDL_free(steam);
|
||||
@@ -58,18 +80,106 @@ static bool STEAM_StorageReady(void *userdata)
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool STEAM_GetStoragePathInfo(void *userdata, const char *path, SDL_PathInfo *info)
|
||||
static char *GetNormalizedStoragePath(const char *path, bool add_separator)
|
||||
{
|
||||
STEAM_RemoteStorage *steam = (STEAM_RemoteStorage*) userdata;
|
||||
if (SDL_strcmp(path, ".") == 0) {
|
||||
path = "";
|
||||
} else {
|
||||
while (*path == '/') {
|
||||
++path;
|
||||
}
|
||||
}
|
||||
|
||||
size_t pathlen = SDL_strlen(path);
|
||||
while (pathlen > 0 && path[pathlen - 1] == '/') {
|
||||
--pathlen;
|
||||
}
|
||||
|
||||
char *normalized = (char *)SDL_malloc(pathlen + add_separator + 1);
|
||||
if (normalized) {
|
||||
SDL_memcpy(normalized, path, pathlen);
|
||||
if (add_separator) {
|
||||
normalized[pathlen++] = '/';
|
||||
}
|
||||
normalized[pathlen] = '\0';
|
||||
}
|
||||
return normalized;
|
||||
}
|
||||
|
||||
static bool STEAM_EnumerateStorageDirectory(void *userdata, const char *path, SDL_EnumerateDirectoryCallback callback, void *callback_userdata)
|
||||
{
|
||||
bool result = true;
|
||||
STEAM_RemoteStorage *steam = (STEAM_RemoteStorage *)userdata;
|
||||
void *steamremotestorage = steam->SteamAPI_SteamRemoteStorage_v016();
|
||||
if (steamremotestorage == NULL) {
|
||||
return SDL_SetError("SteamRemoteStorage unavailable");
|
||||
}
|
||||
|
||||
char *dirname = GetNormalizedStoragePath(path, true);
|
||||
if (!dirname) {
|
||||
return false;
|
||||
}
|
||||
size_t dirlen = SDL_strlen(dirname);
|
||||
|
||||
bool done = false;
|
||||
Sint32 count = steam->SteamAPI_ISteamRemoteStorage_GetFileCount(steamremotestorage);
|
||||
for (Sint32 i = count; i-- && !done; ) {
|
||||
const char *file = steam->SteamAPI_ISteamRemoteStorage_GetFileNameAndSize(steamremotestorage, i, NULL);
|
||||
if (!file) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const char *fname;
|
||||
if (dirlen > 1) {
|
||||
// Make sure the directory matches
|
||||
if (SDL_strncmp(dirname, file, dirlen) != 0) {
|
||||
continue;
|
||||
}
|
||||
fname = file + dirlen;
|
||||
} else {
|
||||
fname = file;
|
||||
}
|
||||
|
||||
// Make sure this is a file in the current directory
|
||||
if (SDL_strchr(fname, '/') != NULL) {
|
||||
continue;
|
||||
}
|
||||
|
||||
switch (callback(callback_userdata, dirname, fname)) {
|
||||
case SDL_ENUM_SUCCESS:
|
||||
done = true;
|
||||
break;
|
||||
case SDL_ENUM_FAILURE:
|
||||
result = false;
|
||||
done = true;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
SDL_free(dirname);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static bool STEAM_GetStoragePathInfo(void *userdata, const char *path, SDL_PathInfo *info)
|
||||
{
|
||||
STEAM_RemoteStorage *steam = (STEAM_RemoteStorage *)userdata;
|
||||
void *steamremotestorage = steam->SteamAPI_SteamRemoteStorage_v016();
|
||||
if (steamremotestorage == NULL) {
|
||||
return SDL_SetError("SteamRemoteStorage unavailable");
|
||||
}
|
||||
|
||||
if (!steam->SteamAPI_ISteamRemoteStorage_FileExists(steamremotestorage, path)) {
|
||||
return SDL_SetError("Can't stat");
|
||||
}
|
||||
|
||||
if (info) {
|
||||
SDL_zerop(info);
|
||||
info->type = SDL_PATHTYPE_FILE;
|
||||
info->size = steam->SteamAPI_ISteamRemoteStorage_GetFileSize(steamremotestorage, path);
|
||||
Sint64 mtime = steam->SteamAPI_ISteamRemoteStorage_GetFileTimestamp(steamremotestorage, path);
|
||||
info->modify_time = (SDL_Time)SDL_SECONDS_TO_NS(mtime);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -77,7 +187,7 @@ static bool STEAM_GetStoragePathInfo(void *userdata, const char *path, SDL_PathI
|
||||
static bool STEAM_ReadStorageFile(void *userdata, const char *path, void *destination, Uint64 length)
|
||||
{
|
||||
bool result = false;
|
||||
STEAM_RemoteStorage *steam = (STEAM_RemoteStorage*) userdata;
|
||||
STEAM_RemoteStorage *steam = (STEAM_RemoteStorage *)userdata;
|
||||
void *steamremotestorage = steam->SteamAPI_SteamRemoteStorage_v016();
|
||||
if (steamremotestorage == NULL) {
|
||||
return SDL_SetError("SteamRemoteStorage unavailable");
|
||||
@@ -88,7 +198,7 @@ static bool STEAM_ReadStorageFile(void *userdata, const char *path, void *destin
|
||||
if (steam->SteamAPI_ISteamRemoteStorage_FileRead(steamremotestorage, path, destination, (Sint32) length) == length) {
|
||||
result = true;
|
||||
} else {
|
||||
SDL_SetError("SteamAPI_ISteamRemoteStorage_FileRead() failed");
|
||||
SDL_SetError("SteamRemoteStorage()->FileRead() failed");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -96,7 +206,7 @@ static bool STEAM_ReadStorageFile(void *userdata, const char *path, void *destin
|
||||
static bool STEAM_WriteStorageFile(void *userdata, const char *path, const void *source, Uint64 length)
|
||||
{
|
||||
bool result = false;
|
||||
STEAM_RemoteStorage *steam = (STEAM_RemoteStorage*) userdata;
|
||||
STEAM_RemoteStorage *steam = (STEAM_RemoteStorage *)userdata;
|
||||
void *steamremotestorage = steam->SteamAPI_SteamRemoteStorage_v016();
|
||||
if (steamremotestorage == NULL) {
|
||||
return SDL_SetError("SteamRemoteStorage unavailable");
|
||||
@@ -104,25 +214,38 @@ static bool STEAM_WriteStorageFile(void *userdata, const char *path, const void
|
||||
if (length > SDL_MAX_SINT32) {
|
||||
return SDL_SetError("SteamRemoteStorage only supports INT32_MAX write size");
|
||||
}
|
||||
if (steam->SteamAPI_ISteamRemoteStorage_FileWrite(steamremotestorage, path, source, (Sint32) length) == length) {
|
||||
if (steam->SteamAPI_ISteamRemoteStorage_FileWrite(steamremotestorage, path, source, (Sint32)length)) {
|
||||
result = true;
|
||||
} else {
|
||||
SDL_SetError("SteamAPI_ISteamRemoteStorage_FileRead() failed");
|
||||
SDL_SetError("SteamRemoteStorage()->FileWrite() failed");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
static bool STEAM_RemoveStoragePath(void *userdata, const char *path)
|
||||
{
|
||||
STEAM_RemoteStorage *steam = (STEAM_RemoteStorage *)userdata;
|
||||
void *steamremotestorage = steam->SteamAPI_SteamRemoteStorage_v016();
|
||||
if (steamremotestorage == NULL) {
|
||||
return SDL_SetError("SteamRemoteStorage unavailable");
|
||||
}
|
||||
if (!steam->SteamAPI_ISteamRemoteStorage_FileDelete(steamremotestorage, path)) {
|
||||
return SDL_SetError("SteamRemoteStorage()->FileDelete() failed");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static Uint64 STEAM_GetStorageSpaceRemaining(void *userdata)
|
||||
{
|
||||
Uint64 total, remaining;
|
||||
STEAM_RemoteStorage *steam = (STEAM_RemoteStorage*) userdata;
|
||||
STEAM_RemoteStorage *steam = (STEAM_RemoteStorage *)userdata;
|
||||
void *steamremotestorage = steam->SteamAPI_SteamRemoteStorage_v016();
|
||||
if (steamremotestorage == NULL) {
|
||||
SDL_SetError("SteamRemoteStorage unavailable");
|
||||
return 0;
|
||||
}
|
||||
if (!steam->SteamAPI_ISteamRemoteStorage_GetQuota(steamremotestorage, &total, &remaining)) {
|
||||
SDL_SetError("SteamRemoteStorage()->GetQuota failed");
|
||||
SDL_SetError("SteamRemoteStorage()->GetQuota() failed");
|
||||
return 0;
|
||||
}
|
||||
return remaining;
|
||||
@@ -132,12 +255,12 @@ static const SDL_StorageInterface STEAM_user_iface = {
|
||||
sizeof(SDL_StorageInterface),
|
||||
STEAM_CloseStorage,
|
||||
STEAM_StorageReady,
|
||||
NULL, // enumerate
|
||||
STEAM_EnumerateStorageDirectory,
|
||||
STEAM_GetStoragePathInfo,
|
||||
STEAM_ReadStorageFile,
|
||||
STEAM_WriteStorageFile,
|
||||
NULL, // mkdir
|
||||
NULL, // remove
|
||||
STEAM_RemoveStoragePath,
|
||||
NULL, // rename
|
||||
NULL, // copy
|
||||
STEAM_GetStorageSpaceRemaining
|
||||
@@ -149,22 +272,12 @@ static SDL_Storage *STEAM_User_Create(const char *org, const char *app, SDL_Prop
|
||||
STEAM_RemoteStorage *steam;
|
||||
void *steamremotestorage;
|
||||
|
||||
steam = (STEAM_RemoteStorage*) SDL_malloc(sizeof(STEAM_RemoteStorage));
|
||||
steam = (STEAM_RemoteStorage *)SDL_malloc(sizeof(STEAM_RemoteStorage));
|
||||
if (steam == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
steam->libsteam_api = SDL_LoadObject(
|
||||
#if defined(_WIN64)
|
||||
"steam_api64.dll"
|
||||
#elif defined(_WIN32)
|
||||
"steam_api.dll"
|
||||
#elif defined(__APPLE__)
|
||||
"libsteam_api.dylib"
|
||||
#else
|
||||
"libsteam_api.so"
|
||||
#endif
|
||||
);
|
||||
steam->libsteam_api = SDL_LoadObject(SDL_DRIVER_STEAMAPI_DYNAMIC);
|
||||
if (steam->libsteam_api == NULL) {
|
||||
SDL_free(steam);
|
||||
return NULL;
|
||||
@@ -191,14 +304,16 @@ static SDL_Storage *STEAM_User_Create(const char *org, const char *app, SDL_Prop
|
||||
SDL_SetError("Steam cloud is disabled for this application");
|
||||
goto steamfail;
|
||||
}
|
||||
if (!steam->SteamAPI_ISteamRemoteStorage_BeginFileWriteBatch(steamremotestorage)) {
|
||||
SDL_SetError("SteamRemoteStorage()->BeginFileWriteBatch failed");
|
||||
|
||||
result = SDL_OpenStorage(&STEAM_user_iface, steam);
|
||||
if (!result) {
|
||||
goto steamfail;
|
||||
}
|
||||
|
||||
result = SDL_OpenStorage(&STEAM_user_iface, steam);
|
||||
if (result == NULL) {
|
||||
goto steamfail;
|
||||
if (SDL_AtomicIncRef(&SDL_steam_storage_refcount) == 0) {
|
||||
if (!steam->SteamAPI_ISteamRemoteStorage_BeginFileWriteBatch(steamremotestorage)) {
|
||||
// We probably already have a batch in progress (maybe we crashed earlier?)
|
||||
}
|
||||
}
|
||||
return result;
|
||||
|
||||
|
||||
@@ -6,9 +6,15 @@ STEAM_PROC(bool, SteamAPI_ISteamRemoteStorage_IsCloudEnabledForApp, (void*))
|
||||
STEAM_PROC(bool, SteamAPI_ISteamRemoteStorage_BeginFileWriteBatch, (void*))
|
||||
STEAM_PROC(bool, SteamAPI_ISteamRemoteStorage_EndFileWriteBatch, (void*))
|
||||
|
||||
STEAM_PROC(bool, SteamAPI_ISteamRemoteStorage_FileExists, (void*, const char*))
|
||||
STEAM_PROC(Sint32, SteamAPI_ISteamRemoteStorage_GetFileSize, (void*, const char*))
|
||||
STEAM_PROC(Sint64, SteamAPI_ISteamRemoteStorage_GetFileTimestamp, (void*, const char *))
|
||||
STEAM_PROC(Sint32, SteamAPI_ISteamRemoteStorage_FileRead, (void*, const char*, void*, Sint32))
|
||||
STEAM_PROC(Sint32, SteamAPI_ISteamRemoteStorage_FileWrite, (void*, const char*, const void*, Sint32))
|
||||
STEAM_PROC(bool, SteamAPI_ISteamRemoteStorage_FileDelete, (void*, const char*))
|
||||
STEAM_PROC(bool, SteamAPI_ISteamRemoteStorage_GetQuota, (void*, Uint64*, Uint64*))
|
||||
|
||||
STEAM_PROC(Sint32, SteamAPI_ISteamRemoteStorage_GetFileCount, (void*))
|
||||
STEAM_PROC(const char *, SteamAPI_ISteamRemoteStorage_GetFileNameAndSize, (void*, int, Sint32*))
|
||||
|
||||
#undef STEAM_PROC
|
||||
|
||||
Reference in New Issue
Block a user