OSDN Git Service

[BUILD] Set SOVERSION and GIT hash automatically.
[csp-qt/common_source_project-fm7.git] / source / src / qt / common / qt_utils.cpp
index 1abb065..d912e3d 100644 (file)
 #include <QDir>
 #include <QTranslator>
 #include <QProcessEnvironment>
+#include <QCommandLineParser>
 
 #include "common.h"
 #include "fileio.h"
+#include "config.h"
 #include "emu.h"
 #include "menuclasses.h"
 #include "mainwidget.h"
 #include "dialog_movie.h"
 #include "../avio/movie_saver.h"
 // emulation core
+#include "../../vm/fmgen/fmgen.h"
 
 EMU* emu;
 QApplication *GuiMain = NULL;
+extern config_t config;
+#if defined(CSP_OS_WINDOWS)
+CSP_Logger DLL_PREFIX_I *csp_logger;
+#else
+extern CSP_Logger *csp_logger;
+#endif
 
 // Start to define MainWindow.
 class META_MainWindow *rMainWindow;
@@ -55,10 +64,10 @@ class META_MainWindow *rMainWindow;
 #endif
 
 // menu
-extern std::string cpp_homedir;
+extern DLL_PREFIX_I std::string cpp_homedir;
 extern DLL_PREFIX_I std::string cpp_confdir;
-extern std::string my_procname;
-std::string sRssDir;
+extern DLL_PREFIX_I std::string my_procname;
+extern DLL_PREFIX_I std::string sRssDir;
 bool now_menuloop = false;
 static int close_notified = 0;
 // timing control
@@ -258,7 +267,7 @@ void Ui_MainWindow::LaunchEmuThread(void)
        connect(hDrawEmu, SIGNAL(message_changed(QString)), this, SLOT(message_status_bar(QString)));
        connect(actionCapture_Screen, SIGNAL(triggered()), glv, SLOT(do_save_frame_screen()));
 
