]> Shamusworld >> Repos - virtualjaguar/commitdiff
Added missing images, added some fixes to ZIP file support
authorShamus Hammons <jlhamm@acm.org>
Mon, 1 Mar 2010 21:23:44 +0000 (21:23 +0000)
committerShamus Hammons <jlhamm@acm.org>
Mon, 1 Mar 2010 21:23:44 +0000 (21:23 +0000)
res/cart-blank.png [new file with mode: 0644]
res/label-blank.png [new file with mode: 0644]
src/file.cpp
src/file.h
src/gui/filepicker.cpp
src/gui/filethread.cpp
src/gui/imagedelegate.cpp
src/gui/mainwin.cpp
src/unzip.c

diff --git a/res/cart-blank.png b/res/cart-blank.png
new file mode 100644 (file)
index 0000000..93338b8
Binary files /dev/null and b/res/cart-blank.png differ
diff --git a/res/label-blank.png b/res/label-blank.png
new file mode 100644 (file)
index 0000000..8605f74
Binary files /dev/null and b/res/label-blank.png differ
index bf8ad546028843c1bb9f8ca37ed709edebcb3413..6e895c57611887c34cb3cf557b64f516d7de70b2 100644 (file)
@@ -10,6 +10,7 @@
 // Who  When        What
 // ---  ----------  -------------------------------------------------------------
 // JLH  01/16/2010  Created this log ;-)
+// JLH  02/28/2010  Added functions to look inside .ZIP files and handle contents
 //
 
 #include "file.h"
@@ -27,6 +28,7 @@
 // Private function prototypes
 
 static int gzfilelength(gzFile gd);
+static bool CheckExtension(const char * filename, const char * ext);
 
 //
 // Generic ROM loading
@@ -35,7 +37,7 @@ uint32 JaguarLoadROM(uint8 * rom, char * path)
 {
 // We really should have some kind of sanity checking for the ROM size here to prevent
 // a buffer overflow... !!! FIX !!!
-#warning !!! FIX !!! Should have sanity checking for ROM size to prevent buffer overflow!
+#warning "!!! FIX !!! Should have sanity checking for ROM size to prevent buffer overflow!"
        uint32 romSize = 0;
 
 WriteLog("JaguarLoadROM: Attempting to load file '%s'...", path);
@@ -287,7 +289,7 @@ Start of Data Segment = 0x00803dd0
                }
                else
                {
-                       WriteLog("GUI: Couldn't find correct ABS format: %02X %02X\n", jaguarMainROM[0], jaguarMainROM[1]);
+                       WriteLog("GUI: Couldn't find correct ABS/COF format: %02X %02X\n", jaguarMainROM[0], jaguarMainROM[1]);
                        return false;
                }
        }
@@ -345,3 +347,78 @@ static int gzfilelength(gzFile gd)
    gzrewind(gd);
    return length;
 }
