mirror of https://github.com/stella-emu/stella.git
More work on the FilesystemNode API.
git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@2597 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba
This commit is contained in:
parent
025100d812
commit
ecdcf6177d
|
@ -629,7 +629,7 @@ string CartDebug::loadSymbolFile(string file)
|
||||||
{
|
{
|
||||||
ifstream in(node.getPath().c_str());
|
ifstream in(node.getPath().c_str());
|
||||||
if(!in.is_open())
|
if(!in.is_open())
|
||||||
return DebuggerParser::red("symbol file '" + node.getRelativePath() + "' not found");
|
return DebuggerParser::red("symbol file '" + node.getShortPath() + "' not found");
|
||||||
|
|
||||||
myUserAddresses.clear();
|
myUserAddresses.clear();
|
||||||
myUserLabels.clear();
|
myUserLabels.clear();
|
||||||
|
@ -648,9 +648,9 @@ string CartDebug::loadSymbolFile(string file)
|
||||||
addLabel(label, value);
|
addLabel(label, value);
|
||||||
}
|
}
|
||||||
in.close();
|
in.close();
|
||||||
return "loaded " + node.getRelativePath() + " OK";
|
return "loaded " + node.getShortPath() + " OK";
|
||||||
}
|
}
|
||||||
return DebuggerParser::red("symbol file '" + node.getRelativePath() + "' not found");
|
return DebuggerParser::red("symbol file '" + node.getShortPath() + "' not found");
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
|
@ -786,7 +786,7 @@ string CartDebug::loadConfigFile(string file)
|
||||||
}
|
}
|
||||||
in.close();
|
in.close();
|
||||||
|
|
||||||
return "loaded " + node.getRelativePath() + " OK";
|
return "loaded " + node.getShortPath() + " OK";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return DebuggerParser::red("config file not found");
|
return DebuggerParser::red("config file not found");
|
||||||
|
@ -830,7 +830,7 @@ string CartDebug::saveConfigFile(string file)
|
||||||
}
|
}
|
||||||
out.close();
|
out.close();
|
||||||
|
|
||||||
return "saved " + node.getRelativePath() + " OK";
|
return "saved " + node.getShortPath() + " OK";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return DebuggerParser::red("config file not found");
|
return DebuggerParser::red("config file not found");
|
||||||
|
|
|
@ -812,12 +812,12 @@ void Debugger::getCompletions(const char* in, StringList& list) const
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
string Debugger::saveROM(const string& filename) const
|
string Debugger::saveROM(const string& filename) const
|
||||||
{
|
{
|
||||||
string path = AbstractFilesystemNode::getAbsolutePath(filename, "~", "a26");
|
string path = FilesystemNode::createAbsolutePath(filename, "~", "a26");
|
||||||
FilesystemNode node(path);
|
FilesystemNode node(path);
|
||||||
|
|
||||||
ofstream out(node.getPath().c_str(), ios::out | ios::binary);
|
ofstream out(node.getPath().c_str(), ios::out | ios::binary);
|
||||||
if(out.is_open() && myConsole.cartridge().save(out))
|
if(out.is_open() && myConsole.cartridge().save(out))
|
||||||
return node.getRelativePath();
|
return node.getShortPath();
|
||||||
else
|
else
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
|
@ -135,7 +135,7 @@ string DebuggerParser::exec(const FilesystemNode& file)
|
||||||
{
|
{
|
||||||
ifstream in(file.getPath().c_str());
|
ifstream in(file.getPath().c_str());
|
||||||
if(!in.is_open())
|
if(!in.is_open())
|
||||||
return red("autoexec file \'" + file.getRelativePath() + "\' not found");
|
return red("autoexec file \'" + file.getShortPath() + "\' not found");
|
||||||
|
|
||||||
ostringstream buf;
|
ostringstream buf;
|
||||||
int count = 0;
|
int count = 0;
|
||||||
|
@ -149,12 +149,12 @@ string DebuggerParser::exec(const FilesystemNode& file)
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
buf << "Executed " << debugger->valueToString(count) << " commands from \""
|
buf << "Executed " << debugger->valueToString(count) << " commands from \""
|
||||||
<< file.getRelativePath() << "\"";
|
<< file.getShortPath() << "\"";
|
||||||
|
|
||||||
return buf.str();
|
return buf.str();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return red("autoexec file \'" + file.getRelativePath() + "\' not found");
|
return red("autoexec file \'" + file.getShortPath() + "\' not found");
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
|
|
|
@ -100,10 +100,10 @@ const string& FilesystemNode::getPath() const
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
string FilesystemNode::getRelativePath() const
|
string FilesystemNode::getShortPath() const
|
||||||
{
|
{
|
||||||
assert(_realNode);
|
assert(_realNode);
|
||||||
return _realNode->getRelativePath();
|
return _realNode->getShortPath();
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
|
@ -130,6 +130,12 @@ bool FilesystemNode::isWritable() const
|
||||||
return _realNode ? _realNode->isWritable() : false;
|
return _realNode ? _realNode->isWritable() : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
|
bool FilesystemNode::isAbsolute() const
|
||||||
|
{
|
||||||
|
return _realNode ? _realNode->isAbsolute() : false;
|
||||||
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
bool FilesystemNode::makeDir()
|
bool FilesystemNode::makeDir()
|
||||||
{
|
{
|
||||||
|
@ -141,3 +147,30 @@ bool FilesystemNode::rename(const string& newfile)
|
||||||
{
|
{
|
||||||
return (_realNode && _realNode->exists()) ? _realNode->rename(newfile) : false;
|
return (_realNode && _realNode->exists()) ? _realNode->rename(newfile) : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
|
string FilesystemNode::createAbsolutePath(
|
||||||
|
const string& p, const string& startpath, const string& ext)
|
||||||
|
{
|
||||||
|
FilesystemNode node(p);
|
||||||
|
string path = node.getShortPath();
|
||||||
|
|
||||||
|
// Is path already absolute, or does it start with the given startpath?
|
||||||
|
// If not, we prepend the given startpath
|
||||||
|
if(!BSPF_startsWithIgnoreCase(p, startpath+BSPF_PATH_SEPARATOR) &&
|
||||||
|
!node.isAbsolute())
|
||||||
|
path = startpath + BSPF_PATH_SEPARATOR + p;
|
||||||
|
|
||||||
|
// Does the path have a valid extension?
|
||||||
|
// If not, we append the given extension
|
||||||
|
string::size_type idx = path.find_last_of('.');
|
||||||
|
if(idx != string::npos)
|
||||||
|
{
|
||||||
|
if(!BSPF_equalsIgnoreCase(path.c_str() + idx + 1, ext))
|
||||||
|
path = path.replace(idx+1, ext.length(), ext);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
path += "." + ext;
|
||||||
|
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
|
|
@ -150,9 +150,6 @@ class FilesystemNode
|
||||||
* This will usually be a 'path' (hence the name of the method), but can
|
* This will usually be a 'path' (hence the name of the method), but can
|
||||||
* be anything that fulfills the above criterions.
|
* be anything that fulfills the above criterions.
|
||||||
*
|
*
|
||||||
* @note Do not assume that this string contains (back)slashes or any
|
|
||||||
* other kind of 'path separators'.
|
|
||||||
*
|
|
||||||
* @return the 'path' represented by this filesystem node
|
* @return the 'path' represented by this filesystem node
|
||||||
*/
|
*/
|
||||||
virtual const string& getPath() const;
|
virtual const string& getPath() const;
|
||||||
|
@ -162,12 +159,9 @@ class FilesystemNode
|
||||||
* symbol (if applicable), and is suitable for archiving (i.e. writing
|
* symbol (if applicable), and is suitable for archiving (i.e. writing
|
||||||
* to the config file).
|
* to the config file).
|
||||||
*
|
*
|
||||||
* @note Do not assume that this string contains (back)slashes or any
|
|
||||||
* other kind of 'path separators'.
|
|
||||||
*
|
|
||||||
* @return the 'path' represented by this filesystem node
|
* @return the 'path' represented by this filesystem node
|
||||||
*/
|
*/
|
||||||
virtual string getRelativePath() const;
|
virtual string getShortPath() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determine whether this node has a parent.
|
* Determine whether this node has a parent.
|
||||||
|
@ -219,6 +213,13 @@ class FilesystemNode
|
||||||
*/
|
*/
|
||||||
virtual bool isWritable() const;
|
virtual bool isWritable() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates whether the path is a fully-qualified, absolute pathname.
|
||||||
|
*
|
||||||
|
* @return bool true if the object contains an absolute path, false otherwise.
|
||||||
|
*/
|
||||||
|
virtual bool isAbsolute() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a directory from the current node path.
|
* Create a directory from the current node path.
|
||||||
*
|
*
|
||||||
|
@ -233,6 +234,15 @@ class FilesystemNode
|
||||||
*/
|
*/
|
||||||
virtual bool rename(const string& newfile);
|
virtual bool rename(const string& newfile);
|
||||||
|
|
||||||
|
// TODO - this function is deprecated, and will be removed soon ...
|
||||||
|
/**
|
||||||
|
Create an absolute pathname from the given path (if it isn't already
|
||||||
|
absolute), pre-pending 'startpath' when necessary. If the path doesn't
|
||||||
|
have an extension matching 'ext', append it to the path.
|
||||||
|
*/
|
||||||
|
static string createAbsolutePath(const string& p, const string& startpath,
|
||||||
|
const string& ext);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Common::SharedPtr<AbstractFilesystemNode> _realNode;
|
Common::SharedPtr<AbstractFilesystemNode> _realNode;
|
||||||
FilesystemNode(AbstractFilesystemNode* realNode);
|
FilesystemNode(AbstractFilesystemNode* realNode);
|
||||||
|
@ -302,7 +312,7 @@ class AbstractFilesystemNode
|
||||||
* Returns the 'path' of the current node, containing '~' and for archiving.
|
* Returns the 'path' of the current node, containing '~' and for archiving.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
virtual string getRelativePath() const = 0;
|
virtual string getShortPath() const = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Indicates whether this path refers to a directory or not.
|
* Indicates whether this path refers to a directory or not.
|
||||||
|
@ -341,6 +351,13 @@ class AbstractFilesystemNode
|
||||||
*/
|
*/
|
||||||
virtual bool isWritable() const = 0;
|
virtual bool isWritable() const = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates whether the path is a fully-qualified, absolute pathname.
|
||||||
|
*
|
||||||
|
* @return bool true if the object contains an absolute path, false otherwise.
|
||||||
|
*/
|
||||||
|
virtual bool isAbsolute() const = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a directory from the current node path.
|
* Create a directory from the current node path.
|
||||||
*
|
*
|
||||||
|
@ -355,14 +372,6 @@ class AbstractFilesystemNode
|
||||||
*/
|
*/
|
||||||
virtual bool rename(const string& newfile) = 0;
|
virtual bool rename(const string& newfile) = 0;
|
||||||
|
|
||||||
/**
|
|
||||||
Create an absolute pathname from the given path (if it isn't already
|
|
||||||
absolute), pre-pending 'startpath' when necessary. If the path doesn't
|
|
||||||
have an extension matching 'ext', append it to the path.
|
|
||||||
*/
|
|
||||||
static string getAbsolutePath(const string& p, const string& startpath,
|
|
||||||
const string& ext);
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/**
|
/**
|
||||||
* The parent node of this directory.
|
* The parent node of this directory.
|
||||||
|
@ -374,10 +383,6 @@ class AbstractFilesystemNode
|
||||||
* Construct a node based on a path; the path is in the same format as it
|
* Construct a node based on a path; the path is in the same format as it
|
||||||
* would be for calls to fopen().
|
* would be for calls to fopen().
|
||||||
*
|
*
|
||||||
* Furthermore getNodeForPath(oldNode.path()) should create a new node
|
|
||||||
* identical to oldNode. Hence, we can use the "path" value for persistent
|
|
||||||
* storage e.g. in the config file.
|
|
||||||
*
|
|
||||||
* @param path The path string to create a FilesystemNode for.
|
* @param path The path string to create a FilesystemNode for.
|
||||||
*/
|
*/
|
||||||
static AbstractFilesystemNode* makeFileNodePath(const string& path);
|
static AbstractFilesystemNode* makeFileNodePath(const string& path);
|
||||||
|
|
|
@ -210,11 +210,11 @@ bool OSystem::create()
|
||||||
<< " Features: " << myFeatures << endl
|
<< " Features: " << myFeatures << endl
|
||||||
<< " " << myBuildInfo << endl << endl
|
<< " " << myBuildInfo << endl << endl
|
||||||
<< "Base directory: '"
|
<< "Base directory: '"
|
||||||
<< FilesystemNode(myBaseDir).getRelativePath() << "'" << endl
|
<< FilesystemNode(myBaseDir).getShortPath() << "'" << endl
|
||||||
<< "Configuration file: '"
|
<< "Configuration file: '"
|
||||||
<< FilesystemNode(myConfigFile).getRelativePath() << "'" << endl
|
<< FilesystemNode(myConfigFile).getShortPath() << "'" << endl
|
||||||
<< "User game properties: '"
|
<< "User game properties: '"
|
||||||
<< FilesystemNode(myPropertiesFile).getRelativePath() << "'" << endl;
|
<< FilesystemNode(myPropertiesFile).getShortPath() << "'" << endl;
|
||||||
logMessage(buf.str(), 1);
|
logMessage(buf.str(), 1);
|
||||||
|
|
||||||
// Get relevant information about the video hardware
|
// Get relevant information about the video hardware
|
||||||
|
@ -356,19 +356,19 @@ void OSystem::setConfigPaths()
|
||||||
if(s == "") s = myBaseDir + "stella.cht";
|
if(s == "") s = myBaseDir + "stella.cht";
|
||||||
node = FilesystemNode(s);
|
node = FilesystemNode(s);
|
||||||
myCheatFile = node.getPath();
|
myCheatFile = node.getPath();
|
||||||
mySettings->setString("cheatfile", node.getRelativePath());
|
mySettings->setString("cheatfile", node.getShortPath());
|
||||||
|
|
||||||
s = mySettings->getString("palettefile");
|
s = mySettings->getString("palettefile");
|
||||||
if(s == "") s = myBaseDir + "stella.pal";
|
if(s == "") s = myBaseDir + "stella.pal";
|
||||||
node = FilesystemNode(s);
|
node = FilesystemNode(s);
|
||||||
myPaletteFile = node.getPath();
|
myPaletteFile = node.getPath();
|
||||||
mySettings->setString("palettefile", node.getRelativePath());
|
mySettings->setString("palettefile", node.getShortPath());
|
||||||
|
|
||||||
s = mySettings->getString("propsfile");
|
s = mySettings->getString("propsfile");
|
||||||
if(s == "") s = myBaseDir + "stella.pro";
|
if(s == "") s = myBaseDir + "stella.pro";
|
||||||
node = FilesystemNode(s);
|
node = FilesystemNode(s);
|
||||||
myPropertiesFile = node.getPath();
|
myPropertiesFile = node.getPath();
|
||||||
mySettings->setString("propsfile", node.getRelativePath());
|
mySettings->setString("propsfile", node.getShortPath());
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
|
@ -565,7 +565,7 @@ bool OSystem::createConsole(const string& romfile, const string& md5sum)
|
||||||
myFrameBuffer->showMessage("Multicart " + type + ", loading ROM" + id);
|
myFrameBuffer->showMessage("Multicart " + type + ", loading ROM" + id);
|
||||||
}
|
}
|
||||||
buf << "Game console created:" << endl
|
buf << "Game console created:" << endl
|
||||||
<< " ROM file: " << FilesystemNode(myRomFile).getRelativePath() << endl << endl
|
<< " ROM file: " << FilesystemNode(myRomFile).getShortPath() << endl << endl
|
||||||
<< getROMInfo(myConsole) << endl;
|
<< getROMInfo(myConsole) << endl;
|
||||||
logMessage(buf.str(), 1);
|
logMessage(buf.str(), 1);
|
||||||
|
|
||||||
|
@ -950,7 +950,7 @@ void OSystem::validatePath(string& path, const string& setting,
|
||||||
if(!node.isDirectory())
|
if(!node.isDirectory())
|
||||||
node.makeDir();
|
node.makeDir();
|
||||||
path = node.getPath();
|
path = node.getPath();
|
||||||
mySettings->setString(setting, node.getRelativePath());
|
mySettings->setString(setting, node.getShortPath());
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
|
|
|
@ -164,7 +164,7 @@ void BrowserDialog::updateListing()
|
||||||
_nodeList->clear();
|
_nodeList->clear();
|
||||||
|
|
||||||
// Update the path display
|
// Update the path display
|
||||||
_currentPath->setLabel(_node.getRelativePath());
|
_currentPath->setLabel(_node.getShortPath());
|
||||||
|
|
||||||
// Read in the data from the file system
|
// Read in the data from the file system
|
||||||
FSList content;
|
FSList content;
|
||||||
|
|
|
@ -225,29 +225,29 @@ void FileSnapDialog::setDefaults()
|
||||||
const string& basedir = instance().baseDir();
|
const string& basedir = instance().baseDir();
|
||||||
|
|
||||||
node = FilesystemNode("~");
|
node = FilesystemNode("~");
|
||||||
myRomPath->setEditString(node.getRelativePath());
|
myRomPath->setEditString(node.getShortPath());
|
||||||
|
|
||||||
mySnapPath->setEditString(instance().defaultSnapDir());
|
mySnapPath->setEditString(instance().defaultSnapDir());
|
||||||
|
|
||||||
const string& cheatfile = basedir + "stella.cht";
|
const string& cheatfile = basedir + "stella.cht";
|
||||||
node = FilesystemNode(cheatfile);
|
node = FilesystemNode(cheatfile);
|
||||||
myCheatFile->setEditString(node.getRelativePath());
|
myCheatFile->setEditString(node.getShortPath());
|
||||||
|
|
||||||
const string& palettefile = basedir + "stella.pal";
|
const string& palettefile = basedir + "stella.pal";
|
||||||
node = FilesystemNode(palettefile);
|
node = FilesystemNode(palettefile);
|
||||||
myPaletteFile->setEditString(node.getRelativePath());
|
myPaletteFile->setEditString(node.getShortPath());
|
||||||
|
|
||||||
const string& propsfile = basedir + "stella.pro";
|
const string& propsfile = basedir + "stella.pro";
|
||||||
node = FilesystemNode(propsfile);
|
node = FilesystemNode(propsfile);
|
||||||
myPropsFile->setEditString(node.getRelativePath());
|
myPropsFile->setEditString(node.getShortPath());
|
||||||
|
|
||||||
const string& eepromdir = basedir;
|
const string& eepromdir = basedir;
|
||||||
node = FilesystemNode(eepromdir);
|
node = FilesystemNode(eepromdir);
|
||||||
myEEPROMPath->setEditString(node.getRelativePath());
|
myEEPROMPath->setEditString(node.getShortPath());
|
||||||
|
|
||||||
const string& statedir = basedir + "state";
|
const string& statedir = basedir + "state";
|
||||||
node = FilesystemNode(statedir);
|
node = FilesystemNode(statedir);
|
||||||
myStatePath->setEditString(node.getRelativePath());
|
myStatePath->setEditString(node.getShortPath());
|
||||||
|
|
||||||
mySnapSingle->setState(false);
|
mySnapSingle->setState(false);
|
||||||
mySnap1x->setState(false);
|
mySnap1x->setState(false);
|
||||||
|
@ -309,49 +309,49 @@ void FileSnapDialog::handleCommand(CommandSender* sender, int cmd,
|
||||||
case kRomDirChosenCmd:
|
case kRomDirChosenCmd:
|
||||||
{
|
{
|
||||||
FilesystemNode dir(myBrowser->getResult());
|
FilesystemNode dir(myBrowser->getResult());
|
||||||
myRomPath->setEditString(dir.getRelativePath());
|
myRomPath->setEditString(dir.getShortPath());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case kSnapDirChosenCmd:
|
case kSnapDirChosenCmd:
|
||||||
{
|
{
|
||||||
FilesystemNode dir(myBrowser->getResult());
|
FilesystemNode dir(myBrowser->getResult());
|
||||||
mySnapPath->setEditString(dir.getRelativePath());
|
mySnapPath->setEditString(dir.getShortPath());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case kCheatFileChosenCmd:
|
case kCheatFileChosenCmd:
|
||||||
{
|
{
|
||||||
FilesystemNode dir(myBrowser->getResult());
|
FilesystemNode dir(myBrowser->getResult());
|
||||||
myCheatFile->setEditString(dir.getRelativePath());
|
myCheatFile->setEditString(dir.getShortPath());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case kPaletteFileChosenCmd:
|
case kPaletteFileChosenCmd:
|
||||||
{
|
{
|
||||||
FilesystemNode dir(myBrowser->getResult());
|
FilesystemNode dir(myBrowser->getResult());
|
||||||
myPaletteFile->setEditString(dir.getRelativePath());
|
myPaletteFile->setEditString(dir.getShortPath());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case kPropsFileChosenCmd:
|
case kPropsFileChosenCmd:
|
||||||
{
|
{
|
||||||
FilesystemNode dir(myBrowser->getResult());
|
FilesystemNode dir(myBrowser->getResult());
|
||||||
myPropsFile->setEditString(dir.getRelativePath());
|
myPropsFile->setEditString(dir.getShortPath());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case kEEPROMDirChosenCmd:
|
case kEEPROMDirChosenCmd:
|
||||||
{
|
{
|
||||||
FilesystemNode dir(myBrowser->getResult());
|
FilesystemNode dir(myBrowser->getResult());
|
||||||
myEEPROMPath->setEditString(dir.getRelativePath());
|
myEEPROMPath->setEditString(dir.getShortPath());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case kStateDirChosenCmd:
|
case kStateDirChosenCmd:
|
||||||
{
|
{
|
||||||
FilesystemNode dir(myBrowser->getResult());
|
FilesystemNode dir(myBrowser->getResult());
|
||||||
myStatePath->setEditString(dir.getRelativePath());
|
myStatePath->setEditString(dir.getShortPath());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -296,7 +296,7 @@ void LauncherDialog::updateListing(const string& nameToSelect)
|
||||||
myPrevDirButton->setEnabled(myCurrentNode.hasParent());
|
myPrevDirButton->setEnabled(myCurrentNode.hasParent());
|
||||||
|
|
||||||
// Show current directory
|
// Show current directory
|
||||||
myDir->setLabel(myCurrentNode.getRelativePath());
|
myDir->setLabel(myCurrentNode.getShortPath());
|
||||||
|
|
||||||
// Now fill the list widget with the contents of the GameList
|
// Now fill the list widget with the contents of the GameList
|
||||||
StringList l;
|
StringList l;
|
||||||
|
@ -379,7 +379,7 @@ void LauncherDialog::loadDirListing()
|
||||||
if(BSPF_equalsIgnoreCase(ext, ".a26") || BSPF_equalsIgnoreCase(ext, ".bin") ||
|
if(BSPF_equalsIgnoreCase(ext, ".a26") || BSPF_equalsIgnoreCase(ext, ".bin") ||
|
||||||
BSPF_equalsIgnoreCase(ext, ".rom"))
|
BSPF_equalsIgnoreCase(ext, ".rom"))
|
||||||
{
|
{
|
||||||
FilesystemNode newFile(AbstractFilesystemNode::getAbsolutePath(
|
FilesystemNode newFile(FilesystemNode::createAbsolutePath(
|
||||||
filename, myCurrentNode.getPath(), ""));
|
filename, myCurrentNode.getPath(), ""));
|
||||||
files.push_back(newFile);
|
files.push_back(newFile);
|
||||||
}
|
}
|
||||||
|
@ -681,7 +681,7 @@ void LauncherDialog::handleCommand(CommandSender* sender, int cmd,
|
||||||
case kStartupRomDirChosenCmd:
|
case kStartupRomDirChosenCmd:
|
||||||
{
|
{
|
||||||
FilesystemNode dir(myRomDir->getResult());
|
FilesystemNode dir(myRomDir->getResult());
|
||||||
instance().settings().setString("romdir", dir.getRelativePath());
|
instance().settings().setString("romdir", dir.getShortPath());
|
||||||
// fall through to the next case
|
// fall through to the next case
|
||||||
}
|
}
|
||||||
case kRomDirChosenCmd:
|
case kRomDirChosenCmd:
|
||||||
|
|
|
@ -109,7 +109,7 @@ RomAuditDialog::~RomAuditDialog()
|
||||||
void RomAuditDialog::loadConfig()
|
void RomAuditDialog::loadConfig()
|
||||||
{
|
{
|
||||||
const string& currentdir =
|
const string& currentdir =
|
||||||
instance().launcher().currentNode().getRelativePath();
|
instance().launcher().currentNode().getShortPath();
|
||||||
const string& path = currentdir == "" ?
|
const string& path = currentdir == "" ?
|
||||||
instance().settings().getString("romdir") : currentdir;
|
instance().settings().getString("romdir") : currentdir;
|
||||||
|
|
||||||
|
@ -209,7 +209,7 @@ void RomAuditDialog::handleCommand(CommandSender* sender, int cmd,
|
||||||
case kAuditDirChosenCmd:
|
case kAuditDirChosenCmd:
|
||||||
{
|
{
|
||||||
FilesystemNode dir(myBrowser->getResult());
|
FilesystemNode dir(myBrowser->getResult());
|
||||||
myRomPath->setEditString(dir.getRelativePath());
|
myRomPath->setEditString(dir.getShortPath());
|
||||||
myResults1->setLabel("");
|
myResults1->setLabel("");
|
||||||
myResults2->setLabel("");
|
myResults2->setLabel("");
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -49,5 +49,5 @@ OSystemMACOSX::~OSystemMACOSX()
|
||||||
string OSystemMACOSX::defaultSnapDir()
|
string OSystemMACOSX::defaultSnapDir()
|
||||||
{
|
{
|
||||||
FilesystemNode desktop("~/Desktop");
|
FilesystemNode desktop("~/Desktop");
|
||||||
return desktop.isDirectory() ? desktop.getRelativePath() : "~";
|
return desktop.isDirectory() ? desktop.getShortPath() : "~";
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,11 +67,12 @@ class POSIXFilesystemNode : public AbstractFilesystemNode
|
||||||
bool exists() const { return access(_path.c_str(), F_OK) == 0; }
|
bool exists() const { return access(_path.c_str(), F_OK) == 0; }
|
||||||
const string& getName() const { return _displayName; }
|
const string& getName() const { return _displayName; }
|
||||||
const string& getPath() const { return _path; }
|
const string& getPath() const { return _path; }
|
||||||
string getRelativePath() const;
|
string getShortPath() const;
|
||||||
bool isDirectory() const { return _isDirectory; }
|
bool isDirectory() const { return _isDirectory; }
|
||||||
bool isFile() const { return _isFile; }
|
bool isFile() const { return _isFile; }
|
||||||
bool isReadable() const { return access(_path.c_str(), R_OK) == 0; }
|
bool isReadable() const { return access(_path.c_str(), R_OK) == 0; }
|
||||||
bool isWritable() const { return access(_path.c_str(), W_OK) == 0; }
|
bool isWritable() const { return access(_path.c_str(), W_OK) == 0; }
|
||||||
|
bool isAbsolute() const;
|
||||||
bool makeDir();
|
bool makeDir();
|
||||||
bool rename(const string& newfile);
|
bool rename(const string& newfile);
|
||||||
|
|
||||||
|
@ -154,10 +155,8 @@ POSIXFilesystemNode::POSIXFilesystemNode(const string& p, bool verify)
|
||||||
if(_path[0] == '~')
|
if(_path[0] == '~')
|
||||||
{
|
{
|
||||||
const char* home = getenv("HOME");
|
const char* home = getenv("HOME");
|
||||||
if (home != NULL && strlen(home) < MAXPATHLEN)
|
if (home != NULL)
|
||||||
{
|
|
||||||
_path.replace(0, 1, home);
|
_path.replace(0, 1, home);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get absolute path
|
// Get absolute path
|
||||||
|
@ -178,7 +177,7 @@ POSIXFilesystemNode::POSIXFilesystemNode(const string& p, bool verify)
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
string POSIXFilesystemNode::getRelativePath() const
|
string POSIXFilesystemNode::getShortPath() const
|
||||||
{
|
{
|
||||||
// If the path starts with the home directory, replace it with '~'
|
// If the path starts with the home directory, replace it with '~'
|
||||||
const char* home = getenv("HOME");
|
const char* home = getenv("HOME");
|
||||||
|
@ -280,6 +279,12 @@ bool POSIXFilesystemNode::getChildren(AbstractFSList& myList, ListMode mode,
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
|
bool POSIXFilesystemNode::isAbsolute() const
|
||||||
|
{
|
||||||
|
return _path.length() > 0 && (_path[0] == '~' || _path[0] == '/');
|
||||||
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
bool POSIXFilesystemNode::makeDir()
|
bool POSIXFilesystemNode::makeDir()
|
||||||
{
|
{
|
||||||
|
@ -345,29 +350,3 @@ AbstractFilesystemNode* AbstractFilesystemNode::makeFileNodePath(const string& p
|
||||||
{
|
{
|
||||||
return new POSIXFilesystemNode(path);
|
return new POSIXFilesystemNode(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
||||||
string AbstractFilesystemNode::getAbsolutePath(const string& p,
|
|
||||||
const string& startpath,
|
|
||||||
const string& ext)
|
|
||||||
{
|
|
||||||
// Does p start with the root directory or the given startpath?
|
|
||||||
// If not, it isn't an absolute path
|
|
||||||
string path = FilesystemNode(p).getRelativePath();
|
|
||||||
if(!BSPF_startsWithIgnoreCase(p, startpath+"/") &&
|
|
||||||
!BSPF_startsWithIgnoreCase(p, "/"))
|
|
||||||
path = startpath + "/" + p;
|
|
||||||
|
|
||||||
// Does the path have a valid extension?
|
|
||||||
// If not, we add the given one
|
|
||||||
string::size_type idx = path.find_last_of('.');
|
|
||||||
if(idx != string::npos)
|
|
||||||
{
|
|
||||||
if(!BSPF_equalsIgnoreCase(path.c_str() + idx + 1, ext))
|
|
||||||
path = path.replace(idx+1, ext.length(), ext);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
path += "." + ext;
|
|
||||||
|
|
||||||
return path;
|
|
||||||
}
|
|
||||||
|
|
|
@ -98,11 +98,12 @@ class WindowsFilesystemNode : public AbstractFilesystemNode
|
||||||
bool exists() const { return _access(_path.c_str(), F_OK) == 0; }
|
bool exists() const { return _access(_path.c_str(), F_OK) == 0; }
|
||||||
const string& getName() const { return _displayName; }
|
const string& getName() const { return _displayName; }
|
||||||
const string& getPath() const { return _path; }
|
const string& getPath() const { return _path; }
|
||||||
string getRelativePath() const;
|
string getShortPath() const;
|
||||||
bool isDirectory() const { return _isDirectory; }
|
bool isDirectory() const { return _isDirectory; }
|
||||||
bool isFile() const { return _isFile; }
|
bool isFile() const { return _isFile; }
|
||||||
bool isReadable() const { return _access(_path.c_str(), R_OK) == 0; }
|
bool isReadable() const { return _access(_path.c_str(), R_OK) == 0; }
|
||||||
bool isWritable() const { return _access(_path.c_str(), W_OK) == 0; }
|
bool isWritable() const { return _access(_path.c_str(), W_OK) == 0; }
|
||||||
|
bool isAbsolute() const;
|
||||||
bool makeDir();
|
bool makeDir();
|
||||||
bool rename(const string& newfile);
|
bool rename(const string& newfile);
|
||||||
|
|
||||||
|
@ -288,7 +289,7 @@ WindowsFilesystemNode::WindowsFilesystemNode(const string& p)
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
string WindowsFilesystemNode::getRelativePath() const
|
string WindowsFilesystemNode::getShortPath() const
|
||||||
{
|
{
|
||||||
// If the path starts with the home directory, replace it with '~'
|
// If the path starts with the home directory, replace it with '~'
|
||||||
const string& home = myHomeFinder.getHomePath();
|
const string& home = myHomeFinder.getHomePath();
|
||||||
|
@ -359,6 +360,12 @@ bool WindowsFilesystemNode::
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
|
bool WindowsFilesystemNode::isAbsolute() const
|
||||||
|
{
|
||||||
|
return _path.length() >= 2 && (_path[0] == '~' || _path[1] == ':');
|
||||||
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
bool WindowsFilesystemNode::makeDir()
|
bool WindowsFilesystemNode::makeDir()
|
||||||
{
|
{
|
||||||
|
@ -411,29 +418,3 @@ AbstractFilesystemNode* AbstractFilesystemNode::makeFileNodePath(const string& p
|
||||||
{
|
{
|
||||||
return new WindowsFilesystemNode(path);
|
return new WindowsFilesystemNode(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
||||||
string AbstractFilesystemNode::getAbsolutePath(const string& p,
|
|
||||||
const string& startpath,
|
|
||||||
const string& ext)
|
|
||||||
{
|
|
||||||
// Does p start with a drive letter or the given startpath?
|
|
||||||
// If not, it isn't an absolute path
|
|
||||||
string path = FilesystemNode(p).getRelativePath();
|
|
||||||
bool startsWithDrive = path.length() >= 2 && path[1] == ':';
|
|
||||||
if(!BSPF_startsWithIgnoreCase(p, startpath+"\\") && !startsWithDrive)
|
|
||||||
path = startpath + "\\" + p;
|
|
||||||
|
|
||||||
// Does the path have a valid extension?
|
|
||||||
// If not, we add the given one
|
|
||||||
string::size_type idx = path.find_last_of('.');
|
|
||||||
if(idx != string::npos)
|
|
||||||
{
|
|
||||||
if(!BSPF_equalsIgnoreCase(path.c_str() + idx + 1, ext))
|
|
||||||
path = path.replace(idx+1, ext.length(), ext);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
path += "." + ext;
|
|
||||||
|
|
||||||
return path;
|
|
||||||
}
|
|
||||||
|
|
|
@ -72,7 +72,7 @@ OSystemWin32::OSystemWin32()
|
||||||
FilesystemNode appdata(homefinder.getAppDataPath());
|
FilesystemNode appdata(homefinder.getAppDataPath());
|
||||||
if(appdata.isDirectory())
|
if(appdata.isDirectory())
|
||||||
{
|
{
|
||||||
basedir = appdata.getRelativePath();
|
basedir = appdata.getShortPath();
|
||||||
if(basedir.length() > 1 && basedir[basedir.length()-1] != '\\')
|
if(basedir.length() > 1 && basedir[basedir.length()-1] != '\\')
|
||||||
basedir += '\\';
|
basedir += '\\';
|
||||||
basedir += "Stella";
|
basedir += "Stella";
|
||||||
|
@ -95,7 +95,7 @@ string OSystemWin32::defaultSnapDir()
|
||||||
{
|
{
|
||||||
HomeFinder homefinder;
|
HomeFinder homefinder;
|
||||||
FilesystemNode desktop(homefinder.getDesktopPath());
|
FilesystemNode desktop(homefinder.getDesktopPath());
|
||||||
return desktop.isDirectory() ? desktop.getRelativePath() : "~";
|
return desktop.isDirectory() ? desktop.getShortPath() : "~";
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
|
|
Loading…
Reference in New Issue