Fix: base GetPathInfo fixup in the SDL implementation, with check for null SDL_PathInfo.

Fix: Disable imgui shell functions.

Todo: Display imgui debug if enabled.
This commit is contained in:
SnepOMatic (Rhew) 2025-11-12 20:18:50 +00:00
parent 63e24a6d38
commit 4a000cc322
3 changed files with 30 additions and 19 deletions

View File

@ -22,6 +22,7 @@ if (NINTENDO_SWITCH)
set(CMAKE_TOOLCHAIN_FILE "${DEVKITPRO}/cmake/Switch.cmake" CACHE PATH "toolchain file")
add_compile_definitions(__SWITCH__)
add_compile_definitions(SDL_VIDEO_DRIVER_SWITCH)
add_compile_definitions(IMGUI_DISABLE_DEFAULT_SHELL_FUNCTIONS)
endif()
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")

View File

@ -1,30 +1,41 @@
#include <cstdio>
#include <sys/stat.h>
#include <dirent.h>
#include <cerrno>
#include <SDL3/SDL.h>
#include "filesys.h"
// Missing from Switch SDL3 implementation
#ifndef S_ISREG
#define S_ISREG(m) (((m) & _S_IFMT) == _S_IFREG)
#endif
// Uses core of SDL's SDL_GetPathInfo but handles null 'info'.
bool NX_GetPathInfo(const char *path, SDL_PathInfo *info)
{
struct stat st_info;
if (stat(path, &st_info) != 0)
{
if (info) info->type = SDL_PATHTYPE_NONE;
return false;
SDL_PathInfo tmp_info;
struct stat statbuf;
const int rc = stat(path, &statbuf);
if (rc < 0) {
return SDL_SetError("Can't stat: %s", strerror(errno));
} else if (S_ISREG(statbuf.st_mode)) {
tmp_info.type = SDL_PATHTYPE_FILE;
tmp_info.size = (Uint64) statbuf.st_size;
} else if (S_ISDIR(statbuf.st_mode)) {
tmp_info.type = SDL_PATHTYPE_DIRECTORY;
tmp_info.size = 0;
} else {
tmp_info.type = SDL_PATHTYPE_OTHER;
tmp_info.size = (Uint64) statbuf.st_size;
}
if (st_info.st_mode & S_IFDIR)
{
if (info)info->type = SDL_PATHTYPE_DIRECTORY;
return true;
}
tmp_info.create_time = (SDL_Time)SDL_SECONDS_TO_NS(statbuf.st_ctime);
tmp_info.modify_time = (SDL_Time)SDL_SECONDS_TO_NS(statbuf.st_mtime);
tmp_info.access_time = (SDL_Time)SDL_SECONDS_TO_NS(statbuf.st_atime);
if (info) info->type = SDL_PATHTYPE_FILE;
if (!info) return true;
auto *fp = fopen(path, "r");
fseek(fp, 0, SEEK_END);
if (info) info->size = ftell(fp);
fclose(fp);
if (info) *info = tmp_info;
return true;
}

View File

@ -4,7 +4,6 @@
#include <SDL3/SDL_filesystem.h>
#define SDL_GetPathInfo NX_GetPathInfo // Override broken SDL_GetPathInfo
bool NX_GetPathInfo(const char *path, SDL_PathInfo *info);
#endif // NX_FILESYS_H