Changeset 8467 for code/trunk/src/libraries
- Timestamp:
- May 12, 2011, 4:35:25 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk/src/libraries/core/GUIManager.cc
r8439 r8467 30 30 #include "GUIManager.h" 31 31 32 #include <fstream> 32 33 #include <memory> 33 34 #include <boost/bind.hpp> … … 62 63 # include <OgreRoot.h> 63 64 # include <OgreSceneManager.h> 65 #endif 66 67 #ifdef ORXONOX_PLATFORM_WINDOWS 68 # include <windows.h> 64 69 #endif 65 70 … … 108 113 CEGUI::DefaultLogger::logEvent(message, level); 109 114 } 115 116 /// Carbon copy from CEGUIDefaultLogger.cpp with a bugfix for Windows 117 void setLogFilename(const CEGUI::String& filename, bool append = false) 118 { 119 // Close current log file (if any) 120 if (d_ostream.is_open()) 121 d_ostream.close(); 122 123 #ifdef ORXONOX_PLATFORM_WINDOWS 124 // filename.c_str() is UTF-8 encoded, but Windows expects characters 125 // according to the current codepage or UTF-16 (wchar) 126 d_ostream.open(utf8ToUtf16(filename.c_str()).c_str(), std::ios_base::out | (append ? std::ios_base::app : std::ios_base::trunc)); 127 #else 128 d_ostream.open(filename.c_str(), std::ios_base::out | (append ? std::ios_base::app : std::ios_base::trunc)); 129 #endif 130 if (!d_ostream) 131 ThrowException(General, "Setting the CEGUI log filename failed"); 132 133 // Initialise width for date & time alignment. 134 d_ostream.width(2); 135 136 // Write out cached log strings. 137 if (d_caching) 138 { 139 d_caching = false; 140 141 std::vector<std::pair<CEGUI::String, CEGUI::LoggingLevel> >::iterator it = d_cache.begin(); 142 143 while (it != d_cache.end()) 144 { 145 if (d_level >= it->second) 146 { 147 d_ostream << it->first; 148 // Ensure new event is written to the file, rather than just being buffered. 149 d_ostream.flush(); 150 } 151 ++it; 152 } 153 154 d_cache.clear(); 155 } 156 } 157 158 #ifdef ORXONOX_PLATFORM_WINDOWS 159 /// Converts a UTF-8 character sequence to Windows UTF-16 160 static std::wstring utf8ToUtf16(const std::string& utf8text) 161 { 162 const int textLen = MultiByteToWideChar(CP_UTF8, 0, utf8text.c_str(), 163 utf8text.size() + 1, 0, 0); 164 165 if (textLen == 0) 166 ThrowException(General, "Utf8ToUtf16 - MultiByteToWideChar failed"); 167 168 std::wstring wideStr(textLen, 0); 169 MultiByteToWideChar(CP_UTF8, 0, utf8text.c_str(), utf8text.size() + 1, 170 &wideStr[0], wideStr.size()); 171 return wideStr; 172 } 173 #endif 110 174 }; 111 175
Note: See TracChangeset
for help on using the changeset viewer.