From 9f74be8fcb3308797a0ceed3e93db9990f890b48 Mon Sep 17 00:00:00 2001 From: scrawl Date: Fri, 1 May 2015 02:04:24 +0200 Subject: [PATCH] Add back the custom MyGUI log facility for utf8 paths on windows --- components/CMakeLists.txt | 2 +- .../myguiplatform/myguiloglistener.cpp | 6 +- components/myguiplatform/myguiloglistener.hpp | 69 +++++++++++++++++++ components/myguiplatform/myguiplatform.hpp | 22 ++++-- libs/openengine/CMakeLists.txt | 2 - libs/openengine/gui/loglistener.hpp | 37 ---------- 6 files changed, 88 insertions(+), 50 deletions(-) rename libs/openengine/gui/loglistener.cpp => components/myguiplatform/myguiloglistener.cpp (78%) create mode 100644 components/myguiplatform/myguiloglistener.hpp delete mode 100644 libs/openengine/gui/loglistener.hpp diff --git a/components/CMakeLists.txt b/components/CMakeLists.txt index 563a77268..ac7eef16a 100644 --- a/components/CMakeLists.txt +++ b/components/CMakeLists.txt @@ -119,7 +119,7 @@ add_component_dir (ogreinit ) add_component_dir (myguiplatform - myguirendermanager myguidatamanager myguiplatform myguitexture + myguirendermanager myguidatamanager myguiplatform myguitexture myguiloglistener ) add_component_dir (widgets diff --git a/libs/openengine/gui/loglistener.cpp b/components/myguiplatform/myguiloglistener.cpp similarity index 78% rename from libs/openengine/gui/loglistener.cpp rename to components/myguiplatform/myguiloglistener.cpp index da36b90a2..b36e0d852 100644 --- a/libs/openengine/gui/loglistener.cpp +++ b/components/myguiplatform/myguiloglistener.cpp @@ -1,11 +1,11 @@ -#include "loglistener.hpp" +#include "myguiloglistener.hpp" #include #include #include -namespace MyGUI +namespace osgMyGUI { void CustomLogListener::open() { @@ -24,7 +24,7 @@ namespace MyGUI mStream.flush(); } - void CustomLogListener::log(const std::string& _section, LogLevel _level, const struct tm* _time, const std::string& _message, const char* _file, int _line) + void CustomLogListener::log(const std::string& _section, MyGUI::LogLevel _level, const struct tm* _time, const std::string& _message, const char* _file, int _line) { if (mStream.is_open()) { diff --git a/components/myguiplatform/myguiloglistener.hpp b/components/myguiplatform/myguiloglistener.hpp new file mode 100644 index 000000000..3da4d3c52 --- /dev/null +++ b/components/myguiplatform/myguiloglistener.hpp @@ -0,0 +1,69 @@ +#ifndef OPENENGINE_MYGUI_LOGLISTENER_H +#define OPENENGINE_MYGUI_LOGLISTENER_H + +#include +#include + +#include +#include +#include +#include + +namespace osgMyGUI +{ + + /// \brief Custom MyGUI::ILogListener interface implementation + /// being able to portably handle UTF-8 encoded path. + /// \todo try patching MyGUI to make this easier + class CustomLogListener : public MyGUI::ILogListener + { + public: + CustomLogListener(const std::string &name) + : mFileName(name) + {} + + ~CustomLogListener() {} + + virtual void open(); + virtual void close(); + virtual void flush(); + + virtual void log(const std::string& _section, MyGUI::LogLevel _level, const struct tm* _time, const std::string& _message, const char* _file, int _line); + + const std::string& getFileName() const { return mFileName; } + + private: + boost::filesystem::ofstream mStream; + std::string mFileName; + }; + + /// \brief Helper class holding data that required during + /// MyGUI log creation + class LogFacility + { + MyGUI::ConsoleLogListener mConsole; + CustomLogListener mFile; + MyGUI::LevelLogFilter mFilter; + MyGUI::LogSource mSource; + + public: + + LogFacility(const std::string &output, bool console) + : mFile(output) + { + mConsole.setEnabled(console); + mFilter.setLoggingLevel(MyGUI::LogLevel::Info); + + mSource.addLogListener(&mFile); + mSource.addLogListener(&mConsole); + mSource.setLogFilter(&mFilter); + + mSource.open(); + } + + MyGUI::LogSource *getSource() { return &mSource; } + }; + +} + +#endif diff --git a/components/myguiplatform/myguiplatform.hpp b/components/myguiplatform/myguiplatform.hpp index 5079b23b0..c0c9e0ce4 100644 --- a/components/myguiplatform/myguiplatform.hpp +++ b/components/myguiplatform/myguiplatform.hpp @@ -6,6 +6,7 @@ #include "myguirendermanager.hpp" #include "myguidatamanager.hpp" +#include "myguiloglistener.hpp" namespace osgMyGUI { @@ -13,10 +14,11 @@ namespace osgMyGUI class Platform { public: - Platform(osgViewer::Viewer* viewer, osg::Group* guiRoot, Resource::TextureManager* textureManager) : - mLogManager(nullptr), - mRenderManager(nullptr), - mDataManager(nullptr) + Platform(osgViewer::Viewer* viewer, osg::Group* guiRoot, Resource::TextureManager* textureManager) + : mRenderManager(nullptr) + , mDataManager(nullptr) + , mLogManager(nullptr) + , mLogFacility(nullptr) { mLogManager = new MyGUI::LogManager(); mRenderManager = new RenderManager(viewer, guiRoot, textureManager); @@ -31,12 +33,17 @@ namespace osgMyGUI mDataManager = nullptr; delete mLogManager; mLogManager = nullptr; + delete mLogFacility; + mLogFacility = nullptr; } void initialise(const std::string& resourcePath, const std::string& _logName = "MyGUI.log") { - if (!_logName.empty()) - MyGUI::LogManager::getInstance().createDefaultSource(_logName); + if (!_logName.empty() && !mLogFacility) + { + mLogFacility = new LogFacility(_logName, false); + mLogManager->addLogSource(mLogFacility->getSource()); + } mDataManager->setResourcePath(resourcePath); @@ -46,7 +53,7 @@ namespace osgMyGUI void shutdown() { - //mRenderManager->shutdown(); + mRenderManager->shutdown(); mDataManager->shutdown(); } @@ -64,6 +71,7 @@ namespace osgMyGUI RenderManager* mRenderManager; DataManager* mDataManager; MyGUI::LogManager* mLogManager; + LogFacility* mLogFacility; }; } diff --git a/libs/openengine/CMakeLists.txt b/libs/openengine/CMakeLists.txt index 07ac60bc6..fa3df0820 100644 --- a/libs/openengine/CMakeLists.txt +++ b/libs/openengine/CMakeLists.txt @@ -1,6 +1,4 @@ set(OENGINE_GUI - gui/loglistener.cpp - #gui/manager.cpp gui/layout.cpp ) diff --git a/libs/openengine/gui/loglistener.hpp b/libs/openengine/gui/loglistener.hpp deleted file mode 100644 index 47978ba44..000000000 --- a/libs/openengine/gui/loglistener.hpp +++ /dev/null @@ -1,37 +0,0 @@ -#ifndef OPENENGINE_MYGUI_LOGLISTENER_H -#define OPENENGINE_MYGUI_LOGLISTENER_H - -#include -#include - -#include - -namespace MyGUI -{ - /// \brief Custom MyGUI::ILogListener interface implementation - /// being able to portably handle UTF-8 encoded path. - class CustomLogListener : public ILogListener - { - public: - CustomLogListener(const std::string &name) - : mFileName(name) - {} - - ~CustomLogListener() {} - - virtual void open(); - virtual void close(); - virtual void flush(); - - virtual void log(const std::string& _section, LogLevel _level, const struct tm* _time, const std::string& _message, const char* _file, int _line); - - const std::string& getFileName() const { return mFileName; } - - private: - boost::filesystem::ofstream mStream; - std::string mFileName; - }; - -} - -#endif