Use a standard config dir on non-Windows. Fixes #192

Also remove WindowInfo::GetDefault which was redundant.
This commit is contained in:
Sacha 2014-07-11 05:45:07 +10:00
parent f256153a2b
commit 3737993bb2
5 changed files with 35 additions and 13 deletions

View file

@ -1,4 +1,5 @@
#include "stdafx.h" #include "stdafx.h"
#include "rPlatform.h"
#include "Log.h" #include "Log.h"
#include <iostream> #include <iostream>
#include <string> #include <string>
@ -98,7 +99,7 @@ struct FileListener : LogListener
bool mPrependChannelName; bool mPrependChannelName;
FileListener(const std::string& name = _PRGNAME_, bool prependChannel = true) FileListener(const std::string& name = _PRGNAME_, bool prependChannel = true)
: mFile(name + ".log", rFile::write), : mFile(std::string(rPlatform::getConfigDir() + name + ".log").c_str(), rFile::write),
mPrependChannelName(prependChannel) mPrependChannelName(prependChannel)
{ {
if (!mFile.IsOpened()) if (!mFile.IsOpened())
@ -236,4 +237,4 @@ LogManager& LogManager::getInstance()
LogChannel &LogManager::getChannel(LogType type) LogChannel &LogManager::getChannel(LogType type)
{ {
return mChannels[static_cast<u32>(type)]; return mChannels[static_cast<u32>(type)];
} }

View file

@ -15,6 +15,10 @@
#include "Emu/Io/XInput/XInputPadHandler.h" #include "Emu/Io/XInput/XInputPadHandler.h"
#endif #endif
#ifndef _WIN32
#include <dirent.h>
#endif
rCanvas::rCanvas(void *parent) rCanvas::rCanvas(void *parent)
{ {
@ -135,6 +139,27 @@ int rPlatform::getMouseHandlerCount()
return 2; return 2;
} }
std::string rPlatform::getConfigDir()
{
static std::string dir = ".";
if (dir == ".") {
#ifdef _WIN32
dir = "";
//mkdir(dir.c_str());
#else
if (getenv("XDG_CONFIG_HOME") != NULL)
dir = getenv("XDG_CONFIG_HOME");
else if (getenv("HOME") != NULL)
dir = getenv("HOME") + std::string("/.config");
else // Just in case
dir = "./config";
dir = dir + "/rpcs3/";
mkdir(dir.c_str());
#endif
}
return dir;
}
MouseHandlerBase *rPlatform::getMouseHandler(int i) MouseHandlerBase *rPlatform::getMouseHandler(int i)
{ {
@ -179,4 +204,4 @@ PadHandlerBase *rPlatform::getPadHandler(int i)
default: default:
return new NullPadHandler(); return new NullPadHandler();
} }
} }

View file

@ -46,6 +46,7 @@ struct rPlatform
static MouseHandlerBase *getMouseHandler(int i); static MouseHandlerBase *getMouseHandler(int i);
static int getPadHandlerCount(); static int getPadHandlerCount();
static PadHandlerBase *getPadHandler(int i); static PadHandlerBase *getPadHandler(int i);
static std::string getConfigDir();
}; };
/********************************************************************** /**********************************************************************

View file

@ -2,6 +2,7 @@
#include "Ini.h" #include "Ini.h"
#include "Utilities/StrFmt.h" #include "Utilities/StrFmt.h"
#include "Utilities/rPlatform.h"
#include <algorithm> #include <algorithm>
#include <cctype> #include <cctype>
@ -16,7 +17,7 @@ CSimpleIniCaseA *getIniFile()
if (inited == false) if (inited == false)
{ {
ini.SetUnicode(true); ini.SetUnicode(true);
ini.LoadFile(DEF_CONFIG_NAME); ini.LoadFile(std::string(rPlatform::getConfigDir() + DEF_CONFIG_NAME).c_str());
inited = true; inited = true;
} }
return &ini; return &ini;
@ -24,7 +25,7 @@ CSimpleIniCaseA *getIniFile()
void saveIniFile() void saveIniFile()
{ {
getIniFile()->SaveFile(DEF_CONFIG_NAME); getIniFile()->SaveFile(std::string(rPlatform::getConfigDir() + DEF_CONFIG_NAME).c_str());
} }
Inis Ini; Inis Ini;
@ -77,14 +78,14 @@ static WindowInfo StringToWindowInfo(const std::string& str)
vec.push_back(std::stoi(str.substr(start, found == std::string::npos ? found : found - start))); vec.push_back(std::stoi(str.substr(start, found == std::string::npos ? found : found - start)));
} }
catch (const std::invalid_argument& e) { catch (const std::invalid_argument& e) {
return WindowInfo::GetDefault(); return WindowInfo();
} }
if (found == std::string::npos) if (found == std::string::npos)
break; break;
start = found + 1; start = found + 1;
} }
if (vec.size() < 4 || vec[0] <= 0 || vec[1] <= 0 || vec[2] < 0 || vec[3] < 0) if (vec.size() < 4 || vec[0] <= 0 || vec[1] <= 0 || vec[2] < 0 || vec[3] < 0)
return WindowInfo::GetDefault(); return WindowInfo();
return WindowInfo(std::make_pair(vec[0], vec[1]), std::make_pair(vec[2], vec[3])); return WindowInfo(std::make_pair(vec[0], vec[1]), std::make_pair(vec[2], vec[3]));
} }

View file

@ -18,12 +18,6 @@ struct WindowInfo
, position(_position) , position(_position)
{ {
} }
//TODO: remove
static WindowInfo GetDefault()
{
return WindowInfo({ -1, -1 }, { -1, -1 });
}
}; };
class Ini class Ini