From 7a93a3d9c82d823a034ee55a0c2226d8966bccf1 Mon Sep 17 00:00:00 2001 From: Sour Date: Fri, 5 Jan 2018 15:03:33 -0500 Subject: [PATCH] Libretro: Removed filesystem API dependency, removed socket dependencies --- InteropDLL/ConsoleWrapper.cpp | 2 +- Utilities/FolderUtilities.cpp | 58 ++++++++++++++++++++++- Utilities/PlatformUtilities.cpp | 6 +-- Utilities/Socket.cpp | 82 +++++++++++++++++++++++++++++++-- Utilities/Socket.h | 2 +- Utilities/Timer.cpp | 4 +- Utilities/UPnPPortMapper.cpp | 2 +- Utilities/Utilities.vcxproj | 4 +- 8 files changed, 146 insertions(+), 14 deletions(-) diff --git a/InteropDLL/ConsoleWrapper.cpp b/InteropDLL/ConsoleWrapper.cpp index a7b13978..760435df 100644 --- a/InteropDLL/ConsoleWrapper.cpp +++ b/InteropDLL/ConsoleWrapper.cpp @@ -29,7 +29,7 @@ #include "../Core/VsSystemActionManager.h" #include "../Core/KeyManager.h" -#ifdef WIN32 +#ifdef _WIN32 #include "../Windows/Renderer.h" #include "../Windows/SoundManager.h" #include "../Windows/WindowsKeyManager.h" diff --git a/Utilities/FolderUtilities.cpp b/Utilities/FolderUtilities.cpp index dc87a854..2068aaf6 100644 --- a/Utilities/FolderUtilities.cpp +++ b/Utilities/FolderUtilities.cpp @@ -1,8 +1,10 @@ #include "stdafx.h" //TODO: Use non-experimental namespace (once it is officially supported by VC & GCC) +#ifndef LIBRETRO #include namespace fs = std::experimental::filesystem; +#endif #include #include @@ -117,6 +119,7 @@ string FolderUtilities::GetRecentGamesFolder() return folder; } +#ifndef LIBRETRO void FolderUtilities::CreateFolder(string folder) { fs::create_directory(fs::u8path(folder)); @@ -194,4 +197,57 @@ string FolderUtilities::CombinePath(string folder, string filename) int64_t FolderUtilities::GetFileModificationTime(string filepath) { return fs::last_write_time(fs::u8path(filepath)).time_since_epoch() / std::chrono::seconds(1); -} \ No newline at end of file +} +#else + +//Libretro: Avoid using filesystem API. + +#ifdef _WIN32 +static const char* PATHSEPARATOR = "\\"; +#else +static const char* PATHSEPARATOR = "/"; +#endif + +void FolderUtilities::CreateFolder(string folder) +{ +} + +vector FolderUtilities::GetFolders(string rootFolder) +{ + return vector(); +} + +vector FolderUtilities::GetFilesInFolder(string rootFolder, std::unordered_set extensions, bool recursive) +{ + return vector(); +} + +string FolderUtilities::GetFilename(string filepath, bool includeExtension) +{ + size_t index = filepath.find_last_of(PATHSEPARATOR); + string filename = (index == std::string::basic_string::npos) ? filepath : filepath.substr(index + 1); + if(!includeExtension) { + filename = filename.substr(0, filename.find_last_of(".")); + } + return filename; +} + +string FolderUtilities::GetFolderName(string filepath) +{ + size_t index = filepath.find_last_of(PATHSEPARATOR); + return filepath.substr(0, index); +} + +string FolderUtilities::CombinePath(string folder, string filename) +{ + if(folder.find_last_of(PATHSEPARATOR) != folder.length() - 1) { + folder += PATHSEPARATOR; + } + return folder + filename; +} + +int64_t FolderUtilities::GetFileModificationTime(string filepath) +{ + return 0; +} +#endif \ No newline at end of file diff --git a/Utilities/PlatformUtilities.cpp b/Utilities/PlatformUtilities.cpp index 3007e33f..2b4dd071 100644 --- a/Utilities/PlatformUtilities.cpp +++ b/Utilities/PlatformUtilities.cpp @@ -1,7 +1,7 @@ #include "stdafx.h" #include "PlatformUtilities.h" -#ifdef WIN32 +#ifdef _WIN32 #include #endif @@ -9,14 +9,14 @@ void PlatformUtilities::DisableScreensaver() { //Prevent screensaver/etc from starting while using the emulator //DirectInput devices apparently do not always count as user input - #ifdef WIN32 + #ifdef _WIN32 SetThreadExecutionState(ES_SYSTEM_REQUIRED | ES_DISPLAY_REQUIRED | ES_CONTINUOUS); #endif // WIN32 } void PlatformUtilities::EnableScreensaver() { - #ifdef WIN32 + #ifdef _WIN32 SetThreadExecutionState(ES_CONTINUOUS); #endif // WIN32 } \ No newline at end of file diff --git a/Utilities/Socket.cpp b/Utilities/Socket.cpp index 02bcf763..65c7236e 100644 --- a/Utilities/Socket.cpp +++ b/Utilities/Socket.cpp @@ -1,12 +1,13 @@ #include "stdafx.h" #include #include - -#include "UPnPPortMapper.h" #include "Socket.h" + +#ifndef LIBRETRO +#include "UPnPPortMapper.h" using namespace std; -#ifdef WIN32 +#ifdef _WIN32 #pragma comment(lib,"ws2_32.lib") //Winsock Library #define WIN32_LEAN_AND_MEAN #include @@ -289,3 +290,78 @@ int Socket::Recv(char *buf, int len, int flags) return returnVal; } + +#else + +//Libretro port does not need sockets. + +Socket::Socket() +{ +} + +Socket::Socket(uintptr_t socket) +{ +} + +Socket::~Socket() +{ +} + +void Socket::SetSocketOptions() +{ +} + +void Socket::SetConnectionErrorFlag() +{ +} + +void Socket::Close() +{ +} + +bool Socket::ConnectionError() +{ + return true; +} + +void Socket::Bind(uint16_t port) +{ +} + +bool Socket::Connect(const char* hostname, uint16_t port) +{ + return false; +} + +void Socket::Listen(int backlog) +{ +} + +shared_ptr Socket::Accept() +{ + return shared_ptr(new Socket(0)); +} + +bool WouldBlock(int nError) +{ + return false; +} + +int Socket::Send(char *buf, int len, int flags) +{ + return 0; +} + +void Socket::BufferedSend(char *buf, int len) +{ +} + +void Socket::SendBuffer() +{ +} + +int Socket::Recv(char *buf, int len, int flags) +{ + return 0; +} +#endif diff --git a/Utilities/Socket.h b/Utilities/Socket.h index 82690c62..4b9241a3 100644 --- a/Utilities/Socket.h +++ b/Utilities/Socket.h @@ -5,7 +5,7 @@ class Socket { private: - #ifdef WIN32 + #ifdef _WIN32 bool _cleanupWSA = false; #endif diff --git a/Utilities/Timer.cpp b/Utilities/Timer.cpp index 0de21c9f..ad160066 100644 --- a/Utilities/Timer.cpp +++ b/Utilities/Timer.cpp @@ -1,7 +1,7 @@ #include "stdafx.h" #include -#ifdef WIN32 +#ifdef _WIN32 #include #else #include @@ -9,7 +9,7 @@ #include "Timer.h" -#ifdef WIN32 +#ifdef _WIN32 Timer::Timer() { diff --git a/Utilities/UPnPPortMapper.cpp b/Utilities/UPnPPortMapper.cpp index 6a942ce5..2b5bc8e6 100644 --- a/Utilities/UPnPPortMapper.cpp +++ b/Utilities/UPnPPortMapper.cpp @@ -1,7 +1,7 @@ #include "stdafx.h" #include "UPnPPortMapper.h" -#ifdef WIN32 +#ifdef _WIN32 #include #include #include diff --git a/Utilities/Utilities.vcxproj b/Utilities/Utilities.vcxproj index cacc92c1..1a36bd01 100644 --- a/Utilities/Utilities.vcxproj +++ b/Utilities/Utilities.vcxproj @@ -258,7 +258,7 @@ MaxSpeed true true - WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) + LIBRETRO;WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) true @@ -342,7 +342,7 @@ MaxSpeed true true - WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) + LIBRETRO;WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) true