Fixed the directory in the enumeration callback for Steam storage
This is guaranteed to have a path separator at the end
This commit is contained in:
@@ -80,6 +80,32 @@ static bool STEAM_StorageReady(void *userdata)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static char *GetNormalizedStoragePath(const char *path, bool add_separator)
|
||||||
|
{
|
||||||
|
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)
|
static bool STEAM_EnumerateStorageDirectory(void *userdata, const char *path, SDL_EnumerateDirectoryCallback callback, void *callback_userdata)
|
||||||
{
|
{
|
||||||
bool result = true;
|
bool result = true;
|
||||||
@@ -89,19 +115,11 @@ static bool STEAM_EnumerateStorageDirectory(void *userdata, const char *path, SD
|
|||||||
return SDL_SetError("SteamRemoteStorage unavailable");
|
return SDL_SetError("SteamRemoteStorage unavailable");
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *prefix;
|
char *dirname = GetNormalizedStoragePath(path, true);
|
||||||
if (SDL_strcmp(path, ".") == 0) {
|
if (!dirname) {
|
||||||
prefix = "";
|
return false;
|
||||||
} else {
|
|
||||||
prefix = path;
|
|
||||||
while (*prefix == '/') {
|
|
||||||
++prefix;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
size_t prefixlen = SDL_strlen(prefix);
|
|
||||||
while (prefixlen > 0 && prefix[prefixlen - 1] == '/') {
|
|
||||||
--prefixlen;
|
|
||||||
}
|
}
|
||||||
|
size_t dirlen = SDL_strlen(dirname);
|
||||||
|
|
||||||
bool done = false;
|
bool done = false;
|
||||||
Sint32 count = steam->SteamAPI_ISteamRemoteStorage_GetFileCount(steamremotestorage);
|
Sint32 count = steam->SteamAPI_ISteamRemoteStorage_GetFileCount(steamremotestorage);
|
||||||
@@ -112,12 +130,12 @@ static bool STEAM_EnumerateStorageDirectory(void *userdata, const char *path, SD
|
|||||||
}
|
}
|
||||||
|
|
||||||
const char *fname;
|
const char *fname;
|
||||||
if (prefixlen > 0) {
|
if (dirlen > 1) {
|
||||||
// Make sure the prefix matches
|
// Make sure the directory matches
|
||||||
if (SDL_strncmp(prefix, file, prefixlen) != 0 || *(file + prefixlen) != '/') {
|
if (SDL_strncmp(dirname, file, dirlen) != 0) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
fname = file + prefixlen + 1;
|
fname = file + dirlen;
|
||||||
} else {
|
} else {
|
||||||
// Make sure this is a top-level file
|
// Make sure this is a top-level file
|
||||||
if (SDL_strchr(file, '/') != NULL) {
|
if (SDL_strchr(file, '/') != NULL) {
|
||||||
@@ -126,7 +144,7 @@ static bool STEAM_EnumerateStorageDirectory(void *userdata, const char *path, SD
|
|||||||
fname = file;
|
fname = file;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (callback(callback_userdata, path, fname)) {
|
switch (callback(callback_userdata, dirname, fname)) {
|
||||||
case SDL_ENUM_SUCCESS:
|
case SDL_ENUM_SUCCESS:
|
||||||
done = true;
|
done = true;
|
||||||
break;
|
break;
|
||||||
@@ -138,6 +156,8 @@ static bool STEAM_EnumerateStorageDirectory(void *userdata, const char *path, SD
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
SDL_free(dirname);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user