Ejemplo n.º 1
0
extern "C" int main(int argc, char* argv[]) {
	mrb_state* const M = Player::create_vm();
	Player::parse_args(argc, argv, M);

#ifdef GEKKO
	// Init libfat (Mount SD/USB)
	if (!fatInitDefault()) {
		Output::Error("Couldn't mount any storage medium!");
	}
	// Wii doesn't provide a correct working directory before mounting
	char gekko_dir[256];
	getcwd(gekko_dir, 255);
	Main_Data::project_path = gekko_dir;
#endif

#if (defined(_WIN32) && defined(NDEBUG) && defined(WINVER) && WINVER >= 0x0600)
	InitMiniDumpWriter();
#endif

	if(! DisplayUi) {
		DisplayUi.reset(new SdlUi(
			SCREEN_TARGET_WIDTH, SCREEN_TARGET_HEIGHT,
			"EasyRPG Player", !Player::window_flag(M)));
	}

	Player::run(M);

	if(M->exc) {
		mrb_print_error(M);
		return EXIT_FAILURE;
	}

	return EXIT_SUCCESS;
}
Ejemplo n.º 2
0
void Player::Init(int argc, char *argv[]) {
	static bool init = false;

	if (init) return;

#ifdef GEKKO
	// Init libfat (Mount SD/USB)
	if (!fatInitDefault()) {
		Output::Error("Couldn't mount any storage medium!");
	}
#endif

#if (defined(_WIN32) && defined(NDEBUG) && defined(WINVER) && WINVER >= 0x0600)
	InitMiniDumpWriter();
#endif

	ParseCommandLine(argc, argv);

	if (Main_Data::project_path.empty()) {
		// Not overwritten by --project-path
		Main_Data::Init();
	}

	FileFinder::Init();

	DisplayUi.reset();

	if(! DisplayUi) {
		DisplayUi = BaseUi::CreateUi
			(SCREEN_TARGET_WIDTH,
			 SCREEN_TARGET_HEIGHT,
			 game_title,
			 !window_flag,
			 RUN_ZOOM);
	}

	init = true;
}
Ejemplo n.º 3
0
int main( int argc, char ** argv )
{
#if defined (FC_OS_LINUX) || defined(FC_OS_BSD)
    // Make sure to setup the Qt locale system before setting LANG and LC_ALL to C.
    // which is needed to use the system locale settings.
    (void)QLocale::system();
    // http://www.freecadweb.org/tracker/view.php?id=399
    // Because of setting LANG=C the Qt automagic to use the correct encoding
    // for file names is broken. This is a workaround to force the use of UTF-8 encoding
    QFile::setEncodingFunction(myEncoderFunc);
    QFile::setDecodingFunction(myDecoderFunc);
    // Make sure that we use '.' as decimal point. See also
    // http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=559846
    putenv("LC_NUMERIC=C");
    putenv("PYTHONPATH=");
#elif defined(FC_OS_MACOSX)
    (void)QLocale::system();
    putenv("LC_NUMERIC=C");
    putenv("PYTHONPATH=");
#else
    setlocale(LC_NUMERIC, "C");
    _putenv("PYTHONPATH=");
#endif

#if defined (FC_OS_WIN32)
    int argc_ = argc;
    QVector<QByteArray> data;
    QVector<char *> argv_;

    // get the command line arguments as unicode string
    {
        QCoreApplication app(argc, argv);
        QStringList args = app.arguments();
        for (QStringList::iterator it = args.begin(); it != args.end(); ++it) {
            data.push_back(it->toUtf8());
            argv_.push_back(data.back().data());
        }
        argv_.push_back(0); // 0-terminated string
    }
#endif

    // Name and Version of the Application
    App::Application::Config()["ExeName"] = "FreeCAD";
    App::Application::Config()["ExeVendor"] = "FreeCAD";
    App::Application::Config()["AppDataSkipVendor"] = "true";
    App::Application::Config()["MaintainerUrl"] = "http://www.freecadweb.org/wiki/index.php?title=Main_Page";

    // set the banner (for logging and console)
    App::Application::Config()["CopyrightInfo"] = sBanner;
    App::Application::Config()["AppIcon"] = "freecad";
    App::Application::Config()["SplashScreen"] = "freecadsplash";
    App::Application::Config()["StartWorkbench"] = "StartWorkbench";
    //App::Application::Config()["HiddenDockWindow"] = "Property editor";
    App::Application::Config()["SplashAlignment" ] = "Bottom|Left";
    App::Application::Config()["SplashTextColor" ] = "#ffffff"; // white
    App::Application::Config()["SplashInfoColor" ] = "#c8c8c8"; // light grey

    try {
        // Init phase ===========================================================
        // sets the default run mode for FC, starts with gui if not overridden in InitConfig...
        App::Application::Config()["RunMode"] = "Gui";

        // Inits the Application 
#if defined (FC_OS_WIN32)
        App::Application::init(argc_, argv_.data());
#else
        App::Application::init(argc, argv);
#endif
#if defined(_MSC_VER)
        // create a dump file when the application crashes
        std::string dmpfile = App::Application::getUserAppDataDir();
        dmpfile += "crash.dmp";
        InitMiniDumpWriter(dmpfile);
#endif
        std::map<std::string, std::string>::iterator it = App::Application::Config().find("NavigationStyle");
        if (it != App::Application::Config().end()) {
            ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/View");
            // if not already defined do it now (for the very first start)
            std::string style = hGrp->GetASCII("NavigationStyle", it->second.c_str());
            hGrp->SetASCII("NavigationStyle", style.c_str());
        }

        Gui::Application::initApplication();

        // Only if 'RunMode' is set to 'Gui' do the replacement
        if (App::Application::Config()["RunMode"] == "Gui")
            Base::Interpreter().replaceStdOutput();
    }
    catch (const Base::UnknownProgramOption& e) {
        QApplication app(argc,argv);
        QString appName = QString::fromAscii(App::Application::Config()["ExeName"].c_str());
        QString msg = QString::fromAscii(e.what());
        QString s = QLatin1String("<pre>") + msg + QLatin1String("</pre>");
        QMessageBox::critical(0, appName, s);
        exit(1);
    }
    catch (const Base::ProgramInformation& e) {
        QApplication app(argc,argv);
        QString appName = QString::fromAscii(App::Application::Config()["ExeName"].c_str());
        QString msg = QString::fromAscii(e.what());
        QString s = QLatin1String("<pre>") + msg + QLatin1String("</pre>");
        QMessageBox::information(0, appName, s);
        exit(0);
    }
    catch (const Base::Exception& e) {
        // Popup an own dialog box instead of that one of Windows
        QApplication app(argc,argv);
        QString appName = QString::fromAscii(App::Application::Config()["ExeName"].c_str());
        QString msg;
        msg = QObject::tr("While initializing %1 the  following exception occurred: '%2'\n\n"
                          "Python is searching for its files in the following directories:\n%3\n\n"
                          "Python version information:\n%4\n")
                          .arg(appName).arg(QString::fromUtf8(e.what()))
                          .arg(QString::fromUtf8(Py_GetPath())).arg(QString::fromAscii(Py_GetVersion()));
        const char* pythonhome = getenv("PYTHONHOME");
        if (pythonhome) {
            msg += QObject::tr("\nThe environment variable PYTHONHOME is set to '%1'.")
                .arg(QString::fromUtf8(pythonhome));
            msg += QObject::tr("\nSetting this environment variable might cause Python to fail. "
                "Please contact your administrator to unset it on your system.\n\n");
        } else {
            msg += QObject::tr("\nPlease contact the application's support team for more information.\n\n");
        }

        QMessageBox::critical(0, QObject::tr("Initialization of %1 failed").arg(appName), msg);
        exit(100);
    }
    catch (...) {
        // Popup an own dialog box instead of that one of Windows
        QApplication app(argc,argv);
        QString appName = QString::fromAscii(App::Application::Config()["ExeName"].c_str());
        QString msg = QObject::tr("Unknown runtime error occurred while initializing %1.\n\n"
                                  "Please contact the application's support team for more information.\n\n").arg(appName);
        QMessageBox::critical(0, QObject::tr("Initialization of %1 failed").arg(appName), msg);
        exit(101);
    }

    // Run phase ===========================================================
    Base::RedirectStdOutput stdcout;
    Base::RedirectStdLog    stdclog;
    Base::RedirectStdError  stdcerr;
    std::streambuf* oldcout = std::cout.rdbuf(&stdcout);
    std::streambuf* oldclog = std::clog.rdbuf(&stdclog);
    std::streambuf* oldcerr = std::cerr.rdbuf(&stdcerr);

    try {
        if (App::Application::Config()["RunMode"] == "Gui")
            Gui::Application::runApplication();
        else
            App::Application::runApplication();
    }
    catch (const Base::SystemExitException&) {
        exit(0);
    }
    catch (const Base::Exception& e) {
        Base::Console().Error("%s\n", e.what());
    }
    catch (...) {
        Base::Console().Error("Application unexpectedly terminated\n");
    }

    std::cout.rdbuf(oldcout);
    std::clog.rdbuf(oldclog);
    std::cerr.rdbuf(oldcerr);

    // Destruction phase ===========================================================
    Base::Console().Log("%s terminating...\n",App::Application::Config()["ExeName"].c_str());

    // cleans up 
    App::Application::destruct();

    Base::Console().Log("%s completely terminated\n",App::Application::Config()["ExeName"].c_str());

    return 0;
}
Ejemplo n.º 4
0
int main( int argc, char ** argv )
{
#if defined (FC_OS_LINUX) || defined(FC_OS_BSD)
    // Make sure to setup the Qt locale system before setting LANG and LC_ALL to C.
    // which is needed to use the system locale settings.
    (void)QLocale::system();
#if QT_VERSION < 0x050000
    // http://www.freecadweb.org/tracker/view.php?id=399
    // Because of setting LANG=C the Qt automagic to use the correct encoding
    // for file names is broken. This is a workaround to force the use of UTF-8 encoding
    QFile::setEncodingFunction(myEncoderFunc);
    QFile::setDecodingFunction(myDecoderFunc);
#endif
    // See https://forum.freecadweb.org/viewtopic.php?f=18&t=20600
    // See Gui::Application::runApplication()
    putenv("LC_NUMERIC=C");
    putenv("PYTHONPATH=");
#elif defined(FC_OS_MACOSX)
    (void)QLocale::system();
    putenv("PYTHONPATH=");
#else
    _putenv("PYTHONPATH=");
    // https://forum.freecadweb.org/viewtopic.php?f=4&t=18288
    // https://forum.freecadweb.org/viewtopic.php?f=3&t=20515
    const char* fc_py_home = getenv("FC_PYTHONHOME");
    if (fc_py_home)
        _putenv_s("PYTHONHOME", fc_py_home);
    else
        _putenv("PYTHONHOME=");
#endif

#if defined (FC_OS_WIN32)
    int argc_ = argc;
    QVector<QByteArray> data;
    QVector<char *> argv_;

    // get the command line arguments as unicode string
    {
        QCoreApplication app(argc, argv);
        QStringList args = app.arguments();
        for (QStringList::iterator it = args.begin(); it != args.end(); ++it) {
            data.push_back(it->toUtf8());
            argv_.push_back(data.back().data());
        }
        argv_.push_back(0); // 0-terminated string
    }
#endif

#if PY_MAJOR_VERSION >= 3
#if defined(_MSC_VER) && _MSC_VER <= 1800
    // See InterpreterSingleton::init
    Redirection out(stdout), err(stderr), inp(stdin);
#endif
#endif // PY_MAJOR_VERSION

    // Name and Version of the Application
    App::Application::Config()["ExeName"] = "FreeCAD";
    App::Application::Config()["ExeVendor"] = "FreeCAD";
    App::Application::Config()["AppDataSkipVendor"] = "true";
    App::Application::Config()["MaintainerUrl"] = "http://www.freecadweb.org/wiki/Main_Page";

    // set the banner (for logging and console)
    App::Application::Config()["CopyrightInfo"] = sBanner;
    App::Application::Config()["AppIcon"] = "freecad";
    App::Application::Config()["SplashScreen"] = "freecadsplash";
    App::Application::Config()["StartWorkbench"] = "StartWorkbench";
    //App::Application::Config()["HiddenDockWindow"] = "Property editor";
    App::Application::Config()["SplashAlignment" ] = "Bottom|Left";
    App::Application::Config()["SplashTextColor" ] = "#ffffff"; // white
    App::Application::Config()["SplashInfoColor" ] = "#c8c8c8"; // light grey

    try {
        // Init phase ===========================================================
        // sets the default run mode for FC, starts with gui if not overridden in InitConfig...
        App::Application::Config()["RunMode"] = "Gui";
        App::Application::Config()["Console"] = "0";

        // Inits the Application 
#if defined (FC_OS_WIN32)
        App::Application::init(argc_, argv_.data());
#else
        App::Application::init(argc, argv);
#endif
#if defined(_MSC_VER)
        // create a dump file when the application crashes
        std::string dmpfile = App::Application::getUserAppDataDir();
        dmpfile += "crash.dmp";
        InitMiniDumpWriter(dmpfile);
#endif
        std::map<std::string, std::string>::iterator it = App::Application::Config().find("NavigationStyle");
        if (it != App::Application::Config().end()) {
            ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/View");
            // if not already defined do it now (for the very first start)
            std::string style = hGrp->GetASCII("NavigationStyle", it->second.c_str());
            hGrp->SetASCII("NavigationStyle", style.c_str());
        }

        Gui::Application::initApplication();

        // Only if 'RunMode' is set to 'Gui' do the replacement
        if (App::Application::Config()["RunMode"] == "Gui")
            Base::Interpreter().replaceStdOutput();
    }
    catch (const Base::UnknownProgramOption& e) {
        QApplication app(argc,argv);
        QString appName = QString::fromLatin1(App::Application::Config()["ExeName"].c_str());
        QString msg = QString::fromLatin1(e.what());
        QString s = QLatin1String("<pre>") + msg + QLatin1String("</pre>");
        QMessageBox::critical(0, appName, s);
        exit(1);
    }
    catch (const Base::ProgramInformation& e) {
        QApplication app(argc,argv);
        QString appName = QString::fromLatin1(App::Application::Config()["ExeName"].c_str());
        QString msg = QString::fromUtf8(e.what());
        QString s = QLatin1String("<pre>") + msg + QLatin1String("</pre>");

        QMessageBox msgBox;
        msgBox.setIcon(QMessageBox::Information);
        msgBox.setWindowTitle(appName);
        msgBox.setDetailedText(msg);
        msgBox.setText(s);
        msgBox.exec();
        exit(0);
    }
    catch (const Base::Exception& e) {
        // Popup an own dialog box instead of that one of Windows
        QApplication app(argc,argv);
        QString appName = QString::fromLatin1(App::Application::Config()["ExeName"].c_str());
        QString msg;
        msg = QObject::tr("While initializing %1 the following exception occurred: '%2'\n\n"
                          "Python is searching for its files in the following directories:\n%3\n\n"
                          "Python version information:\n%4\n")
                          .arg(appName).arg(QString::fromUtf8(e.what()))
#if PY_MAJOR_VERSION >= 3
#if PY_MINOR_VERSION >= 5
                          .arg(QString::fromUtf8(Py_EncodeLocale(Py_GetPath(),NULL))).arg(QString::fromLatin1(Py_GetVersion()));
#else
                          .arg(QString::fromUtf8(_Py_wchar2char(Py_GetPath(),NULL))).arg(QString::fromLatin1(Py_GetVersion()));
#endif
#else
                          .arg(QString::fromUtf8(Py_GetPath())).arg(QString::fromLatin1(Py_GetVersion()));
Ejemplo n.º 5
0
void Player::Init(int argc, char *argv[]) {
	static bool init = false;
	frames = 0;

	if (init) return;

	// Display a nice version string
	std::stringstream header;
	std::string addtl_ver(PLAYER_ADDTL);
	header << "EasyRPG Player " << PLAYER_VERSION;
	if (!addtl_ver.empty())
		header << " " << addtl_ver;
	header << " started";
	Output::Debug(header.str().c_str());

	unsigned int header_width = header.str().length();
	header.str("");
	header << std::setfill('=') << std::setw(header_width) << "=";
	Output::Debug(header.str().c_str());

#ifdef GEKKO
	// Init libfat (Mount SD/USB)
	if (!fatInitDefault()) {
		Output::Error("Couldn't mount any storage medium!");
	}
#elif defined(_3DS)
	// Starting debug console
	gfxInitDefault();
	consoleInit(GFX_BOTTOM, NULL);

	APT_SetAppCpuTimeLimit(30);
	if (osGetKernelVersion() <  SYSTEM_VERSION(2, 48, 3)) khaxInit(); // Executing libkhax just to be sure...
	consoleClear();

	// Check if we already have access to csnd:SND, if not, we will perform a kernel privilege escalation
	Handle csndHandle = 0;
	use_dsp = false;
#ifndef FORCE_DSP
	srvGetServiceHandleDirect(&csndHandle, "csnd:SND");
	if (csndHandle) {
		Output::Debug("csnd:SND has been selected as audio service.");
		svcCloseHandle(csndHandle);
	} else {
		Output::Debug("csnd:SND is unavailable...");
#endif
		srvGetServiceHandleDirect(&csndHandle, "dsp::DSP");
		if (csndHandle) {
			Output::Debug("dsp::DSP has been selected as audio service.");
			use_dsp = true;
			svcCloseHandle(csndHandle);
		} else {
			Output::Error("dsp::DSP is unavailable. Please dump a DSP firmware to use EasyRPG Player. If the problem persists, please report us the issue.");
		}
#ifndef FORCE_DSP
	}
#endif

	fsInit();
	sdmcInit();
#ifndef CITRA3DS_COMPATIBLE
	romfsInit();
#endif

	hidInit();

	// Enable 804 Mhz mode if on N3DS
	bool isN3DS;
	APT_CheckNew3DS(&isN3DS);
	if (isN3DS) {
		osSetSpeedupEnable(true);
	}
#endif

#if (defined(_WIN32) && defined(NDEBUG) && defined(WINVER) && WINVER >= 0x0600)
	InitMiniDumpWriter();
#endif

	srand(time(NULL));

	ParseCommandLine(argc, argv);

#ifdef EMSCRIPTEN
	Output::IgnorePause(true);

	// Create initial directory structure in our private area
	// Retrieve save directory from persistent storage
	EM_ASM(

		FS.mkdir("easyrpg");
		FS.chdir("easyrpg");

		var dirs = ['Backdrop', 'Battle', 'Battle2', 'BattleCharSet', 'BattleWeapon', 'CharSet', 'ChipSet', 'FaceSet', 'Frame', 'GameOver', 'Monster', 'Movie', 'Music', 'Panorama', 'Picture', 'Sound', 'System', 'System2', 'Title', 'Save'];
		dirs.forEach(function(dir) { FS.mkdir(dir) });

		FS.mount(IDBFS, {}, 'Save');

		FS.syncfs(true, function(err) {
		});
	);
Ejemplo n.º 6
0
int main(int argc, char *argv[])
{
#ifndef _DEBUG
	InitMiniDumpWriter(GetNeoVersion(true).toStdWString().c_str());
#endif

#ifndef WIN32
    setup_unix_signal_handlers();
#endif

    bool bGui = false;
    bool bCore = false;
	bool bTray = false;
    bool bDaemon = false;

    for(int i=0; i<argc; i++)
    {
        if(strcmp(argv[i],"-unify") == 0)
        {
            bGui = true;
            bCore = true;
        }
        else if(strcmp(argv[i],"-gui") == 0)
            bGui = true;
        else if(strcmp(argv[i],"-core") == 0)
            bCore = true;
        else if(strcmp(argv[i],"-daemon") == 0)
            bDaemon = true;
		else if(strcmp(argv[i],"-tray") == 0)
			bTray = true;
    }

    bool bConsole = (bCore || bDaemon) && !bTray;

    // Note: we need a Q*Applicatio instance to read the settings, so here we can start the core always onl with command lin
    CScoped<QCoreApplication> pApp = bConsole ? new QCoreApplication(argc, argv) : new QApplication(argc, argv);

	if(bDaemon)
    {
        setbuf(stdout, NULL);

        if(bCore)
        {
#ifndef WIN32
            // Note: when a process becomes orphan (that is, its parent dies) it is adopted by init.
            g_NoInt = true;
#endif
        }
        else
        {
            QProcess* pCoreProcess = new QProcess();
            pCoreProcess->setProcessChannelMode(QProcess::MergedChannels);
            QStringList Arguments;
            Arguments.append("-core");
            Arguments.append("-daemon");
            pCoreProcess->start(QApplication::applicationFilePath(), Arguments);

            pCoreProcess->waitForStarted();

            for(;pCoreProcess->state() == QProcess::Running;)
            {
                QCoreApplication::processEvents();

                if(!pCoreProcess->canReadLine())
                {
                    QThread::currentThread()->msleep(10);
                    continue;
                }

                printf("%s", pCoreProcess->readLine().data());
            }

            return 0;
        }
    }

	CScoped<QtLocalPeer> pPeer = new QtLocalPeer(bConsole ? "NeoCore" : (bGui && bTray ? "NeoGUI" : "NeoApp"));
	if(pPeer->isClient())
	{
		QStringList Args = QApplication::instance()->arguments();
		for(int i=1; i < Args.count(); i++)
		{
			QString Arg = Args.at(i);
			if(Arg.left(1) != "-")
				pPeer->sendMessage(Arg);
		}
		return 0;
	}

    CSettings::InitSettingsEnvironment(APP_ORGANISATION, APP_NAME, APP_DOMAIN);
    CScoped<CSettings> Settings = new CSettings("NeoLoader", CNeoLoader::GetDefaultSettings());

#ifndef WIN32
    g_NoHup = Settings->GetBool("Integration/NoHUP") || bDaemon;
#endif

    for(int i=0; i<argc; i++)
    {

        if(strcmp(argv[i],"-name") == 0 && ++i<argc)
            Settings->SetSetting("Core/LocalName", QString(argv[i]));
        else if(strcmp(argv[i],"-port") == 0 && ++i<argc)
            Settings->SetSetting("Core/RemotePort", QString(argv[i]).toInt());
		else if(strcmp(argv[i],"-password") == 0 && ++i<argc)
            Settings->SetSetting("Core/Password", QString(argv[i]));
    }

	int NeoMode = CNeoLoader::eNoNeo;
	if(bConsole)
		NeoMode = CNeoLoader::eNeoCore;
	else // Some kind of GUI mode
	{
		if(bGui)
			NeoMode = bTray ? CNeoLoader::eGUIProcess : CNeoLoader::eRemoteGUI;
		else if(bCore) // Core with Tray
		{
			NeoMode = CNeoLoader::eCoreProcess;
			if(bTray)
				NeoMode |= CNeoLoader::eMinimized;
		}
		else
		{
			QString Mode = Settings->GetString("Core/Mode");
			if(Mode == "Separate")
				NeoMode = CNeoLoader::eCoreProcess;
			else if(Mode == "Local")
				NeoMode = CNeoLoader::eLocalGUI;
			else if(Mode == "Remote")
				NeoMode = CNeoLoader::eRemoteGUI;
			else //if(Mode == "Unified")
				NeoMode = CNeoLoader::eUnified;
		}
	}

    if ((NeoMode & CNeoLoader::eNeoCore) != 0)
		new CNeoCore(Settings);

	if ((NeoMode & CNeoLoader::eNeoGUI) != 0)
        new CNeoLoader(Settings, NeoMode);

	int Ret = 0;

    if(theLoader || theCore)
    {
		QObject::connect(pPeer, SIGNAL(messageReceived(const QString&)), bConsole ? (QObject*)theCore : (QObject*)theLoader, SLOT(OnMessage(const QString&)));

		QStringList Args = QApplication::instance()->arguments();
		for(int i=1; i < Args.count(); i++)
		{
			QString Arg = Args.at(i);
			if(Arg.left(1) != "-")
				QMetaObject::invokeMethod(bConsole ? (QObject*)theCore : (QObject*)theLoader, "OnMessage", Qt::QueuedConnection, Q_ARG(const QString&, Arg));
		}

        Ret = pApp->exec();

        delete theCore;
        delete theLoader;
    }