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/KeyManager.h"
#ifdef WIN32
#ifdef _WIN32
#include "../Windows/Renderer.h"
#include "../Windows/SoundManager.h"
#include "../Windows/WindowsKeyManager.h"

View file

@ -1,8 +1,10 @@
#include "stdafx.h"
//TODO: Use non-experimental namespace (once it is officially supported by VC & GCC)
#ifndef LIBRETRO
#include <experimental/filesystem>
namespace fs = std::experimental::filesystem;
#endif
#include <unordered_set>
#include <algorithm>
@ -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);
}
}
#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 "PlatformUtilities.h"
#ifdef WIN32
#ifdef _WIN32
#include <Windows.h>
#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
}

View file

@ -1,12 +1,13 @@
#include "stdafx.h"
#include <cstring>
#include <thread>
#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 <winsock2.h>
@ -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> 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
{
private:
#ifdef WIN32
#ifdef _WIN32
bool _cleanupWSA = false;
#endif

View file

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

View file

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

View file

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