Ticket #7889: mythgame.diff

File mythgame.diff, 22.1 KB (added by paulh, 14 years ago)
  • mythgame/gamehandler.cpp

     
    55#include <QObject>
    66#include <QRegExp>
    77#include <QDir>
    8 #include <Q3PtrList>
     8#include <QList>
    99
    1010#include <mythcontext.h>
    1111#include <mythdbcon.h>
     
    1616#define LOC_ERR QString("MythGame:GAMEHANDLER Error: ")
    1717#define LOC QString("MythGame:GAMEHANDLER: ")
    1818
    19 static Q3PtrList<GameHandler> *handlers = NULL;
     19static QList<GameHandler*> *handlers = NULL;
    2020
    2121bool existsHandler(const QString name)
    2222{
    23     GameHandler *handler = handlers->first();
    24     while(handler)
     23    for (int i = 0; i < handlers->size(); i++)
    2524    {
     25        GameHandler *handler = handlers->at(i);
    2626        if (handler->SystemName() == name)
    27         {
    28             return TRUE;
    29         }
    30        
    31         handler = handlers->next();
     27            return true;
    3228    }
    3329
    34     return FALSE;
     30    return false;
    3531}
    3632
    3733static void checkHandlers(void)
    3834{
    3935    // If a handlers list doesn't currently exist create one. Otherwise
    4036    // clear the existing list so that we can regenerate a new one.
    41     if (! handlers)
    42     {   
    43         handlers = new Q3PtrList<GameHandler>;
    44     }
    45     else {
     37    if (!handlers)
     38        handlers = new QList<GameHandler*>;
     39    else
     40    {
     41        while (!handlers->isEmpty())
     42            delete handlers->takeFirst();
    4643        handlers->clear();
    4744    }
    4845
     
    5249        MythDB::DBError("checkHandlers - selecting playername", query);
    5350
    5451    while (query.next())
    55     {   
     52    {
    5653        QString name = query.value(0).toString();
    5754        GameHandler::registerHandler(GameHandler::newHandler(name));
    58     }   
    59 
     55    }
    6056}
    6157
    62 GameHandler* GameHandler::getHandler(uint i)
     58GameHandler *GameHandler::getHandler(uint i)
    6359{
    6460    return handlers->at(i);
    6561}
     
    8278        handler->screenshots = query.value(3).toString();
    8379        handler->gameplayerid = query.value(4).toInt();
    8480        handler->gametype = query.value(5).toString();
    85         handler->validextensions = QStringList::split(",",
    86                      query.value(6).toString().stripWhiteSpace().remove(" "));
     81        handler->validextensions = query.value(6).toString().trimmed()
     82                                        .remove(" ").split(",");
    8783        handler->spandisks = query.value(7).toInt();
    8884    }
    89 
    9085}
    9186
    9287GameHandler* GameHandler::newInstance = 0;
     
    307302{
    308303    MSqlQuery query(MSqlQuery::InitCon());
    309304
    310     QRegExp multiDiskRGXP = QRegExp( "[0-4]$", TRUE, FALSE );
     305    QRegExp multiDiskRGXP = QRegExp( "[0-4]$", Qt::CaseSensitive, QRegExp::RegExp);
    311306    int diskcount = 0;
    312307    int pos = 0;
    313308
     
    344339                {
    345340                    {
    346341
    347                         pos = RomName.findRev(".");
     342                        pos = RomName.lastIndexOf(".");
    348343                        if (pos > 1)
    349344                        {   
    350345                            extlength = RomName.length() - pos;
     
    428423    for (iter = m_GameMap.begin(); iter != m_GameMap.end(); iter++)
    429424    {
    430425
    431         if (iter.data().FoundLoc() == inFileSystem)
     426        if (iter.value().FoundLoc() == inFileSystem)
    432427        {
    433428            if (indepth)
    434429            {
    435                 GetMetadata(handler, iter.data().RomFullPath(), &Genre, &Year, &Country, &CRC32, &GameName,
     430                GetMetadata(handler, iter.value().RomFullPath(), &Genre, &Year, &Country, &CRC32, &GameName,
    436431                            &Plot, &Publisher, &Version, &Fanart, &Boxart);
    437432            }
    438433            else
    439434            {
    440                 Genre = QObject::tr( QString("Unknown%1").arg( handler->GameType() ));
     435                Genre = QObject::tr("Unknown") + handler->GameType();
    441436                Country = QObject::tr("Unknown");
    442437                CRC32 = "";
    443438                Year = QObject::tr("19xx");
     
    450445            }
    451446
    452447            if (GameName == QObject::tr("Unknown"))
    453                 GameName = iter.data().GameName();
     448                GameName = iter.value().GameName();
    454449
    455             int suffixPos = iter.data().Rom().lastIndexOf(QChar('.'));
    456             QString baseName = iter.data().Rom();
     450            int suffixPos = iter.value().Rom().lastIndexOf(QChar('.'));
     451            QString baseName = iter.value().Rom();
    457452
    458453            if (suffixPos > 0)
    459                 baseName = iter.data().Rom().left(suffixPos);
     454                baseName = iter.value().Rom().left(suffixPos);
    460455
    461             baseName = screenShotPath + "/" + baseName;
     456            baseName = screenShotPath + "/" + baseName;
    462457
    463             if (QFile(baseName + ".png").exists())
     458            if (QFile(baseName + ".png").exists())
    464459                ScreenShot = baseName + ".png";
    465460            else if (QFile(baseName + ".jpg").exists())
    466461                ScreenShot = baseName + ".jpg";
     
    481476                          ":FANART, :BOXART, :SCREENSHOT)");
    482477
    483478            query.bindValue(":SYSTEM",handler->SystemName());
    484             query.bindValue(":ROMNAME",iter.data().Rom());
     479            query.bindValue(":ROMNAME",iter.value().Rom());
    485480            query.bindValue(":GAMENAME",GameName);
    486481            query.bindValue(":GENRE",Genre);
    487482            query.bindValue(":YEAR",Year);
    488483            query.bindValue(":GAMETYPE",handler->GameType());
    489             query.bindValue(":ROMPATH",iter.data().RomPath());
     484            query.bindValue(":ROMPATH",iter.value().RomPath());
    490485            query.bindValue(":COUNTRY",Country);
    491486            query.bindValue(":CRC32", CRC32);
    492487            query.bindValue(":PLOT", Plot);
     
    494489            query.bindValue(":VERSION", Version);
    495490            query.bindValue(":FANART", Fanart);
    496491            query.bindValue(":BOXART", Boxart);
    497             query.bindValue(":SCREENSHOT", ScreenShot);
     492            query.bindValue(":SCREENSHOT", ScreenShot);
    498493
    499494            if (!query.exec())
    500495                MythDB::DBError("GameHandler::UpdateGameDB - "
    501496                                "insert gamemetadata", query);
    502497        }
    503         else if ((iter.data().FoundLoc() == inDatabase) && (removalprompt))
     498        else if ((iter.value().FoundLoc() == inDatabase) && (removalprompt))
    504499        {
    505500
    506             promptForRemoval( iter.data().Rom() , iter.data().RomPath() );
     501            promptForRemoval( iter.value().Rom() , iter.value().RomPath() );
    507502        }
    508503
    509504        progressDlg->setProgress(++counter);
     
    545540                if ((iter = m_GameMap.find(RomName)) != m_GameMap.end())
    546541                {
    547542                    // If it's both on disk and in the database we're done with it.
    548                     m_GameMap.remove(iter);
     543                    m_GameMap.erase(iter);
    549544                }
    550545                else
    551546                {
     
    569564    int filecount = 0;
    570565    QDir RomDir(directory);
    571566
    572                                 // If we can't read it's contents move on
     567    // If we can't read it's contents move on
    573568    if (!RomDir.isReadable())
    574569        return 0;
    575570
    576571    QFileInfoList List = RomDir.entryInfoList();
    577572    for (QFileInfoList::const_iterator it = List.begin();
    578573         it != List.end(); ++it)
    579     {   
     574    {
    580575        QFileInfo Info = *it;
    581576        QString RomName = Info.fileName();
    582577
    583578        if (RomName == "." ||
    584579            RomName == "..")
    585         {   
     580        {
    586581            continue;
    587582        }
    588583
    589584        if (Info.isDir())
    590         {   
     585        {
    591586            filecount += buildFileCount(Info.filePath(), handler);
    592587            continue;
    593588        }
    594589        else
    595         {   
     590        {
    596591            if (handler->validextensions.count() > 0)
    597             {   
     592            {
    598593                QRegExp r;
    599594
    600                 r.setPattern("^" + Info.extension( FALSE ) + "$");
    601                 r.setCaseSensitive(false);
    602                 QStringList result = handler->validextensions.grep(r);
    603                 if (result.isEmpty()) {
     595                r.setPattern("^" + Info.suffix() + "$");
     596                r.setCaseSensitivity(Qt::CaseInsensitive);
     597                QStringList result;
     598                for (int x = 0; x < handler->validextensions.size(); x++)
     599                {
     600                    QString extension = handler->validextensions.at(x);
     601                    if (extension.contains(r))
     602                        result.append(extension);
     603                }
     604                if (result.isEmpty())
    604605                    continue;
    605                 }
    606606            }
     607
    607608            filecount++;
    608 
    609609        }
    610610    }
    611611
     
    658658    {
    659659        QFileInfo Info = *it;
    660660        QString RomName = Info.fileName();
    661         QString GameName = Info.baseName(TRUE);
     661        QString GameName = Info.completeBaseName();
    662662
    663663        if (RomName == "." ||
    664664            RomName == "..")
     
    678678            {
    679679                QRegExp r;
    680680
    681                 r.setPattern("^" + Info.extension( FALSE ) + "$");
    682                 r.setCaseSensitive(false);
    683                 QStringList result = handler->validextensions.grep(r);
    684                 if (result.isEmpty()) {
     681                r.setPattern("^" + Info.suffix() + "$");
     682                r.setCaseSensitivity(Qt::CaseInsensitive);
     683                QStringList result;
     684                for (int x = 0; x < handler->validextensions.size(); x++)
     685                {
     686                    QString extension = handler->validextensions.at(x);
     687                    if (extension.contains(r))
     688                        result.append(extension);
     689                }
     690
     691                if (result.isEmpty())
    685692                    continue;
    686                 }
    687693            }
    688694
    689695            m_GameMap[RomName] = GameScan(RomName,Info.filePath(),inFileSystem,
    690                                  GameName,Info.dirPath());
     696                                 GameName, Info.absoluteDir().path());
    691697
    692             VERBOSE(VB_GENERAL, LOC + QString("Found Rom : (%1) - %2")
    693                                       .arg(handler->SystemName())
    694                                       .arg(RomName));
     698            VERBOSE(VB_GENERAL, LOC + QString("Found Rom : (%1) - %2")
     699                    .arg(handler->SystemName()).arg(RomName));
    695700
    696701            *filecount = *filecount + 1;
    697702            pdial->setProgress(*filecount);
     
    728733
    729734    if (handler->GameType() == "PC")
    730735    {
    731         m_GameMap[handler->SystemCmdLine()] = GameScan(handler->SystemCmdLine(),
    732                                                        handler->SystemCmdLine(),
    733                                                        inFileSystem,
    734                                                        handler->SystemName(),
    735                                                        handler->SystemCmdLine().left(handler->SystemCmdLine().findRev(QRegExp("/"))));
     736        m_GameMap[handler->SystemCmdLine()] =
     737                GameScan(handler->SystemCmdLine(),
     738                    handler->SystemCmdLine(),
     739                    inFileSystem,
     740                    handler->SystemName(),
     741                    handler->SystemCmdLine().left(handler->SystemCmdLine().lastIndexOf(QRegExp("/"))));
    736742
    737743
    738744        pdial->setProgress(maxcount);
     
    770776    checkHandlers();
    771777    QStringList updatelist;
    772778
    773     GameHandler *handler = handlers->first();
    774 
    775     while(handler)
     779    for (int x = 0; x < handlers->size(); x++)
    776780    {
    777         updateSettings(handler);
    778         handler->processGames(handler);
     781        GameHandler *handler = handlers->at(x);
    779782
    780         if (handler->needRebuild())
    781             updatelist.append(handler->GameType());
     783        if (handler)
     784        {
     785            updateSettings(handler);
     786            handler->processGames(handler);
    782787
    783         handler = handlers->next();
     788            if (handler->needRebuild())
     789                updatelist.append(handler->GameType());
     790        }
    784791    }
    785792
    786793    if (!updatelist.isEmpty())
     
    792799    if (!rominfo)
    793800        return NULL;
    794801
    795     GameHandler *handler = handlers->first();
    796     while(handler)
    797     {   
    798         if(rominfo->System() == handler->SystemName())
    799         {   
    800             return handler;
     802    for (int x = 0; x < handlers->size(); x++)
     803    {
     804        GameHandler *handler = handlers->at(x);
     805        if (handler)
     806        {
     807            if (rominfo->System() == handler->SystemName())
     808                return handler;
    801809        }
    802         handler = handlers->next();
    803810    }
    804     return handler;
     811
     812    return NULL;
    805813}
    806814
    807815GameHandler* GameHandler::GetHandlerByName(QString systemname)
     
    809817    if (systemname.isEmpty() || systemname.isNull())
    810818        return NULL;
    811819
    812     GameHandler *handler = handlers->first();
    813     while(handler)
     820    for (int x = 0; x < handlers->size(); x++)
    814821    {
    815         if(handler->SystemName() == systemname)
     822        GameHandler *handler = handlers->at(x);
     823
     824        if (handler)
    816825        {
    817             return handler;
     826            if (handler->SystemName() == systemname)
     827                return handler;
    818828        }
    819         handler = handlers->next();
    820829    }
    821     return handler;
     830
     831    return NULL;
    822832}
    823833
    824834void GameHandler::Launchgame(RomInfo *romdata, QString systemname)
     
    850860
    851861            if (handler->SpanDisks())
    852862            {
    853                 QRegExp rxp = QRegExp( "%d[0-4]", TRUE, FALSE );
     863                QRegExp rxp = QRegExp( "%d[0-4]", Qt::CaseSensitive, QRegExp::RegExp);
    854864
    855865                if (exec.contains(rxp))
    856866                {
    857867                    if (romdata->DiskCount() > 1)
    858868                    {
    859                         // Chop off the extension, .  and last character of the name which we are assuming is the disk #
     869                        // Chop off the extension, .  and last character of the name which we are assuming is the disk #
    860870                        QString basename = romdata->Romname().left(romdata->Romname().length() - (romdata->getExtension().length() + 2));
    861871                        QString extension = romdata->getExtension();
    862872                        QString rom;
     
    886896        }
    887897    }
    888898
    889     QString savedir = QDir::currentDirPath ();
     899    QString savedir = QDir::current().path();
    890900    QDir d;
    891     if (!handler->SystemWorkingPath().isEmpty()) {
     901    if (!handler->SystemWorkingPath().isEmpty())
     902    {
    892903        if (!d.cd(handler->SystemWorkingPath()))
    893904        {
    894905            VERBOSE(VB_GENERAL, LOC_ERR + QString("Failed to change to specified Working Directory: %1")
    895                                           .arg(handler->SystemWorkingPath()));
     906                    .arg(handler->SystemWorkingPath()));
    896907        }
    897908    }
    898909    VERBOSE(VB_GENERAL, LOC + QString("Launching Game : %1 : %2")
    899                               .arg(handler->SystemName())
    900                               .arg(exec));
     910           .arg(handler->SystemName())
     911           .arg(exec));
    901912
    902913
    903     QStringList cmdlist = QStringList::split(";", exec);
     914    QStringList cmdlist = exec.split(";");
    904915    if (cmdlist.count() > 0) {
    905916        for ( QStringList::Iterator cmd = cmdlist.begin(); cmd != cmdlist.end(); ++cmd ) {
    906917            VERBOSE(VB_GENERAL, LOC + QString("Executing : %1").arg(*cmd));
  • mythgame/gameui.cpp

     
    2222{
    2323  public:
    2424    GameTreeInfo(const QString& levels, const QString& filter)
    25       : m_levels(QStringList::split(" ", levels))
     25      : m_levels(levels.split(" "))
    2626      , m_filter(filter)
    2727    {
    2828    }
     
    120120
    121121    if (m_showHashed)
    122122    {
    123         int pos = levels.find("gamename",0);
     123        int pos = levels.indexOf("gamename");
    124124        if (pos >= 0)
    125125            levels.insert(pos, " hash ");
    126126    }
     
    253253            {
    254254                chooseSystemPopup->SetReturnEvent(this, "chooseSystemPopup");
    255255                QString all_systems = romInfo->AllSystems();
    256                 QStringList players = QStringList::split(",", all_systems);
     256                QStringList players = all_systems.split(",");
    257257                for (QStringList::Iterator it = players.begin();
    258258                     it != players.end(); ++it)
    259259                {
     
    546546            filter += " and romname like '" + layer + "%'";
    547547
    548548    }
    549     else if ((childLevel == "gamename") && (layer.length() == 1)) {
     549    else if ((childLevel == "gamename") && (layer.length() == 1))
     550    {
    550551        columns = childIsLeaf
    551552                    ? childLevel + ",system,year,genre,gamename"
    552553                    : childLevel;
     
    555556            filter += " and gamename like '" + layer + "%'";
    556557
    557558    }
    558     else if (childLevel == "hash") {
     559    else if (childLevel == "hash")
     560    {
    559561        columns = "left(gamename,1)";
    560562    }
    561     else {
     563    else
     564    {
    562565
    563566        columns = childIsLeaf
    564567                    ? childLevel + ",system,year,genre,gamename"
     
    567570
    568571    //  this whole section ought to be in rominfo.cpp really, but I've put it
    569572    //  in here for now to minimise the number of files changed by this mod
    570     if (romInfo) {
     573    if (romInfo)
     574    {
    571575        if (!romInfo->System().isEmpty())
    572576        {
    573577            filter += conj + "trim(system)=:SYSTEM";
     
    605609    QString sql;
    606610
    607611    if ((childLevel == "gamename") && (m_gameShowFileName))
    608     {   
     612    {
    609613        sql = "select distinct "
    610614                + columns
    611615                + " from gamemetadata "
     
    613617                + " order by romname"
    614618                + ";";
    615619    }
    616     else if (childLevel == "hash") {
     620    else if (childLevel == "hash")
     621    {
    617622        sql = "select distinct "
    618623                + columns
    619624                + " from gamemetadata "
     
    697702    {
    698703        while (query.next())
    699704        {
    700             QString current = query.value(0).toString().stripWhiteSpace();
     705            QString current = query.value(0).toString().trimmed();
    701706            MythGenericTree *new_node =
    702707                new MythGenericTree(current, node->getInt() + 1, false);
    703708            if (IsLeaf)
    704709            {
    705710                RomInfo *temp = new RomInfo();
    706                 temp->setSystem(query.value(1).toString().stripWhiteSpace());
     711                temp->setSystem(query.value(1).toString().trimmed());
    707712                temp->setYear(query.value(2).toString());
    708                 temp->setGenre(query.value(3).toString().stripWhiteSpace());
    709                 temp->setGamename(query.value(4).toString().stripWhiteSpace());
     713                temp->setGenre(query.value(3).toString().trimmed());
     714                temp->setGamename(query.value(4).toString().trimmed());
    710715                new_node->SetData(qVariantFromValue(temp));
    711716                node->addNode(new_node);
    712717            }
  • mythgame/rominfo.cpp

     
    130130    graphic_formats.append("tif");
    131131    graphic_formats.append("tiff");
    132132
    133     int dotLocation = BaseFileName.findRev('.');
     133    int dotLocation = BaseFileName.lastIndexOf('.');
    134134    if (dotLocation == -1)
    135135    {
    136136        BaseFileName.append('.');
     
    210210
    211211QString RomInfo::getExtension()
    212212{
    213     int pos = Romname().findRev(".");
     213    int pos = Romname().lastIndexOf(".");
    214214    if (pos == -1)
    215215        return NULL;
    216216
  • mythgame/gamehandler.h

     
    66#include <QMap>
    77
    88#include <mythdbcon.h>
    9 //#include <mythdialogs.h>
    109
    1110#include "rom_metadata.h"
    1211#include "rominfo.h"
     
    6261        m_RemoveAll(false),         m_KeepAll(false) {}
    6362
    6463    static void updateSettings(GameHandler*);
    65     static GameHandler* getHandler(uint i);
    66     static GameHandler* newHandler(QString name);
     64    static GameHandler *getHandler(uint i);
     65    static GameHandler *newHandler(QString name);
    6766    static uint count(void);
    6867    void InitMetaDataMap(QString GameType);
    6968    void GetMetadata(GameHandler *handler, QString rom,
  • mythgame/main.cpp

     
    3131void GameCallback(void *data, QString &selection)
    3232{
    3333    GameData *ddata = (GameData *)data;
    34     QString sel = selection.lower();
     34    QString sel = selection.toLower();
    3535
    3636    (void)ddata;
    3737
  • mythgame/mythgame.pro

     
    2323LIBS += -lz
    2424
    2525#The following line was inserted by qt3to4
    26 QT += xml sql opengl qt3support
     26QT += xml sql opengl
    2727
    2828include ( ../../libs-targetfix.pro )
  • mythgame/gamesettings.cpp

     
    140140QString GameDBStorage::GetSetClause(MSqlBindings &bindings) const
    141141{
    142142    QString playerID(":SETPLAYERID");
    143     QString colTag(":SET" + GetColumnName().upper());
     143    QString colTag(":SET" + GetColumnName().toUpper());
    144144
    145145    QString query("gameplayerid = " + playerID + ", " +
    146146                  GetColumnName() + " = " + colTag);
  • mythgame/rom_metadata.cpp

     
    3737    if (tmpcrc == "0")
    3838        tmpcrc = "";
    3939    else
    40         tmpcrc = tmpcrc.rightJustify( 8,'0');
     40        tmpcrc = tmpcrc.rightJustified(8, '0');
    4141
    4242    return tmpcrc;
    4343}
     
    5959    blocksize = 8192;
    6060    // VERBOSE(VB_GENERAL, QString("crcinfo : %1 : %2 :").arg(romname).arg(GameType));
    6161
    62     if ((zf = unzOpen(romname)))
     62    if ((zf = unzOpen(qPrintable(romname))))
    6363    {
    6464        int FoundFile;
    6565        for (FoundFile = unzGoToFirstFile(zf); FoundFile == UNZ_OK;
     
    105105            offset = calcOffset(GameType, f.size());
    106106
    107107            if (offset > 0)
    108                 f.readBlock(block, offset);
     108                f.read(block, offset);
    109109
    110110            // Get CRC of rom data
    111             Q_LONG count;
    112             while ((count = f.readBlock(block, blocksize)) > 0)
     111            qint64 count;
     112            while ((count = f.read(block, blocksize)) > 0)
    113113            {
    114114                crc = crc32(crc, (Bytef *)block, (uInt)count);
    115             }   
     115            }
    116116
    117117            crcRes = crcStr(crc);
    118118            *key = QString("%1:").arg(crcRes);