diff --git a/CMakeLists.txt b/CMakeLists.txt index 4bb16b8e50..bdbc68825d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -244,8 +244,6 @@ add_library(Common STATIC Common/FileUtil.h Common/Hash.cpp Common/Hash.h - Common/IniFile.cpp - Common/IniFile.h Common/LogManager.cpp Common/LogManager.h Common/MathUtil.cpp @@ -512,6 +510,8 @@ add_library(native STATIC native/file/fd_util.h native/file/file_util.cpp native/file/file_util.h + native/file/ini_file.cpp + native/file/ini_file.h native/file/vfs.h native/file/zip_read.cpp native/file/zip_read.h @@ -536,6 +536,8 @@ add_library(native STATIC native/gfx_es2/glsl_program.h native/gfx_es2/vertex_format.cpp native/gfx_es2/vertex_format.h + native/i18n/i18n.cpp + native/i18n/i18n.h native/image/png_load.cpp native/image/png_load.h native/image/zim_load.cpp diff --git a/Common/Common.vcxproj b/Common/Common.vcxproj index 421bbcc8b6..0b727ccea2 100644 --- a/Common/Common.vcxproj +++ b/Common/Common.vcxproj @@ -69,6 +69,7 @@ WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions);_CRT_SECURE_NO_WARNINGS stdafx.h MultiThreadedDebugDLL + ../native Windows @@ -86,6 +87,7 @@ stdafx.h MultiThreadedDebugDLL WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) + ../native Windows @@ -107,6 +109,7 @@ false StreamingSIMDExtensions2 Fast + ../native Windows @@ -127,6 +130,7 @@ true WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) stdafx.h + ../native Windows @@ -160,7 +164,6 @@ - @@ -198,7 +201,6 @@ - @@ -222,6 +224,11 @@ + + + {c4df647e-80ea-4111-a0a8-218b1b711e18} + + diff --git a/Common/Common.vcxproj.filters b/Common/Common.vcxproj.filters index c35ca9dbea..395566ba23 100644 --- a/Common/Common.vcxproj.filters +++ b/Common/Common.vcxproj.filters @@ -22,7 +22,6 @@ - @@ -54,7 +53,6 @@ - diff --git a/Common/IniFile.cpp b/Common/IniFile.cpp deleted file mode 100644 index 40abe02806..0000000000 --- a/Common/IniFile.cpp +++ /dev/null @@ -1,565 +0,0 @@ -// Copyright (C) 2003 Dolphin Project. - -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, version 2.0 or later versions. - -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License 2.0 for more details. - -// A copy of the GPL 2.0 should have been included with the program. -// If not, see http://www.gnu.org/licenses/ - -// Official SVN repository and contact information can be found at -// http://code.google.com/p/dolphin-emu/ -// see IniFile.h - -#include -#include - -#ifndef _MSC_VER -#include -#endif - -#include -#include -#include -#include -#include - -#include "StringUtil.h" -#include "IniFile.h" - -namespace { - -static void ParseLine(const std::string& line, std::string* keyOut, std::string* valueOut, std::string* commentOut) -{ - int FirstEquals = (int)line.find("=", 0); - int FirstCommentChar = -1; - - // Comments - if (FirstCommentChar < 0) - FirstCommentChar = - (int)line.find("#", FirstEquals > 0 ? FirstEquals : 0); - if (FirstCommentChar < 0 && line[0] == ';') - FirstCommentChar = 0; - - // Allow preservation of spacing before comment - if (FirstCommentChar > 0) - { - while (line[FirstCommentChar - 1] == ' ' || line[FirstCommentChar - 1] == 9) // 9 == tab - { - FirstCommentChar--; - } - } - - if ((FirstEquals >= 0) && ((FirstCommentChar < 0) || (FirstEquals < FirstCommentChar))) - { - // Yes, a valid line! - *keyOut = StripSpaces(line.substr(0, FirstEquals)); - if (commentOut) *commentOut = FirstCommentChar > 0 ? line.substr(FirstCommentChar) : std::string(""); - if (valueOut) *valueOut = StripQuotes(StripSpaces(line.substr(FirstEquals + 1, FirstCommentChar - FirstEquals - 1))); - } -} - -} - -std::string* IniFile::Section::GetLine(const char* key, std::string* valueOut, std::string* commentOut) -{ - for (std::vector::iterator iter = lines.begin(); iter != lines.end(); ++iter) - { - std::string& line = *iter; - std::string lineKey; - ParseLine(line, &lineKey, valueOut, commentOut); - if (!strcasecmp(lineKey.c_str(), key)) - return &line; - } - return 0; -} - -void IniFile::Section::Set(const char* key, const char* newValue) -{ - std::string value, commented; - std::string* line = GetLine(key, &value, &commented); - if (line) - { - // Change the value - keep the key and comment - *line = StripSpaces(key) + " = " + newValue + commented; - } - else - { - // The key did not already exist in this section - let's add it. - lines.push_back(std::string(key) + " = " + newValue); - } -} - -void IniFile::Section::Set(const char* key, const std::string& newValue, const std::string& defaultValue) -{ - if (newValue != defaultValue) - Set(key, newValue); - else - Delete(key); -} - -bool IniFile::Section::Get(const char* key, std::string* value, const char* defaultValue) -{ - std::string* line = GetLine(key, value, 0); - if (!line) - { - if (defaultValue) - { - *value = defaultValue; - } - return false; - } - return true; -} - -void IniFile::Section::Set(const char* key, const float newValue, const float defaultValue) -{ - if (newValue != defaultValue) - Set(key, newValue); - else - Delete(key); -} - -void IniFile::Section::Set(const char* key, int newValue, int defaultValue) -{ - if (newValue != defaultValue) - Set(key, newValue); - else - Delete(key); -} - -void IniFile::Section::Set(const char* key, bool newValue, bool defaultValue) -{ - if (newValue != defaultValue) - Set(key, newValue); - else - Delete(key); -} - -void IniFile::Section::Set(const char* key, const std::vector& newValues) -{ - std::string temp; - // Join the strings with , - std::vector::const_iterator it; - for (it = newValues.begin(); it != newValues.end(); ++it) - { - temp += (*it) + ","; - } - // remove last , - if (temp.length()) - temp.resize(temp.length() - 1); - Set(key, temp.c_str()); -} - -bool IniFile::Section::Get(const char* key, std::vector& values) -{ - std::string temp; - bool retval = Get(key, &temp, 0); - if (!retval || temp.empty()) - { - return false; - } - // ignore starting , if any - size_t subStart = temp.find_first_not_of(","); - size_t subEnd; - - // split by , - while (subStart != std::string::npos) { - - // Find next , - subEnd = temp.find_first_of(",", subStart); - if (subStart != subEnd) - // take from first char until next , - values.push_back(StripSpaces(temp.substr(subStart, subEnd - subStart))); - - // Find the next non , char - subStart = temp.find_first_not_of(",", subEnd); - } - - return true; -} - -bool IniFile::Section::Get(const char* key, int* value, int defaultValue) -{ - std::string temp; - bool retval = Get(key, &temp, 0); - if (retval && TryParse(temp.c_str(), value)) - return true; - *value = defaultValue; - return false; -} - -bool IniFile::Section::Get(const char* key, u32* value, u32 defaultValue) -{ - std::string temp; - bool retval = Get(key, &temp, 0); - if (retval && TryParse(temp, value)) - return true; - *value = defaultValue; - return false; -} - -bool IniFile::Section::Get(const char* key, bool* value, bool defaultValue) -{ - std::string temp; - bool retval = Get(key, &temp, 0); - if (retval && TryParse(temp.c_str(), value)) - return true; - *value = defaultValue; - return false; -} - -bool IniFile::Section::Get(const char* key, float* value, float defaultValue) -{ - std::string temp; - bool retval = Get(key, &temp, 0); - if (retval && TryParse(temp.c_str(), value)) - return true; - *value = defaultValue; - return false; -} - -bool IniFile::Section::Get(const char* key, double* value, double defaultValue) -{ - std::string temp; - bool retval = Get(key, &temp, 0); - if (retval && TryParse(temp.c_str(), value)) - return true; - *value = defaultValue; - return false; -} - -bool IniFile::Section::Exists(const char *key) const -{ - for (std::vector::const_iterator iter = lines.begin(); iter != lines.end(); ++iter) - { - std::string lineKey; - ParseLine(*iter, &lineKey, NULL, NULL); - if (!strcasecmp(lineKey.c_str(), key)) - return true; - } - return false; -} - -bool IniFile::Section::Delete(const char *key) -{ - std::string* line = GetLine(key, 0, 0); - for (std::vector::iterator liter = lines.begin(); liter != lines.end(); ++liter) - { - if (line == &*liter) - { - lines.erase(liter); - return true; - } - } - return false; -} - -// IniFile - -const IniFile::Section* IniFile::GetSection(const char* sectionName) const -{ - for (std::vector
::const_iterator iter = sections.begin(); iter != sections.end(); ++iter) - if (!strcasecmp(iter->name.c_str(), sectionName)) - return (&(*iter)); - return 0; -} - -IniFile::Section* IniFile::GetSection(const char* sectionName) -{ - for (std::vector
::iterator iter = sections.begin(); iter != sections.end(); ++iter) - if (!strcasecmp(iter->name.c_str(), sectionName)) - return (&(*iter)); - return 0; -} - -IniFile::Section* IniFile::GetOrCreateSection(const char* sectionName) -{ - Section* section = GetSection(sectionName); - if (!section) - { - sections.push_back(Section(sectionName)); - section = §ions[sections.size() - 1]; - } - return section; -} - -bool IniFile::DeleteSection(const char* sectionName) -{ - Section* s = GetSection(sectionName); - if (!s) - return false; - for (std::vector
::iterator iter = sections.begin(); iter != sections.end(); ++iter) - { - if (&(*iter) == s) - { - sections.erase(iter); - return true; - } - } - return false; -} - -bool IniFile::Exists(const char* sectionName, const char* key) const -{ - const Section* section = GetSection(sectionName); - if (!section) - return false; - return section->Exists(key); -} - -void IniFile::SetLines(const char* sectionName, const std::vector &lines) -{ - Section* section = GetOrCreateSection(sectionName); - section->lines.clear(); - for (std::vector::const_iterator iter = lines.begin(); iter != lines.end(); ++iter) - { - section->lines.push_back(*iter); - } -} - -bool IniFile::DeleteKey(const char* sectionName, const char* key) -{ - Section* section = GetSection(sectionName); - if (!section) - return false; - std::string* line = section->GetLine(key, 0, 0); - for (std::vector::iterator liter = section->lines.begin(); liter != section->lines.end(); ++liter) - { - if (line == &(*liter)) - { - section->lines.erase(liter); - return true; - } - } - return false; //shouldn't happen -} - -// Return a list of all keys in a section -bool IniFile::GetKeys(const char* sectionName, std::vector& keys) const -{ - const Section* section = GetSection(sectionName); - if (!section) - return false; - keys.clear(); - for (std::vector::const_iterator liter = section->lines.begin(); liter != section->lines.end(); ++liter) - { - std::string key; - ParseLine(*liter, &key, 0, 0); - keys.push_back(key); - } - return true; -} - -// Return a list of all lines in a section -bool IniFile::GetLines(const char* sectionName, std::vector& lines, const bool remove_comments) const -{ - const Section* section = GetSection(sectionName); - if (!section) - return false; - - lines.clear(); - for (std::vector::const_iterator iter = section->lines.begin(); iter != section->lines.end(); ++iter) - { - std::string line = StripSpaces(*iter); - - if (remove_comments) - { - int commentPos = (int)line.find('#'); - if (commentPos == 0) - { - continue; - } - - if (commentPos != (int)std::string::npos) - { - line = StripSpaces(line.substr(0, commentPos)); - } - } - - lines.push_back(line); - } - - return true; -} - - -void IniFile::SortSections() -{ - std::sort(sections.begin(), sections.end()); -} - -bool IniFile::Load(const char* filename) -{ - // Maximum number of letters in a line - static const int MAX_BYTES = 1024*32; - - sections.clear(); - sections.push_back(Section("")); - // first section consists of the comments before the first real section - - // Open file - std::ifstream in; - in.open(filename, std::ios::in); - - if (in.fail()) return false; - - while (!in.eof()) - { - char templine[MAX_BYTES]; - in.getline(templine, MAX_BYTES); - std::string line = templine; - -#ifndef _WIN32 - // Check for CRLF eol and convert it to LF - if (!line.empty() && line.at(line.size()-1) == '\r') - { - line.erase(line.size()-1); - } -#endif - - if (in.eof()) break; - - if (line.size() > 0) - { - if (line[0] == '[') - { - size_t endpos = line.find("]"); - - if (endpos != std::string::npos) - { - // New section! - std::string sub = line.substr(1, endpos - 1); - sections.push_back(Section(sub)); - - if (endpos + 1 < line.size()) - { - sections[sections.size() - 1].comment = line.substr(endpos + 1); - } - } - } - else - { - sections[sections.size() - 1].lines.push_back(line); - } - } - } - - in.close(); - return true; -} - -bool IniFile::Save(const char* filename) -{ - std::ofstream out; - out.open(filename, std::ios::out); - - if (out.fail()) - { - return false; - } - - // Currently testing if dolphin community can handle the requirements of C++11 compilation - // If you get a compiler error on this line, your compiler is probably old. - // Update to g++ 4.4 or a recent version of clang (XCode 4.2 on OS X). - // If you don't want to update, complain in a google code issue, the dolphin forums or #dolphin-emu. - for (std::vector
::iterator iter = sections.begin(); iter != sections.end(); ++iter) - { - const Section& section = *iter; - - if (section.name != "") - { - out << "[" << section.name << "]" << section.comment << std::endl; - } - - for (std::vector::const_iterator liter = section.lines.begin(); liter != section.lines.end(); ++liter) - { - std::string s = *liter; - out << s << std::endl; - } - } - - out.close(); - return true; -} - - -bool IniFile::Get(const char* sectionName, const char* key, std::string* value, const char* defaultValue) -{ - Section* section = GetSection(sectionName); - if (!section) { - if (defaultValue) { - *value = defaultValue; - } - return false; - } - return section->Get(key, value, defaultValue); -} - -bool IniFile::Get(const char *sectionName, const char* key, std::vector& values) -{ - Section *section = GetSection(sectionName); - if (!section) - return false; - return section->Get(key, values); -} - -bool IniFile::Get(const char* sectionName, const char* key, int* value, int defaultValue) -{ - Section *section = GetSection(sectionName); - if (!section) { - *value = defaultValue; - return false; - } else { - return section->Get(key, value, defaultValue); - } -} - -bool IniFile::Get(const char* sectionName, const char* key, u32* value, u32 defaultValue) -{ - Section *section = GetSection(sectionName); - if (!section) { - *value = defaultValue; - return false; - } else { - return section->Get(key, value, defaultValue); - } -} - -bool IniFile::Get(const char* sectionName, const char* key, bool* value, bool defaultValue) -{ - Section *section = GetSection(sectionName); - if (!section) { - *value = defaultValue; - return false; - } else { - return section->Get(key, value, defaultValue); - } -} - - -// Unit test. TODO: Move to the real unit test framework. -/* - int main() - { - IniFile ini; - ini.Load("my.ini"); - ini.Set("Hej", "A", "amaskdfl"); - ini.Set("Mossa", "A", "amaskdfl"); - ini.Set("Aissa", "A", "amaskdfl"); - //ini.Read("my.ini"); - std::string x; - ini.Get("Hej", "B", &x, "boo"); - ini.DeleteKey("Mossa", "A"); - ini.DeleteSection("Mossa"); - ini.SortSections(); - ini.Save("my.ini"); - //UpdateVars(ini); - return 0; - } - */ diff --git a/Common/IniFile.h b/Common/IniFile.h deleted file mode 100644 index 29410e21cc..0000000000 --- a/Common/IniFile.h +++ /dev/null @@ -1,188 +0,0 @@ -// Copyright (C) 2003 Dolphin Project. - -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, version 2.0 or later versions. - -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License 2.0 for more details. - -// A copy of the GPL 2.0 should have been included with the program. -// If not, see http://www.gnu.org/licenses/ - -// Official SVN repository and contact information can be found at -// http://code.google.com/p/dolphin-emu/ - -#ifndef _INIFILE_H_ -#define _INIFILE_H_ - -#include -#include -#include - -#include "StringUtil.h" - -class IniFile -{ -public: - class Section - { - friend class IniFile; - - public: - Section() {} - Section(const std::string& _name) : name(_name) {} - - bool Exists(const char *key) const; - bool Delete(const char *key); - - std::string* GetLine(const char* key, std::string* valueOut, std::string* commentOut); - void Set(const char* key, const char* newValue); - void Set(const char* key, const std::string& newValue, const std::string& defaultValue); - - void Set(const std::string &key, const std::string &value) { - Set(key.c_str(), value.c_str()); - } - bool Get(const char* key, std::string* value, const char* defaultValue); - - void Set(const char* key, u32 newValue) { - Set(key, StringFromFormat("0x%08x", newValue).c_str()); - } - void Set(const char* key, float newValue) { - Set(key, StringFromFormat("%f", newValue).c_str()); - } - void Set(const char* key, const float newValue, const float defaultValue); - void Set(const char* key, double newValue) { - Set(key, StringFromFormat("%f", newValue).c_str()); - } - - void Set(const char* key, int newValue, int defaultValue); - void Set(const char* key, int newValue) { - Set(key, StringFromInt(newValue).c_str()); - } - - void Set(const char* key, bool newValue, bool defaultValue); - void Set(const char* key, bool newValue) { - Set(key, StringFromBool(newValue).c_str()); - } - void Set(const char* key, const std::vector& newValues); - - template - void Set(const char* key, const std::map& newValues) - { - std::vector temp; - for(typename std::map::const_iterator it = newValues.begin(); it != newValues.end(); it++) - { - temp.push_back(ValueToString(it->first)+"_"+ValueToString(it->second)); - } - Set(key,temp); - } - - bool Get(const char* key, int* value, int defaultValue = 0); - bool Get(const char* key, u32* value, u32 defaultValue = 0); - bool Get(const char* key, bool* value, bool defaultValue = false); - bool Get(const char* key, float* value, float defaultValue = false); - bool Get(const char* key, double* value, double defaultValue = false); - bool Get(const char* key, std::vector& values); - template - bool Get(const char* key, std::map& values) - { - std::vector temp; - if(!Get(key,temp)) - { - return false; - } - values.clear(); - for(size_t i = 0; i < temp.size(); i++) - { - std::vector key_val; - SplitString(temp[i],'_',key_val); - if(key_val.size() < 2) - continue; - U mapKey; - V mapValue; - if(!TryParse(key_val[0],&mapKey)) - continue; - if(!TryParse(key_val[1],&mapValue)) - continue; - values[mapKey] = mapValue; - } - return true; - } - - bool operator < (const Section& other) const { - return name < other.name; - } - - protected: - std::vector lines; - std::string name; - std::string comment; - }; - - bool Load(const char* filename); - bool Load(const std::string &filename) { return Load(filename.c_str()); } - bool Save(const char* filename); - bool Save(const std::string &filename) { return Save(filename.c_str()); } - - // Returns true if key exists in section - bool Exists(const char* sectionName, const char* key) const; - - // TODO: Get rid of these, in favor of the Section ones. - void Set(const char* sectionName, const char* key, const char* newValue) { - GetOrCreateSection(sectionName)->Set(key, newValue); - } - void Set(const char* sectionName, const char* key, const std::string& newValue) { - GetOrCreateSection(sectionName)->Set(key, newValue.c_str()); - } - void Set(const char* sectionName, const char* key, int newValue) { - GetOrCreateSection(sectionName)->Set(key, newValue); - } - void Set(const char* sectionName, const char* key, u32 newValue) { - GetOrCreateSection(sectionName)->Set(key, newValue); - } - void Set(const char* sectionName, const char* key, bool newValue) { - GetOrCreateSection(sectionName)->Set(key, newValue); - } - void Set(const char* sectionName, const char* key, const std::vector& newValues) { - GetOrCreateSection(sectionName)->Set(key, newValues); - } - - // TODO: Get rid of these, in favor of the Section ones. - bool Get(const char* sectionName, const char* key, std::string* value, const char* defaultValue = ""); - bool Get(const char* sectionName, const char* key, int* value, int defaultValue = 0); - bool Get(const char* sectionName, const char* key, u32* value, u32 defaultValue = 0); - bool Get(const char* sectionName, const char* key, bool* value, bool defaultValue = false); - bool Get(const char* sectionName, const char* key, std::vector& values); - - template bool GetIfExists(const char* sectionName, const char* key, T value) - { - if (Exists(sectionName, key)) - return Get(sectionName, key, value); - return false; - } - - bool GetKeys(const char* sectionName, std::vector& keys) const; - - void SetLines(const char* sectionName, const std::vector &lines); - bool GetLines(const char* sectionName, std::vector& lines, const bool remove_comments = true) const; - - bool DeleteKey(const char* sectionName, const char* key); - bool DeleteSection(const char* sectionName); - - void SortSections(); - - Section* GetOrCreateSection(const char* section); - -private: - std::vector
sections; - - const Section* GetSection(const char* section) const; - Section* GetSection(const char* section); - std::string* GetLine(const char* section, const char* key); - void CreateSection(const char* section); -}; - -#endif // _INIFILE_H_ diff --git a/Common/LogManager.h b/Common/LogManager.h index faf94f798a..dc801043ed 100644 --- a/Common/LogManager.h +++ b/Common/LogManager.h @@ -15,14 +15,13 @@ // Official SVN repository and contact information can be found at // http://code.google.com/p/dolphin-emu/ -#ifndef _LOGMANAGER_H_ -#define _LOGMANAGER_H_ +#pragma once #include "Log.h" #include "StringUtil.h" #include "Thread.h" #include "FileUtil.h" -#include "IniFile.h" +#include "file/ini_file.h" #include #include @@ -191,5 +190,3 @@ public: void SaveConfig(IniFile::Section *section); void LoadConfig(IniFile::Section *section); }; - -#endif // _LOGMANAGER_H_ diff --git a/Common/StringUtil.cpp b/Common/StringUtil.cpp index 4c8662d2e0..ca63120278 100644 --- a/Common/StringUtil.cpp +++ b/Common/StringUtil.cpp @@ -51,134 +51,6 @@ bool CharArrayFromFormatV(char* out, int outsize, const char* format, va_list ar } } -std::string StringFromFormat(const char* format, ...) -{ - va_list args; - char *buf = NULL; - std::string temp = ""; -#ifdef _WIN32 - int required = 0; - - va_start(args, format); - required = _vscprintf(format, args); - buf = new char[required + 1]; - if(vsnprintf(buf, required, format, args) < 0) - buf[0] = '\0'; - va_end(args); - - buf[required] = '\0'; - temp = buf; - delete[] buf; -#else - va_start(args, format); - if(vasprintf(&buf, format, args) < 0) - buf = NULL; - va_end(args); - - if(buf != NULL) { - temp = buf; - free(buf); - } -#endif - return temp; -} - -// For Debugging. Read out an u8 array. -std::string ArrayToString(const u8 *data, u32 size, int line_len, bool spaces) -{ - std::ostringstream oss; - oss << std::setfill('0') << std::hex; - - for (int line = 0; size; ++data, --size) - { - oss << std::setw(2) << (int)*data; - if (line_len == ++line) - { - oss << '\n'; - line = 0; - } - else if (spaces) - oss << ' '; - } - - return oss.str(); -} - -// Turns " hej " into "hej". Also handles tabs. -std::string StripSpaces(const std::string &str) -{ - const size_t s = str.find_first_not_of(" \t\r\n"); - - if (str.npos != s) - return str.substr(s, str.find_last_not_of(" \t\r\n") - s + 1); - else - return ""; -} - -// "\"hello\"" is turned to "hello" -// This one assumes that the string has already been space stripped in both -// ends, as done by StripSpaces above, for example. -std::string StripQuotes(const std::string& s) -{ - if (s.size() && '\"' == s[0] && '\"' == *s.rbegin()) - return s.substr(1, s.size() - 2); - else - return s; -} - -bool TryParse(const std::string &str, u32 *const output) -{ - char *endptr = NULL; - - // Reset errno to a value other than ERANGE - errno = 0; - - unsigned long value = strtoul(str.c_str(), &endptr, 0); - - if (!endptr || *endptr) - return false; - - if (errno == ERANGE) - return false; - - if (ULONG_MAX > UINT_MAX) { -#ifdef _MSC_VER -#pragma warning (disable:4309) -#endif - // Note: The typecasts avoid GCC warnings when long is 32 bits wide. - if (value >= static_cast(0x100000000ull) - && value <= static_cast(0xFFFFFFFF00000000ull)) - return false; - } - - *output = static_cast(value); - return true; -} - -bool TryParse(const std::string &str, bool *const output) -{ - if ("1" == str || !strcasecmp("true", str.c_str())) - *output = true; - else if ("0" == str || !strcasecmp("false", str.c_str())) - *output = false; - else - return false; - - return true; -} - -std::string StringFromInt(int value) -{ - char temp[16]; - sprintf(temp, "%i", value); - return temp; -} - -std::string StringFromBool(bool value) -{ - return value ? "True" : "False"; -} - bool SplitPath(const std::string& full_path, std::string* _pPath, std::string* _pFilename, std::string* _pExtension) { if (full_path.empty()) @@ -223,17 +95,6 @@ void BuildCompleteFilename(std::string& _CompleteFilename, const std::string& _P _CompleteFilename += _Filename; } -void SplitString(const std::string& str, const char delim, std::vector& output) -{ - std::istringstream iss(str); - output.resize(1); - - while (std::getline(iss, *output.rbegin(), delim)) - output.push_back(""); - - output.pop_back(); -} - std::string TabsToSpaces(int tab_size, const std::string &in) { const std::string spaces(tab_size, ' '); diff --git a/Common/StringUtil.h b/Common/StringUtil.h index f27678ebf8..bd323d7040 100644 --- a/Common/StringUtil.h +++ b/Common/StringUtil.h @@ -76,12 +76,6 @@ inline void CharArrayFromFormat(char (& out)[Count], const char* format, ...) va_end(args); } -// Good -std::string ArrayToString(const u8 *data, u32 size, int line_len = 20, bool spaces = true); - -std::string StripSpaces(const std::string &s); -std::string StripQuotes(const std::string &s); - // Thousand separator. Turns 12345678 into 12,345,678 template std::string ThousandSeparate(I value, int spaces = 0) @@ -97,42 +91,11 @@ std::string ThousandSeparate(I value, int spaces = 0) return oss.str(); } -std::string StringFromInt(int value); -std::string StringFromBool(bool value); - -bool TryParse(const std::string &str, bool *output); -bool TryParse(const std::string &str, u32 *output); - -template -static bool TryParse(const std::string &str, N *const output) -{ - std::istringstream iss(str); - - N tmp = 0; - if (iss >> tmp) - { - *output = tmp; - return true; - } - else - return false; -} - -template -static std::string ValueToString(const N value) -{ - std::stringstream string; - string << value; - return string.str(); -} - // TODO: kill this bool AsciiToHex(const char* _szValue, u32& result); std::string TabsToSpaces(int tab_size, const std::string &in); -void SplitString(const std::string& str, char delim, std::vector& output); - // "C:/Windows/winhelp.exe" to "C:/Windows/", "winhelp", ".exe" bool SplitPath(const std::string& full_path, std::string* _pPath, std::string* _pFilename, std::string* _pExtension); diff --git a/Core/Config.cpp b/Core/Config.cpp index df352fdeb9..e462c22ada 100644 --- a/Core/Config.cpp +++ b/Core/Config.cpp @@ -18,7 +18,7 @@ #include "Common/FileUtil.h" #include "Config.h" -#include "IniFile.h" +#include "file/ini_file.h" #include "HLE/sceUtility.h" Config g_Config; @@ -56,6 +56,8 @@ void Config::Load(const char *iniFileName) general->Get("IgnoreBadMemAccess", &bIgnoreBadMemAccess, true); general->Get("CurrentDirectory", ¤tDirectory, ""); general->Get("ShowDebuggerOnLoad", &bShowDebuggerOnLoad, false); + general->Get("Language", &languageIni, "en_US"); + // "default" means let emulator decide, "" means disable. general->Get("ReportHost", &sReportHost, "default"); general->Get("Recent", recentIsos); @@ -148,6 +150,7 @@ void Config::Save() general->Set("WindowX", iWindowX); general->Set("WindowY", iWindowY); general->Set("AutoSaveSymbolMap", bAutoSaveSymbolMap); + general->Set("Language", languageIni); IniFile::Section *cpu = iniFile.GetOrCreateSection("CPU"); cpu->Set("Jit", bJit); diff --git a/Core/Config.h b/Core/Config.h index 8b9e5cfb53..560e5ee713 100644 --- a/Core/Config.h +++ b/Core/Config.h @@ -47,6 +47,7 @@ public: bool bAutoSaveSymbolMap; std::string sReportHost; std::vector recentIsos; + std::string languageIni; // GFX bool bDisplayFramebuffer; diff --git a/UI/MenuScreens.cpp b/UI/MenuScreens.cpp index 0d84e8c663..1812951ec6 100644 --- a/UI/MenuScreens.cpp +++ b/UI/MenuScreens.cpp @@ -34,6 +34,7 @@ namespace MainWindow { #include "base/colorutil.h" #include "base/timeutil.h" #include "base/NativeApp.h" +#include "i18n/i18n.h" #include "gfx_es2/glsl_program.h" #include "gfx_es2/gl_state.h" #include "input/input_state.h" @@ -204,7 +205,9 @@ void MenuScreen::render() { ui_draw2d.SetFontScale(1.0f, 1.0f); VLinear vlinear(dp_xres + xoff, 100, 20); - if (UIButton(GEN_ID, vlinear, w, 0, "Load...", ALIGN_RIGHT)) { + I18NCategory *m = GetI18NCategory("MainMenu"); + + if (UIButton(GEN_ID, vlinear, w, 0, m->T("Load", "Load..."), ALIGN_RIGHT)) { #if defined(USING_QT_UI) && !defined(MEEGO_EDITION_HARMATTAN) QString fileName = QFileDialog::getOpenFileName(NULL, "Load ROM", g_Config.currentDirectory.c_str(), "PSP ROMs (*.iso *.cso *.pbp *.elf)"); if (QFile::exists(fileName)) { @@ -229,17 +232,17 @@ void MenuScreen::render() { UIReset(); } - if (UIButton(GEN_ID, vlinear, w, 0, "Settings", ALIGN_RIGHT)) { + if (UIButton(GEN_ID, vlinear, w, 0, m->T("Settings"), ALIGN_RIGHT)) { screenManager()->push(new SettingsScreen(), 0); UIReset(); } - if (UIButton(GEN_ID, vlinear, w, 0, "Credits", ALIGN_RIGHT)) { + if (UIButton(GEN_ID, vlinear, w, 0, m->T("Credits"), ALIGN_RIGHT)) { screenManager()->switchScreen(new CreditsScreen()); UIReset(); } - if (UIButton(GEN_ID, vlinear, w, 0, "Exit", ALIGN_RIGHT)) { + if (UIButton(GEN_ID, vlinear, w, 0, m->T("Exit"), ALIGN_RIGHT)) { // TODO: Save when setting changes, rather than when we quit NativeShutdown(); // TODO: Need a more elegant way to quit @@ -256,7 +259,7 @@ void MenuScreen::render() { int recentW = 350; if (g_Config.recentIsos.size()) { - ui_draw2d.DrawText(UBUNTU24, "Recent", -xoff, 80, 0xFFFFFFFF, ALIGN_BOTTOMLEFT); + ui_draw2d.DrawText(UBUNTU24, m->T("Recent"), -xoff, 80, 0xFFFFFFFF, ALIGN_BOTTOMLEFT); } int spacing = 15; @@ -383,43 +386,50 @@ void PauseScreen::render() { int y = 50; int stride = 40; int columnw = 400; - UICheckBox(GEN_ID, x, y += stride, "Show Debug Statistics", ALIGN_TOPLEFT, &g_Config.bShowDebugStats); - UICheckBox(GEN_ID, x, y += stride, "Show FPS", ALIGN_TOPLEFT, &g_Config.bShowFPSCounter); + + // Shared with settings + I18NCategory *ss = GetI18NCategory("System"); + I18NCategory *gs = GetI18NCategory("Graphics"); + + UICheckBox(GEN_ID, x, y += stride, ss->T("Show Debug Statistics"), ALIGN_TOPLEFT, &g_Config.bShowDebugStats); + UICheckBox(GEN_ID, x, y += stride, ss->T("Show FPS"), ALIGN_TOPLEFT, &g_Config.bShowFPSCounter); // TODO: Maybe shouldn't show this if the screen ratios are very close... - UICheckBox(GEN_ID, x, y += stride, "Stretch to display", ALIGN_TOPLEFT, &g_Config.bStretchToDisplay); + UICheckBox(GEN_ID, x, y += stride, gs->T("Stretch to Display"), ALIGN_TOPLEFT, &g_Config.bStretchToDisplay); - UICheckBox(GEN_ID, x, y += stride, "Hardware Transform", ALIGN_TOPLEFT, &g_Config.bHardwareTransform); - if (UICheckBox(GEN_ID, x, y += stride, "Buffered Rendering", ALIGN_TOPLEFT, &g_Config.bBufferedRendering)) { + UICheckBox(GEN_ID, x, y += stride, gs->T("Hardware Transform"), ALIGN_TOPLEFT, &g_Config.bHardwareTransform); + if (UICheckBox(GEN_ID, x, y += stride, gs->T("Buffered Rendering"), ALIGN_TOPLEFT, &g_Config.bBufferedRendering)) { if (gpu) gpu->Resized(); } bool fs = g_Config.iFrameSkip == 1; - UICheckBox(GEN_ID, x, y += stride, "Frame Skipping", ALIGN_TOPLEFT, &fs); - UICheckBox(GEN_ID, x, y += stride, "Use Media Engine", ALIGN_TOPLEFT, &g_Config.bUseMediaEngine); + UICheckBox(GEN_ID, x, y += stride, gs->T("Frame Skipping"), ALIGN_TOPLEFT, &fs); + UICheckBox(GEN_ID, x, y += stride, gs->T("Media Engine"), ALIGN_TOPLEFT, &g_Config.bUseMediaEngine); g_Config.iFrameSkip = fs ? 1 : 0; + I18NCategory *i = GetI18NCategory("PauseScreen"); + // TODO: Add UI for more than one slot. HLinear hlinear1(x, y + 80, 20); - if (UIButton(GEN_ID, hlinear1, LARGE_BUTTON_WIDTH, 0, "Save State", ALIGN_LEFT)) { + if (UIButton(GEN_ID, hlinear1, LARGE_BUTTON_WIDTH, 0, i->T("Save State"), ALIGN_LEFT)) { SaveState::SaveSlot(0, 0, 0); screenManager()->finishDialog(this, DR_CANCEL); } - if (UIButton(GEN_ID, hlinear1, LARGE_BUTTON_WIDTH, 0, "Load State", ALIGN_LEFT)) { + if (UIButton(GEN_ID, hlinear1, LARGE_BUTTON_WIDTH, 0, i->T("Load State"), ALIGN_LEFT)) { SaveState::LoadSlot(0, 0, 0); screenManager()->finishDialog(this, DR_CANCEL); } VLinear vlinear(dp_xres - 10, 160, 20); - if (UIButton(GEN_ID, vlinear, LARGE_BUTTON_WIDTH, 0, "Continue", ALIGN_RIGHT)) { + if (UIButton(GEN_ID, vlinear, LARGE_BUTTON_WIDTH, 0, i->T("Continue"), ALIGN_RIGHT)) { screenManager()->finishDialog(this, DR_CANCEL); } - if (UIButton(GEN_ID, vlinear, LARGE_BUTTON_WIDTH, 0, "Settings", ALIGN_RIGHT)) { + if (UIButton(GEN_ID, vlinear, LARGE_BUTTON_WIDTH, 0, i->T("Settings"), ALIGN_RIGHT)) { screenManager()->push(new SettingsScreen(), 0); } - if (UIButton(GEN_ID, vlinear, LARGE_BUTTON_WIDTH, 0, "Back to Menu", ALIGN_RIGHT)) { + if (UIButton(GEN_ID, vlinear, LARGE_BUTTON_WIDTH, 0, i->T("Back to Menu"), ALIGN_RIGHT)) { screenManager()->finishDialog(this, DR_OK); } @@ -446,41 +456,44 @@ void SettingsScreen::render() { UIBegin(UIShader_Get()); DrawBackground(1.0f); - ui_draw2d.DrawText(UBUNTU48, "Settings", dp_xres / 2, 20, 0xFFFFFFFF, ALIGN_HCENTER); + I18NCategory *g = GetI18NCategory("General"); + I18NCategory *ms = GetI18NCategory("MainSettings"); + + ui_draw2d.DrawText(UBUNTU48, ms->T("Settings"), dp_xres / 2, 20, 0xFFFFFFFF, ALIGN_HCENTER); VLinear vlinear(40, 150, 20); - if (UIButton(GEN_ID, Pos(dp_xres - 10, dp_yres-10), LARGE_BUTTON_WIDTH, 0, "Back", ALIGN_RIGHT | ALIGN_BOTTOM)) { + if (UIButton(GEN_ID, Pos(dp_xres - 10, dp_yres-10), LARGE_BUTTON_WIDTH, 0, g->T("Back"), ALIGN_RIGHT | ALIGN_BOTTOM)) { screenManager()->finishDialog(this, DR_OK); } int w = LARGE_BUTTON_WIDTH - 10; int s = 240; - if (UIButton(GEN_ID, vlinear, w, 0, "Audio", ALIGN_BOTTOMLEFT)) { + if (UIButton(GEN_ID, vlinear, w, 0, ms->T("Audio"), ALIGN_BOTTOMLEFT)) { screenManager()->push(new AudioScreen()); } - ui_draw2d.DrawText(UBUNTU24, "Adjust Audio Setting, Toggle Sound Emulation", s, 110, 0xFFFFFFFF, ALIGN_LEFT); + ui_draw2d.DrawText(UBUNTU24, ms->T("AudioDesc", "Adjust Audio Settings"), s, 110, 0xFFFFFFFF, ALIGN_LEFT); - if (UIButton(GEN_ID, vlinear, w, 0, "Graphics", ALIGN_BOTTOMLEFT)) { + if (UIButton(GEN_ID, vlinear, w, 0, ms->T("Graphics"), ALIGN_BOTTOMLEFT)) { screenManager()->push(new GraphicsScreen()); } - ui_draw2d.DrawText(UBUNTU24, "Toggle Vertex Cache, Hardware Transform, VBO", s, 180, 0xFFFFFFFF, ALIGN_LEFT); + ui_draw2d.DrawText(UBUNTU24, ms->T("GraphicsDesc", "Change graphics options"), s, 180, 0xFFFFFFFF, ALIGN_LEFT); - if (UIButton(GEN_ID, vlinear, w, 0, "System", ALIGN_BOTTOMLEFT)) { + if (UIButton(GEN_ID, vlinear, w, 0, ms->T("System"), ALIGN_BOTTOMLEFT)) { screenManager()->push(new SystemScreen()); } - ui_draw2d.DrawText(UBUNTU24, "Turn on Dynarec (JIT), Fast Memory, FPS", s, 250, 0xFFFFFFFF, ALIGN_LEFT); + ui_draw2d.DrawText(UBUNTU24, ms->T("SystemDesc", "Turn on Dynarec (JIT), Fast Memory"), s, 250, 0xFFFFFFFF, ALIGN_LEFT); - if (UIButton(GEN_ID, vlinear, w, 0, "Controls", ALIGN_BOTTOMLEFT)) { + if (UIButton(GEN_ID, vlinear, w, 0, ms->T("Controls"), ALIGN_BOTTOMLEFT)) { screenManager()->push(new ControlsScreen()); } - ui_draw2d.DrawText(UBUNTU24, "Enable On Screen Touch Controls, Analog Stick", s, 320, 0xFFFFFFFF, ALIGN_LEFT); + ui_draw2d.DrawText(UBUNTU24, ms->T("ControlsDesc", "On Screen Controls, Large Buttons"), s, 320, 0xFFFFFFFF, ALIGN_LEFT); - if (UIButton(GEN_ID, vlinear, w, 0, "Developer", ALIGN_BOTTOMLEFT)) { + if (UIButton(GEN_ID, vlinear, w, 0, ms->T("Developer"), ALIGN_BOTTOMLEFT)) { screenManager()->push(new DeveloperScreen()); } - ui_draw2d.DrawText(UBUNTU24, "Run CPU test, Dump Next Frame Log", s, 390, 0xFFFFFFFF, ALIGN_LEFT); + ui_draw2d.DrawText(UBUNTU24, ms->T("DeveloperDesc", "Run CPU test, Dump Next Frame Log"), s, 390, 0xFFFFFFFF, ALIGN_LEFT); UIEnd(); } @@ -527,17 +540,33 @@ void DeveloperScreen::render() { ui_draw2d.DrawText(UBUNTU48, "Developer Tools", dp_xres / 2, 20, 0xFFFFFFFF, ALIGN_HCENTER); VLinear vlinear(50, 100, 20); - if (UIButton(GEN_ID, Pos(dp_xres - 10, dp_yres-10), LARGE_BUTTON_WIDTH, 0, "Back", ALIGN_RIGHT | ALIGN_BOTTOM)) { + int w = 400; + + I18NCategory *g = GetI18NCategory("General"); + I18NCategory *d = GetI18NCategory("Developer"); + + if (UIButton(GEN_ID, Pos(dp_xres - 10, dp_yres-10), LARGE_BUTTON_WIDTH, 0, g->T("Back"), ALIGN_RIGHT | ALIGN_BOTTOM)) { screenManager()->finishDialog(this, DR_OK); } - if (UIButton(GEN_ID, vlinear, LARGE_BUTTON_WIDTH + 20, 0, "Run CPU tests", ALIGN_LEFT)) { + if (UIButton(GEN_ID, vlinear, w, 0, d->T("Load language ini"), ALIGN_LEFT)) { + i18nrepo.LoadIni(g_Config.languageIni); + // After this, g and s are no longer valid. Need to reload them. + g = GetI18NCategory("General"); + d = GetI18NCategory("Developer"); + } + + if (UIButton(GEN_ID, vlinear, w, 0, d->T("Save language ini"), ALIGN_LEFT)) { + i18nrepo.SaveIni(g_Config.languageIni); + } + + if (UIButton(GEN_ID, vlinear, w, 0, d->T("Run CPU tests"), ALIGN_LEFT)) { // TODO: Run tests RunTests(); // screenManager()->push(new EmuScreen()) } - if (UIButton(GEN_ID, vlinear, LARGE_BUTTON_WIDTH + 80, 0, "Dump frame to log", ALIGN_LEFT)) { + if (UIButton(GEN_ID, vlinear, w, 0, d->T("Dump frame to log"), ALIGN_LEFT)) { gpu->DumpNextFrame(); } @@ -549,9 +578,12 @@ void AudioScreen::render() { UIBegin(UIShader_Get()); DrawBackground(1.0f); - ui_draw2d.DrawText(UBUNTU48, "Audio Settings", dp_xres / 2, 20, 0xFFFFFFFF, ALIGN_HCENTER); + I18NCategory *g = GetI18NCategory("General"); + I18NCategory *a = GetI18NCategory("Audio"); - if (UIButton(GEN_ID, Pos(dp_xres - 10, dp_yres-10), LARGE_BUTTON_WIDTH, 0, "Back", ALIGN_RIGHT | ALIGN_BOTTOM)) { + ui_draw2d.DrawText(UBUNTU48, a->T("Audio Settings"), dp_xres / 2, 20, 0xFFFFFFFF, ALIGN_HCENTER); + + if (UIButton(GEN_ID, Pos(dp_xres - 10, dp_yres-10), LARGE_BUTTON_WIDTH, 0, g->T("Back"), ALIGN_RIGHT | ALIGN_BOTTOM)) { screenManager()->finishDialog(this, DR_OK); } @@ -559,7 +591,7 @@ void AudioScreen::render() { int y = 30; int stride = 40; int columnw = 400; - UICheckBox(GEN_ID, x, y += stride, "Enable Sound", ALIGN_TOPLEFT, &g_Config.bEnableSound); + UICheckBox(GEN_ID, x, y += stride, a->T("Enable Sound"), ALIGN_TOPLEFT, &g_Config.bEnableSound); UIEnd(); } @@ -569,9 +601,11 @@ void GraphicsScreen::render() { UIBegin(UIShader_Get()); DrawBackground(1.0f); - ui_draw2d.DrawText(UBUNTU48, "Graphics Settings", dp_xres / 2, 20, 0xFFFFFFFF, ALIGN_HCENTER); + I18NCategory *g = GetI18NCategory("General"); + I18NCategory *gs = GetI18NCategory("Graphics"); + ui_draw2d.DrawText(UBUNTU48, gs->T("Graphics Settings"), dp_xres / 2, 20, 0xFFFFFFFF, ALIGN_HCENTER); - if (UIButton(GEN_ID, Pos(dp_xres - 10, dp_yres-10), LARGE_BUTTON_WIDTH, 0, "Back", ALIGN_RIGHT | ALIGN_BOTTOM)) { + if (UIButton(GEN_ID, Pos(dp_xres - 10, dp_yres-10), LARGE_BUTTON_WIDTH, 0, g->T("Back"), ALIGN_RIGHT | ALIGN_BOTTOM)) { screenManager()->finishDialog(this, DR_OK); } @@ -580,24 +614,24 @@ void GraphicsScreen::render() { int stride = 40; int columnw = 400; - UICheckBox(GEN_ID, x, y += stride, "Vertex Cache", ALIGN_TOPLEFT, &g_Config.bVertexCache); + UICheckBox(GEN_ID, x, y += stride, gs->T("Vertex Cache"), ALIGN_TOPLEFT, &g_Config.bVertexCache); #ifndef __SYMBIAN32__ - UICheckBox(GEN_ID, x, y += stride, "Hardware Transform", ALIGN_TOPLEFT, &g_Config.bHardwareTransform); - UICheckBox(GEN_ID, x, y += stride, "Use Stream VBO", ALIGN_TOPLEFT, &g_Config.bUseVBO); + UICheckBox(GEN_ID, x, y += stride, gs->T("Hardware Transform"), ALIGN_TOPLEFT, &g_Config.bHardwareTransform); + UICheckBox(GEN_ID, x, y += stride, gs->T("Stream VBO"), ALIGN_TOPLEFT, &g_Config.bUseVBO); #endif - UICheckBox(GEN_ID, x, y += stride, "Use Media Engine", ALIGN_TOPLEFT, &g_Config.bUseMediaEngine); - UICheckBox(GEN_ID, x, y += stride, "Linear Filtering", ALIGN_TOPLEFT, &g_Config.bLinearFiltering); + UICheckBox(GEN_ID, x, y += stride, gs->T("Media Engine"), ALIGN_TOPLEFT, &g_Config.bUseMediaEngine); + UICheckBox(GEN_ID, x, y += stride, gs->T("Linear Filtering"), ALIGN_TOPLEFT, &g_Config.bLinearFiltering); bool fs = g_Config.iFrameSkip == 1; - UICheckBox(GEN_ID, x, y += stride, "Frame Skipping", ALIGN_TOPLEFT, &fs); + UICheckBox(GEN_ID, x, y += stride, gs->T("Frame Skipping"), ALIGN_TOPLEFT, &fs); g_Config.iFrameSkip = fs ? 1 : 0; - UICheckBox(GEN_ID, x, y += stride, "MipMapping", ALIGN_TOPLEFT, &g_Config.bMipMap); - if (UICheckBox(GEN_ID, x, y += stride, "Buffered Rendering", ALIGN_TOPLEFT, &g_Config.bBufferedRendering)) { + UICheckBox(GEN_ID, x, y += stride, gs->T("Mipmapping"), ALIGN_TOPLEFT, &g_Config.bMipMap); + if (UICheckBox(GEN_ID, x, y += stride, gs->T("Buffered Rendering"), ALIGN_TOPLEFT, &g_Config.bBufferedRendering)) { if (gpu) gpu->Resized(); } if (g_Config.bBufferedRendering) { bool doubleRes = g_Config.iWindowZoom == 2; - if (UICheckBox(GEN_ID, x, y += stride, "2x Render Resolution", ALIGN_TOPLEFT, &doubleRes)) { + if (UICheckBox(GEN_ID, x, y += stride, gs->T("2X", "2x Render Resolution"), ALIGN_TOPLEFT, &doubleRes)) { if (gpu) gpu->Resized(); } @@ -611,9 +645,12 @@ void SystemScreen::render() { UIBegin(UIShader_Get()); DrawBackground(1.0f); - ui_draw2d.DrawText(UBUNTU48, "System Settings", dp_xres / 2, 20, 0xFFFFFFFF, ALIGN_HCENTER); + I18NCategory *s = GetI18NCategory("System"); + I18NCategory *g = GetI18NCategory("General"); - if (UIButton(GEN_ID, Pos(dp_xres - 10, dp_yres-10), LARGE_BUTTON_WIDTH, 0, "Back", ALIGN_RIGHT | ALIGN_BOTTOM)) { + ui_draw2d.DrawText(UBUNTU48, s->T("System Settings"), dp_xres / 2, 20, 0xFFFFFFFF, ALIGN_HCENTER); + + if (UIButton(GEN_ID, Pos(dp_xres - 10, dp_yres-10), LARGE_BUTTON_WIDTH, 0, g->T("Back"), ALIGN_RIGHT | ALIGN_BOTTOM)) { screenManager()->finishDialog(this, DR_OK); } @@ -622,11 +659,34 @@ void SystemScreen::render() { int stride = 40; int columnw = 400; - UICheckBox(GEN_ID, x, y += stride, "Dynarec (JIT)", ALIGN_TOPLEFT, &g_Config.bJit); + UICheckBox(GEN_ID, x, y += stride, s->T("Dynarec", "Dynarec (JIT)"), ALIGN_TOPLEFT, &g_Config.bJit); if (g_Config.bJit) - UICheckBox(GEN_ID, x, y += stride, "Fast Memory (unstable)", ALIGN_TOPLEFT, &g_Config.bFastMemory); - UICheckBox(GEN_ID, x, y += stride, "Show Debug Statistics", ALIGN_TOPLEFT, &g_Config.bShowDebugStats); - UICheckBox(GEN_ID, x, y += stride, "Show FPS", ALIGN_TOPLEFT, &g_Config.bShowFPSCounter); + UICheckBox(GEN_ID, x, y += stride, s->T("Fast Memory", "Fast Memory (unstable)"), ALIGN_TOPLEFT, &g_Config.bFastMemory); + UICheckBox(GEN_ID, x, y += stride, s->T("Show Debug Statistics"), ALIGN_TOPLEFT, &g_Config.bShowDebugStats); + UICheckBox(GEN_ID, x, y += stride, s->T("Show FPS"), ALIGN_TOPLEFT, &g_Config.bShowFPSCounter); + + // TODO: Make a dynamic language selector that looks for INI files. + + VLinear vlang(500, 70, 10); + if (UIButton(GEN_ID, vlang, LARGE_BUTTON_WIDTH, 0, "English", ALIGN_TOPLEFT)) { + g_Config.languageIni = "en_US"; + i18nrepo.LoadIni(g_Config.languageIni); + // After this, g and s are no longer valid. Let's return, some flicker is okay. + g = GetI18NCategory("General"); + s = GetI18NCategory("System"); + } + if (UIButton(GEN_ID, vlang, LARGE_BUTTON_WIDTH, 0, "Swedish", ALIGN_TOPLEFT)) { + g_Config.languageIni = "sv_SE"; + i18nrepo.LoadIni(g_Config.languageIni); + g = GetI18NCategory("General"); + s = GetI18NCategory("System"); + } + if (UIButton(GEN_ID, vlang, LARGE_BUTTON_WIDTH, 0, "German", ALIGN_TOPLEFT)) { + g_Config.languageIni = "de_DE"; + i18nrepo.LoadIni(g_Config.languageIni); + g = GetI18NCategory("General"); + s = GetI18NCategory("System"); + } UIEnd(); } @@ -635,9 +695,12 @@ void ControlsScreen::render() { UIBegin(UIShader_Get()); DrawBackground(1.0f); - ui_draw2d.DrawText(UBUNTU48, "Controls Settings", dp_xres / 2, 20, 0xFFFFFFFF, ALIGN_HCENTER); + I18NCategory *c = GetI18NCategory("Controls"); + I18NCategory *g = GetI18NCategory("General"); - if (UIButton(GEN_ID, Pos(dp_xres - 10, dp_yres-10), LARGE_BUTTON_WIDTH, 0, "Back", ALIGN_RIGHT | ALIGN_BOTTOM)) { + ui_draw2d.DrawText(UBUNTU48, c->T("Controls Settings"), dp_xres / 2, 20, 0xFFFFFFFF, ALIGN_HCENTER); + + if (UIButton(GEN_ID, Pos(dp_xres - 10, dp_yres-10), LARGE_BUTTON_WIDTH, 0, g->T("Back"), ALIGN_RIGHT | ALIGN_BOTTOM)) { screenManager()->finishDialog(this, DR_OK); } @@ -646,14 +709,14 @@ void ControlsScreen::render() { int stride = 40; int columnw = 440; - UICheckBox(GEN_ID, x, y += stride, "On-screen Touch Controls", ALIGN_TOPLEFT, &g_Config.bShowTouchControls); + UICheckBox(GEN_ID, x, y += stride, c->T("OnScreen", "On-Screen Touch Controls"), ALIGN_TOPLEFT, &g_Config.bShowTouchControls); if (g_Config.bShowTouchControls) { - UICheckBox(GEN_ID, x + columnw, y, "Large Controls", ALIGN_TOPLEFT, &g_Config.bLargeControls); - UICheckBox(GEN_ID, x + columnw, y += stride, "Show Analog Stick", ALIGN_TOPLEFT, &g_Config.bShowAnalogStick); + UICheckBox(GEN_ID, x + columnw, y, c->T("Large Controls"), ALIGN_TOPLEFT, &g_Config.bLargeControls); + UICheckBox(GEN_ID, x + columnw, y += stride, c->T("Show Analog Stick"), ALIGN_TOPLEFT, &g_Config.bShowAnalogStick); } else { y += stride; } - UICheckBox(GEN_ID, x, y, "Tilt to Analog (horizontal)", ALIGN_TOPLEFT, &g_Config.bAccelerometerToAnalogHoriz); + UICheckBox(GEN_ID, x, y, c->T("Tilt", "Tilt to Analog (horizontal)"), ALIGN_TOPLEFT, &g_Config.bAccelerometerToAnalogHoriz); UIEnd(); } @@ -740,6 +803,8 @@ void FileSelectScreen::update(InputState &input_state) { void FileSelectScreen::render() { FileListAdapter adapter(options_, &listing_, screenManager()->getUIContext()); + I18NCategory *g = GetI18NCategory("General"); + UIShader_Prepare(); UIBegin(UIShader_Get()); DrawBackground(1.0f); @@ -762,13 +827,12 @@ void FileSelectScreen::render() { ui_draw2d.DrawImageStretch(I_BUTTON, 0, 0, dp_xres, 70); - if (UIButton(GEN_ID, Pos(10,10), SMALL_BUTTON_WIDTH, 0, "Up", ALIGN_TOPLEFT)) { + if (UIButton(GEN_ID, Pos(10,10), SMALL_BUTTON_WIDTH, 0, g->T("Up"), ALIGN_TOPLEFT)) { currentDirectory_ = getDir(currentDirectory_); updateListing(); } ui_draw2d.DrawTextShadow(UBUNTU24, currentDirectory_.c_str(), 20 + SMALL_BUTTON_WIDTH, 10 + 25, 0xFFFFFFFF, ALIGN_LEFT | ALIGN_VCENTER); - - if (UIButton(GEN_ID, Pos(dp_xres - 10, 10), SMALL_BUTTON_WIDTH, 0, "Back", ALIGN_RIGHT)) { + if (UIButton(GEN_ID, Pos(dp_xres - 10, 10), SMALL_BUTTON_WIDTH, 0, g->T("Back"), ALIGN_RIGHT)) { g_Config.Save(); screenManager()->switchScreen(new MenuScreen()); } @@ -871,8 +935,9 @@ void CreditsScreen::render() { } y += itemHeight; } + I18NCategory *g = GetI18NCategory("General"); - if (UIButton(GEN_ID, Pos(dp_xres - 10, dp_yres - 10), 200, 0, "Back", ALIGN_BOTTOMRIGHT)) { + if (UIButton(GEN_ID, Pos(dp_xres - 10, dp_yres - 10), 200, 0, g->T("Back"), ALIGN_BOTTOMRIGHT)) { screenManager()->switchScreen(new MenuScreen()); } @@ -894,7 +959,9 @@ void ErrorScreen::render() ui_draw2d.DrawText(UBUNTU48, errorTitle_.c_str(), dp_xres / 2, 30, 0xFFFFFFFF, ALIGN_HCENTER); ui_draw2d.DrawText(UBUNTU24, errorMessage_.c_str(), 40, 120, 0xFFFFFFFF, ALIGN_LEFT); - if (UIButton(GEN_ID, Pos(dp_xres - 10, dp_yres - 10), 200, 0, "Back", ALIGN_BOTTOMRIGHT)) { + I18NCategory *g = GetI18NCategory("General"); + + if (UIButton(GEN_ID, Pos(dp_xres - 10, dp_yres - 10), 200, 0, g->T("Back"), ALIGN_BOTTOMRIGHT)) { screenManager()->finishDialog(this, DR_OK); } diff --git a/UI/NativeApp.cpp b/UI/NativeApp.cpp index 4c844321d0..a0b840e04e 100644 --- a/UI/NativeApp.cpp +++ b/UI/NativeApp.cpp @@ -36,6 +36,7 @@ #include "gfx_es2/gl_state.h" #include "gfx/gl_lost_manager.h" #include "gfx/texture.h" +#include "i18n/i18n.h" #include "input/input_state.h" #include "math/math_util.h" #include "math/lin/matrix4x4.h" @@ -328,9 +329,11 @@ void NativeInit(int argc, const char *argv[], const char *savegame_directory, co INFO_LOG(BOOT, "Logger inited."); #endif + i18nrepo.LoadIni(g_Config.languageIni); + if (!boot_filename.empty() && stateToLoad != NULL) SaveState::Load(stateToLoad); - + g_gameInfoCache.Init(); } @@ -477,6 +480,7 @@ void NativeShutdownGraphics() void NativeShutdown() { + i18nrepo.SaveIni("D:\\lang.ini"); g_gameInfoCache.Shutdown(); delete host; diff --git a/Windows/Globals.cpp b/Windows/Globals.cpp index be86385206..7c0016385b 100644 --- a/Windows/Globals.cpp +++ b/Windows/Globals.cpp @@ -18,7 +18,6 @@ #include "Globals.h" #include "MsgHandler.h" -#include "IniFile.h" #ifdef _WIN32 #include diff --git a/Windows/PPSSPP.sln b/Windows/PPSSPP.sln index 50f699bea1..a16438b72d 100644 --- a/Windows/PPSSPP.sln +++ b/Windows/PPSSPP.sln @@ -1,4 +1,4 @@ -Microsoft Visual Studio Solution File, Format Version 11.00 +Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 2012 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "PPSSPPWindows", "PPSSPP.vcxproj", "{567AF8DB-42C1-4D08-96CD-D70A2DFEFC6B}" ProjectSection(ProjectDependencies) = postProject @@ -12,6 +12,9 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "PPSSPPWindows", "PPSSPP.vcx EndProjectSection EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Common", "..\Common\Common.vcxproj", "{3FCDBAE2-5103-4350-9A8E-848CE9C73195}" + ProjectSection(ProjectDependencies) = postProject + {C4DF647E-80EA-4111-A0A8-218B1B711E18} = {C4DF647E-80EA-4111-A0A8-218B1B711E18} + EndProjectSection EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "zlib", "..\ext\zlib\zlib.vcxproj", "{F761046E-6C38-4428-A5F1-38391A37BB34}" EndProject @@ -42,6 +45,9 @@ EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libkirk", "..\ext\libkirk\libkirk.vcxproj", "{3BAAE095-E0AB-4B0E-B5DF-CE39C8AE31DE}" EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "UnitTest", "..\unittest\UnitTests.vcxproj", "{37CBC214-7CE7-4655-B619-F7CEE16E3313}" + ProjectSection(ProjectDependencies) = postProject + {C4DF647E-80EA-4111-A0A8-218B1B711E18} = {C4DF647E-80EA-4111-A0A8-218B1B711E18} + EndProjectSection EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "UI", "..\UI\UI.vcxproj", "{004B8D11-2BE3-4BD9-AB40-2BE04CF2096F}" ProjectSection(ProjectDependencies) = postProject diff --git a/android/jni/Android.mk b/android/jni/Android.mk index 61343fd780..7cb21f7e51 100644 --- a/android/jni/Android.mk +++ b/android/jni/Android.mk @@ -135,7 +135,6 @@ LOCAL_SRC_FILES := \ $(SRC)/Common/MemArena.cpp \ $(SRC)/Common/MemoryUtil.cpp \ $(SRC)/Common/MsgHandler.cpp \ - $(SRC)/Common/IniFile.cpp \ $(SRC)/Common/FileUtil.cpp \ $(SRC)/Common/StringUtil.cpp \ $(SRC)/Common/Thread.cpp \ diff --git a/lang/de_DE.ini b/lang/de_DE.ini new file mode 100644 index 0000000000..0e3d3a0c11 --- /dev/null +++ b/lang/de_DE.ini @@ -0,0 +1,49 @@ +#Very bad German +[MainMenu] +Credits = Krediten +Exit = Abschliessen +Load = Laden... +Settings = Einstellungen +[Audio] +Audio Settings = Audio Settings +Enable Sound = Enable Sound +[Controls] +Controls Settings = Controls Settings +OnScreen = On-Screen Touch Controls +Tilt = Tilt to Analog (horizontal) +[Developer] +Dump frame to log = Dump frame to log +Load language ini = Load language ini +Run CPU tests = Run CPU tests +Save language ini = Save language ini +[General] +Back = Back +[Graphics] +2X = 2x Render Resolution +Buffered Rendering = Buffered Rendering +Frame Skipping = Frame Skipping +Graphics Settings = Graphics Settings +Hardware Transform = Hardware Transform +Linear Filtering = Linear Filtering +Media Engine = Media Engine +Mipmapping = Mipmapping +Stream VBO = Stream VBO +Vertex Cache = Vertex Cache +[MainSettings] +Audio = Audio +AudioDesc = Adjust Audio Settings +Controls = Controls +ControlsDesc = On Screen Controls, Large Buttons +Developer = Developer +DeveloperDesc = Run CPU test, Dump Next Frame Log +Graphics = Graphics +GraphicsDesc = Change graphics options +Settings = Settings +System = System +SystemDesc = Turn on Dynarec (JIT), Fast Memory +[System] +Dynarec = Dynarec (JIT) +Fast Memory = Fast Memory (unstable) +Show Debug Statistics = Show Debug Statistics +Show FPS = Show FPS +System Settings = System Settings diff --git a/lang/en_US.ini b/lang/en_US.ini new file mode 100644 index 0000000000..609b99e6a2 --- /dev/null +++ b/lang/en_US.ini @@ -0,0 +1,30 @@ +[MainMenu] +Credits = Credits +Exit = Quit +Load = Load... +Settings = Settings +[Developer] +Dump frame to log = Dump frame to log +Load language ini = Load language ini +Run CPU tests = Run CPU tests +Save language ini = Save language ini +[General] +Back = Back +[MainSettings] +Audio = Audio +AudioDesc = Adjust Audio Settings +Controls = Controls +ControlsDesc = On Screen Controls, Large Buttons +Developer = Developer +DeveloperDesc = Run CPU test, Dump Next Frame Log +Graphics = Graphics +GraphicsDesc = Change graphics options +Settings = Settings +System = System +SystemDesc = Turn on Dynarec (JIT), Fast Memory +[System] +Dynarec = Dynarec (JIT) +Fast Memory = Fast Memory (unstable) +Show Debug Statistics = Show Debug Statistics +Show FPS = Show FPS +System Settings = System Settings diff --git a/lang/sv_SE.ini b/lang/sv_SE.ini new file mode 100644 index 0000000000..96f64a9f97 --- /dev/null +++ b/lang/sv_SE.ini @@ -0,0 +1,49 @@ +[General] +Back = Tillbaka +[MainMenu] +Credits = Om +Exit = Avsluta +Load = Ladda... +Settings = Inställningar +Recent = Recent +[Developer] +Dump frame to log = Dumpa frame till logg +Load language ini = Ladda språk-ini +Run CPU tests = Kör CPU-tester +Save language ini = Spara språk-ini +[MainSettings] +Audio = Ljud +Controls = Kontroller +Developer = Developer +Graphics = Grafik +Settings = Inställningar +System = System +AudioDesc = Justera ljud-inställningar +ControlsDesc = Touchkontroller, tilt +DeveloperDesc = Verktyg för utvecklare +GraphicsDesc = Ändra grafikinställningar +SystemDesc = Dynarec (JIT), språk +[System] +Dynarec = Dynarec (JIT) +Fast Memory = Snabbt minne (ostabilt) +Show Debug Statistics = Visa debug-statistik +Show FPS = Visa FPS +System Settings = Systeminställningar +[Audio] +Audio Settings = Ljudinställningar +Enable Sound = Ljud på +[Controls] +Controls Settings = Kontrollinställningar +OnScreen = Touchkontroller på skärmen +Tilt = Tilt till analog stick (horisontell) +[Graphics] +2X = Dubbel upplösning +Buffered Rendering = Buffrad rendering +Frame Skipping = Skippa frames +Graphics Settings = Grafikinställningar +Hardware Transform = Hårdvarutransform +Linear Filtering = Linjärfiltrering +Media Engine = Media Engine +Mipmapping = Mipmappning +Stream VBO = Stream VBO +Vertex Cache = Vertex Cache diff --git a/native b/native index 909b67743e..43b78be9dd 160000 --- a/native +++ b/native @@ -1 +1 @@ -Subproject commit 909b67743e221d8f838ffca384bbe6c9199cface +Subproject commit 43b78be9dd5d343a2133e42501ba9b56552c9d4e diff --git a/unittest/UnitTests.vcxproj b/unittest/UnitTests.vcxproj index 757c39ee66..6b87d33fae 100644 --- a/unittest/UnitTests.vcxproj +++ b/unittest/UnitTests.vcxproj @@ -157,6 +157,9 @@ {533f1d30-d04d-47cc-ad71-20f658907e36} + + {c4df647e-80ea-4111-a0a8-218b1b711e18} +