[mythtv] [PATCH] (MythGames) Automatic MAME image downloading

mian mythtv at mian.net.au
Mon Feb 2 02:56:00 EST 2004


This patch adds 2 options to the MAME settings (misc 2) page.  The first
setting is the path to a MAME image downloader, this can be a perl script
preferably.  The program is passed 3 arguments, the screenshot directory,
the rom name and finally the full game name.  The second checkbox,
automatically download missing images will launch the image downloader
when browsing the game tree, if an image does not exist.  The database is
utilized so the try is only attempted once on each game, if you wish to
force a re-download on a game try something like

UPDATE mamemetadata SET image_searched=0 WHERE romname='1943';

for installation
ALTER TABLE mamemetadata ADD image_searched tinyint(1) NOT NULL DEFAULT 0;
as I didn't want to touch the original MythGame SQL files.

as you browse over games with missing screenshots for the first time the
mythfrontend screen will show output like
Launching: /usr/bin/mame_imagedl "/usr/share/games/xmame/screens" "1942"
"1942 (set 1)"
Launching: /usr/bin/mame_imagedl "/usr/share/games/xmame/screens" "1943"
"1943 - The Battle of Midway (US)"

I don't actually remember enough Perl to write the image downloader as yet
:), can figure it out over time but my weekend is almost up for playtime
coding so I won't be able to try till next week.  If anyone is experienced
with Perl and would like to write a script it would be welcomed.  The idea
is to search http://www.vgmuseum.com/test95.html for the full game name
then store the image as [screenshots]/[romname].jpg

--
mian
-------------- next part --------------
--- work-orig/mythgame/mythgame/mametypes.h	2004-02-02 16:26:27.590659584 +1030
+++ work-mameimagedler/mythgame/mythgame/mametypes.h	2004-02-02 17:08:39.596736152 +1030
@@ -32,7 +32,9 @@
 
     int show_disclaimer;
     int show_gameinfo;
-
+    int automatically_download_images;
+    
+    QString image_downloader;
     QString rom_url;
     QString screenshot_url;
     QString flyer_url;
--- work-orig/mythgame/mythgame/gamesettings.cpp	2004-02-02 16:26:27.589659736 +1030
+++ work-mameimagedler/mythgame/mythgame/gamesettings.cpp	2004-02-02 17:16:32.069909312 +1030
@@ -121,6 +121,26 @@
     };
 };
 
+class MameImageDownloader: public LineEditSetting, public GlobalSetting {
+public:
+    MameImageDownloader():
+        GlobalSetting("MameImageDownloader") {
+        setLabel(QObject::tr("MAME image downloader"));
+        setValue("");
+        setHelpText(QObject::tr("The path to the MAME image downloader helper."));
+    };
+};
+
+class MameAutomaticallyDownloadImages: public CheckBoxSetting, public GlobalSetting {
+public:
+    MameAutomaticallyDownloadImages():
+        GlobalSetting("MameAutomaticallyDownloadImages") {
+        setLabel(QObject::tr("Automatically download images"));
+        setValue(true);
+        setHelpText(QObject::tr("Attempt to automatically download ROM images if they don't exist."));
+    };
+};
+
 class MameShowDisclaimer: public CheckBoxSetting, public GlobalSetting {
 public:
     MameShowDisclaimer():
@@ -260,6 +280,8 @@
     mame2->addChild(new MameCabinetsLocation());
     mame2->addChild(new MameHistoryLocation());
     mame2->addChild(new MameCheatLocation());
+    mame2->addChild(new MameImageDownloader());
+    mame2->addChild(new MameAutomaticallyDownloadImages());
     mame2->addChild(new MameShowDisclaimer());
     mame2->addChild(new MameShowGameInfo());
     addChild(mame2);
--- work-orig/mythgame/mythgame/mamehandler.cpp	2004-02-02 16:26:27.590659584 +1030
+++ work-mameimagedler/mythgame/mythgame/mamehandler.cpp	2004-02-02 17:13:09.449712264 +1030
@@ -930,6 +930,8 @@
     general_prefs.cheat_file = gContext->GetSetting("MameCheatLocation");
     general_prefs.show_disclaimer = gContext->GetNumSetting("MameShowDisclaimer");
     general_prefs.show_gameinfo = gContext->GetNumSetting("MameShowGameInfo");
+    general_prefs.automatically_download_images = gContext->GetNumSetting("MameAutomaticallyDownloadImages");
+    general_prefs.image_downloader = gContext->GetSetting("MameImageDownloader");
 }
 
 void MameHandler::SetGameSettings(GameSettings &game_settings, MameRomInfo *rominfo)