-       /*if(using_flags->get_config_ptr()->use_separate_thread_draw) {
+       /*if(config.use_separate_thread_draw) {
                connect(hRunEmu, SIGNAL(sig_draw_thread(bool)), hDrawEmu, SLOT(doDraw(bool)), Qt::QueuedConnection);
                connect(hRunEmu, SIGNAL(sig_set_draw_fps(double)), hDrawEmu, SLOT(do_set_frames_per_second(double)), Qt::QueuedConnection);
                connect(hRunEmu, SIGNAL(sig_draw_one_turn(bool)), hDrawEmu, SLOT(do_draw_one_turn(bool)), Qt::QueuedConnection);
@@ -297,11 +306,11 @@ void Ui_MainWindow::LaunchEmuThread(void)
        objNameStr = QString("EmuDrawThread");
        hDrawEmu->setObjectName(objNameStr);
 
-       if(using_flags->get_config_ptr()->use_separate_thread_draw) hDrawEmu->start();
+       if(config.use_separate_thread_draw) hDrawEmu->start();
 
        csp_logger->debug_log(CSP_LOG_INFO, CSP_LOG_TYPE_GENERAL, "DrawThread : Launch done.");
 
-       hSaveMovieThread = new MOVIE_SAVER(640, 400,  30, emu->get_osd(), using_flags->get_config_ptr());
+       hSaveMovieThread = new MOVIE_SAVER(640, 400,  30, emu->get_osd(), &config);
        
        connect(actionStart_Record_Movie->binds, SIGNAL(sig_start_record_movie(int)), hRunEmu, SLOT(do_start_record_video(int)));
        connect(this, SIGNAL(sig_start_saving_movie()),
@@ -345,7 +354,7 @@ void Ui_MainWindow::LaunchEmuThread(void)
 
        hRunEmu->start();
        csp_logger->debug_log(CSP_LOG_INFO, CSP_LOG_TYPE_GENERAL, "EmuThread : Launch done.");
-       this->set_screen_aspect(using_flags->get_config_ptr()->window_stretch_type);
+       this->set_screen_aspect(config.window_stretch_type);
        emit sig_movie_set_width(SCREEN_WIDTH);
        emit sig_movie_set_height(SCREEN_HEIGHT);
 }
@@ -353,7 +362,7 @@ void Ui_MainWindow::LaunchEmuThread(void)
 void Ui_MainWindow::LaunchJoyThread(void)
 {
 #if defined(USE_JOYSTICK)
-       hRunJoy = new JoyThreadClass(emu, emu->get_osd(), using_flags, using_flags->get_config_ptr(), csp_logger);
+       hRunJoy = new JoyThreadClass(emu, emu->get_osd(), using_flags, &config, csp_logger);
        connect(this, SIGNAL(quit_joy_thread()), hRunJoy, SLOT(doExit()));
        hRunJoy->setObjectName("JoyThread");
        hRunJoy->start();
@@ -571,9 +580,6 @@ static void setup_logs(void)
 #endif
 }
 
-#include <QString>
-#include <QCommandLineParser>
-CSP_Logger *csp_logger;
 QStringList virtualMediaList; // {TYPE, POSITION}
 QCommandLineOption *_opt_fds[8];
 QCommandLineOption *_opt_hdds[8];
@@ -584,16 +590,16 @@ QCommandLineOption *_opt_binaries[8];
 QCommandLineOption *_opt_bubbles[8];
 QCommandLineOption *_opt_qds[8];
 QCommandLineOption *_opt_carts[8];
-QCommandLineOption *_opt_homedir;
-QCommandLineOption *_opt_cfgfile;
-QCommandLineOption *_opt_cfgdir;
-QCommandLineOption *_opt_resdir;
-QCommandLineOption *_opt_opengl;
-QCommandLineOption *_opt_envver;
-QCommandLineOption *_opt_dump_envver;
-QCommandLineOption *_opt_dipsw_on;
-QCommandLineOption *_opt_dipsw_off;
-QProcessEnvironment _envvers;
+extern QCommandLineOption *_opt_homedir;
+extern QCommandLineOption *_opt_cfgfile;
+extern QCommandLineOption *_opt_cfgdir;
+extern QCommandLineOption *_opt_resdir;
+extern QCommandLineOption *_opt_opengl;
+extern QCommandLineOption *_opt_envver;
+extern QCommandLineOption *_opt_dump_envver;
+extern QCommandLineOption *_opt_dipsw_on;
+extern QCommandLineOption *_opt_dipsw_off;
+extern QProcessEnvironment _envvers;
 bool _b_dump_envver;
 std::string config_fullpath;
 
@@ -896,7 +902,7 @@ void SetProcCmdCD(QCommandLineParser *cmdparser, QStringList *_l)
 #endif
 }
 
-
+extern void SetOptions_Sub(QCommandLineParser *cmdparser);
 void SetOptions(QCommandLineParser *cmdparser)
 {
        QString emudesc = QString::fromUtf8("Emulator for ");
@@ -904,51 +910,9 @@ void SetOptions(QCommandLineParser *cmdparser)
     cmdparser->setApplicationDescription(emudesc);
     cmdparser->addHelpOption();
     //cmdparser->addVersionOption();
-       QStringList _cl;
-    _cl.append("d");
-    _cl.append("homedir");
-    _opt_homedir = new QCommandLineOption(_cl, QCoreApplication::translate("main", "Custom home directory."), "homedir");
-    _cl.clear();
-   
-    _cl.append("c");
-    _cl.append("cfgfile");
-    _opt_cfgfile = new QCommandLineOption(_cl, QCoreApplication::translate("main", "Custom config file (without path)."), "cfgfile");
-    _cl.clear();
-   
-    _opt_cfgdir = new QCommandLineOption("cfgdir", QCoreApplication::translate("main", "Custom config directory."), "cfgdir");
 
-    _cl.append("r");
-    _cl.append("res");
-    _opt_resdir = new QCommandLineOption(_cl, QCoreApplication::translate("main", "Custom resource directory (ROMs, WAVs, etc)."), "resdir");
-    _cl.clear();
-
-    _cl.append("on");
-    _cl.append("dipsw-on");
-    _opt_dipsw_on = new QCommandLineOption(_cl, QCoreApplication::translate("main", "Turn on <onbit> of dip switch."), "onbit");
-    _cl.clear();
-   
-    _cl.append("off");
-    _cl.append("dipsw-off");
-    _opt_dipsw_off = new QCommandLineOption(_cl, QCoreApplication::translate("main", "Turn off <offbit> of dip switch."), "offbit");
-    _cl.clear();
-       
-    _cl.append("g");
-    _cl.append("gl");
-    _cl.append("opengl");
-    _cl.append("render");
-    _opt_opengl = new QCommandLineOption(_cl, QCoreApplication::translate("main", "Force set using renderer type."), "{ GL | GL2 | GLES}");
-    _cl.clear();
-       
-    _cl.append("v");
-    _cl.append("env");
-    _cl.append("envver");
-    _opt_envver = new QCommandLineOption(_cl, QCoreApplication::translate("main", "Set / Delete environment variable."), "{NAME[=VAL] | -NAME}");
-    _cl.clear();
-
-    _cl.append("dump-env");
-    _cl.append("dump-envver");
-    _opt_dump_envver = new QCommandLineOption(_cl, QCoreApplication::translate("main", "Dump environment variables."), "");
-    _cl.clear();
+       SetOptions_Sub(cmdparser);
+       QStringList _cl;
        
        for(int i = 0; i < 8; i++) {
                _opt_fds[i] = NULL;
@@ -963,14 +927,6 @@ void SetOptions(QCommandLineParser *cmdparser)
                _opt_lds[i] = NULL;
                _opt_cds[i] = NULL;
        }               
-               
-    cmdparser->addOption(*_opt_opengl);
-    cmdparser->addOption(*_opt_homedir);
-    cmdparser->addOption(*_opt_cfgfile);
-    cmdparser->addOption(*_opt_cfgdir);
-    cmdparser->addOption(*_opt_resdir);
-    cmdparser->addOption(*_opt_dipsw_on);
-    cmdparser->addOption(*_opt_dipsw_off);
 
        SetFDOptions(cmdparser);
        SetHDDOptions(cmdparser);
@@ -986,6 +942,8 @@ void SetOptions(QCommandLineParser *cmdparser)
     cmdparser->addOption(*_opt_dump_envver);
 }
 
+extern void ProcessCmdLine_Sub(QCommandLineParser *cmdparser, QStringList *_l);
+
 void ProcessCmdLine(QCommandLineParser *cmdparser, QStringList *_l)
 {
        char homedir[PATH_MAX];
@@ -995,7 +953,67 @@ void ProcessCmdLine(QCommandLineParser *cmdparser, QStringList *_l)
 #else
        delim = "/";
 #endif
-       
+       ProcessCmdLine_Sub(cmdparser, _l);      
+       {
+               char tmps[128];
+               std::string localstr;
+               memset(tmps, 0x00, 128);
+               if(cmdparser->isSet(*_opt_cfgfile)) {
+                       strncpy(tmps, cmdparser->value(*_opt_cfgfile).toLocal8Bit().constData(), 127);
+               }
+               if(strlen(tmps) <= 0){
+                       snprintf(tmps, sizeof(tmps), _T("%s.ini"), _T(CONFIG_NAME));
+               }
+               localstr = tmps;
+               localstr = cpp_confdir + localstr;
+               load_config(localstr.c_str());
+               config_fullpath = localstr;
+       }
+       if(cmdparser->isSet(*_opt_opengl)) {
+               char tmps[128] = {0};
+               strncpy(tmps, cmdparser->value(*_opt_opengl).toLocal8Bit().constData(), 128 - 1);
+               if(strlen(tmps) > 0) {
+                       QString render = QString::fromLocal8Bit(tmps).toUpper();
+                       if((render == QString::fromUtf8("GL2")) ||
+                          (render == QString::fromUtf8("GLV2"))) {
+                               config.render_platform = CONFIG_RENDER_PLATFORM_OPENGL_MAIN;
+                               config.render_major_version = 2;
+                               config.render_minor_version = 0;
+                               GuiMain->setAttribute(Qt::AA_UseDesktopOpenGL, true);
+                               GuiMain->setAttribute(Qt::AA_UseOpenGLES, false);
+                       } else if((render == QString::fromUtf8("GL3")) ||
+                                         (render == QString::fromUtf8("GLV3")) ||
+                                         (render == QString::fromUtf8("OPENGLV3")) ||
+                                         (render == QString::fromUtf8("OPENGL")) ||
+                                         (render == QString::fromUtf8("GL"))) {
+                               config.render_platform = CONFIG_RENDER_PLATFORM_OPENGL_MAIN;
+                               config.render_major_version = 3;
+                               config.render_minor_version = 0;
+                               GuiMain->setAttribute(Qt::AA_UseDesktopOpenGL, true);
+                               GuiMain->setAttribute(Qt::AA_UseOpenGLES, false);
+                       } else if((render == QString::fromUtf8("GLES2")) ||
+                                        (render == QString::fromUtf8("GLESV2")) ||
+                                        (render == QString::fromUtf8("GLES3")) ||
+                                        (render == QString::fromUtf8("GLESV3")) ||
+                                        (render == QString::fromUtf8("GLES"))) {
+                               config.render_platform = CONFIG_RENDER_PLATFORM_OPENGL_ES;
+                               config.render_major_version = 2;
+                               config.render_minor_version = 1;
+                               GuiMain->setAttribute(Qt::AA_UseDesktopOpenGL, false);
+                               GuiMain->setAttribute(Qt::AA_UseOpenGLES, true);
+                       } else if((render == QString::fromUtf8("GL4")) ||
+                                        (render == QString::fromUtf8("GL43")) ||
+                                        (render == QString::fromUtf8("GL4.3")) ||
+                                        (render == QString::fromUtf8("GL4_3")) ||
+                                        (render == QString::fromUtf8("GL4_CORE"))) {
+                               config.render_platform = CONFIG_RENDER_PLATFORM_OPENGL_CORE;
+                               config.render_major_version = 4;
+                               config.render_minor_version = 3;
+                               GuiMain->setAttribute(Qt::AA_UseDesktopOpenGL, true);
+                               GuiMain->setAttribute(Qt::AA_UseOpenGLES, false);
+                       }
+               }
+       }
        SetProcCmdFD(cmdparser, _l);
        SetProcCmdHDD(cmdparser, _l);
        SetProcCmdQuickDisk(cmdparser, _l);
@@ -1006,6 +1024,7 @@ void ProcessCmdLine(QCommandLineParser *cmdparser, QStringList *_l)
        SetProcCmdLD(cmdparser, _l);
        SetProcCmdCD(cmdparser, _l);
 
+#if 0
        memset(homedir, 0x00, PATH_MAX);
        if(cmdparser->isSet(*_opt_homedir)) {
                strncpy(homedir, cmdparser->value(*_opt_homedir).toLocal8Bit().constData(), PATH_MAX - 1);
@@ -1094,6 +1113,16 @@ void ProcessCmdLine(QCommandLineParser *cmdparser, QStringList *_l)
                                config.render_minor_version = 1;
                                GuiMain->setAttribute(Qt::AA_UseDesktopOpenGL, false);
                                GuiMain->setAttribute(Qt::AA_UseOpenGLES, true);
+                       } else if((render == QString::fromUtf8("GL4")) ||
+                                        (render == QString::fromUtf8("GL43")) ||
+                                        (render == QString::fromUtf8("GL4.3")) ||
+                                        (render == QString::fromUtf8("GL4_3")) ||
+                                        (render == QString::fromUtf8("GL4_CORE"))) {
+                               config.render_platform = CONFIG_RENDER_PLATFORM_OPENGL_CORE;
+                               config.render_major_version = 4;
+                               config.render_minor_version = 3;
+                               GuiMain->setAttribute(Qt::AA_UseDesktopOpenGL, true);
+                               GuiMain->setAttribute(Qt::AA_UseOpenGLES, false);
                        }
                }
        }
@@ -1140,6 +1169,7 @@ void ProcessCmdLine(QCommandLineParser *cmdparser, QStringList *_l)
        if(cmdparser->isSet(*_opt_dump_envver)) {
                _b_dump_envver = true;
        }
+#endif
        uint32_t dipsw_onbits = 0x0000000;
        uint32_t dipsw_offmask = 0xffffffff;
        if(cmdparser->isSet(*_opt_dipsw_off)) {
@@ -1172,7 +1202,6 @@ void ProcessCmdLine(QCommandLineParser *cmdparser, QStringList *_l)
        }
        config.dipswitch &= dipsw_offmask;
        config.dipswitch |= dipsw_onbits;
-
 }
 
 void OpeningMessage(std::string archstr)
@@ -1235,10 +1264,11 @@ void SetupSDL(void)
        csp_logger->debug_log(CSP_LOG_INFO, CSP_LOG_TYPE_GENERAL, "Audio and JOYSTICK subsystem was initialised.");
 }
 
-void SetupLogger(std::string emustr, int _size)
+
+void SetupLogger(QObject *parent, std::string emustr, int _size)
 {
 
-       csp_logger = new CSP_Logger(config.log_to_syslog, config.log_to_console, emustr.c_str()); // Write to syslog, console
+       csp_logger = new CSP_Logger(parent, config.log_to_syslog, config.log_to_console, emustr.c_str()); // Write to syslog, console
        csp_logger->set_log_stdout(CSP_LOG_DEBUG, true);
        csp_logger->set_log_stdout(CSP_LOG_INFO, true);
        csp_logger->set_log_stdout(CSP_LOG_WARN, true);
@@ -1287,7 +1317,7 @@ int MainLoop(int argc, char *argv[])
 
        emustr = emustr + cfgstr;
 
-       SetupLogger(emustr, CSP_LOG_TYPE_VM_DEVICE_END - CSP_LOG_TYPE_VM_DEVICE_0 + 1);
+       SetupLogger(GuiMain, emustr, CSP_LOG_TYPE_VM_DEVICE_END - CSP_LOG_TYPE_VM_DEVICE_0 + 1);
 
        
        archstr = "Generic";
@@ -1302,8 +1332,6 @@ int MainLoop(int argc, char *argv[])
        /*
         * Into Qt's Loop.
         */
