diff --git a/Common/ConsoleListener.cpp b/Common/ConsoleListener.cpp index 6b50ae0742..2d2851d905 100644 --- a/Common/ConsoleListener.cpp +++ b/Common/ConsoleListener.cpp @@ -64,11 +64,7 @@ ConsoleListener::ConsoleListener() : bHidden(true) logPending = new char[LOG_PENDING_MAX]; } ++refCount; -#elif defined(ANDROID) - bUseColor = false; -#elif defined(IOS) - bUseColor = false; -#elif PPSSPP_PLATFORM(UWP) || PPSSPP_PLATFORM(SWITCH) +#elif PPSSPP_PLATFORM(ANDROID) || PPSSPP_PLATFORM(IOS) || PPSSPP_PLATFORM(UWP) || PPSSPP_PLATFORM(SWITCH) bUseColor = false; #elif defined(_MSC_VER) bUseColor = false; diff --git a/Core/FileLoaders/DiskCachingFileLoader.cpp b/Core/FileLoaders/DiskCachingFileLoader.cpp index bb48ad3dbf..62f733dc89 100644 --- a/Core/FileLoaders/DiskCachingFileLoader.cpp +++ b/Core/FileLoaders/DiskCachingFileLoader.cpp @@ -21,6 +21,7 @@ #include #include +#include "ppsspp_config.h" #include "file/file_util.h" #include "file/free.h" #include "util/text/utf8.h" @@ -29,6 +30,11 @@ #include "Core/FileLoaders/DiskCachingFileLoader.h" #include "Core/System.h" +#if PPSSPP_PLATFORM(SWITCH) +// Far from optimal, but I guess it works... +#define fseeko fseek +#endif + static const char *CACHEFILE_MAGIC = "ppssppDC"; static const s64 SAFETY_FREE_DISK_SPACE = 768 * 1024 * 1024; // 768 MB // Aim to allow this many files cached at once. diff --git a/Core/FileLoaders/LocalFileLoader.cpp b/Core/FileLoaders/LocalFileLoader.cpp index c373e4dac6..8e757b3315 100644 --- a/Core/FileLoaders/LocalFileLoader.cpp +++ b/Core/FileLoaders/LocalFileLoader.cpp @@ -117,7 +117,12 @@ std::string LocalFileLoader::Path() const { } size_t LocalFileLoader::ReadAt(s64 absolutePos, size_t bytes, size_t count, void *data, Flags flags) { -#if PPSSPP_PLATFORM(ANDROID) +#if PPSSPP_PLATFORM(SWITCH) + // Toolchain has no fancy IO API. We must lock. + std::lock_guard guard(readLock_); + lseek(fd_, absolutePos, SEEK_SET); + return read(fd_, data, bytes * count) / bytes; +#elif PPSSPP_PLATFORM(ANDROID) // pread64 doesn't appear to actually be 64-bit safe, though such ISOs are uncommon. See #10862. if (absolutePos <= 0x7FFFFFFF) { #if defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS < 64 diff --git a/Core/FileSystems/DirectoryFileSystem.cpp b/Core/FileSystems/DirectoryFileSystem.cpp index 972c1c5d03..42f3bb6212 100644 --- a/Core/FileSystems/DirectoryFileSystem.cpp +++ b/Core/FileSystems/DirectoryFileSystem.cpp @@ -442,7 +442,8 @@ void DirectoryFileHandle::Close() if (SetEndOfFile(hFile) == 0) { ERROR_LOG_REPORT(FILESYS, "Failed to truncate file."); } -#else +#elif !PPSSPP_PLATFORM(SWITCH) + // Note: it's not great that Switch cannot truncate appropriately... if (ftruncate(hFile, (off_t)needsTrunc_) != 0) { ERROR_LOG_REPORT(FILESYS, "Failed to truncate file."); } diff --git a/Core/System.cpp b/Core/System.cpp index 5ccd0ddd55..e4a07d4f07 100644 --- a/Core/System.cpp +++ b/Core/System.cpp @@ -609,7 +609,7 @@ void InitSysDirectories() { INFO_LOG(COMMON, "Memstick directory not present, creating at '%s'", g_Config.memStickDirectory.c_str()); } - const std::string testFile = g_Config.memStickDirectory + "/_writable_test.$$$"; + const std::string testFile = g_Config.memStickDirectory + "_writable_test.$$$"; // If any directory is read-only, fall back to the Documents directory. // We're screwed anyway if we can't write to Documents, or can't detect it. diff --git a/Core/Util/GameManager.cpp b/Core/Util/GameManager.cpp index 1e23a5fa79..da0617dd43 100644 --- a/Core/Util/GameManager.cpp +++ b/Core/Util/GameManager.cpp @@ -55,7 +55,7 @@ std::string GameManager::GetTempFilename() const { GetTempFileName(tempPath, L"PSP", 1, buffer); return ConvertWStringToUTF8(buffer); #else - return g_Config.memStickDirectory + "/ppsspp.dl"; + return g_Config.memStickDirectory + "ppsspp.dl"; #endif } diff --git a/SDL/SDLMain.cpp b/SDL/SDLMain.cpp index 548d588ea5..64b74539dd 100644 --- a/SDL/SDLMain.cpp +++ b/SDL/SDLMain.cpp @@ -5,6 +5,7 @@ #include #include +#include "ppsspp_config.h" #include "SDL.h" #include "SDL/SDLJoystick.h" SDLJoystick *joystick = NULL; @@ -196,7 +197,11 @@ void OpenDirectory(const char *path) { } void LaunchBrowser(const char *url) { -#if defined(MOBILE_DEVICE) +#if PPSSPP_PLATFORM(SWITCH) + WebWifiConfig conf; + webWifiCreate(&conf, NULL, url, 0, 0); + webWifiShow(&conf, NULL); +#elif defined(MOBILE_DEVICE) ILOG("Would have gone to %s but LaunchBrowser is not implemented on this platform", url); #elif defined(_WIN32) std::wstring wurl = ConvertUTF8ToWString(url); @@ -214,7 +219,11 @@ void LaunchBrowser(const char *url) { } void LaunchMarket(const char *url) { -#if defined(MOBILE_DEVICE) +#if PPSSPP_PLATFORM(SWITCH) + WebWifiConfig conf; + webWifiCreate(&conf, NULL, url, 0, 0); + webWifiShow(&conf, NULL); +#elif defined(MOBILE_DEVICE) ILOG("Would have gone to %s but LaunchMarket is not implemented on this platform", url); #elif defined(_WIN32) std::wstring wurl = ConvertUTF8ToWString(url); @@ -258,6 +267,8 @@ std::string System_GetProperty(SystemProperty prop) { return "SDL:Linux"; #elif __APPLE__ return "SDL:macOS"; +#elif PPSSPP_PLATFORM(SWITCH) + return "SDL:Horizon"; #else return "SDL:"; #endif diff --git a/UI/MainScreen.cpp b/UI/MainScreen.cpp index 57c842e82d..b2064b5ef3 100644 --- a/UI/MainScreen.cpp +++ b/UI/MainScreen.cpp @@ -518,7 +518,7 @@ UI::EventReturn GameBrowser::LastClick(UI::EventParams &e) { } UI::EventReturn GameBrowser::HomeClick(UI::EventParams &e) { -#ifdef __ANDROID__ +#if PPSSPP_PLATFORM(ANDROID) || PPSSPP_PLATFORM(SWITCH) SetPath(g_Config.memStickDirectory); #elif defined(USING_QT_UI) || defined(USING_WIN_UI) if (System_GetPropertyBool(SYSPROP_HAS_FILE_BROWSER)) { diff --git a/UI/NativeApp.cpp b/UI/NativeApp.cpp index c37968bb7d..1df859aa0e 100644 --- a/UI/NativeApp.cpp +++ b/UI/NativeApp.cpp @@ -459,7 +459,7 @@ void NativeInit(int argc, const char *argv[], const char *savegame_dir, const ch VFSRegister("", new DirectoryAssetReader("/usr/share/ppsspp/assets/")); #endif #if PPSSPP_PLATFORM(SWITCH) - std::string assetPath = savegame_dir + "assets/"; + std::string assetPath = user_data_path + "assets/"; VFSRegister("", new DirectoryAssetReader(assetPath.c_str())); #else VFSRegister("", new DirectoryAssetReader("assets/")); diff --git a/ext/native/file/file_util.cpp b/ext/native/file/file_util.cpp index a870518969..57fd61926e 100644 --- a/ext/native/file/file_util.cpp +++ b/ext/native/file/file_util.cpp @@ -8,6 +8,7 @@ #define strcasecmp _stricmp #endif #else +#include #include #include #include @@ -29,6 +30,13 @@ #define stat64 stat #endif +#ifdef HAVE_LIBNX +// Far from optimal, but I guess it works... +#define fseeko fseek +#define ftello ftell +#define fileno +#endif // HAVE_LIBNX + FILE *openCFile(const std::string &filename, const char *mode) { #if defined(_WIN32) && defined(UNICODE) diff --git a/ext/native/net/http_server.cpp b/ext/native/net/http_server.cpp index 1c0b5995b3..c4120bae6a 100644 --- a/ext/native/net/http_server.cpp +++ b/ext/native/net/http_server.cpp @@ -131,6 +131,10 @@ Server::Server(threading::Executor *executor) SetFallbackHandler(std::bind(&Server::Handle404, this, std::placeholders::_1)); } +Server::~Server() { + delete executor_; +} + void Server::RegisterHandler(const char *url_path, UrlHandlerFunc handler) { handlers_[std::string(url_path)] = handler; } diff --git a/ext/native/net/http_server.h b/ext/native/net/http_server.h index 2c84c4d283..0b5dfbe668 100644 --- a/ext/native/net/http_server.h +++ b/ext/native/net/http_server.h @@ -62,8 +62,9 @@ private: // Register handlers on this class to serve stuff. class Server { public: + // Takes ownership. Server(threading::Executor *executor); - virtual ~Server() {} + virtual ~Server(); typedef std::function UrlHandlerFunc; typedef std::map UrlHandlerMap; diff --git a/ext/native/thread/executor.cpp b/ext/native/thread/executor.cpp index 197f9d7920..e20fac09b1 100644 --- a/ext/native/thread/executor.cpp +++ b/ext/native/thread/executor.cpp @@ -10,7 +10,13 @@ void SameThreadExecutor::Run(std::function func) { } void NewThreadExecutor::Run(std::function func) { - std::thread(func).detach(); + thread_ = std::thread(func); +} + +NewThreadExecutor::~NewThreadExecutor() { + // If Run was ever called... + if (thread_.joinable()) + thread_.join(); } } // namespace threading diff --git a/ext/native/thread/executor.h b/ext/native/thread/executor.h index 6d6515920c..6a3122e920 100644 --- a/ext/native/thread/executor.h +++ b/ext/native/thread/executor.h @@ -1,6 +1,7 @@ #pragma once #include +#include namespace threading { @@ -8,6 +9,7 @@ namespace threading { class Executor { public: virtual void Run(std::function func) = 0; + virtual ~Executor() {} }; class SameThreadExecutor : public Executor { @@ -17,7 +19,11 @@ public: class NewThreadExecutor : public Executor { public: + ~NewThreadExecutor() override; void Run(std::function func) override; + +private: + std::thread thread_; }; } // namespace threading