mirror of
https://github.com/OpenMW/openmw.git
synced 2025-02-07 04:15:34 +00:00
Add back the custom MyGUI log facility for utf8 paths on windows
This commit is contained in:
parent
6afb0e43ef
commit
9f74be8fcb
6 changed files with 88 additions and 50 deletions
|
@ -119,7 +119,7 @@ add_component_dir (ogreinit
|
||||||
)
|
)
|
||||||
|
|
||||||
add_component_dir (myguiplatform
|
add_component_dir (myguiplatform
|
||||||
myguirendermanager myguidatamanager myguiplatform myguitexture
|
myguirendermanager myguidatamanager myguiplatform myguitexture myguiloglistener
|
||||||
)
|
)
|
||||||
|
|
||||||
add_component_dir (widgets
|
add_component_dir (widgets
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
#include "loglistener.hpp"
|
#include "myguiloglistener.hpp"
|
||||||
|
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
#include <boost/filesystem/path.hpp>
|
#include <boost/filesystem/path.hpp>
|
||||||
|
|
||||||
namespace MyGUI
|
namespace osgMyGUI
|
||||||
{
|
{
|
||||||
void CustomLogListener::open()
|
void CustomLogListener::open()
|
||||||
{
|
{
|
||||||
|
@ -24,7 +24,7 @@ namespace MyGUI
|
||||||
mStream.flush();
|
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())
|
if (mStream.is_open())
|
||||||
{
|
{
|
69
components/myguiplatform/myguiloglistener.hpp
Normal file
69
components/myguiplatform/myguiloglistener.hpp
Normal file
|
@ -0,0 +1,69 @@
|
||||||
|
#ifndef OPENENGINE_MYGUI_LOGLISTENER_H
|
||||||
|
#define OPENENGINE_MYGUI_LOGLISTENER_H
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <boost/filesystem/fstream.hpp>
|
||||||
|
|
||||||
|
#include <MyGUI_ILogListener.h>
|
||||||
|
#include <MyGUI_LogSource.h>
|
||||||
|
#include <MyGUI_ConsoleLogListener.h>
|
||||||
|
#include <MyGUI_LevelLogFilter.h>
|
||||||
|
|
||||||
|
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
|
|
@ -6,6 +6,7 @@
|
||||||
|
|
||||||
#include "myguirendermanager.hpp"
|
#include "myguirendermanager.hpp"
|
||||||
#include "myguidatamanager.hpp"
|
#include "myguidatamanager.hpp"
|
||||||
|
#include "myguiloglistener.hpp"
|
||||||
|
|
||||||
namespace osgMyGUI
|
namespace osgMyGUI
|
||||||
{
|
{
|
||||||
|
@ -13,10 +14,11 @@ namespace osgMyGUI
|
||||||
class Platform
|
class Platform
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Platform(osgViewer::Viewer* viewer, osg::Group* guiRoot, Resource::TextureManager* textureManager) :
|
Platform(osgViewer::Viewer* viewer, osg::Group* guiRoot, Resource::TextureManager* textureManager)
|
||||||
mLogManager(nullptr),
|
: mRenderManager(nullptr)
|
||||||
mRenderManager(nullptr),
|
, mDataManager(nullptr)
|
||||||
mDataManager(nullptr)
|
, mLogManager(nullptr)
|
||||||
|
, mLogFacility(nullptr)
|
||||||
{
|
{
|
||||||
mLogManager = new MyGUI::LogManager();
|
mLogManager = new MyGUI::LogManager();
|
||||||
mRenderManager = new RenderManager(viewer, guiRoot, textureManager);
|
mRenderManager = new RenderManager(viewer, guiRoot, textureManager);
|
||||||
|
@ -31,12 +33,17 @@ namespace osgMyGUI
|
||||||
mDataManager = nullptr;
|
mDataManager = nullptr;
|
||||||
delete mLogManager;
|
delete mLogManager;
|
||||||
mLogManager = nullptr;
|
mLogManager = nullptr;
|
||||||
|
delete mLogFacility;
|
||||||
|
mLogFacility = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void initialise(const std::string& resourcePath, const std::string& _logName = "MyGUI.log")
|
void initialise(const std::string& resourcePath, const std::string& _logName = "MyGUI.log")
|
||||||
{
|
{
|
||||||
if (!_logName.empty())
|
if (!_logName.empty() && !mLogFacility)
|
||||||
MyGUI::LogManager::getInstance().createDefaultSource(_logName);
|
{
|
||||||
|
mLogFacility = new LogFacility(_logName, false);
|
||||||
|
mLogManager->addLogSource(mLogFacility->getSource());
|
||||||
|
}
|
||||||
|
|
||||||
mDataManager->setResourcePath(resourcePath);
|
mDataManager->setResourcePath(resourcePath);
|
||||||
|
|
||||||
|
@ -46,7 +53,7 @@ namespace osgMyGUI
|
||||||
|
|
||||||
void shutdown()
|
void shutdown()
|
||||||
{
|
{
|
||||||
//mRenderManager->shutdown();
|
mRenderManager->shutdown();
|
||||||
mDataManager->shutdown();
|
mDataManager->shutdown();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -64,6 +71,7 @@ namespace osgMyGUI
|
||||||
RenderManager* mRenderManager;
|
RenderManager* mRenderManager;
|
||||||
DataManager* mDataManager;
|
DataManager* mDataManager;
|
||||||
MyGUI::LogManager* mLogManager;
|
MyGUI::LogManager* mLogManager;
|
||||||
|
LogFacility* mLogFacility;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,4 @@
|
||||||
set(OENGINE_GUI
|
set(OENGINE_GUI
|
||||||
gui/loglistener.cpp
|
|
||||||
#gui/manager.cpp
|
|
||||||
gui/layout.cpp
|
gui/layout.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -1,37 +0,0 @@
|
||||||
#ifndef OPENENGINE_MYGUI_LOGLISTENER_H
|
|
||||||
#define OPENENGINE_MYGUI_LOGLISTENER_H
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include <boost/filesystem/fstream.hpp>
|
|
||||||
|
|
||||||
#include <MyGUI_ILogListener.h>
|
|
||||||
|
|
||||||
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
|
|
Loading…
Reference in a new issue