+
+//
+// Compare extension to passed in filename. If equal, return true; otherwise false.
+//
+static bool CheckExtension(const char * filename, const char * ext)
+{
+       const char * filenameExt = strrchr(filename, '.');      // Get the file's extension (if any)
+       return (strcasecmp(filenameExt, ext) == 0 ? true : false);
+}
+
+//
+// Get file from .ZIP
+// Returns the size of the file inside the .ZIP file that we're looking at
+//
+uint32 GetFileFromZIP(const char * zipFile, FileType type, uint8 * buffer)
+{
+#warning "!!! FIX !!! Should have sanity checking for ROM size to prevent buffer overflow!"
+       const char ftStrings[5][32] = { "Software", "EEPROM", "Label", "Box Art", "Controller Overlay" };
+       ZIP * zip = openzip(0, 0, zipFile);
+
+       if (zip == NULL)
+       {
+               WriteLog("FILE: Could not open file '%s'!\n", zipFile);
+               return 0;
+       }
+
+       while (readzip(zip))
+       {
+               zipent * ze = &zip->ent;
+               bool found = false;
+
+               if ((type == FT_LABEL) && (CheckExtension(ze->name, ".png") || CheckExtension(ze->name, ".jpg") || CheckExtension(ze->name, ".gif")))
+               {
+                       found = true;
+                       WriteLog("FILE: Found image file '%s'.\n", ze->name);
+               }
+
+               if ((type == FT_SOFTWARE) && (CheckExtension(ze->name, ".j64") || CheckExtension(ze->name, ".rom") || CheckExtension(ze->name, ".abs") || CheckExtension(ze->name, ".cof")))
+               {
+                       found = true;
+                       WriteLog("FILE: Found software file '%s'.\n", ze->name);
+               }
+
+               if ((type == FT_EEPROM) && (CheckExtension(ze->name, ".eep") || CheckExtension(ze->name, ".eeprom")))
+               {
+                       found = true;
+                       WriteLog("FILE: Found EEPROM file '%s'.\n", ze->name);
+               }
+
+               if (found)
+               {
+                       WriteLog("FILE: Uncompressing...");
+
+                       if (readuncompresszip(zip, ze, (char *)buffer) == 0)
+                       {
+                               WriteLog("success! (%u bytes)\n", ze->uncompressed_size);
+                               return ze->uncompressed_size;
+                       }
+                       else
+                       {
+                               WriteLog("FAILED!\n");
+                               return 0;
+                       }
+               }
+       }
+
+       closezip(zip);
+
+       WriteLog("FILE: Failed to find file of type %s...\n", ftStrings[type]);
+       // Didn't find what we're looking for...
+       return 0;
+}
+
+//ParseFileType, etc.
+
index 7fa3daf4907687a08d6d9d420df4de9300e2aa0a..901124465dacc337be938f1c0cf98322575ac116 100644 (file)
 extern "C" {
 #endif
 
+enum FileType { FT_SOFTWARE=0, FT_EEPROM, FT_LABEL, FT_BOXART, FT_OVERLAY };
+
 uint32 JaguarLoadROM(uint8 * rom, char * path);
 bool JaguarLoadFile(char * path);
+uint32 GetFileFromZIP(const char * zipFile, FileType type, uint8 * buffer);
 
 #ifdef __cplusplus
 }
index 1129d17ca905e165ec5672e9a39e70ad922a6967..9f85885f6f9b96cdfc0c8b4c489ec6cebdd66253 100644 (file)
@@ -68,7 +68,7 @@ FilePickerWindow::FilePickerWindow(QWidget * parent/*= 0*/): QWidget(parent, Qt:
 void FilePickerWindow::AddFileToList(unsigned long index)
 {
 printf("FilePickerWindow: Found match [%s]...\n", romList[index].name);
-       // NOTE: The model *ignores* what you send it, so this is crap. !!! FIX !!!
+       // NOTE: The model *ignores* what you send it, so this is crap. !!! FIX !!! [DONE, somewhat]
 //     model->AddData(QIcon(":/res/generic.png"));
        model->AddData(index);
 }
index d4cccc2ea3fbf3a11692a8d5da470ecec96a0726..3229c3521a4bb5c2445ff8198067d8a21bae1305 100644 (file)
@@ -92,6 +92,7 @@ printf("FileThread: Aborting!!!\n");
 
                        uint32 index = FindCRCIndexInFileList(crc);
 
+// Mebbe we should pass a index AND a QImage here???
                        if (index != 0xFFFFFFFF && !(romList[index].flags & FF_BIOS))
                                emit FoundAFile(index);
                }
index 827bc007df39ff8715733b55fbf32435554d14dc..d148c2c12c76db30b006f13d8875c3f926fb6ae6 100644 (file)
@@ -80,13 +80,13 @@ The foreground of the item (the circle representing a pixel) must be rendered us
        if (romList[i].file[0] == 0)
        {
 //     painter->drawPixmap(option.rect.x()+14, option.rect.y()+50, 433/2, 203/2, QPixmap(":/res/label-blank.png"));
-       painter->drawPixmap(option.rect.x()+7, option.rect.y()+25, 433/4, 203/4, QPixmap(":/res/label-blank.png"));
+               painter->drawPixmap(option.rect.x()+7, option.rect.y()+25, 433/4, 203/4, QPixmap(":/res/label-blank.png"));
 //Need to query the model for the data we're supposed to draw here...
 //     painter->drawText(17, 73, QString(romList[i].name));
 //     painter->setPen(Qt::white);
-       painter->setPen(QColor(255, 128, 0, 255));
+               painter->setPen(QColor(255, 128, 0, 255));
 //     painter->drawText(QRect(option.rect.x()+20, option.rect.y()+73, 196, 70), Qt::TextWordWrap | Qt::AlignHCenter, QString(romList[i].name));
-       painter->drawText(QRect(option.rect.x()+10, option.rect.y()+36, 196/2, 70/2), Qt::TextWordWrap | Qt::AlignHCenter, QString(romList[i].name));
+               painter->drawText(QRect(option.rect.x()+10, option.rect.y()+36, 196/2, 70/2), Qt::TextWordWrap | Qt::AlignHCenter, QString(romList[i].name));
        }
        else
        {
index 3d9276f3d77d309a28cacc285acb271b1a635bec..7b7a2de3e21735497d76b7164a071566e6f5e783 100644 (file)
@@ -281,7 +281,8 @@ void MainWin::ReadSettings(void)
        vjs.renderType       = settings.value("renderType", 0).toInt();
 
        // Hardcoded, !!! FIX !!!
-       strcpy(vjs.ROMPath, "./roms");
+#warning "!!! FIX !!! ROMPath is hardcoded!"
+       strcpy(vjs.ROMPath, "./software");
 }
 
 void MainWin::WriteSettings(void)
