mirror of
https://github.com/RetroDECK/ES-DE.git
synced 2025-02-18 04:45:39 +00:00
Fixed crash when the ~/.emulationstation folder does not exist.
This commit is contained in:
parent
e59c430b89
commit
9da01403a0
|
@ -11,6 +11,7 @@ SDL_Event* InputManager::lastEvent = NULL;
|
||||||
std::map<int, InputManager::InputButton> InputManager::joystickButtonMap, InputManager::joystickAxisPosMap, InputManager::joystickAxisNegMap;
|
std::map<int, InputManager::InputButton> InputManager::joystickButtonMap, InputManager::joystickAxisPosMap, InputManager::joystickAxisNegMap;
|
||||||
std::map<int, int> InputManager::axisState;
|
std::map<int, int> InputManager::axisState;
|
||||||
InputManager::InputButton InputManager::hatState = InputManager::UNKNOWN;
|
InputManager::InputButton InputManager::hatState = InputManager::UNKNOWN;
|
||||||
|
std::string InputManager::joystickName = "";
|
||||||
|
|
||||||
int InputManager::deadzone = 28000;
|
int InputManager::deadzone = 28000;
|
||||||
|
|
||||||
|
@ -204,7 +205,7 @@ void InputManager::loadConfig()
|
||||||
|
|
||||||
std::ifstream file(path.c_str());
|
std::ifstream file(path.c_str());
|
||||||
|
|
||||||
std::string joystickName = "";
|
joystickName = "";
|
||||||
|
|
||||||
while(file.good())
|
while(file.good())
|
||||||
{
|
{
|
||||||
|
@ -257,6 +258,13 @@ void InputManager::loadConfig()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LOG(LogDebug) << "Finished loading input config";
|
||||||
|
|
||||||
|
openJoystick();
|
||||||
|
}
|
||||||
|
|
||||||
|
void InputManager::openJoystick()
|
||||||
|
{
|
||||||
//if any joystick is plugged in
|
//if any joystick is plugged in
|
||||||
if(SDL_NumJoysticks() > 0)
|
if(SDL_NumJoysticks() > 0)
|
||||||
{
|
{
|
||||||
|
@ -282,12 +290,12 @@ void InputManager::loadConfig()
|
||||||
LOG(LogWarning) << " could not find named joystick! You could try manually removing the joystick name entry in the input config file.";
|
LOG(LogWarning) << " could not find named joystick! You could try manually removing the joystick name entry in the input config file.";
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
LOG(LogDebug) << " opening first joystick";
|
LOG(LogDebug) << " opening first joystick (no name saved)";
|
||||||
|
|
||||||
SDL_JoystickOpen(0); //if we don't have a specific joystick in mind, take the first
|
SDL_JoystickOpen(0); //if we don't have a specific joystick in mind, take the first
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
LOG(LogDebug) << " no joysticks detected by SDL_NumJoysticks(), input loaded but no joystick opened";
|
LOG(LogDebug) << " no joysticks detected by SDL_NumJoysticks(), so no joystick opened";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,7 @@ namespace InputManager {
|
||||||
void unregisterComponent(GuiComponent* comp);
|
void unregisterComponent(GuiComponent* comp);
|
||||||
|
|
||||||
void loadConfig();
|
void loadConfig();
|
||||||
|
void openJoystick();
|
||||||
|
|
||||||
//enum for identifying input, regardless of configuration
|
//enum for identifying input, regardless of configuration
|
||||||
enum InputButton { UNKNOWN, UP, DOWN, LEFT, RIGHT, BUTTON1, BUTTON2, MENU, SELECT, PAGEUP, PAGEDOWN};
|
enum InputButton { UNKNOWN, UP, DOWN, LEFT, RIGHT, BUTTON1, BUTTON2, MENU, SELECT, PAGEUP, PAGEDOWN};
|
||||||
|
@ -30,6 +31,7 @@ namespace InputManager {
|
||||||
extern std::map<int, InputButton> joystickAxisPosMap, joystickAxisNegMap;
|
extern std::map<int, InputButton> joystickAxisPosMap, joystickAxisNegMap;
|
||||||
extern std::map<int, int> axisState;
|
extern std::map<int, int> axisState;
|
||||||
extern InputButton hatState;
|
extern InputButton hatState;
|
||||||
|
extern std::string joystickName;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
14
src/Log.cpp
14
src/Log.cpp
|
@ -4,7 +4,7 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
LogLevel Log::reportingLevel = LogInfo;
|
LogLevel Log::reportingLevel = LogInfo;
|
||||||
FILE* Log::file = fopen(getLogPath().c_str(), "w");
|
FILE* Log::file = NULL; //fopen(getLogPath().c_str(), "w");
|
||||||
|
|
||||||
LogLevel Log::getReportingLevel()
|
LogLevel Log::getReportingLevel()
|
||||||
{
|
{
|
||||||
|
@ -22,6 +22,11 @@ void Log::setReportingLevel(LogLevel level)
|
||||||
reportingLevel = level;
|
reportingLevel = level;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Log::open()
|
||||||
|
{
|
||||||
|
file = fopen(getLogPath().c_str(), "w");
|
||||||
|
}
|
||||||
|
|
||||||
std::ostringstream& Log::get(LogLevel level)
|
std::ostringstream& Log::get(LogLevel level)
|
||||||
{
|
{
|
||||||
os << "lvl" << level << ": \t";
|
os << "lvl" << level << ": \t";
|
||||||
|
@ -49,6 +54,13 @@ FILE* Log::getOutput()
|
||||||
Log::~Log()
|
Log::~Log()
|
||||||
{
|
{
|
||||||
os << std::endl;
|
os << std::endl;
|
||||||
|
|
||||||
|
if(getOutput() == NULL)
|
||||||
|
{
|
||||||
|
std::cerr << "ERROR - tried to write to log file before it was open!\n";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
fprintf(getOutput(), "%s", os.str().c_str());
|
fprintf(getOutput(), "%s", os.str().c_str());
|
||||||
|
|
||||||
//if it's an error, also print to console
|
//if it's an error, also print to console
|
||||||
|
|
|
@ -23,6 +23,7 @@ public:
|
||||||
static std::string getLogPath();
|
static std::string getLogPath();
|
||||||
|
|
||||||
static void flush();
|
static void flush();
|
||||||
|
static void open();
|
||||||
static void close();
|
static void close();
|
||||||
protected:
|
protected:
|
||||||
std::ostringstream os;
|
std::ostringstream os;
|
||||||
|
|
|
@ -44,10 +44,6 @@ namespace Renderer
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
//have to reload config to re-open SDL joysticks
|
|
||||||
InputManager::loadConfig();
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
LOG(LogInfo) << "Creating surface...";
|
LOG(LogInfo) << "Creating surface...";
|
||||||
|
|
||||||
|
|
|
@ -40,9 +40,6 @@ namespace Renderer
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
//we need to reload input too since SDL shut down
|
|
||||||
InputManager::loadConfig();
|
|
||||||
|
|
||||||
//usually display width/height are not specified, i.e. zero, which SDL automatically takes as "native resolution"
|
//usually display width/height are not specified, i.e. zero, which SDL automatically takes as "native resolution"
|
||||||
//so, since other things rely on the size of the screen (damn currently unnormalized coordinate system), we set it here
|
//so, since other things rely on the size of the screen (damn currently unnormalized coordinate system), we set it here
|
||||||
//even though the system was already initialized
|
//even though the system was already initialized
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
#include "Renderer.h"
|
#include "Renderer.h"
|
||||||
#include "AudioManager.h"
|
#include "AudioManager.h"
|
||||||
#include "Log.h"
|
#include "Log.h"
|
||||||
|
#include "InputManager.h"
|
||||||
|
|
||||||
std::vector<SystemData*> SystemData::sSystemVector;
|
std::vector<SystemData*> SystemData::sSystemVector;
|
||||||
|
|
||||||
|
@ -88,6 +89,7 @@ void SystemData::launchGame(GameData* game)
|
||||||
}
|
}
|
||||||
|
|
||||||
Renderer::init(0, 0);
|
Renderer::init(0, 0);
|
||||||
|
InputManager::openJoystick();
|
||||||
AudioManager::init();
|
AudioManager::init();
|
||||||
|
|
||||||
//re-enable SDL joystick events
|
//re-enable SDL joystick events
|
||||||
|
|
21
src/main.cpp
21
src/main.cpp
|
@ -82,6 +82,18 @@ int main(int argc, char* argv[])
|
||||||
|
|
||||||
bool running = true;
|
bool running = true;
|
||||||
|
|
||||||
|
//make sure the config directory exists
|
||||||
|
std::string home = getenv("HOME");
|
||||||
|
std::string configDir = home + "/.emulationstation";
|
||||||
|
if(!fs::exists(configDir))
|
||||||
|
{
|
||||||
|
std::cout << "Creating config directory \"" << configDir << "\"\n";
|
||||||
|
fs::create_directory(configDir);
|
||||||
|
}
|
||||||
|
|
||||||
|
//start the logger
|
||||||
|
Log::open();
|
||||||
|
|
||||||
//the renderer also takes care of setting up SDL for input and sound
|
//the renderer also takes care of setting up SDL for input and sound
|
||||||
bool renderInit = Renderer::init(width, height);
|
bool renderInit = Renderer::init(width, height);
|
||||||
if(!renderInit)
|
if(!renderInit)
|
||||||
|
@ -98,15 +110,6 @@ int main(int argc, char* argv[])
|
||||||
|
|
||||||
SDL_JoystickEventState(SDL_ENABLE);
|
SDL_JoystickEventState(SDL_ENABLE);
|
||||||
|
|
||||||
//make sure the config directory exists
|
|
||||||
std::string home = getenv("HOME");
|
|
||||||
std::string configDir = home + "/.emulationstation";
|
|
||||||
if(!fs::exists(configDir))
|
|
||||||
{
|
|
||||||
std::cout << "Creating config directory \"" << configDir << "\"\n";
|
|
||||||
fs::create_directory(configDir);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//try loading the system config file
|
//try loading the system config file
|
||||||
if(!fs::exists(SystemData::getConfigPath())) //if it doesn't exist, create the example and quit
|
if(!fs::exists(SystemData::getConfigPath())) //if it doesn't exist, create the example and quit
|
||||||
|
|
Loading…
Reference in a new issue