Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 8467


Ignore:
Timestamp:
May 12, 2011, 4:35:25 PM (13 years ago)
Author:
rgrieder
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/trunk/src/libraries/core/GUIManager.cc

    r8439 r8467  
    3030#include "GUIManager.h"
    3131
     32#include <fstream>
    3233#include <memory>
    3334#include <boost/bind.hpp>
     
    6263#  include <OgreRoot.h>
    6364#  include <OgreSceneManager.h>
     65#endif
     66
     67#ifdef ORXONOX_PLATFORM_WINDOWS
     68#  include <windows.h>
    6469#endif
    6570
     
    108113            CEGUI::DefaultLogger::logEvent(message, level);
    109114        }
     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
    110174    };
    111175
Note: See TracChangeset for help on using the changeset viewer.