index 5c3d119f9eacc201719a631a5891a794825ae080..509da18e1a1730ca01201a22b99d8c9fecad9867 100644 (file)
@@ -1,5 +1,6 @@
 //
 // ZIP file support (mostly ripped from MAME--thx MAME team!)
+// Mostly this is here to simplify interfacing to zlib...
 //
 // Added by James L. Hammons
 // (C) 2010 Underground Software
@@ -9,6 +10,7 @@
 // Who  When        What
 // ---  ----------  -------------------------------------------------------------
 // JLH  01/16/2010  Created this log ;-)
+// JLH  02/28/2010  Removed unnecessary cruft
 //
 
 #include <stdlib.h>
@@ -40,7 +42,7 @@ void errormsg(const char * extmsg, const char * usermsg, const char * zipname)
        if (!gUnzipQuiet)
                printf("Error in zipfile %s\n%s\n", zipname, usermsg);
        /* Output to log file with all informations */
-       WriteLog("Error in zipfile %s: %s\n", zipname, extmsg);
+//     WriteLog("Error in zipfile %s: %s\n", zipname, extmsg);
 }
 
 /* -------------------------------------------------------------------------
@@ -48,15 +50,17 @@ void errormsg(const char * extmsg, const char * usermsg, const char * zipname)
  ------------------------------------------------------------------------- */
 
 /* Use these to avoid structure padding and byte-ordering problems */
