mirror of
https://github.com/edubart/otclient.git
synced 2025-10-22 23:35:54 +02:00
Fix platform issues regarding charsets
* IMPORTANT: A new dependency is required, boost_locale, comes with boost 1.50.0 or later * Copying and pasting special characters should now work * Running otclient from filepaths with special characters should work now too
This commit is contained in:
@@ -29,26 +29,24 @@
|
||||
#include <framework/core/configmanager.h>
|
||||
#include <framework/luaengine/luainterface.h>
|
||||
#include <framework/platform/crashhandler.h>
|
||||
#include <framework/platform/platform.h>
|
||||
|
||||
#include <boost/locale.hpp>
|
||||
#include <boost/filesystem.hpp>
|
||||
#include <boost/filesystem/fstream.hpp>
|
||||
#include <locale>
|
||||
|
||||
#ifdef FW_NET
|
||||
#include <framework/net/connection.h>
|
||||
#endif
|
||||
|
||||
/* Ugly hack but works. */
|
||||
#if defined __APPLE__ && defined CRASH_HANDLER
|
||||
/* UNIX Crash handler for some reason did not go as expected on a Mac system
|
||||
* TODO: RTFM it.
|
||||
*/
|
||||
#undef CRASH_HANDLER
|
||||
#endif
|
||||
|
||||
void exitSignalHandler(int sig)
|
||||
{
|
||||
static bool signaled = false;
|
||||
switch(sig) {
|
||||
case SIGTERM:
|
||||
case SIGINT:
|
||||
if(!signaled) {
|
||||
if(!signaled && !g_app.isStopping() && !g_app.isTerminated()) {
|
||||
signaled = true;
|
||||
g_dispatcher.addEvent(std::bind(&Application::close, &g_app));
|
||||
}
|
||||
@@ -65,7 +63,7 @@ Application::Application()
|
||||
m_stopping = false;
|
||||
}
|
||||
|
||||
void Application::init(const std::vector<std::string>& args)
|
||||
void Application::init(std::vector<std::string>& args)
|
||||
{
|
||||
// capture exit signals
|
||||
signal(SIGTERM, exitSignalHandler);
|
||||
@@ -75,6 +73,15 @@ void Application::init(const std::vector<std::string>& args)
|
||||
installCrashHandler();
|
||||
#endif
|
||||
|
||||
// setup locale
|
||||
boost::locale::generator locgen;
|
||||
std::locale::global(locgen.generate(""));
|
||||
std::locale utf8Loc = locgen.generate("en_US.UTF-8");
|
||||
boost::filesystem::path::imbue(utf8Loc);
|
||||
|
||||
// process args encoding
|
||||
g_platform.processArgs(args);
|
||||
|
||||
std::string startupOptions;
|
||||
for(uint i=1;i<args.size();++i) {
|
||||
const std::string& arg = args[i];
|
||||
@@ -129,6 +136,9 @@ void Application::terminate()
|
||||
g_lua.terminate();
|
||||
|
||||
m_terminated = true;
|
||||
|
||||
signal(SIGTERM, SIG_DFL);
|
||||
signal(SIGINT, SIG_DFL);
|
||||
}
|
||||
|
||||
void Application::poll()
|
||||
@@ -142,8 +152,8 @@ void Application::poll()
|
||||
|
||||
void Application::exit()
|
||||
{
|
||||
g_logger.info("Exiting application..");
|
||||
m_stopping = true;
|
||||
g_logger.info("Exiting application..");
|
||||
}
|
||||
|
||||
void Application::close()
|
||||
@@ -158,8 +168,10 @@ std::string Application::getOs()
|
||||
return "windows";
|
||||
#elif defined(__APPLE__)
|
||||
return "mac";
|
||||
#else
|
||||
#elif __linux
|
||||
return "linux";
|
||||
#else
|
||||
return "unknown";
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@@ -33,7 +33,7 @@ public:
|
||||
Application();
|
||||
virtual ~Application() {}
|
||||
|
||||
virtual void init(const std::vector<std::string>& args);
|
||||
virtual void init(std::vector<std::string>& args);
|
||||
virtual void deinit();
|
||||
virtual void terminate();
|
||||
virtual void run() = 0;
|
||||
|
@@ -28,6 +28,7 @@
|
||||
#include <framework/ui/uimanager.h>
|
||||
#include <framework/graphics/graphics.h>
|
||||
#include <framework/graphics/particlemanager.h>
|
||||
#include <framework/graphics/texturemanager.h>
|
||||
#include <framework/graphics/painter.h>
|
||||
|
||||
#ifdef FW_SOUND
|
||||
@@ -36,7 +37,7 @@
|
||||
|
||||
GraphicalApplication g_app;
|
||||
|
||||
void GraphicalApplication::init(const std::vector<std::string>& args)
|
||||
void GraphicalApplication::init(std::vector<std::string>& args)
|
||||
{
|
||||
Application::init(args);
|
||||
|
||||
@@ -78,14 +79,14 @@ void GraphicalApplication::terminate()
|
||||
// destroy any remaining widget
|
||||
g_ui.terminate();
|
||||
|
||||
Application::terminate();
|
||||
m_terminated = false;
|
||||
|
||||
#ifdef FW_SOUND
|
||||
// terminate sound
|
||||
g_sounds.terminate();
|
||||
#endif
|
||||
|
||||
Application::terminate();
|
||||
m_terminated = false;
|
||||
|
||||
// terminate graphics
|
||||
m_foreground = nullptr;
|
||||
g_graphics.terminate();
|
||||
@@ -106,16 +107,21 @@ void GraphicalApplication::run()
|
||||
poll();
|
||||
g_clock.update();
|
||||
|
||||
g_lua.callGlobalField("g_app", "onRun");
|
||||
|
||||
// show window
|
||||
g_window.show();
|
||||
|
||||
// run the second poll
|
||||
poll();
|
||||
g_clock.update();
|
||||
|
||||
g_lua.callGlobalField("g_app", "onRun");
|
||||
|
||||
while(!m_stopping) {
|
||||
// poll all events before rendering
|
||||
poll();
|
||||
|
||||
if(g_window.isVisible()) {
|
||||
// the otclient's screen consists of two panes
|
||||
// the screen consists of two panes
|
||||
// background pane - high updated and animated pane (where the game are stuff happens)
|
||||
// foreground pane - steady pane with few animated stuff (UI)
|
||||
bool redraw = false;
|
||||
|
@@ -35,7 +35,7 @@ class GraphicalApplication : public Application
|
||||
};
|
||||
|
||||
public:
|
||||
void init(const std::vector< std::string >& args);
|
||||
void init(std::vector<std::string>& args);
|
||||
void deinit();
|
||||
void terminate();
|
||||
void run();
|
||||
|
@@ -23,8 +23,12 @@
|
||||
#include "logger.h"
|
||||
#include "eventdispatcher.h"
|
||||
|
||||
#include <boost/regex.hpp>
|
||||
#include <framework/core/resourcemanager.h>
|
||||
|
||||
#ifdef FW_GRAPHICS
|
||||
#include <framework/platform/platformwindow.h>
|
||||
#include <framework/luaengine/luainterface.h>
|
||||
#endif
|
||||
|
||||
Logger g_logger;
|
||||
@@ -43,6 +47,21 @@ void Logger::log(Fw::LogLevel level, const std::string& message)
|
||||
const static std::string logPrefixes[] = { "", "", "WARNING: ", "ERROR: ", "FATAL ERROR: " };
|
||||
|
||||
std::string outmsg = logPrefixes[level] + message;
|
||||
|
||||
#if !defined(NDEBUG) && !defined(WIN32)
|
||||
// replace paths for improved debug with vim
|
||||
std::stringstream tmp;
|
||||
boost::smatch m;
|
||||
boost::regex e ("/[^ :]+");
|
||||
while(boost::regex_search(outmsg,m,e)) {
|
||||
tmp << m.prefix().str();
|
||||
tmp << g_resources.getRealDir(m.str()) << m.str();
|
||||
outmsg = m.suffix().str();
|
||||
}
|
||||
if(!tmp.str().empty())
|
||||
outmsg = tmp.str();
|
||||
#endif
|
||||
|
||||
std::cout << outmsg << std::endl;
|
||||
|
||||
if(m_outFile.good()) {
|
||||
@@ -74,16 +93,21 @@ void Logger::log(Fw::LogLevel level, const std::string& message)
|
||||
|
||||
void Logger::logFunc(Fw::LogLevel level, const std::string& message, std::string prettyFunction)
|
||||
{
|
||||
std::stringstream ss;
|
||||
prettyFunction = prettyFunction.substr(0, prettyFunction.find_first_of('('));
|
||||
if(prettyFunction.find_last_of(' ') != std::string::npos)
|
||||
prettyFunction = prettyFunction.substr(prettyFunction.find_last_of(' ') + 1);
|
||||
|
||||
if(!prettyFunction.empty())
|
||||
ss << "[" << prettyFunction << "] ";
|
||||
|
||||
ss << message;
|
||||
log(level, ss.str());
|
||||
std::string out = message;
|
||||
|
||||
if(!prettyFunction.empty()) {
|
||||
if(g_lua.isInCppCallback())
|
||||
out = g_lua.traceback(out, 1);
|
||||
else
|
||||
out += "\nat:\t[C++]: " + prettyFunction;
|
||||
}
|
||||
|
||||
log(level, out);
|
||||
}
|
||||
|
||||
void Logger::fireOldMessages()
|
||||
|
Reference in New Issue
Block a user