--- work-orig/mythgame/mythgame/mamerominfo.cpp	2004-02-02 16:26:27.590659584 +1030
+++ work-mameimagedler/mythgame/mythgame/mamerominfo.cpp	2004-02-02 18:01:21.721020192 +1030
@@ -1,4 +1,9 @@
+#include <iostream>
 #include <qsqldatabase.h>
+#include <mythtv/mythcontext.h>
+#include <sys/types.h>
+#include <stdlib.h>
+#include <unistd.h>
 #include "mamerominfo.h"
 #include "mametypes.h"
 
@@ -15,7 +20,7 @@
 
     QString thequery = "SELECT manu,cloneof,romof,driver,"
                        "cpu1,cpu2,cpu3,cpu4,sound1,sound2,sound3,sound4,"
-                       "players,buttons FROM mamemetadata WHERE "
+                       "players,buttons,image_searched FROM mamemetadata WHERE "
                        "romname=\"" + romname + "\";";
 
     QSqlQuery query = db->exec(thequery);
@@ -37,6 +42,7 @@
         sound1 = query.value(11).toString();
         num_players = query.value(12).toInt();
         num_buttons = query.value(13).toInt();
+        image_searched = query.value(14).toInt();
     }
 }
 
@@ -107,11 +113,36 @@
     }
 
     /* if image does not exist launch, check if we want to automatically try download */
-    if (*result == "")
+    if (type == "screenshot" && *result == "")
     {
-        if (1)
+        /* if we are automatically downloading images and this rom has not been processed before */
+        if (general_prefs.automatically_download_images && !ImageSearched() &&
+            dirs.size() > 0 && !general_prefs.image_downloader.isEmpty() &&
+            !dirs[0].isEmpty()
+        )
         {
+            /* spawn background image downloader */
+            QString cmdline;
 
+            cmdline = "\"" + dirs[0] + "\" ";
+            cmdline += "\"" + games[0] + "\" ";
+            cmdline += "\"" + gamename + "\"";
+
+            cout << "Launching: " + general_prefs.image_downloader + " " + cmdline << endl;
+
+            if (fork() == 0)
+            {
+                execl(general_prefs.image_downloader, cmdline.ascii());
+                exit(0);
+            }
+
+            /* update SQL */
+            QString theQuery = "UPDATE mamemetadata SET image_searched = 1 WHERE "
+                               "romname=\"" + romname + "\";";
+
+            QSqlDatabase* db = QSqlDatabase::database(); 
+            QSqlQuery query = db->exec(theQuery);
+            setImageSearched(true);
         }
     }    
 
--- work-orig/mythgame/mythgame/mamerominfo.h	2004-02-02 16:26:27.590659584 +1030
+++ work-mameimagedler/mythgame/mythgame/mamerominfo.h	2004-02-02 17:03:44.404612176 +1030
@@ -20,8 +20,9 @@
                 QString lsystem = "",
                 QString lgamename ="",
                 QString lgenre = "",
-                int lyear = 0) :
-            RomInfo(lromname, lsystem, lgamename, lgenre, lyear)
+                int lyear = 0,
+                bool limage_searched = false) :
+            RomInfo(lromname, lsystem, lgamename, lgenre, lyear, limage_searched)
             {}
     MameRomInfo(const MameRomInfo &lhs) :
                 RomInfo(lhs)
@@ -48,6 +49,7 @@
                 vector = lhs.vector;
                 favourite = lhs.favourite;
                 timesplayed = lhs.timesplayed;
+                image_searched = lhs.image_searched;
             }
     MameRomInfo(const RomInfo &lhs) :
                 RomInfo(lhs) {}
@@ -116,6 +118,9 @@
 
     bool Favourite() const { return favourite; }
     void setFavourite(bool lfavourite) { favourite = lfavourite; }
+ 
+    bool ImageSearched() const { return image_searched; }
+    void setImageSearched(bool limage_searched) { image_searched = limage_searched; }
 
     int Timesplayed() const { return timesplayed; }
     void setTimesplayed(int ltimesplayed) { timesplayed = ltimesplayed; }
@@ -146,6 +151,7 @@
     bool vector;
     bool favourite;
     int timesplayed;
+    bool image_searched;
 };
 
 #endif


More information about the mythtv-dev mailing list