Improved error messages when loading ROMs from ZIP files.

git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@2746 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba
This commit is contained in:
stephena 2013-06-10 14:19:56 +00:00
parent 4c6667f64d
commit 5cdd536a5a
3 changed files with 37 additions and 31 deletions

View File

@ -30,7 +30,7 @@ FilesystemNodeZIP::FilesystemNodeZIP()
{
// We need a name, else the node is invalid
_path = _shortPath = _virtualFile = "";
_isValid = false;
_error = ZIPERR_NOT_A_FILE;
_numFiles = 0;
AbstractFSNode* tmp = 0;
@ -41,7 +41,7 @@ FilesystemNodeZIP::FilesystemNodeZIP()
FilesystemNodeZIP::FilesystemNodeZIP(const string& p)
{
_path = _shortPath = _virtualFile = "";
_isValid = false;
_error = ZIPERR_NOT_A_FILE;
// Extract ZIP file and virtual file (if specified)
size_t pos = BSPF_findIgnoreCase(p, ".zip");
@ -54,7 +54,10 @@ FilesystemNodeZIP::FilesystemNodeZIP(const string& p)
ZipHandler& zip = OSystem::zip(_zipFile);
_numFiles = zip.romFiles();
if(_numFiles == 0)
{
_error = ZIPERR_NO_ROMS;
return;
}
// We always need a virtual file
// Either one is given, or we use the first one
@ -111,7 +114,11 @@ void FilesystemNodeZIP::setFlags(const string& zipfile,
_shortPath += ("/" + _virtualFile);
_numFiles = 1;
}
_isValid = _realNode->isFile() && _realNode->isReadable();
_error = ZIPERR_NONE;
if(!_realNode->isFile())
_error = ZIPERR_NOT_A_FILE;
if(!_realNode->isReadable())
_error = ZIPERR_NOT_READABLE;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -119,7 +126,7 @@ bool FilesystemNodeZIP::getChildren(AbstractFSList& myList, ListMode mode,
bool hidden) const
{
// Files within ZIP archives don't contain children
if(!isDirectory() || !_isValid)
if(!isDirectory() || _error != ZIPERR_NONE)
return false;
ZipHandler& zip = OSystem::zip(_zipFile);
@ -135,8 +142,13 @@ bool FilesystemNodeZIP::getChildren(AbstractFSList& myList, ListMode mode,
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
uInt32 FilesystemNodeZIP::read(uInt8*& image) const
{
if(!_isValid)
throw "ZIP file not found/readable";
switch(_error)
{
case ZIPERR_NONE: break;
case ZIPERR_NOT_A_FILE: throw "ZIP file contains errors/not found";
case ZIPERR_NOT_READABLE: throw "ZIP file not readable";
case ZIPERR_NO_ROMS: throw "ZIP file doesn't contain any ROMs";
}
ZipHandler& zip = OSystem::zip(_zipFile);

View File

@ -55,8 +55,8 @@ class FilesystemNodeZIP : public AbstractFSNode
const string& getName() const { return _virtualFile; }
const string& getPath() const { return _path; }
string getShortPath() const { return _shortPath; }
bool isDirectory() const { return _numFiles > 1; }
bool isFile() const { return _numFiles == 1; }
bool isDirectory() const { return _numFiles > 1; }
bool isFile() const { return _numFiles == 1; }
bool isReadable() const { return _realNode && _realNode->isReadable(); }
bool isWritable() const { return false; }
@ -78,11 +78,20 @@ class FilesystemNodeZIP : public AbstractFSNode
void setFlags(const string& zipfile, const string& virtualfile,
Common::SharedPtr<AbstractFSNode> realnode);
protected:
private:
/* Error types */
enum zip_error
{
ZIPERR_NONE = 0,
ZIPERR_NOT_A_FILE,
ZIPERR_NOT_READABLE,
ZIPERR_NO_ROMS
};
Common::SharedPtr<AbstractFSNode> _realNode;
string _zipFile, _virtualFile;
string _path, _shortPath;
bool _isValid;
zip_error _error;
uInt32 _numFiles;
};

View File

@ -493,16 +493,8 @@ void LauncherDialog::handleCommand(CommandSender* sender, int cmd,
{
const FilesystemNode romnode(myGameList->path(item));
// If a node isn't a file or directory, there's nothing we can
// do with it
if(!romnode.isDirectory() && !romnode.isFile())
{
instance().frameBuffer().showMessage(
"Invalid file (check file size and/or contents)",
kMiddleCenter, true);
}
// Directory's should be selected (ie, enter them and redisplay)
else if(romnode.isDirectory())
if(romnode.isDirectory())
{
string dirname = "";
if(myGameList->name(item) == " [..]")
@ -520,19 +512,12 @@ void LauncherDialog::handleCommand(CommandSender* sender, int cmd,
}
else
{
string extension;
if(LauncherFilterDialog::isValidRomName(romnode, extension))
{
const string& result =
instance().createConsole(romnode, myGameList->md5(item));
if(result == EmptyString)
instance().settings().setValue("lastrom", myList->getSelectedString());
else
instance().frameBuffer().showMessage(result, kMiddleCenter, true);
}
const string& result =
instance().createConsole(romnode, myGameList->md5(item));
if(result == EmptyString)
instance().settings().setValue("lastrom", myList->getSelectedString());
else
instance().frameBuffer().showMessage("Not a valid ROM filename",
kMiddleCenter, true);
instance().frameBuffer().showMessage(result, kMiddleCenter, true);
}
}
break;