Libretro: Removed filesystem API dependency, removed socket dependencies

This commit is contained in:
Sour 2018-01-05 15:03:33 -05:00
parent 017ca631e1
commit 7a93a3d9c8
8 changed files with 146 additions and 14 deletions

View file

@ -29,7 +29,7 @@
#include "../Core/VsSystemActionManager.h" #include "../Core/VsSystemActionManager.h"
#include "../Core/KeyManager.h" #include "../Core/KeyManager.h"
#ifdef WIN32 #ifdef _WIN32
#include "../Windows/Renderer.h" #include "../Windows/Renderer.h"
#include "../Windows/SoundManager.h" #include "../Windows/SoundManager.h"
#include "../Windows/WindowsKeyManager.h" #include "../Windows/WindowsKeyManager.h"

View file

@ -1,8 +1,10 @@
#include "stdafx.h" #include "stdafx.h"
//TODO: Use non-experimental namespace (once it is officially supported by VC & GCC) //TODO: Use non-experimental namespace (once it is officially supported by VC & GCC)
#ifndef LIBRETRO
#include <experimental/filesystem> #include <experimental/filesystem>
namespace fs = std::experimental::filesystem; namespace fs = std::experimental::filesystem;
#endif
#include <unordered_set> #include <unordered_set>
#include <algorithm> #include <algorithm>
@ -117,6 +119,7 @@ string FolderUtilities::GetRecentGamesFolder()
return folder; return folder;
} }
#ifndef LIBRETRO
void FolderUtilities::CreateFolder(string folder) void FolderUtilities::CreateFolder(string folder)
{ {
fs::create_directory(fs::u8path(folder)); fs::create_directory(fs::u8path(folder));
@ -194,4 +197,57 @@ string FolderUtilities::CombinePath(string folder, string filename)
int64_t FolderUtilities::GetFileModificationTime(string filepath) int64_t FolderUtilities::GetFileModificationTime(string filepath)
{ {
return fs::last_write_time(fs::u8path(filepath)).time_since_epoch() / std::chrono::seconds(1); return fs::last_write_time(fs::u8path(filepath)).time_since_epoch() / std::chrono::seconds(1);
} }
#else
//Libretro: Avoid using filesystem API.
#ifdef _WIN32
static const char* PATHSEPARATOR = "\\";
#else
static const char* PATHSEPARATOR = "/";
#endif
void FolderUtilities::CreateFolder(string folder)
{
}
vector<string> FolderUtilities::GetFolders(string rootFolder)
{
return vector<string>();
}
vector<string> FolderUtilities::GetFilesInFolder(string rootFolder, std::unordered_set<string> extensions, bool recursive)
{
return vector<string>();
}
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

View file

@ -1,7 +1,7 @@
#include "stdafx.h" #include "stdafx.h"
#include "PlatformUtilities.h" #include "PlatformUtilities.h"
#ifdef WIN32 #ifdef _WIN32
#include <Windows.h> #include <Windows.h>
#endif #endif
@ -9,14 +9,14 @@ void PlatformUtilities::DisableScreensaver()
{ {
//Prevent screensaver/etc from starting while using the emulator //Prevent screensaver/etc from starting while using the emulator
//DirectInput devices apparently do not always count as user input //DirectInput devices apparently do not always count as user input
#ifdef WIN32 #ifdef _WIN32
SetThreadExecutionState(ES_SYSTEM_REQUIRED | ES_DISPLAY_REQUIRED | ES_CONTINUOUS); SetThreadExecutionState(ES_SYSTEM_REQUIRED | ES_DISPLAY_REQUIRED | ES_CONTINUOUS);
#endif // WIN32 #endif // WIN32
} }
void PlatformUtilities::EnableScreensaver() void PlatformUtilities::EnableScreensaver()
{ {
#ifdef WIN32 #ifdef _WIN32
SetThreadExecutionState(ES_CONTINUOUS); SetThreadExecutionState(ES_CONTINUOUS);
#endif // WIN32 #endif // WIN32
} }

View file

@ -1,12 +1,13 @@
#include "stdafx.h" #include "stdafx.h"
#include <cstring> #include <cstring>
#include <thread> #include <thread>
#include "UPnPPortMapper.h"
#include "Socket.h" #include "Socket.h"
#ifndef LIBRETRO
#include "UPnPPortMapper.h"
using namespace std; using namespace std;
#ifdef WIN32 #ifdef _WIN32
#pragma comment(lib,"ws2_32.lib") //Winsock Library #pragma comment(lib,"ws2_32.lib") //Winsock Library
#define WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN
#include <winsock2.h> #include <winsock2.h>
@ -289,3 +290,78 @@ int Socket::Recv(char *buf, int len, int flags)
return returnVal; 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> Socket::Accept()
{
return shared_ptr<Socket>(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

View file

@ -5,7 +5,7 @@
class Socket class Socket
{ {
private: private:
#ifdef WIN32 #ifdef _WIN32
bool _cleanupWSA = false; bool _cleanupWSA = false;
#endif #endif

View file

@ -1,7 +1,7 @@
#include "stdafx.h" #include "stdafx.h"
#include <thread> #include <thread>
#ifdef WIN32 #ifdef _WIN32
#include <Windows.h> #include <Windows.h>
#else #else
#include <time.h> #include <time.h>
@ -9,7 +9,7 @@
#include "Timer.h" #include "Timer.h"
#ifdef WIN32 #ifdef _WIN32
Timer::Timer() Timer::Timer()
{ {

View file

@ -1,7 +1,7 @@
#include "stdafx.h" #include "stdafx.h"
#include "UPnPPortMapper.h" #include "UPnPPortMapper.h"
#ifdef WIN32 #ifdef _WIN32
#include <winsock2.h> #include <winsock2.h>
#include <natupnp.h> #include <natupnp.h>
#include <ws2tcpip.h> #include <ws2tcpip.h>

View file

@ -258,7 +258,7 @@
<Optimization>MaxSpeed</Optimization> <Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking> <FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions> <IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>LIBRETRO;WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck> <SDLCheck>true</SDLCheck>
<AdditionalIncludeDirectories> <AdditionalIncludeDirectories>
</AdditionalIncludeDirectories> </AdditionalIncludeDirectories>
@ -342,7 +342,7 @@
<Optimization>MaxSpeed</Optimization> <Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking> <FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions> <IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>LIBRETRO;WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck> <SDLCheck>true</SDLCheck>
<AdditionalIncludeDirectories> <AdditionalIncludeDirectories>
</AdditionalIncludeDirectories> </AdditionalIncludeDirectories>