-static uint16_t read_word (char *buf) {
-   unsigned char *ubuf = (unsigned char *) buf;
+static uint16_t read_word(char * buf)
+{
+   unsigned char * ubuf = (unsigned char *)buf;
 
    return ((uint16_t)ubuf[1] << 8) | (uint16_t)ubuf[0];
 }
 
 /* Use these to avoid structure padding and byte-ordering problems */
-static uint32_t read_dword (char *buf) {
-   unsigned char *ubuf = (unsigned char *) buf;
+static uint32_t read_dword(char * buf)
+{
+   unsigned char * ubuf = (unsigned char *)buf;
 
    return ((uint32_t)ubuf[3] << 24) | ((uint32_t)ubuf[2] << 16) | ((uint32_t)ubuf[1] << 8) | (uint32_t)ubuf[0];
 }
@@ -68,16 +72,20 @@ static uint32_t read_dword (char *buf) {
        ==0 not found
        !=0 found, *offset valid
 */
-static int ecd_find_sig (char *buffer, int buflen, int *offset)
+static int ecd_find_sig(char * buffer, int buflen, int * offset)
 {
        static char ecdsig[] = { 'P', 'K', 0x05, 0x06 };
        int i;
-       for (i=buflen-22; i>=0; i--) {
-               if (memcmp(buffer+i, ecdsig, 4) == 0) {
+
+       for(i=buflen-22; i>=0; i--)
+       {
+               if (memcmp(buffer+i, ecdsig, 4) == 0)
+               {
                        *offset = i;
                        return 1;
                }
        }
+
        return 0;
 }
 
@@ -106,6 +114,7 @@ static int ecd_read(ZIP * zip)
 
                /* allocate buffer */
                buf = (char *)malloc(buf_length);
+
                if (!buf)
                {
                        return -1;
@@ -117,32 +126,34 @@ static int ecd_read(ZIP * zip)
                        return -1;
                }
 
-               if (ecd_find_sig(buf, buf_length, &offset)) {
+               if (ecd_find_sig(buf, buf_length, &offset))
+               {
                        zip->ecd_length = buf_length - offset;
 
-                       zip->ecd = (char*)malloc( zip->ecd_length );
-                       if (!zip->ecd) {
+                       zip->ecd = (char *)malloc(zip->ecd_length);
+
+                       if (!zip->ecd)
+                       {
                                free(buf);
                                return -1;
                        }
 
                        memcpy(zip->ecd, buf + offset, zip->ecd_length);
-
                        free(buf);
                        return 0;
                }
 
                free(buf);
 
-               if (buf_length < zip->length) {
+               if (buf_length < zip->length)
+               {
                        /* double buffer */
-                       buf_length = 2*buf_length;
-
+                       buf_length = 2 * buf_length;
                        WriteLog("Retry reading of zip ecd for %d bytes\n",buf_length);
 
-               } else {
-                       return -1;
                }
+               else
+                       return -1;
        }
 }
 
@@ -204,9 +215,7 @@ ZIP * openzip(int pathtype, int pathindex, const char * zipfile)
        /* allocate */
        ZIP * zip = (ZIP *)malloc(sizeof(ZIP));
        if (!zip)
-       {
                return 0;
-       }
 
        /* open */
        zip->fp = fopen(zipfile, "rb");
@@ -264,9 +273,9 @@ ZIP * openzip(int pathtype, int pathindex, const char * zipfile)
        zip->zipfile_comment = zip->ecd+ZIPECOM;
 
        /* verify that we can work with this zipfile (no disk spanning allowed) */
-       if ((zip->number_of_this_disk != zip->number_of_disk_start_cent_dir) ||
-               (zip->total_entries_cent_dir_this_disk != zip->total_entries_cent_dir) ||
-               (zip->total_entries_cent_dir < 1))
+       if ((zip->number_of_this_disk != zip->number_of_disk_start_cent_dir)
+               || (zip->total_entries_cent_dir_this_disk != zip->total_entries_cent_dir)
+               || (zip->total_entries_cent_dir < 1))
        {
                errormsg("Cannot span disks", ERROR_UNSUPPORTED, zipfile);
                free(zip->ecd);
@@ -334,7 +343,8 @@ ZIP * openzip(int pathtype, int pathindex, const char * zipfile)
      !=0 success
      ==0 error
 */
-struct zipent* readzip(ZIP* zip) {
+struct zipent * readzip(ZIP * zip)
+{
 
        /* end of directory */
        if (zip->cd_pos >= zip->size_of_cent_dir)
@@ -388,9 +398,11 @@ void closezip(ZIP * zip)
        free(zip->ent.name);
        free(zip->cd);
        free(zip->ecd);
+
        /* only if not suspended */
        if (zip->fp)
                fclose(zip->fp);
+
        free(zip->zip);
        free(zip);
 }
@@ -665,137 +677,6 @@ int readuncompresszip(ZIP * zip, struct zipent * ent, char * data)
        }
 }
 
-/* -------------------------------------------------------------------------
-   Zip cache support
- ------------------------------------------------------------------------- */
-
-/* Use the zip cache */
-// No, don't
-//#define ZIP_CACHE
-
-#ifdef ZIP_CACHE
-
-/* ZIP cache entries */
-#define ZIP_CACHE_MAX 5
-
-/* ZIP cache buffer LRU ( Last Recently Used )
-     zip_cache_map[0] is the newer
-     zip_cache_map[ZIP_CACHE_MAX-1] is the older
-*/
-static ZIP* zip_cache_map[ZIP_CACHE_MAX];
-
-static ZIP* cache_openzip(int pathtype, int pathindex, const char* zipfile) {
-       ZIP* zip;
-       unsigned i;
-
-       /* search in the cache buffer */
-       for(i=0;i<ZIP_CACHE_MAX;++i) {
-               if (zip_cache_map[i] && zip_cache_map[i]->pathtype == pathtype && zip_cache_map[i]->pathindex == pathindex && strcmp(zip_cache_map[i]->zip,zipfile)==0) {
-                       /* found */
-                       unsigned j;
-
-/*
-                       WriteLog("Zip cache HIT  for %s\n", zipfile);
-*/
-
-                       /* reset the zip directory */
-                       rewindzip( zip_cache_map[i] );
-
-                       /* store */
-                       zip = zip_cache_map[i];
-
-                       /* shift */
-                       for(j=i;j>0;--j)
-                               zip_cache_map[j] = zip_cache_map[j-1];
-
-                       /* set the first entry */
-                       zip_cache_map[0] = zip;
-
-                       return zip_cache_map[0];
-               }
-       }
-       /* not found */
-
-/*
-       WriteLog("Zip cache FAIL for %s\n", zipfile);
-*/
-
-       /* open the zip */
-       zip = openzip( pathtype, pathindex, zipfile );
-       if (!zip)
-               return 0;
-
-       /* close the oldest entry */
-       if (zip_cache_map[ZIP_CACHE_MAX-1]) {
-               /* close last zip */
-               closezip(zip_cache_map[ZIP_CACHE_MAX-1]);
-               /* reset the entry */
-               zip_cache_map[ZIP_CACHE_MAX-1] = 0;
-       }
-
-       /* shift */
-       for(i=ZIP_CACHE_MAX-1;i>0;--i)
-               zip_cache_map[i] = zip_cache_map[i-1];
-
-       /* set the first entry */
-       zip_cache_map[0] = zip;
-
-       return zip_cache_map[0];
-}
-
-static void cache_closezip(ZIP* zip) {
-       unsigned i;
-
-       /* search in the cache buffer */
-       for(i=0;i<ZIP_CACHE_MAX;++i) {
-               if (zip_cache_map[i]==zip) {
-                       /* close zip */
-                       closezip(zip);
-
-                       /* reset cache entry */
-                       zip_cache_map[i] = 0;
-                       return;
-
-               }
-       }
-       /* not found */
-
-       /* close zip */
-       closezip(zip);
-}
-
-/* CK980415 added to allow osd code to clear zip cache for auditing--each time
-   the user opens up an audit for a game we should reread the zip */
-void unzip_cache_clear()
-{
-       unsigned i;
-
-       /* search in the cache buffer for any zip info and clear it */
-       for(i=0;i<ZIP_CACHE_MAX;++i) {
-               if (zip_cache_map[i] != NULL) {
-                       /* close zip */
-                       closezip(zip_cache_map[i]);
-
-                       /* reset cache entry */
-                       zip_cache_map[i] = 0;
-/*                     return; */
-
-               }
-       }
-}
-
-#define cache_suspendzip(a) suspendzip(a)
-
-#else
-
-#define cache_openzip(a,b,c) openzip(a,b,c)
-#define cache_closezip(a) closezip(a)
-#define cache_suspendzip(a) closezip(a)
-
-#define unzip_cache_clear()
-
-#endif
-
 /* -------------------------------------------------------------------------
    Backward MAME compatibility
  ------------------------------------------------------------------------- */
@@ -838,10 +719,8 @@ static int equal_filename(const char * zipfile, const char * file)
 //
 int load_zipped_file(int pathtype, int pathindex, const char * zipfile, const char * filename, unsigned char ** buf, uint32_t * length)
 {
-       ZIP * zip;
-       struct zipent * ent;
+       ZIP * zip = openzip(pathtype, pathindex, zipfile);
 
-       zip = cache_openzip(pathtype, pathindex, zipfile);
        if (!zip)
                return -1;
 
@@ -850,7 +729,7 @@ int load_zipped_file(int pathtype, int pathindex, const char * zipfile, const ch
                /* NS981003: support for "load by CRC" */
                char crc[9];
 
-               ent = &(zip->ent);
+               struct zipent * ent = &(zip->ent);
                sprintf(crc, "%08x", (unsigned int)ent->crc32);
 
                if (filename == NULL || equal_filename(ent->name, filename)
@@ -860,15 +739,15 @@ int load_zipped_file(int pathtype, int pathindex, const char * zipfile, const ch
 
                        if (readuncompresszip(zip, ent, (char *)*buf) != 0)
                        {
-                               cache_closezip(zip);
+                               closezip(zip);
                                return -1;
                        }
 
-                       cache_suspendzip(zip);
+                       suspendzip(zip);
                        return 0;
                }
        }
 
-       cache_suspendzip(zip);
+       suspendzip(zip);
        return -1;
 }