2012-11-22 12:30:02 +00:00
|
|
|
#include "editor.hpp"
|
|
|
|
|
2012-12-04 19:43:47 +00:00
|
|
|
#include <exception>
|
|
|
|
#include <iostream>
|
2014-05-03 11:01:29 +00:00
|
|
|
#include <string>
|
2012-12-04 19:43:47 +00:00
|
|
|
|
2013-08-21 22:14:29 +00:00
|
|
|
#include <QApplication>
|
2013-02-17 13:46:50 +00:00
|
|
|
#include <QIcon>
|
2014-05-03 11:01:29 +00:00
|
|
|
#include <QMetaType>
|
2012-11-22 12:30:02 +00:00
|
|
|
|
2018-08-03 04:58:50 +00:00
|
|
|
#include <components/misc/debugging.hpp>
|
2015-06-20 15:56:42 +00:00
|
|
|
|
2018-08-03 04:58:50 +00:00
|
|
|
#include "model/doc/messages.hpp"
|
2014-05-08 10:42:29 +00:00
|
|
|
#include "model/world/universalid.hpp"
|
|
|
|
|
2018-08-03 04:58:50 +00:00
|
|
|
#include <SDL_messagebox.h>
|
|
|
|
|
2013-11-10 18:19:32 +00:00
|
|
|
#ifdef Q_OS_MAC
|
|
|
|
#include <QDir>
|
2013-11-10 16:39:35 +00:00
|
|
|
#endif
|
|
|
|
|
2014-05-03 11:01:29 +00:00
|
|
|
Q_DECLARE_METATYPE (std::string)
|
|
|
|
|
2012-12-04 19:43:47 +00:00
|
|
|
class Application : public QApplication
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
|
|
|
|
bool notify (QObject *receiver, QEvent *event)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
return QApplication::notify (receiver, event);
|
|
|
|
}
|
|
|
|
catch (const std::exception& exception)
|
|
|
|
{
|
|
|
|
std::cerr << "An exception has been caught: " << exception.what() << std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
Application (int& argc, char *argv[]) : QApplication (argc, argv) {}
|
|
|
|
};
|
|
|
|
|
2012-11-21 16:31:18 +00:00
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
2015-11-12 20:40:59 +00:00
|
|
|
#ifdef Q_OS_MAC
|
|
|
|
setenv("OSG_GL_TEXTURE_STORAGE", "OFF", 0);
|
|
|
|
#endif
|
|
|
|
|
2018-08-03 04:58:50 +00:00
|
|
|
// Some objects used to redirect cout and cerr
|
|
|
|
// Scope must be here, so this still works inside the catch block for logging exceptions
|
|
|
|
std::streambuf* cout_rdbuf = std::cout.rdbuf ();
|
|
|
|
std::streambuf* cerr_rdbuf = std::cerr.rdbuf ();
|
|
|
|
|
|
|
|
#if !(defined(_WIN32) && defined(_DEBUG))
|
|
|
|
boost::iostreams::stream_buffer<Misc::Tee> coutsb;
|
|
|
|
boost::iostreams::stream_buffer<Misc::Tee> cerrsb;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
std::ostream oldcout(cout_rdbuf);
|
|
|
|
std::ostream oldcerr(cerr_rdbuf);
|
|
|
|
|
|
|
|
boost::filesystem::ofstream logfile;
|
|
|
|
|
|
|
|
int ret = 0;
|
2014-12-18 02:24:10 +00:00
|
|
|
try
|
2018-08-03 04:58:50 +00:00
|
|
|
{
|
|
|
|
Files::ConfigurationManager cfgMgr;
|
|
|
|
|
|
|
|
#if defined(_WIN32) && defined(_DEBUG)
|
|
|
|
// Redirect cout and cerr to VS debug output when running in debug mode
|
|
|
|
boost::iostreams::stream_buffer<Misc::DebugOutput> sb;
|
|
|
|
sb.open(Misc::DebugOutput());
|
|
|
|
std::cout.rdbuf (&sb);
|
|
|
|
std::cerr.rdbuf (&sb);
|
|
|
|
#else
|
|
|
|
// Redirect cout and cerr to openmw.log
|
|
|
|
logfile.open (boost::filesystem::path(cfgMgr.getLogPath() / "/openmw-cs.log"));
|
|
|
|
|
|
|
|
coutsb.open (Misc::Tee(logfile, oldcout));
|
|
|
|
cerrsb.open (Misc::Tee(logfile, oldcerr));
|
|
|
|
|
|
|
|
std::cout.rdbuf (&coutsb);
|
|
|
|
std::cerr.rdbuf (&cerrsb);
|
|
|
|
#endif
|
|
|
|
|
2015-03-19 22:27:14 +00:00
|
|
|
// To allow background thread drawing in OSG
|
|
|
|
QApplication::setAttribute(Qt::AA_X11InitThreads, true);
|
|
|
|
|
2014-12-18 02:24:10 +00:00
|
|
|
Q_INIT_RESOURCE (resources);
|
2013-11-02 01:48:30 +00:00
|
|
|
|
2014-12-18 02:24:10 +00:00
|
|
|
qRegisterMetaType<std::string> ("std::string");
|
|
|
|
qRegisterMetaType<CSMWorld::UniversalId> ("CSMWorld::UniversalId");
|
2015-06-20 15:56:42 +00:00
|
|
|
qRegisterMetaType<CSMDoc::Message> ("CSMDoc::Message");
|
2014-05-03 11:01:29 +00:00
|
|
|
|
2014-12-18 02:24:10 +00:00
|
|
|
Application application (argc, argv);
|
2012-11-22 12:30:02 +00:00
|
|
|
|
2014-12-18 02:24:10 +00:00
|
|
|
#ifdef Q_OS_MAC
|
|
|
|
QDir dir(QCoreApplication::applicationDirPath());
|
|
|
|
QDir::setCurrent(dir.absolutePath());
|
|
|
|
#endif
|
2013-11-10 18:19:32 +00:00
|
|
|
|
2015-02-03 12:18:03 +00:00
|
|
|
application.setWindowIcon (QIcon (":./openmw-cs.png"));
|
2013-02-17 13:46:50 +00:00
|
|
|
|
2018-07-05 20:55:19 +00:00
|
|
|
CS::Editor editor(argc, argv);
|
2012-11-21 16:31:18 +00:00
|
|
|
|
2014-12-18 02:24:10 +00:00
|
|
|
if(!editor.makeIPCServer())
|
|
|
|
{
|
|
|
|
editor.connectToIPCServer();
|
|
|
|
return 0;
|
|
|
|
}
|
2018-08-03 04:58:50 +00:00
|
|
|
ret = editor.run();
|
2014-12-18 02:24:10 +00:00
|
|
|
}
|
|
|
|
catch (std::exception& e)
|
2013-09-03 06:44:21 +00:00
|
|
|
{
|
2018-08-03 04:58:50 +00:00
|
|
|
#if (defined(__APPLE__) || defined(__linux) || defined(__unix) || defined(__posix))
|
|
|
|
if (!isatty(fileno(stdin)))
|
|
|
|
#endif
|
|
|
|
SDL_ShowSimpleMessageBox(0, "OpenMW-CS: Fatal error", e.what(), NULL);
|
|
|
|
|
|
|
|
std::cerr << "\nERROR: " << e.what() << std::endl;
|
|
|
|
|
|
|
|
ret = 1;
|
2013-09-03 06:44:21 +00:00
|
|
|
}
|
|
|
|
|
2018-08-03 04:58:50 +00:00
|
|
|
// Restore cout and cerr
|
|
|
|
std::cout.rdbuf(cout_rdbuf);
|
|
|
|
std::cerr.rdbuf(cerr_rdbuf);
|
|
|
|
|
|
|
|
return ret;
|
2013-02-17 13:46:50 +00:00
|
|
|
}
|