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());
|
||||
if(!in.is_open())
|
||||
return DebuggerParser::red("symbol file '" + node.getRelativePath() + "' not found");
|
||||
return DebuggerParser::red("symbol file '" + node.getShortPath() + "' not found");
|
||||
|
||||
myUserAddresses.clear();
|
||||
myUserLabels.clear();
|
||||
|
@ -648,9 +648,9 @@ string CartDebug::loadSymbolFile(string file)
|
|||
addLabel(label, value);
|
||||
}
|
||||
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();
|
||||
|
||||
return "loaded " + node.getRelativePath() + " OK";
|
||||
return "loaded " + node.getShortPath() + " OK";
|
||||
}
|
||||
else
|
||||
return DebuggerParser::red("config file not found");
|
||||
|
@ -830,7 +830,7 @@ string CartDebug::saveConfigFile(string file)
|
|||
}
|
||||
out.close();
|
||||
|
||||
return "saved " + node.getRelativePath() + " OK";
|
||||
return "saved " + node.getShortPath() + " OK";
|
||||
}
|
||||
else
|
||||
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 path = AbstractFilesystemNode::getAbsolutePath(filename, "~", "a26");
|
||||
string path = FilesystemNode::createAbsolutePath(filename, "~", "a26");
|
||||
FilesystemNode node(path);
|
||||
|
||||
ofstream out(node.getPath().c_str(), ios::out | ios::binary);
|
||||
if(out.is_open() && myConsole.cartridge().save(out))
|
||||
return node.getRelativePath();
|
||||
return node.getShortPath();
|
||||
else
|
||||
return "";
|
||||
}
|
||||
|
|
|
@ -135,7 +135,7 @@ string DebuggerParser::exec(const FilesystemNode& file)
|
|||
{
|
||||
ifstream in(file.getPath().c_str());
|
||||
if(!in.is_open())
|
||||
return red("autoexec file \'" + file.getRelativePath() + "\' not found");
|
||||
return red("autoexec file \'" + file.getShortPath() + "\' not found");
|
||||
|
||||
ostringstream buf;
|
||||
int count = 0;
|
||||
|
@ -149,12 +149,12 @@ string DebuggerParser::exec(const FilesystemNode& file)
|
|||
count++;
|
||||
}
|
||||
buf << "Executed " << debugger->valueToString(count) << " commands from \""
|
||||
<< file.getRelativePath() << "\"";
|
||||
<< file.getShortPath() << "\"";
|
||||
|
||||
return buf.str();
|
||||
}
|
||||
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);
|
||||
return _realNode->getRelativePath();
|
||||
return _realNode->getShortPath();
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
@ -130,6 +130,12 @@ bool FilesystemNode::isWritable() const
|
|||
return _realNode ? _realNode->isWritable() : false;
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
bool FilesystemNode::isAbsolute() const
|
||||
{
|
||||
return _realNode ? _realNode->isAbsolute() : false;
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
bool FilesystemNode::makeDir()
|
||||
{
|
||||
|
@ -141,3 +147,30 @@ bool FilesystemNode::rename(const string& newfile)
|
|||
{
|
||||
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
|
||||
* 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
|
||||
*/
|
||||
virtual const string& getPath() const;
|
||||
|
@ -162,12 +159,9 @@ class FilesystemNode
|
|||
* symbol (if applicable), and is suitable for archiving (i.e. writing
|
||||
* 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
|
||||
*/
|
||||
virtual string getRelativePath() const;
|
||||
virtual string getShortPath() const;
|
||||
|
||||
/**
|
||||
* Determine whether this node has a parent.
|
||||
|
@ -219,6 +213,13 @@ class FilesystemNode
|
|||
*/
|
||||
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.
|
||||
*
|
||||
|
@ -233,6 +234,15 @@ class FilesystemNode
|
|||
*/
|
||||
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:
|
||||
Common::SharedPtr<AbstractFilesystemNode> _realNode;
|
||||
FilesystemNode(AbstractFilesystemNode* realNode);
|
||||
|
@ -302,7 +312,7 @@ class AbstractFilesystemNode
|
|||
* 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.
|
||||
|
@ -341,6 +351,13 @@ class AbstractFilesystemNode
|
|||
*/
|
||||
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.
|
||||
*
|
||||
|
@ -355,14 +372,6 @@ class AbstractFilesystemNode
|
|||
*/
|
||||
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:
|
||||
/**
|
||||
* 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
|
||||
* 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.
|
||||
*/
|
||||
static AbstractFilesystemNode* makeFileNodePath(const string& path);
|
||||
|
|
|
@ -210,11 +210,11 @@ bool OSystem::create()
|
|||
<< " Features: " << myFeatures << endl
|
||||
<< " " << myBuildInfo << endl << endl
|
||||
<< "Base directory: '"
|
||||
<< FilesystemNode(myBaseDir).getRelativePath() << "'" << endl
|
||||
<< FilesystemNode(myBaseDir).getShortPath() << "'" << endl
|
||||
<< "Configuration file: '"
|
||||
<< FilesystemNode(myConfigFile).getRelativePath() << "'" << endl
|
||||
<< FilesystemNode(myConfigFile).getShortPath() << "'" << endl
|
||||
<< "User game properties: '"
|
||||
<< FilesystemNode(myPropertiesFile).getRelativePath() << "'" << endl;
|
||||
<< FilesystemNode(myPropertiesFile).getShortPath() << "'" << endl;
|
||||
logMessage(buf.str(), 1);
|
||||
|
||||
// Get relevant information about the video hardware
|
||||
|
@ -356,19 +356,19 @@ void OSystem::setConfigPaths()
|
|||
if(s == "") s = myBaseDir + "stella.cht";
|
||||
node = FilesystemNode(s);
|
||||
myCheatFile = node.getPath();
|
||||
mySettings->setString("cheatfile", node.getRelativePath());
|
||||
mySettings->setString("cheatfile", node.getShortPath());
|
||||
|
||||
s = mySettings->getString("palettefile");
|
||||
if(s == "") s = myBaseDir + "stella.pal";
|
||||
node = FilesystemNode(s);
|
||||
myPaletteFile = node.getPath();
|
||||
mySettings->setString("palettefile", node.getRelativePath());
|
||||
mySettings->setString("palettefile", node.getShortPath());
|
||||
|
||||
s = mySettings->getString("propsfile");
|
||||
if(s == "") s = myBaseDir + "stella.pro";
|
||||
node = FilesystemNode(s);
|
||||
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);
|
||||
}
|
||||
buf << "Game console created:" << endl
|
||||
<< " ROM file: " << FilesystemNode(myRomFile).getRelativePath() << endl << endl
|
||||
<< " ROM file: " << FilesystemNode(myRomFile).getShortPath() << endl << endl
|
||||
<< getROMInfo(myConsole) << endl;
|
||||
logMessage(buf.str(), 1);
|
||||
|
||||
|
@ -950,7 +950,7 @@ void OSystem::validatePath(string& path, const string& setting,
|
|||
if(!node.isDirectory())
|
||||
node.makeDir();
|
||||
path = node.getPath();
|
||||
mySettings->setString(setting, node.getRelativePath());
|
||||
mySettings->setString(setting, node.getShortPath());
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
|
|
@ -164,7 +164,7 @@ void BrowserDialog::updateListing()
|
|||
_nodeList->clear();
|
||||
|
||||
// Update the path display
|
||||
_currentPath->setLabel(_node.getRelativePath());
|
||||
_currentPath->setLabel(_node.getShortPath());
|
||||
|
||||
// Read in the data from the file system
|
||||
FSList content;
|
||||
|
|
|
@ -225,29 +225,29 @@ void FileSnapDialog::setDefaults()
|
|||
const string& basedir = instance().baseDir();
|
||||
|
||||
node = FilesystemNode("~");
|
||||
myRomPath->setEditString(node.getRelativePath());
|
||||
myRomPath->setEditString(node.getShortPath());
|
||||
|
||||
mySnapPath->setEditString(instance().defaultSnapDir());
|
||||
|
||||
const string& cheatfile = basedir + "stella.cht";
|
||||
node = FilesystemNode(cheatfile);
|
||||
myCheatFile->setEditString(node.getRelativePath());
|
||||
myCheatFile->setEditString(node.getShortPath());
|
||||
|
||||
const string& palettefile = basedir + "stella.pal";
|
||||
node = FilesystemNode(palettefile);
|
||||
myPaletteFile->setEditString(node.getRelativePath());
|
||||
myPaletteFile->setEditString(node.getShortPath());
|
||||
|
||||
const string& propsfile = basedir + "stella.pro";
|
||||
node = FilesystemNode(propsfile);
|
||||
myPropsFile->setEditString(node.getRelativePath());
|
||||
myPropsFile->setEditString(node.getShortPath());
|
||||
|
||||
const string& eepromdir = basedir;
|
||||
node = FilesystemNode(eepromdir);
|
||||
myEEPROMPath->setEditString(node.getRelativePath());
|
||||
myEEPROMPath->setEditString(node.getShortPath());
|
||||
|
||||
const string& statedir = basedir + "state";
|
||||
node = FilesystemNode(statedir);
|
||||
myStatePath->setEditString(node.getRelativePath());
|
||||
myStatePath->setEditString(node.getShortPath());
|
||||
|
||||
mySnapSingle->setState(false);
|
||||
mySnap1x->setState(false);
|
||||
|
@ -309,49 +309,49 @@ void FileSnapDialog::handleCommand(CommandSender* sender, int cmd,
|
|||
case kRomDirChosenCmd:
|
||||
{
|
||||
FilesystemNode dir(myBrowser->getResult());
|
||||
myRomPath->setEditString(dir.getRelativePath());
|
||||
myRomPath->setEditString(dir.getShortPath());
|
||||
break;
|
||||
}
|
||||
|
||||
case kSnapDirChosenCmd:
|
||||
{
|
||||
FilesystemNode dir(myBrowser->getResult());
|
||||
mySnapPath->setEditString(dir.getRelativePath());
|
||||
mySnapPath->setEditString(dir.getShortPath());
|
||||
break;
|
||||
}
|
||||
|
||||
case kCheatFileChosenCmd:
|
||||
{
|
||||
FilesystemNode dir(myBrowser->getResult());
|
||||
myCheatFile->setEditString(dir.getRelativePath());
|
||||
myCheatFile->setEditString(dir.getShortPath());
|
||||
break;
|
||||
}
|
||||
|
||||
case kPaletteFileChosenCmd:
|
||||
{
|
||||
FilesystemNode dir(myBrowser->getResult());
|
||||
myPaletteFile->setEditString(dir.getRelativePath());
|
||||
myPaletteFile->setEditString(dir.getShortPath());
|
||||
break;
|
||||
}
|
||||
|
||||
case kPropsFileChosenCmd:
|
||||
{
|
||||
FilesystemNode dir(myBrowser->getResult());
|
||||
myPropsFile->setEditString(dir.getRelativePath());
|
||||
myPropsFile->setEditString(dir.getShortPath());
|
||||
break;
|
||||
}
|
||||
|
||||
case kEEPROMDirChosenCmd:
|
||||
{
|
||||
FilesystemNode dir(myBrowser->getResult());
|
||||
myEEPROMPath->setEditString(dir.getRelativePath());
|
||||
myEEPROMPath->setEditString(dir.getShortPath());
|
||||
break;
|
||||
}
|
||||
|
||||
case kStateDirChosenCmd:
|
||||
{
|
||||
FilesystemNode dir(myBrowser->getResult());
|
||||
myStatePath->setEditString(dir.getRelativePath());
|
||||
myStatePath->setEditString(dir.getShortPath());
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
@ -296,7 +296,7 @@ void LauncherDialog::updateListing(const string& nameToSelect)
|
|||
myPrevDirButton->setEnabled(myCurrentNode.hasParent());
|
||||
|
||||
// Show current directory
|
||||
myDir->setLabel(myCurrentNode.getRelativePath());
|
||||
myDir->setLabel(myCurrentNode.getShortPath());
|
||||
|
||||
// Now fill the list widget with the contents of the GameList
|
||||
StringList l;
|
||||
|
@ -379,7 +379,7 @@ void LauncherDialog::loadDirListing()
|
|||
if(BSPF_equalsIgnoreCase(ext, ".a26") || BSPF_equalsIgnoreCase(ext, ".bin") ||
|
||||
BSPF_equalsIgnoreCase(ext, ".rom"))
|
||||
{
|
||||
FilesystemNode newFile(AbstractFilesystemNode::getAbsolutePath(
|
||||
FilesystemNode newFile(FilesystemNode::createAbsolutePath(
|
||||
filename, myCurrentNode.getPath(), ""));
|
||||
files.push_back(newFile);
|
||||
}
|
||||
|
@ -681,7 +681,7 @@ void LauncherDialog::handleCommand(CommandSender* sender, int cmd,
|
|||
case kStartupRomDirChosenCmd:
|
||||
{
|
||||
FilesystemNode dir(myRomDir->getResult());
|
||||
instance().settings().setString("romdir", dir.getRelativePath());
|
||||
instance().settings().setString("romdir", dir.getShortPath());
|
||||
// fall through to the next case
|
||||
}
|
||||
case kRomDirChosenCmd:
|
||||
|
|
|
@ -109,7 +109,7 @@ RomAuditDialog::~RomAuditDialog()
|
|||
void RomAuditDialog::loadConfig()
|
||||
{
|
||||
const string& currentdir =
|
||||
instance().launcher().currentNode().getRelativePath();
|
||||
instance().launcher().currentNode().getShortPath();
|
||||
const string& path = currentdir == "" ?
|
||||
instance().settings().getString("romdir") : currentdir;
|
||||
|
||||
|
@ -209,7 +209,7 @@ void RomAuditDialog::handleCommand(CommandSender* sender, int cmd,
|
|||
case kAuditDirChosenCmd:
|
||||
{
|
||||
FilesystemNode dir(myBrowser->getResult());
|
||||
myRomPath->setEditString(dir.getRelativePath());
|
||||
myRomPath->setEditString(dir.getShortPath());
|
||||
myResults1->setLabel("");
|
||||
myResults2->setLabel("");
|
||||
break;
|
||||
|
|
|
@ -49,5 +49,5 @@ OSystemMACOSX::~OSystemMACOSX()
|
|||
string OSystemMACOSX::defaultSnapDir()
|
||||
{
|
||||
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; }
|
||||
const string& getName() const { return _displayName; }
|
||||
const string& getPath() const { return _path; }
|
||||
string getRelativePath() const;
|
||||
string getShortPath() const;
|
||||
bool isDirectory() const { return _isDirectory; }
|
||||
bool isFile() const { return _isFile; }
|
||||
bool isReadable() const { return access(_path.c_str(), R_OK) == 0; }
|
||||
bool isWritable() const { return access(_path.c_str(), W_OK) == 0; }
|
||||
bool isAbsolute() const;
|
||||
bool makeDir();
|
||||
bool rename(const string& newfile);
|
||||
|
||||
|
@ -154,10 +155,8 @@ POSIXFilesystemNode::POSIXFilesystemNode(const string& p, bool verify)
|
|||
if(_path[0] == '~')
|
||||
{
|
||||
const char* home = getenv("HOME");
|
||||
if (home != NULL && strlen(home) < MAXPATHLEN)
|
||||
{
|
||||
if (home != NULL)
|
||||
_path.replace(0, 1, home);
|
||||
}
|
||||
}
|
||||
|
||||
// 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 '~'
|
||||
const char* home = getenv("HOME");
|
||||
|
@ -280,6 +279,12 @@ bool POSIXFilesystemNode::getChildren(AbstractFSList& myList, ListMode mode,
|
|||
return true;
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
bool POSIXFilesystemNode::isAbsolute() const
|
||||
{
|
||||
return _path.length() > 0 && (_path[0] == '~' || _path[0] == '/');
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
bool POSIXFilesystemNode::makeDir()
|
||||
{
|
||||
|
@ -345,29 +350,3 @@ AbstractFilesystemNode* AbstractFilesystemNode::makeFileNodePath(const string& p
|
|||
{
|
||||
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; }
|
||||
const string& getName() const { return _displayName; }
|
||||
const string& getPath() const { return _path; }
|
||||
string getRelativePath() const;
|
||||
string getShortPath() const;
|
||||
bool isDirectory() const { return _isDirectory; }
|
||||
bool isFile() const { return _isFile; }
|
||||
bool isReadable() const { return _access(_path.c_str(), R_OK) == 0; }
|
||||
bool isWritable() const { return _access(_path.c_str(), W_OK) == 0; }
|
||||
bool isAbsolute() const;
|
||||
bool makeDir();
|
||||
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 '~'
|
||||
const string& home = myHomeFinder.getHomePath();
|
||||
|
@ -359,6 +360,12 @@ bool WindowsFilesystemNode::
|
|||
return true;
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
bool WindowsFilesystemNode::isAbsolute() const
|
||||
{
|
||||
return _path.length() >= 2 && (_path[0] == '~' || _path[1] == ':');
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
bool WindowsFilesystemNode::makeDir()
|
||||
{
|
||||
|
@ -411,29 +418,3 @@ AbstractFilesystemNode* AbstractFilesystemNode::makeFileNodePath(const string& p
|
|||
{
|
||||
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());
|
||||
if(appdata.isDirectory())
|
||||
{
|
||||
basedir = appdata.getRelativePath();
|
||||
basedir = appdata.getShortPath();
|
||||
if(basedir.length() > 1 && basedir[basedir.length()-1] != '\\')
|
||||
basedir += '\\';
|
||||
basedir += "Stella";
|
||||
|
@ -95,7 +95,7 @@ string OSystemWin32::defaultSnapDir()
|
|||
{
|
||||
HomeFinder homefinder;
|
||||
FilesystemNode desktop(homefinder.getDesktopPath());
|
||||
return desktop.isDirectory() ? desktop.getRelativePath() : "~";
|
||||
return desktop.isDirectory() ? desktop.getShortPath() : "~";
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
|
Loading…
Reference in New Issue