diff --git a/CMakeLists.txt b/CMakeLists.txt index f47211e0..9a6a2d58 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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") diff --git a/ISLE/switch/filesys.cpp b/ISLE/switch/filesys.cpp index dd34b69d..69a52146 100644 --- a/ISLE/switch/filesys.cpp +++ b/ISLE/switch/filesys.cpp @@ -1,30 +1,41 @@ #include #include - +#include +#include +#include #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; } \ No newline at end of file diff --git a/ISLE/switch/filesys.h b/ISLE/switch/filesys.h index 51c52e37..33beadd8 100644 --- a/ISLE/switch/filesys.h +++ b/ISLE/switch/filesys.h @@ -4,7 +4,6 @@ #include #define SDL_GetPathInfo NX_GetPathInfo // Override broken SDL_GetPathInfo - bool NX_GetPathInfo(const char *path, SDL_PathInfo *info); #endif // NX_FILESYS_H \ No newline at end of file