From 68e8886a9aaf48fcc130334d8cf4fe35a4534a02 Mon Sep 17 00:00:00 2001 From: Shamus Hammons Date: Wed, 3 Mar 2010 04:10:20 +0000 Subject: [PATCH] Added logfile logging, ZIP file fishing --- src/file.cpp | 4 +++- src/file.h | 2 +- src/gui/app.cpp | 6 ++++- src/gui/filethread.cpp | 52 ++++++++++++++++++++++++++++++++++-------- 4 files changed, 51 insertions(+), 13 deletions(-) diff --git a/src/file.cpp b/src/file.cpp index 6e895c5..8c1a703 100644 --- a/src/file.cpp +++ b/src/file.cpp @@ -361,7 +361,7 @@ static bool CheckExtension(const char * filename, const char * ext) // 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) +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" }; @@ -399,6 +399,7 @@ uint32 GetFileFromZIP(const char * zipFile, FileType type, uint8 * buffer) if (found) { WriteLog("FILE: Uncompressing..."); + buffer = new uint8[ze->uncompressed_size]; if (readuncompresszip(zip, ze, (char *)buffer) == 0) { @@ -408,6 +409,7 @@ uint32 GetFileFromZIP(const char * zipFile, FileType type, uint8 * buffer) else { WriteLog("FAILED!\n"); + delete[] buffer; return 0; } } diff --git a/src/file.h b/src/file.h index 9011244..45d2dd3 100644 --- a/src/file.h +++ b/src/file.h @@ -17,7 +17,7 @@ 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); +uint32 GetFileFromZIP(const char * zipFile, FileType type, uint8 * &buffer); #ifdef __cplusplus } diff --git a/src/gui/app.cpp b/src/gui/app.cpp index 9a2cdbf..264a79a 100644 --- a/src/gui/app.cpp +++ b/src/gui/app.cpp @@ -14,6 +14,7 @@ #include "app.h" #include +#include "log.h" #include "mainwin.h" #include "types.h" @@ -36,9 +37,12 @@ int main(int argc, char * argv[]) // This is so we can pass this stuff using signal/slot mechanism... //ick int id = qRegisterMetaType(); + LogInit("vj.log"); // Init logfile App app(argc, argv); // Declare an instance of the application - return app.exec(); // And run it! + int retVal = app.exec(); // And run it! + LogDone(); // Close logfile + return retVal; } // Main app constructor--we stick globally accessible stuff here... diff --git a/src/gui/filethread.cpp b/src/gui/filethread.cpp index 3229c35..dec070f 100644 --- a/src/gui/filethread.cpp +++ b/src/gui/filethread.cpp @@ -16,6 +16,7 @@ #include #include "crc32.h" +#include "file.h" #include "filedb.h" #include "settings.h" @@ -81,23 +82,54 @@ printf("FileThread: Aborting!!!\n"); #endif QFileInfo fileInfo = list.at(i); - QFile file(romDir.filePath(fileInfo.fileName())); - uint8 * buffer = new uint8[fileInfo.size()]; - if (file.open(QIODevice::ReadOnly)) + if (fileInfo.suffix().compare("zip", Qt::CaseInsensitive) == 0) { - file.read((char *)buffer, fileInfo.size()); - uint32 crc = crc32_calcCheckSum(buffer, fileInfo.size()); - file.close(); + uint8 * buffer = NULL; + uint32 size = GetFileFromZIP(fileInfo.canonicalFilePath().toAscii(), FT_SOFTWARE, buffer); - uint32 index = FindCRCIndexInFileList(crc); + if (size > 0) + { +//printf("FileThread: About to calc checksum on file with size %u... (buffer=%08X)\n", size, buffer); + uint32 crc = crc32_calcCheckSum(buffer, size); + uint32 index = FindCRCIndexInFileList(crc); + delete[] buffer; // Mebbe we should pass a index AND a QImage here??? - if (index != 0xFFFFFFFF && !(romList[index].flags & FF_BIOS)) - emit FoundAFile(index); + if (index != 0xFFFFFFFF && !(romList[index].flags & FF_BIOS)) + { + QImage img; + size = GetFileFromZIP(fileInfo.canonicalFilePath().toAscii(), FT_LABEL, buffer); + + if (size > 0) + { + img.loadFromData(buffer, size); + delete[] buffer; + } +//printf("FileThread: Attempted to load image. Size: %u x %u...\n", img.width(), img.height()); + + emit FoundAFile(index); + } + } } + else + { + QFile file(romDir.filePath(fileInfo.fileName())); + + if (file.open(QIODevice::ReadOnly)) + { + uint8 * buffer = new uint8[fileInfo.size()]; + file.read((char *)buffer, fileInfo.size()); + file.close(); + uint32 crc = crc32_calcCheckSum(buffer, fileInfo.size()); + uint32 index = FindCRCIndexInFileList(crc); + delete[] buffer; - delete[] buffer; +// Mebbe we should pass a index AND a QImage here??? + if (index != 0xFFFFFFFF && !(romList[index].flags & FF_BIOS)) + emit FoundAFile(index); + } + } } } -- 2.37.2