Ticket #1810: gamePatch4.patch

File gamePatch4.patch, 18.3 KB (added by ryebrye@…, 17 years ago)

gamePatch4.patch

  • mythgame/gamehandler.cpp

     
    33#include "rom_metadata.h"
    44
    55#include <qobject.h>
     6#include <qapplication.h>
     7#include <qtimer.h>
     8#include <qprocess.h>
    69#include <qptrlist.h>
    710#include <qstringlist.h>
    811#include <iostream>
     
    1417#include <mythtv/mythdialogs.h>
    1518#include <mythtv/util.h>
    1619
     20QProcess *process;
     21QString screencmd;
     22
    1723using namespace std;
    1824
    1925static QPtrList<GameHandler> *handlers = 0;
     
    6470void GameHandler::updateSettings(GameHandler *handler)
    6571{
    6672    MSqlQuery query(MSqlQuery::InitCon());
    67     query.exec("SELECT rompath, workingpath, commandline, screenshots, gameplayerid, gametype, extensions, spandisks  FROM gameplayers WHERE playername = \"" + handler->SystemName() + "\";");
     73    query.exec("SELECT rompath, workingpath, commandline, screenshots, gameplayerid, gametype, extensions, spandisks, screenshotenabled, screenshotcmd FROM gameplayers WHERE playername = \"" + handler->SystemName() + "\";");
    6874
    6975    query.next();
    7076    handler->rompath = query.value(0).toString();
     
    7581    handler->gametype = query.value(5).toString();
    7682    handler->validextensions = QStringList::split(",", query.value(6).toString().stripWhiteSpace().remove(" "));
    7783    handler->spandisks = query.value(7).toInt();
     84    handler->screenshotenabled = query.value(8).toInt();
     85    handler->screenshotcmd = query.value(9).toInt();
    7886
    7987}
    8088
     
    131139        cerr << "No romDB data read from database. Not imported?" << endl;
    132140    else
    133141        cerr << "Loaded " << romDB.count() << " items from romDB Database" << endl;
    134 
    135142}
    136143
    137144void GameHandler::GetMetadata(GameHandler *handler, QString rom, QString* Genre, QString* Year,
     
    227234
    228235}
    229236
     237
    230238void updateDisplayRom(QString romname, int display, QString Systemname)
    231239{
    232240    MSqlQuery query(MSqlQuery::InitCon());
     
    731739    else if (!(handler = GetHandler(romdata)))
    732740    {
    733741        // Couldn't get handler so abort.
    734         return;
     742        return ;
    735743    }
    736744    QString exec = handler->SystemCmdLine();
    737745
     
    824832    handlers->append(handler);
    825833}
    826834
     835bool GameHandler::promptShouldOverwrite()
     836{
     837        QStringList buttonText;
     838    buttonText += QObject::tr("No");
     839    buttonText += QObject::tr("Yes");
     840
     841
     842    int result = MythPopupBox::showButtonPopup(gContext->GetMainWindow(),
     843                               QObject::tr("Overwrite existing screenshots?"),
     844                               QString(QObject::tr("Would you like to overwrite any existing screenshots?")),
     845                                                    buttonText, 0 );
     846    switch (result)
     847    {
     848        case 0:
     849            return false;
     850        case 1:
     851            return true;
     852    };
     853       
     854        return false;
     855}
     856
     857void GameHandler::generateScreenshots(void)
     858{
     859    checkHandlers();
     860
     861    GameHandler *handler = handlers->first();
     862
     863    MSqlQuery query(MSqlQuery::InitCon());
     864   // MSqlQuery squery(MSqlQuery::InitCon());   
     865
     866       
     867    while(handler)
     868    {
     869        updateSettings(handler);
     870       
     871        if (handler->ScreenShotEnabled())
     872        {
     873       
     874               
     875       
     876                QString thequery;       
     877                thequery = QString("SELECT romname, rompath, gamename, diskcount "
     878                                                        "FROM gamemetadata WHERE system = '%1';")
     879                           .arg(handler->SystemName());
     880                           
     881        query.exec(thequery);
     882
     883                // display a dialog box to show the number of roms left to process as it flashes by.
     884                MythProgressDialog screenshotDlg(QString("Generating %1(%2) screenshots")
     885                                   .arg(handler->SystemName())
     886                                   .arg(handler->GameType()),
     887                                   query.numRowsAffected());
     888       
     889                //QString screenquery;
     890                //screenquery = QString("SELECT screenshots FROM gameplayers WHERE playername  = '%1';").arg(handler->PlayerName());
     891                //squery.exec(screenquery);
     892               
     893                //QString screenpath = query.value(0).toString();
     894
     895                // boolean value to skip existing screenshots from being generated again.
     896                bool should_overwrite = promptShouldOverwrite();
     897               
     898       
     899                if (should_overwrite)
     900                        cout << "Screenshot generation started. Overwriting existing screenshots." << endl;
     901                else
     902                        cout << "Screenshot generation started. NOT Overwriting existing screenshots." << endl;
     903               
     904                // start at -1 so we can pre-increment the screenshot counter as the
     905                // first step in the loop - thus letting us break out of the loop
     906                // and go to the next iteration without having to worry about the
     907                // progress bar
     908                int counter = -1;
     909               
     910               
     911                if (query.isActive() && query.size() >0)
     912                {
     913                       
     914                        while (query.next())
     915                        {
     916                       
     917                                screenshotDlg.setProgress(++counter);
     918                               
     919                                QString romname = query.value(0).toString();
     920                                QString rompath = query.value(1).toString();
     921                                int diskcount   = query.value(3).toInt();
     922                                //Get the Extension via the RomInfo Class
     923                                RomInfo temp;
     924                                temp.setRomname(romname);
     925                                QString extension = temp.getExtension();
     926                               
     927                                QString basename = romname.left(romname.length() - (extension.length() + 1));
     928                               
     929                                QString exec = handler->SystemCmdLine();
     930                               
     931                               
     932                                                               
     933                                if (handler->GameType() != "PC")
     934                                {
     935                                        QString arg = "\"" + rompath + "/" + romname + "\"";
     936                                       
     937                                        // only bother checking if a screenshot exists if the user specified they care to keep them
     938                                        // - doing this saves time at execution.
     939                                        if (!should_overwrite) {
     940                                                QString ImageCheck(romname);
     941                                                cout << "Searching for existing screenshot for rom: " << ImageCheck <<  " at " << handler->SystemScreenShots() << "/" << romname << endl;
     942                                               
     943                                                if (RomInfo::FindImage(handler->SystemScreenShots() + "/" + romname, &ImageCheck)) {
     944                                                        cout << "\tFound at: " << ImageCheck << endl;
     945                                                        continue;
     946                                                }
     947                                               
     948                                        }
     949                                       
     950                                        // If they specified a %s in the commandline place the romname
     951                                        // in that location, otherwise tack it on to the end of
     952                                        // the command.
     953                                        if (exec.contains("%s") || handler->SpanDisks())
     954                                        {
     955                                                exec = exec.replace(QRegExp("%s"),arg);
     956                                               
     957                                                if (handler->SpanDisks())
     958                                                {
     959                                                        QRegExp rxp = QRegExp( "%d[0-4]", TRUE, FALSE );
     960                                                       
     961                                                        if (exec.contains(rxp))
     962                                                        {
     963                                                                if (diskcount > 1)
     964                                                                {
     965                                                                        // Chop off the extension, .  and last character of the name which we are assuming is the disk #
     966                                                                        QString rom;
     967                                                                        QString diskid[] = { "%d0", "%d1", "%d2", "%d3", "%d4", "%d5", "%d6" };
     968                                                                       
     969                                                                        for (int disk = 1; disk <= diskcount; disk++)
     970                                                                        {
     971                                                                                rom = QString("\"%1/%2%3.%4\"")
     972                                                                                .arg(rompath)
     973                                                                                .arg(basename)
     974                                                                                .arg(disk)
     975                                                                                .arg(extension);
     976                                                                                exec = exec.replace(QRegExp(diskid[disk]),rom);
     977                                                                        }
     978                                                                }
     979                                                               
     980                                                                else
     981                                                                {   // If there is only one disk make sure we replace %d1 just like %s
     982                                                                        exec = exec.replace(QRegExp("%d1"),arg);
     983                                                                }
     984                                                        }
     985                                                }
     986                                        }
     987                                        else
     988                                        {
     989                                                exec = exec + " \"" +
     990                            rompath + "/" +
     991                            romname + "\"";
     992                                        }
     993                                }
     994                               
     995                                QString savedir = QDir::currentDirPath ();
     996                                QDir d;
     997                                if (handler->SystemWorkingPath()) {
     998                                        if (!d.cd(handler->SystemWorkingPath()))
     999                                        {
     1000                                                cout << "Failed to change to specified Working Directory : " << handler->SystemWorkingPath() << endl;
     1001                                        }
     1002                                }
     1003                               
     1004                                if (handler->ScreenShotCmd().length() < 2)
     1005                                        screencmd = gContext->GetSetting("GameScreenshotCmd");
     1006                                else
     1007                                        screencmd = handler->ScreenShotCmd();
     1008                               
     1009                                if (screencmd.contains("%p"))
     1010                                {
     1011                                        QString reptxt = handler->SystemScreenShots() + "/" + basename;
     1012                                        screencmd = screencmd.replace(QRegExp("%p"),reptxt);
     1013                                }
     1014                               
     1015                                if (screencmd.contains("%s"))
     1016                                {
     1017                                        QString reptxt = rompath + "/" + romname;
     1018                                        screencmd = screencmd.replace(QRegExp("%s"),reptxt);       
     1019                                }
     1020                               
     1021                                process = new QProcess();
     1022                               
     1023                                // We need to pass separate args to QProcess. Rather than split
     1024                                // "exec" up, (which would require parsing the user-supplied
     1025                                // command), get sh to do it
     1026                                QStringList shellCmd;
     1027                               
     1028                                shellCmd.append("sh");
     1029                                shellCmd.append("-c");
     1030                                shellCmd.append(exec);
     1031                               
     1032                                process->setArguments(shellCmd);
     1033                               
     1034                                QString ShotTime = gContext->GetSetting("GameScreenshotTime");
     1035                                int myShotTime = ShotTime.toInt() * 1000;
     1036                               
     1037                                m_TimerDone = false;
     1038                               
     1039                                QTimer::singleShot( myShotTime, this, SLOT( screenshotTimeout() ) );
     1040                               
     1041                                if (!process->start())
     1042                                        cout << "Error running Process:" << exec << endl;
     1043                               
     1044                                // some emulators such as xmame or sdlmess will
     1045                                // quit prematurely if it is fed a bad ROM file. The m_TimerDone
     1046                                // variable is set to true when the timer kills the process.
     1047                                // if this is not done, the program can trip over itself because
     1048                                // it would iterate throuh the next step in the loop, and then then
     1049                                // when the timer is run out - it would kill whatever process happened
     1050                                // to be pointing to.
     1051                                while (process->isRunning() | !m_TimerDone){
     1052                                        qApp->processEvents();
     1053                                }
     1054                               
     1055                                delete process;
     1056                        }
     1057                }
     1058               
     1059                screenshotDlg.Close();
     1060        }
     1061               
     1062        handler = handlers->next();
     1063       
     1064    }
     1065}
     1066void GameHandler::screenshotTimeout(void)
     1067{
     1068        // there is a chance the process already killed itself...
     1069        // in which case we don't need to take a screenshot of the MythTV Gui
     1070        if (process->isRunning()) {
     1071                myth_system(screencmd);
     1072                process->kill();
     1073        }
     1074        m_TimerDone = true;
     1075}
  • mythgame/game_settings.xml

     
    2424      <text>Game Players</text>
    2525      <text lang="IT">Impostazioni generali</text>
    2626      <text lang="ES">Opciones Reproductores</text>
    27       <text lang="CA">Opcions Generals</text>
    28       <text lang="DE">Grundeinstellungen</text>
     27      <text lang="CA"></text>
     28      <text lang="DE">Spielestarter</text>
    2929      <text lang="DK">Spil Systemer</text>
    3030      <text lang="NL">Algemeen</text>
    3131      <text lang="PT">Jogadores</text>
     
    5959      <text>Clear Game Data</text>
    6060      <text lang="IT">Impostazioni generali</text>
    6161      <text lang="ES">Borrar Datos</text>
    62       <text lang="CA">Opcions Generals</text>
    63       <text lang="DE">Grundeinstellungen</text>
     62      <text lang="CA"></text>
     63      <text lang="DE">Loesche Spieleliste</text>
    6464      <text lang="DK">Slet spil data</text>
    65       <text lang="NL">Algemeen</text>
     65      <text lang="NL"></text>
    6666      <text lang="PT">Apagar Dados de Jogos</text>
    6767      <text lang="SV">Generella instÀllningar</text>
    6868      <text lang="SI">SploÅ¡ne nastavitve</text>
     
    7373      <action>CLEAR_GAME_DATA</action>
    7474   </button>
    7575
     76   <button>
     77      <type>GAME_SETTINGS_GENERAL</type>
     78      <text>Generate Screenshots</text>
     79      <text lang="IT"></text>
     80      <text lang="ES"></text>
     81      <text lang="CA"></text>
     82      <text lang="DE">Screenshots erzeugen</text>
     83      <text lang="DK"></text>
     84      <text lang="NL"></text>
     85      <text lang="PT"></text>
     86      <text lang="SV"></text>
     87      <text lang="SI"></text>
     88      <text lang="FI"></text>
     89      <action>GENERATE_SCREENSHOTS</action>
     90   </button>
    7691
    7792</mythmenu>
  • mythgame/gamehandler.h

     
    5353
    5454typedef QMap <QString, GameScan> GameScanMap;
    5555
    56 class GameHandler
    57 {
     56class GameHandler : public QObject
     57
     58 
     59  Q_OBJECT
     60 
    5861  public:
    5962    GameHandler()
    6063    {
    6164        m_RemoveAll = false;
    6265        m_KeepAll = false;
     66                m_TimerDone = false;
    6367        rebuild = false;
    6468    }
    6569
     
    7478                             QString* Publisher, QString* Version);
    7579
    7680    void promptForRemoval(QString filename, QString RomPath );
    77     void UpdateGameDB(GameHandler *handler);
     81        void UpdateGameDB(GameHandler *handler);
    7882    void VerifyGameDB(GameHandler *handler);
    7983
    8084    static void clearAllGameData(void);
     85    void generateScreenshots(void);
    8186
    8287    static int buildFileCount(QString directory, GameHandler *handler);
    8388    void buildFileList(QString directory, GameHandler *handler,
     
    96101
    97102    static RomInfo* create_rominfo(RomInfo* parent);
    98103    int SpanDisks() const { return spandisks; }
     104       
     105    int ScreenShotEnabled() const { return screenshotenabled; }
     106        bool promptShouldOverwrite();
     107       
    99108    QString SystemName() const { return systemname; }
    100109    QString SystemCmdLine() const { return commandline; }
    101110    QString SystemRomPath() const { return rompath; }
     
    103112    QString SystemScreenShots() const { return screenshots; }
    104113    uint GamePlayerID() const { return gameplayerid; }
    105114    QString GameType() const { return gametype; }
     115    QString ScreenShotCmd() const { return screenshotcmd; }
     116   
     117  public slots:
     118    void screenshotTimeout(void);
    106119
    107120  protected:
    108121    static GameHandler* GetHandler(RomInfo *rominfo);
     
    110123
    111124    bool rebuild;
    112125    int spandisks;
     126    int screenshotenabled;
    113127    QString systemname;
    114128    QString rompath;
    115129    QString commandline;
     
    117131    QString screenshots;
    118132    uint gameplayerid;
    119133    QString gametype;
     134    QString screenshotcmd;
    120135    QStringList validextensions;
    121136
    122137    RomDBMap romDB;
     
    124139
    125140    bool m_RemoveAll;
    126141    bool m_KeepAll;
    127 
     142        bool m_TimerDone;
     143       
    128144  private:
    129145    static GameHandler* newInstance;
    130146
  • mythgame/rominfo.h

     
    5252
    5353    virtual ~RomInfo() {}
    5454
    55     bool FindImage(QString BaseFileName, QString *result);
     55    static bool FindImage(QString BaseFileName, QString *result);
    5656
    5757    QString Rompath() const { return rompath; }
    5858    void setRompath(const QString &lrompath) { rompath = lrompath; }
  • mythgame/dbcheck.cpp

     
    1010
    1111#include "gamesettings.h"
    1212
    13 const QString currentDatabaseVersion = "1012";
     13const QString currentDatabaseVersion = "1013";
    1414
    1515static bool UpdateDBVersionNumber(const QString &newnumber)
    1616{
     
    320320    }
    321321
    322322
     323    if (dbver == "1012")
     324    {
     325        const QString updates[] = {
     326"ALTER TABLE gameplayers ADD COLUMN screenshotcmd text NOT NULL default ''; ",
     327"ALTER TABLE gameplayers ADD COLUMN screenshotenabled tinyint(1) NOT NULL default '0'; ",
     328""
     329};
    323330
     331        if (!performActualUpdate(updates, "1013", dbver))
     332            return false;
     333    }
    324334
    325335
     336
     337
     338
    326339    return true;
    327340}
  • mythgame/main.cpp

     
    3434        settings.exec();
    3535    }
    3636
    37     if (sel == "game_players")
     37    else if (sel == "game_players")
    3838    {
    3939        MythGamePlayerEditor mgpe;
    4040        mgpe.exec();
     
    4343    {
    4444        GameHandler::processAllGames();
    4545    }
    46     if (sel == "clear_game_data")
     46   
     47    else if (sel == "clear_game_data")
    4748    {
    4849        GameHandler::clearAllGameData();
    4950    }
    5051
     52    else if (sel == "generate_screenshots")
     53    {
     54        GameHandler myHandler;
     55        myHandler.generateScreenshots();
     56    }
     57
    5158}
    5259
    5360void runMenu(QString which_menu)
  • mythgame/gamesettings.cpp

     
    7575    gc->setHelpText(QObject::tr("Enabling this causes the filenames to be displayed in the game tree rather than the trimmed/looked up gamename"));
    7676    return gc;
    7777}   
     78static HostLineEdit *GameScreenshotCmd()
     79{
     80    HostLineEdit *gc = new HostLineEdit("GameScreenshotCmd");
     81    gc->setLabel(QObject::tr("Screenshot Command"));
     82    gc->setValue("/usr/bin/scrot --quality 1 \"%p.png\"");
     83    gc->setHelpText(QObject::tr("Program which generates Screenshots "
     84                    "when the Rom is started in Background "
     85                    "use %s for romname and %p for the imagename without extension."));
     86    return gc;
     87}
    7888
     89static HostLineEdit *GameScreenshotTime()
     90{
     91    HostLineEdit *gc = new HostLineEdit("GameScreenshotTime");
     92    gc->setLabel(QObject::tr("Screenshot Timeout:"));
     93    gc->setValue("10");
     94    gc->setHelpText(QObject::tr("Enter Time (in seconds) after which a Screenshot is taken"));
     95    return gc;
     96}
     97
    7998static HostCheckBox *GameTreeView()
    8099{
    81100    HostCheckBox *gc = new HostCheckBox("GameTreeView");
     
    95114    general->addChild(GameRemovalPrompt());
    96115    general->addChild(GameShowFileNames());
    97116    general->addChild(GameTreeView());
     117    VerticalConfigurationGroup *screenshot = new VerticalConfigurationGroup(false);
     118    screenshot->setLabel(QObject::tr("MythGame Settings -- Screenshots"));
     119    screenshot->addChild(GameScreenshotCmd());
     120    screenshot->addChild(GameScreenshotTime());
     121
    98122    addChild(general);
     123    addChild(screenshot);
    99124}
    100125
    101126// Player Settings
     
    190215    };
    191216};
    192217
     218class GenerateScreenshots: virtual public MGSetting, virtual public CheckBoxSetting {
     219public:
     220    GenerateScreenshots(const MythGamePlayerSettings& parent):
     221        MGSetting(parent, "screenshotenabled") {
     222        setLabel(QObject::tr("Generate screenshots"));
     223        setHelpText(QObject::tr("This setting means that this Gameplayer is included in the generation of screenshots."));
     224    };
     225};
     226
     227class GenerateScreenshotsCmd: virtual public MGSetting, virtual public LineEditSetting {
     228public:
     229    GenerateScreenshotsCmd(const MythGamePlayerSettings& parent):
     230        MGSetting(parent, "screenshotcmd") {
     231        setLabel(QObject::tr("Screenshot Command"));
     232        setHelpText(QObject::tr("If you want another Command then the global to Generate Screenshots, Enter it here!"));
     233    };
     234};
     235
    193236MythGamePlayerSettings::MythGamePlayerSettings()
    194237{
    195238    // must be first
     
    205248    group->addChild(new WorkingDirPath(*this));
    206249    group->addChild(new Extensions(*this));
    207250    group->addChild(new AllowMultipleRoms(*this));
     251    group->addChild(new GenerateScreenshots(*this));
     252    group->addChild(new GenerateScreenshotsCmd(*this));
    208253    addChild(group);
    209254};
    210255