[Orxonox-commit 3787] r8467 - code/trunk/src/libraries/core
rgrieder at orxonox.net
rgrieder at orxonox.net
Thu May 12 16:35:26 CEST 2011
Author: rgrieder
Date: 2011-05-12 16:35:25 +0200 (Thu, 12 May 2011)
New Revision: 8467
Modified:
code/trunk/src/libraries/core/GUIManager.cc
Log:
Bugfix for log file paths containing non ASCII characters.
Only works for Western European Codepage 1252 because it's mostly identical to UTF-32 used in CEGUI.
Modified: code/trunk/src/libraries/core/GUIManager.cc
===================================================================
--- code/trunk/src/libraries/core/GUIManager.cc 2011-05-12 14:15:36 UTC (rev 8466)
+++ code/trunk/src/libraries/core/GUIManager.cc 2011-05-12 14:35:25 UTC (rev 8467)
@@ -29,6 +29,7 @@
#include "GUIManager.h"
+#include <fstream>
#include <memory>
#include <boost/bind.hpp>
#include <OgreRenderQueue.h>
@@ -63,6 +64,10 @@
# include <OgreSceneManager.h>
#endif
+#ifdef ORXONOX_PLATFORM_WINDOWS
+# include <windows.h>
+#endif
+
#include "util/Clock.h"
#include "util/Convert.h"
#include "util/Debug.h"
@@ -107,6 +112,65 @@
CEGUI::DefaultLogger::logEvent(message, level);
}
+
+ /// Carbon copy from CEGUIDefaultLogger.cpp with a bugfix for Windows
+ void setLogFilename(const CEGUI::String& filename, bool append = false)
+ {
+ // Close current log file (if any)
+ if (d_ostream.is_open())
+ d_ostream.close();
+
+#ifdef ORXONOX_PLATFORM_WINDOWS
+ // filename.c_str() is UTF-8 encoded, but Windows expects characters
+ // according to the current codepage or UTF-16 (wchar)
+ d_ostream.open(utf8ToUtf16(filename.c_str()).c_str(), std::ios_base::out | (append ? std::ios_base::app : std::ios_base::trunc));
+#else
+ d_ostream.open(filename.c_str(), std::ios_base::out | (append ? std::ios_base::app : std::ios_base::trunc));
+#endif
+ if (!d_ostream)
+ ThrowException(General, "Setting the CEGUI log filename failed");
+
+ // Initialise width for date & time alignment.
+ d_ostream.width(2);
+
+ // Write out cached log strings.
+ if (d_caching)
+ {
+ d_caching = false;
+
+ std::vector<std::pair<CEGUI::String, CEGUI::LoggingLevel> >::iterator it = d_cache.begin();
+
+ while (it != d_cache.end())
+ {
+ if (d_level >= it->second)
+ {
+ d_ostream << it->first;
+ // Ensure new event is written to the file, rather than just being buffered.
+ d_ostream.flush();
+ }
+ ++it;
+ }
+
+ d_cache.clear();
+ }
+ }
+
+#ifdef ORXONOX_PLATFORM_WINDOWS
+ /// Converts a UTF-8 character sequence to Windows UTF-16
+ static std::wstring utf8ToUtf16(const std::string& utf8text)
+ {
+ const int textLen = MultiByteToWideChar(CP_UTF8, 0, utf8text.c_str(),
+ utf8text.size() + 1, 0, 0);
+
+ if (textLen == 0)
+ ThrowException(General, "Utf8ToUtf16 - MultiByteToWideChar failed");
+
+ std::wstring wideStr(textLen, 0);
+ MultiByteToWideChar(CP_UTF8, 0, utf8text.c_str(), utf8text.size() + 1,
+ &wideStr[0], wideStr.size());
+ return wideStr;
+ }
+#endif
};
#ifdef ORXONOX_OLD_CEGUI
More information about the Orxonox-commit
mailing list