Merge pull request #405 from xsacha/master

wxRemoval: Ini.cpp
This commit is contained in:
Alexandro Sánchez Bach 2014-07-09 22:57:40 +02:00
commit 2e06e8152e
2 changed files with 40 additions and 117 deletions

View File

@ -8,6 +8,9 @@ branches:
only:
- master
git:
submodules: false
before_install:
- echo "yes" | sudo apt-key adv --fetch-keys http://repos.codelite.org/CodeLite.asc
- echo "yes" | sudo apt-add-repository 'deb http://repos.codelite.org/wx3.0/ubuntu/ precise universe'
@ -25,11 +28,11 @@ before_install:
sudo ./cmake-2.8.12.1-Linux-i386.sh --skip-license --prefix=/usr;
before_script:
- git submodule update --init --recursive
- git submodule update --init asmjit ffmpeg
- mkdir build
- cd build
- cmake ..
script:
- make
- make -j 4

View File

@ -5,6 +5,7 @@
#include <algorithm>
#include <cctype>
#include <regex>
#define DEF_CONFIG_NAME "./rpcs3.ini"
@ -26,69 +27,40 @@ void saveIniFile()
getIniFile()->SaveFile(DEF_CONFIG_NAME);
}
std::pair<int, int> rDefaultSize = { -1, -1 };
Inis Ini;
static bool StringToBool(const wxString& str)
static bool StringToBool(const std::string& str)
{
if (
!str.CmpNoCase("enable") ||
!str.CmpNoCase("e") ||
!str.CmpNoCase("1") ||
!str.CmpNoCase("true") ||
!str.CmpNoCase("t"))
{
return true;
}
return false;
return std::regex_match(str.begin(), str.end(),
std::regex("1|e|t|enable|true", std::regex_constants::icase));
}
static wxString BoolToString(const bool b)
static inline std::string BoolToString(const bool b)
{
if (b) return "true";
return "false";
return b ? "true" : "false";
}
//takes a string of format "[number]x[number]" and returns a pair of ints
//example input would be "123x456" and the returned value would be {123,456}
static std::pair<int, int> StringToSize(const std::string& str)
{
std::pair<int, int> ret;
std::string s[2] = { "", "" };
for (uint i = 0, a = 0; i<str.size(); ++i)
{
if (!fmt::CmpNoCase(str.substr(i, 1), "x"))
{
if (++a >= 2) return rDefaultSize;
continue;
std::size_t start = 0, found;
std::vector<int> vec;
for (int i = 0; i < 2 && (found = str.find_first_of('x', start)); i++) {
try {
vec.push_back(std::stoi(str.substr(start, found == std::string::npos ? found : found - start)));
}
catch (const std::invalid_argument& e) {
return std::make_pair(-1, -1);
}
if (found == std::string::npos)
break;
start = found + 1;
}
if (vec.size() < 2 || vec[0] < 0 || vec[1] < 0)
return std::make_pair(-1, -1);
s[a] += str.substr(i, 1);
}
if (s[0].empty() || s[1].empty())
{
return rDefaultSize;
}
try{
ret.first = std::stoi(s[0]);
ret.first = std::stoi(s[1]);
}
catch (const std::invalid_argument &e)
{
return rDefaultSize;
}
if (ret.first < 0 || ret.second < 0)
{
return rDefaultSize;
}
return ret;
return std::make_pair(vec[0], vec[1]);
}
static std::string SizeToString(const std::pair<int, int>& size)
@ -96,77 +68,25 @@ static std::string SizeToString(const std::pair<int, int>& size)
return fmt::Format("%dx%d", size.first, size.second);
}
static wxPoint StringToPosition(const wxString& str)
{
wxPoint ret;
wxString s[2] = { wxEmptyString, wxEmptyString };
for (uint i = 0, a = 0; i<str.Length(); ++i)
{
if (!str(i, 1).CmpNoCase("x"))
{
if (++a >= 2) return wxDefaultPosition;
continue;
}
s[a] += str(i, 1);
}
if (s[0].IsEmpty() || s[1].IsEmpty())
{
return wxDefaultPosition;
}
s[0].ToLong((long*)&ret.x);
s[1].ToLong((long*)&ret.y);
if (ret.x <= 0 || ret.y <= 0)
{
return wxDefaultPosition;
}
return ret;
}
static WindowInfo StringToWindowInfo(const std::string& str)
{
WindowInfo ret = WindowInfo(rDefaultSize, rDefaultSize);
std::string s[4] = { "", "", "", "" };
for (uint i = 0, a = 0; i<str.size(); ++i)
{
if (!fmt::CmpNoCase(str.substr(i, 1), "x") || !fmt::CmpNoCase(str.substr(i, 1), ":"))
{
if (++a >= 4) return WindowInfo::GetDefault();
continue;
std::size_t start = 0, found;
std::vector<int> vec;
for (int i = 0; i < 4 && (found = str.find_first_of("x:", start)); i++) {
try {
vec.push_back(std::stoi(str.substr(start, found == std::string::npos ? found : found - start)));
}
s[a] += str.substr(i, 1);
catch (const std::invalid_argument& e) {
return WindowInfo::GetDefault();
}
if (found == std::string::npos)
break;
start = found + 1;
}
if (s[0].empty() || s[1].empty() || s[2].empty() || s[3].empty())
{
if (vec.size() < 4 || vec[0] <= 0 || vec[1] <= 0 || vec[2] < 0 || vec[3] < 0)
return WindowInfo::GetDefault();
}
try{
ret.size.first = std::stoi(s[0]);
ret.size.second = std::stoi(s[1]);
ret.position.first = std::stoi(s[2]);
ret.position.second = std::stoi(s[3]);
}
catch (const std::invalid_argument &e)
{
return WindowInfo::GetDefault();
}
if (ret.size.first <= 0 || ret.size.second <= 0)
{
return WindowInfo::GetDefault();
}
return ret;
return WindowInfo(std::make_pair(vec[0], vec[1]), std::make_pair(vec[2], vec[3]));
}
static std::string WindowInfoToString(const WindowInfo& wind)
@ -246,4 +166,4 @@ WindowInfo Ini::Load(const std::string& section, const std::string& key, const W
{
return StringToWindowInfo(m_Config->GetValue(section.c_str(), key.c_str(), WindowInfoToString(def_value).c_str()));
saveIniFile();
}
}