Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Misc #774

Merged
merged 3 commits into from Jan 25, 2022
Merged

Misc #774

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion es-app/src/SystemScreenSaver.cpp
Expand Up @@ -340,7 +340,7 @@ std::vector<FileData*> SystemScreenSaver::getAllGamelistNodes()

void SystemScreenSaver::pickGameListNode(const char *nodeName, std::string& path)
{
FileData *itf;
FileData *itf = nullptr;
bool found = false;
int missCtr = 0;
while (!found) {
Expand Down
4 changes: 3 additions & 1 deletion es-core/src/InputManager.cpp
Expand Up @@ -57,8 +57,10 @@ void InputManager::init()
Settings::getInstance()->getBool("BackgroundJoystickInput") ? "1" : "0");
// Don't enable the HIDAPI drivers by default, it will break the existing configurations
// for a few controller types, since the names and the input mappings are different.
#if SDL_VERSION_ATLEAST(2,0,9) and not(_WIN32)
#if !defined(_WIN32)
#if SDL_VERSION_ATLEAST(2,0,9)
SDL_SetHint(SDL_HINT_JOYSTICK_HIDAPI, "0");
#endif
#endif
SDL_InitSubSystem(SDL_INIT_JOYSTICK);
SDL_JoystickEventState(SDL_ENABLE);
Expand Down
1 change: 1 addition & 0 deletions es-core/src/resources/ResourceManager.h
Expand Up @@ -4,6 +4,7 @@

#include <list>
#include <memory>
#include <string>

//The ResourceManager exists to...
//Allow loading resources embedded into the executable like an actual file.
Expand Down
21 changes: 5 additions & 16 deletions es-core/src/resources/TextureData.cpp
Expand Up @@ -46,33 +46,22 @@ bool TextureData::initSVGFromMemory(const unsigned char* fileData, size_t length

NSVGimage* svgImage = nsvgParse(copy, "px", DPI);
free(copy);
if (!svgImage)
if (!svgImage || (svgImage->width == 0) || (svgImage->height == 0))
{
LOG(LogError) << "Error parsing SVG image.";
return false;
}

// We want to rasterise this texture at a specific resolution. If the source size
// variables are set then use them otherwise set them from the parsed file
if ((mSourceWidth == 0.0f) && (mSourceHeight == 0.0f))
{
mSourceWidth = svgImage->width;
if (mSourceHeight == 0.0f)
pjft marked this conversation as resolved.
Show resolved Hide resolved
mSourceHeight = svgImage->height;
}

mSourceWidth = (mSourceHeight * svgImage->width) / svgImage->height;

mWidth = (size_t)Math::round(mSourceWidth);
mHeight = (size_t)Math::round(mSourceHeight);

if (mWidth == 0)
pjft marked this conversation as resolved.
Show resolved Hide resolved
{
// auto scale width to keep aspect
mWidth = (size_t)Math::round(((float)mHeight / svgImage->height) * svgImage->width);
}
else if (mHeight == 0)
{
// auto scale height to keep aspect
mHeight = (size_t)Math::round(((float)mWidth / svgImage->width) * svgImage->height);
}

unsigned char* dataRGBA = new unsigned char[mWidth * mHeight * 4];

NSVGrasterizer* rast = nsvgCreateRasterizer();
Expand Down
33 changes: 17 additions & 16 deletions es-core/src/utils/FileSystemUtil.cpp
Expand Up @@ -5,12 +5,12 @@
#include <sys/stat.h>
#include <string.h>
#include <map>
#include <mutex>

#if defined(_WIN32)
// because windows...
#include <direct.h>
#include <Windows.h>
#include <mutex>
#define getcwd _getcwd
#define mkdir(x,y) _mkdir(x)
#define snprintf _snprintf
Expand All @@ -29,15 +29,14 @@ namespace Utils
{
namespace FileSystem
{
static std::string homePath = "";
static std::string exePath = "";
static std::map<std::string, bool> mPathExistsIndex = std::map<std::string, bool>();
static std::recursive_mutex mutex = {};
static std::string homePath = "";
static std::string exePath = "";
static std::map<std::string, bool> pathExistsIndex = std::map<std::string, bool>();

//////////////////////////////////////////////////////////////////////////

#if defined(_WIN32)
std::mutex mFileMutex; // Avoids enumerating N folders at the same time in threaded loadings

static std::string convertFromWideString(const std::wstring _wstring)
{
const int numBytes = WideCharToMultiByte(CP_UTF8, 0, _wstring.c_str(), (int)_wstring.length(), nullptr, 0, nullptr, nullptr);
Expand All @@ -62,11 +61,10 @@ namespace Utils
{

#if defined(_WIN32)
std::unique_lock<std::mutex> lock(mFileMutex);

WIN32_FIND_DATAW findData;
const std::string wildcard = path + "/*";
const HANDLE hFind = FindFirstFileW(std::wstring(wildcard.begin(), wildcard.end()).c_str(), &findData);
const std::unique_lock<std::recursive_mutex> lock(mutex);
WIN32_FIND_DATAW findData;
const std::string wildcard = path + "/*";
const HANDLE hFind = FindFirstFileW(std::wstring(wildcard.begin(), wildcard.end()).c_str(), &findData);

if(hFind != INVALID_HANDLE_VALUE)
{
Expand Down Expand Up @@ -600,7 +598,8 @@ namespace Utils

bool removeFile(const std::string& _path)
{
const std::string path = getGenericPath(_path);
const std::unique_lock<std::recursive_mutex> lock(mutex);
const std::string path = getGenericPath(_path);

// don't remove if it doesn't exists
if(!exists(path))
Expand All @@ -610,7 +609,7 @@ namespace Utils

// if removed, let's remove it from the index
if (removed)
mPathExistsIndex[_path] = false;
pathExistsIndex[_path] = false;

// try to remove file
return removed;
Expand Down Expand Up @@ -647,15 +646,17 @@ namespace Utils

bool exists(const std::string& _path)
{
if (mPathExistsIndex.find(_path) == mPathExistsIndex.cend())
const std::unique_lock<std::recursive_mutex> lock(mutex);

if (pathExistsIndex.find(_path) == pathExistsIndex.cend())
{
const std::string path = getGenericPath(_path);
struct stat64 info;
// check if stat64 succeeded
mPathExistsIndex[_path] = (stat64(path.c_str(), &info) == 0);
pathExistsIndex[_path] = (stat64(path.c_str(), &info) == 0);
}

return mPathExistsIndex.at(_path);
return pathExistsIndex.at(_path);

} // exists

Expand Down
11 changes: 6 additions & 5 deletions es-core/src/utils/TimeUtil.cpp
Expand Up @@ -216,19 +216,20 @@ namespace Utils

std::string timeToString(const time_t& _time, const std::string& _format)
{
const char* f = _format.c_str();
const tm timeStruct = *localtime(&_time);
char buf[256] = { '\0' };
const int MAX_LENGTH = 256;
const tm timeStruct = *localtime(&_time);
char buf[256] = { '\0' };
const int MAX_LENGTH = 256;

// Use strftime to format the string
if (!strftime(buf, MAX_LENGTH, _format.c_str(), &timeStruct)) {
if(!strftime(buf, MAX_LENGTH, _format.c_str(), &timeStruct))
{
return "";
}
else
{
return std::string(buf);
}

} // timeToString

//////////////////////////////////////////////////////////////////////////
Expand Down