mirror of https://github.com/stella-emu/stella.git
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:
parent
4c6667f64d
commit
5cdd536a5a
|
@ -30,7 +30,7 @@ FilesystemNodeZIP::FilesystemNodeZIP()
|
||||||
{
|
{
|
||||||
// We need a name, else the node is invalid
|
// We need a name, else the node is invalid
|
||||||
_path = _shortPath = _virtualFile = "";
|
_path = _shortPath = _virtualFile = "";
|
||||||
_isValid = false;
|
_error = ZIPERR_NOT_A_FILE;
|
||||||
_numFiles = 0;
|
_numFiles = 0;
|
||||||
|
|
||||||
AbstractFSNode* tmp = 0;
|
AbstractFSNode* tmp = 0;
|
||||||
|
@ -41,7 +41,7 @@ FilesystemNodeZIP::FilesystemNodeZIP()
|
||||||
FilesystemNodeZIP::FilesystemNodeZIP(const string& p)
|
FilesystemNodeZIP::FilesystemNodeZIP(const string& p)
|
||||||
{
|
{
|
||||||
_path = _shortPath = _virtualFile = "";
|
_path = _shortPath = _virtualFile = "";
|
||||||
_isValid = false;
|
_error = ZIPERR_NOT_A_FILE;
|
||||||
|
|
||||||
// Extract ZIP file and virtual file (if specified)
|
// Extract ZIP file and virtual file (if specified)
|
||||||
size_t pos = BSPF_findIgnoreCase(p, ".zip");
|
size_t pos = BSPF_findIgnoreCase(p, ".zip");
|
||||||
|
@ -54,7 +54,10 @@ FilesystemNodeZIP::FilesystemNodeZIP(const string& p)
|
||||||
ZipHandler& zip = OSystem::zip(_zipFile);
|
ZipHandler& zip = OSystem::zip(_zipFile);
|
||||||
_numFiles = zip.romFiles();
|
_numFiles = zip.romFiles();
|
||||||
if(_numFiles == 0)
|
if(_numFiles == 0)
|
||||||
|
{
|
||||||
|
_error = ZIPERR_NO_ROMS;
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// We always need a virtual file
|
// We always need a virtual file
|
||||||
// Either one is given, or we use the first one
|
// Either one is given, or we use the first one
|
||||||
|
@ -111,7 +114,11 @@ void FilesystemNodeZIP::setFlags(const string& zipfile,
|
||||||
_shortPath += ("/" + _virtualFile);
|
_shortPath += ("/" + _virtualFile);
|
||||||
_numFiles = 1;
|
_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
|
bool hidden) const
|
||||||
{
|
{
|
||||||
// Files within ZIP archives don't contain children
|
// Files within ZIP archives don't contain children
|
||||||
if(!isDirectory() || !_isValid)
|
if(!isDirectory() || _error != ZIPERR_NONE)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
ZipHandler& zip = OSystem::zip(_zipFile);
|
ZipHandler& zip = OSystem::zip(_zipFile);
|
||||||
|
@ -135,8 +142,13 @@ bool FilesystemNodeZIP::getChildren(AbstractFSList& myList, ListMode mode,
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
uInt32 FilesystemNodeZIP::read(uInt8*& image) const
|
uInt32 FilesystemNodeZIP::read(uInt8*& image) const
|
||||||
{
|
{
|
||||||
if(!_isValid)
|
switch(_error)
|
||||||
throw "ZIP file not found/readable";
|
{
|
||||||
|
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);
|
ZipHandler& zip = OSystem::zip(_zipFile);
|
||||||
|
|
||||||
|
|
|
@ -55,8 +55,8 @@ class FilesystemNodeZIP : public AbstractFSNode
|
||||||
const string& getName() const { return _virtualFile; }
|
const string& getName() const { return _virtualFile; }
|
||||||
const string& getPath() const { return _path; }
|
const string& getPath() const { return _path; }
|
||||||
string getShortPath() const { return _shortPath; }
|
string getShortPath() const { return _shortPath; }
|
||||||
bool isDirectory() const { return _numFiles > 1; }
|
bool isDirectory() const { return _numFiles > 1; }
|
||||||
bool isFile() const { return _numFiles == 1; }
|
bool isFile() const { return _numFiles == 1; }
|
||||||
bool isReadable() const { return _realNode && _realNode->isReadable(); }
|
bool isReadable() const { return _realNode && _realNode->isReadable(); }
|
||||||
bool isWritable() const { return false; }
|
bool isWritable() const { return false; }
|
||||||
|
|
||||||
|
@ -78,11 +78,20 @@ class FilesystemNodeZIP : public AbstractFSNode
|
||||||
void setFlags(const string& zipfile, const string& virtualfile,
|
void setFlags(const string& zipfile, const string& virtualfile,
|
||||||
Common::SharedPtr<AbstractFSNode> realnode);
|
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;
|
Common::SharedPtr<AbstractFSNode> _realNode;
|
||||||
string _zipFile, _virtualFile;
|
string _zipFile, _virtualFile;
|
||||||
string _path, _shortPath;
|
string _path, _shortPath;
|
||||||
bool _isValid;
|
zip_error _error;
|
||||||
uInt32 _numFiles;
|
uInt32 _numFiles;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -493,16 +493,8 @@ void LauncherDialog::handleCommand(CommandSender* sender, int cmd,
|
||||||
{
|
{
|
||||||
const FilesystemNode romnode(myGameList->path(item));
|
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)
|
// Directory's should be selected (ie, enter them and redisplay)
|
||||||
else if(romnode.isDirectory())
|
if(romnode.isDirectory())
|
||||||
{
|
{
|
||||||
string dirname = "";
|
string dirname = "";
|
||||||
if(myGameList->name(item) == " [..]")
|
if(myGameList->name(item) == " [..]")
|
||||||
|
@ -520,19 +512,12 @@ void LauncherDialog::handleCommand(CommandSender* sender, int cmd,
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
string extension;
|
const string& result =
|
||||||
if(LauncherFilterDialog::isValidRomName(romnode, extension))
|
instance().createConsole(romnode, myGameList->md5(item));
|
||||||
{
|
if(result == EmptyString)
|
||||||
const string& result =
|
instance().settings().setValue("lastrom", myList->getSelectedString());
|
||||||
instance().createConsole(romnode, myGameList->md5(item));
|
|
||||||
if(result == EmptyString)
|
|
||||||
instance().settings().setValue("lastrom", myList->getSelectedString());
|
|
||||||
else
|
|
||||||
instance().frameBuffer().showMessage(result, kMiddleCenter, true);
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
instance().frameBuffer().showMessage("Not a valid ROM filename",
|
instance().frameBuffer().showMessage(result, kMiddleCenter, true);
|
||||||
kMiddleCenter, true);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in New Issue