-       USING_FLAGS_EXT *using_flags = new USING_FLAGS_EXT(&config);
-       // initialize emulation core
 
        //SetupTranslators();
        QTranslator local_translator;
@@ -1336,6 +1364,8 @@ int MainLoop(int argc, char *argv[])
                }
        }
        
+       USING_FLAGS_EXT *using_flags = new USING_FLAGS_EXT(&config);
+       // initialize emulation core
        rMainWindow = new META_MainWindow(using_flags, csp_logger);
        rMainWindow->connect(rMainWindow, SIGNAL(sig_quit_all(void)), rMainWindow, SLOT(deleteLater(void)));
        rMainWindow->setCoreApplication(GuiMain);
@@ -1526,3 +1556,85 @@ void Ui_MainWindow::OnCloseDebugger(void )
 }
 #endif
 
+QString Ui_MainWindow::get_system_version()
+{
+       QString guiver = get_gui_version();
+       QString aviover;
+       QString vm_gitver;
+       QString common_vmver;
+       QString osdver;
+       QString libcommon_ver;
+       QString libfmgen_ver;
+       QString build_date;
+       
+       QString outstr;
+       
+       aviover.clear();
+       common_vmver.clear();
+       vm_gitver.clear();
+       osdver.clear();
+       libcommon_ver.clear();
+       
+       if(hSaveMovieThread != NULL) {
+               aviover = hSaveMovieThread->get_avio_version();
+       }
+       if(emu != NULL) {
+               if(emu->get_osd() != NULL) {
+                       _TCHAR *cvp = emu->get_osd()->get_lib_common_vm_version();
+                       _TCHAR *gvp = emu->get_osd()->get_lib_common_vm_git_version();
+                       _TCHAR *ovp = emu->get_osd()->get_lib_osd_version();
+                       if(cvp != NULL) {
+                               common_vmver = QString::fromUtf8(cvp);
+                       }
+                       if(gvp != NULL) {
+                               vm_gitver = QString::fromUtf8(gvp);
+                       }
+                       if(ovp != NULL) {
+                               osdver = QString::fromUtf8(ovp);
+                       }
+               }
+       }
+       
+       const _TCHAR *pp = get_lib_common_version();
+       if(pp != NULL) {
+               libcommon_ver = QString::fromUtf8(pp);
+       }
+       libfmgen_ver = QString::fromUtf8(FM::get_libfmgen_version());
+       
+       outstr.clear();
+       if(!(common_vmver.isEmpty())) {
+               outstr.append(common_vmver);
+               outstr.append("<BR>\n");
+       }
+       if(!(libcommon_ver.isEmpty())) {
+               outstr.append(libcommon_ver);
+               outstr.append("<BR>\n");
+       }
+       if(!(libfmgen_ver.isEmpty())) {
+               outstr.append(libfmgen_ver);
+               outstr.append("<BR>\n");
+       }
+       if(!(guiver.isEmpty())) {
+               outstr.append(guiver);
+               outstr.append("<BR>\n");
+       }
+       if(!(aviover.isEmpty())) {
+               outstr.append(aviover);
+               outstr.append("<BR>\n");
+       }
+       if(!(vm_gitver.isEmpty())) {
+               outstr.append("Build Version: ");
+               outstr.append(vm_gitver);
+               outstr.append("<BR>\n");
+       }
+       return outstr;
+}
+
+QString Ui_MainWindow::get_build_date()
+{
+#if defined(__BUILD_DATE)
+       return QString::fromUtf8(__BUILD_DATE);
+#else
+       return QString::fromUtf8("");
+#endif
+}