|
From: rainbyte <rai...@us...> - 2012-07-17 10:42:51
|
Author: Tapio Vierros <tap...@gm...>
Date: Tue Oct 25 21:21:11 2011 +0300
Added config option to toggle fallback encoding between CP1250 and CP1252.
---
data/schema.xml | 12 ++++++++++--
game/unicode.cc | 11 +++++++++--
2 files changed, 19 insertions(+), 4 deletions(-)
diff --git a/data/schema.xml b/data/schema.xml
index ac324e6..7d5530a 100644
--- a/data/schema.xml
+++ b/data/schema.xml
@@ -75,6 +75,14 @@ to save the current settings to XML.
<short>Hardware MIDI input device</short>
<long>Part of sound card name or its number or empty to use the first available device. Used currently for MIDI drum controllers.</long>
</entry>
+ <entry name="game/fallback_encoding" type="int" value="1">
+ <limits>
+ <enum>CP1250</enum>
+ <enum>CP1252</enum>
+ </limits>
+ <short>Fallback song encoding</short>
+ <long>Pick the text codec used for song files that are not UTF-8.</long>
+ </entry>
<!-- Graphic preferences -->
<entry name="graphic/window_width" type="int" value="800" hidden="true">
@@ -103,8 +111,8 @@ to save the current settings to XML.
<enum>Green/Magenta</enum>
<enum>Over/Under</enum>
</limits>
- <short>Stereo3D type</short>
- <long>Some modes may only get activated in fullscreen mode.</long>
+ <short>Stereo3D type</short>
+ <long>Some modes may only get activated in fullscreen mode.</long>
</entry>
<entry name="graphic/stereo3dseparation" type="float" value="50">
<ui unit=" %" />
diff --git a/game/unicode.cc b/game/unicode.cc
index 95053b0..5fe8c4e 100644
--- a/game/unicode.cc
+++ b/game/unicode.cc
@@ -1,4 +1,5 @@
#include "unicode.hh"
+#include "configuration.hh"
#include <boost/scoped_ptr.hpp>
#include <glibmm/ustring.h>
@@ -7,6 +8,9 @@
#include <stdexcept>
namespace {
+ // Codepage choices from config
+ static const char* codesets[] = { "CP1250", "CP1252" };
+
// Convert a string using Glib, throw exception on error.
// This is in fact (slightly modified) Glib::convert from glibmm.
std::string convert(const std::string& str, const std::string& to_codeset, const std::string& from_codeset) {
@@ -33,9 +37,12 @@ void convertToUTF8(std::stringstream &_stream, std::string _filename) {
_stream.str(data.substr(3)); // Remove BOM if there is one
}
} catch(...) {
- if (!_filename.empty()) std::clog << "unicode/warning: " << _filename << " is not UTF-8.\n Assuming CP1252 for now. Use recode CP1252..UTF-8 */*.txt to convert your files." << std::endl;
+ const char* codeset = codesets[config["game/fallback_encoding"].i()];
+ if (!_filename.empty())
+ std::clog << "unicode/warning: " << _filename << " is not UTF-8.\n Assuming " << codeset
+ << ". Use recode " << codeset << "..UTF-8 */*.txt to convert your files." << std::endl;
try {
- _stream.str(convert(_stream.str(), "UTF-8", "CP1252")); // Convert from Microsoft CP1252
+ _stream.str(convert(_stream.str(), "UTF-8", codeset)); // Convert from fallback encoding
} catch (...) {
// Filter out anything but ASCII
std::string tmp;
|