mirror of https://github.com/stella-emu/stella.git
Reverted FSNode getPath() modifications introduced in Stella 3.4.1, since it causes massive performance regressions in Windows XP.
git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@2292 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba
This commit is contained in:
parent
56694b5934
commit
52cf172661
|
@ -626,7 +626,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.getPath(false) + "' not found");
|
return DebuggerParser::red("symbol file '" + node.getRelativePath() + "' not found");
|
||||||
|
|
||||||
myUserAddresses.clear();
|
myUserAddresses.clear();
|
||||||
myUserLabels.clear();
|
myUserLabels.clear();
|
||||||
|
@ -645,9 +645,9 @@ string CartDebug::loadSymbolFile(string file)
|
||||||
addLabel(label, value);
|
addLabel(label, value);
|
||||||
}
|
}
|
||||||
in.close();
|
in.close();
|
||||||
return "loaded " + node.getPath(false) + " OK";
|
return "loaded " + node.getRelativePath() + " OK";
|
||||||
}
|
}
|
||||||
return DebuggerParser::red("symbol file '" + node.getPath(false) + "' not found");
|
return DebuggerParser::red("symbol file '" + node.getRelativePath() + "' not found");
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
|
@ -783,7 +783,7 @@ string CartDebug::loadConfigFile(string file)
|
||||||
}
|
}
|
||||||
in.close();
|
in.close();
|
||||||
|
|
||||||
return "loaded " + node.getPath(false) + " OK";
|
return "loaded " + node.getRelativePath() + " OK";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return DebuggerParser::red("config file not found");
|
return DebuggerParser::red("config file not found");
|
||||||
|
@ -827,7 +827,7 @@ string CartDebug::saveConfigFile(string file)
|
||||||
}
|
}
|
||||||
out.close();
|
out.close();
|
||||||
|
|
||||||
return "saved " + node.getPath(false) + " OK";
|
return "saved " + node.getRelativePath() + " OK";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return DebuggerParser::red("config file not found");
|
return DebuggerParser::red("config file not found");
|
||||||
|
|
|
@ -842,9 +842,9 @@ string Debugger::saveROM(const string& filename) const
|
||||||
string path = AbstractFilesystemNode::getAbsolutePath(filename, "~", "a26");
|
string path = AbstractFilesystemNode::getAbsolutePath(filename, "~", "a26");
|
||||||
FilesystemNode node(path);
|
FilesystemNode node(path);
|
||||||
|
|
||||||
ofstream out(node.getPath(true).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.getPath(false);
|
return node.getRelativePath();
|
||||||
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.getPath(false) + "\' not found");
|
return red("autoexec file \'" + file.getRelativePath() + "\' 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.getPath(false) << "\"";
|
<< file.getRelativePath() << "\"";
|
||||||
|
|
||||||
return buf.str();
|
return buf.str();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return red("autoexec file \'" + file.getPath(false) + "\' not found");
|
return red("autoexec file \'" + file.getRelativePath() + "\' not found");
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
|
|
|
@ -122,10 +122,17 @@ FilesystemNode FilesystemNode::getParent() const
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
string FilesystemNode::getPath(bool fqn) const
|
string FilesystemNode::getPath() const
|
||||||
{
|
{
|
||||||
assert(_realNode);
|
assert(_realNode);
|
||||||
return _realNode->getPath(fqn);
|
return _realNode->getPath();
|
||||||
|
}
|
||||||
|
|
||||||
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
|
string FilesystemNode::getRelativePath() const
|
||||||
|
{
|
||||||
|
assert(_realNode);
|
||||||
|
return _realNode->getRelativePath();
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
|
|
|
@ -166,11 +166,7 @@ class FilesystemNode
|
||||||
virtual string getName() const;
|
virtual string getName() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return a string representation of the file with the following properties:
|
* Return a string representation of the file which can be passed to fopen().
|
||||||
* 1) can be passed to fopen() if fqn is true
|
|
||||||
* 2) contains the '~' symbol (if applicable), and is suitable for archiving
|
|
||||||
* (i.e. writing to the config file) if fqn is false
|
|
||||||
*
|
|
||||||
* 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.
|
||||||
*
|
*
|
||||||
|
@ -179,7 +175,19 @@ class FilesystemNode
|
||||||
*
|
*
|
||||||
* @return the 'path' represented by this filesystem node
|
* @return the 'path' represented by this filesystem node
|
||||||
*/
|
*/
|
||||||
virtual string getPath(bool fqn = true) const;
|
virtual string getPath() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return a string representation of the file which contains the '~'
|
||||||
|
* 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;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determine whether this node has a parent.
|
* Determine whether this node has a parent.
|
||||||
|
@ -294,10 +302,15 @@ class AbstractFilesystemNode
|
||||||
virtual string getName() const = 0;
|
virtual string getName() const = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the 'path' of the current node, usable in fopen() or
|
* Returns the 'path' of the current node, usable in fopen().
|
||||||
containing '~' and for archiving.
|
|
||||||
*/
|
*/
|
||||||
virtual string getPath(bool fqn = true) const = 0;
|
virtual string getPath() const = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the 'path' of the current node, containing '~' and for archiving.
|
||||||
|
*/
|
||||||
|
|
||||||
|
virtual string getRelativePath() const = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Indicates whether this path refers to a directory or not.
|
* Indicates whether this path refers to a directory or not.
|
||||||
|
|
|
@ -204,11 +204,11 @@ bool OSystem::create()
|
||||||
setConfigPaths();
|
setConfigPaths();
|
||||||
ostringstream buf;
|
ostringstream buf;
|
||||||
buf << "Base directory: '"
|
buf << "Base directory: '"
|
||||||
<< FilesystemNode(myBaseDir).getPath(false) << "'" << endl
|
<< FilesystemNode(myBaseDir).getRelativePath() << "'" << endl
|
||||||
<< "Configuration file: '"
|
<< "Configuration file: '"
|
||||||
<< FilesystemNode(myConfigFile).getPath(false) << "'" << endl
|
<< FilesystemNode(myConfigFile).getRelativePath() << "'" << endl
|
||||||
<< "User game properties: '"
|
<< "User game properties: '"
|
||||||
<< FilesystemNode(myPropertiesFile).getPath(false) << "'" << endl
|
<< FilesystemNode(myPropertiesFile).getRelativePath() << "'" << endl
|
||||||
<< endl;
|
<< endl;
|
||||||
logMessage(buf.str(), 1);
|
logMessage(buf.str(), 1);
|
||||||
|
|
||||||
|
@ -325,19 +325,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.getPath(false));
|
mySettings->setString("cheatfile", node.getRelativePath());
|
||||||
|
|
||||||
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.getPath(false));
|
mySettings->setString("palettefile", node.getRelativePath());
|
||||||
|
|
||||||
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.getPath(false));
|
mySettings->setString("propsfile", node.getRelativePath());
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
|
@ -538,7 +538,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).getPath(false) << endl << endl
|
<< " ROM file: " << FilesystemNode(myRomFile).getRelativePath() << endl << endl
|
||||||
<< getROMInfo(myConsole) << endl;
|
<< getROMInfo(myConsole) << endl;
|
||||||
logMessage(buf.str(), 1);
|
logMessage(buf.str(), 1);
|
||||||
|
|
||||||
|
@ -881,7 +881,7 @@ void OSystem::validatePath(string& path, const string& setting,
|
||||||
node = FilesystemNode(node.getPath());
|
node = FilesystemNode(node.getPath());
|
||||||
}
|
}
|
||||||
path = node.getPath();
|
path = node.getPath();
|
||||||
mySettings->setString(setting, node.getPath(false));
|
mySettings->setString(setting, node.getRelativePath());
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
|
|
|
@ -164,7 +164,7 @@ void BrowserDialog::updateListing()
|
||||||
_nodeList->clear();
|
_nodeList->clear();
|
||||||
|
|
||||||
// Update the path display
|
// Update the path display
|
||||||
_currentPath->setLabel(_node.getPath(false));
|
_currentPath->setLabel(_node.getRelativePath());
|
||||||
|
|
||||||
// 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.getPath(false));
|
myRomPath->setEditString(node.getRelativePath());
|
||||||
|
|
||||||
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.getPath(false));
|
myCheatFile->setEditString(node.getRelativePath());
|
||||||
|
|
||||||
const string& palettefile = basedir + "stella.pal";
|
const string& palettefile = basedir + "stella.pal";
|
||||||
node = FilesystemNode(palettefile);
|
node = FilesystemNode(palettefile);
|
||||||
myPaletteFile->setEditString(node.getPath(false));
|
myPaletteFile->setEditString(node.getRelativePath());
|
||||||
|
|
||||||
const string& propsfile = basedir + "stella.pro";
|
const string& propsfile = basedir + "stella.pro";
|
||||||
node = FilesystemNode(propsfile);
|
node = FilesystemNode(propsfile);
|
||||||
myPropsFile->setEditString(node.getPath(false));
|
myPropsFile->setEditString(node.getRelativePath());
|
||||||
|
|
||||||
const string& eepromdir = basedir;
|
const string& eepromdir = basedir;
|
||||||
node = FilesystemNode(eepromdir);
|
node = FilesystemNode(eepromdir);
|
||||||
myEEPROMPath->setEditString(node.getPath(false));
|
myEEPROMPath->setEditString(node.getRelativePath());
|
||||||
|
|
||||||
const string& statedir = basedir + "state";
|
const string& statedir = basedir + "state";
|
||||||
node = FilesystemNode(statedir);
|
node = FilesystemNode(statedir);
|
||||||
myStatePath->setEditString(node.getPath(false));
|
myStatePath->setEditString(node.getRelativePath());
|
||||||
|
|
||||||
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.getPath(false));
|
myRomPath->setEditString(dir.getRelativePath());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case kSnapDirChosenCmd:
|
case kSnapDirChosenCmd:
|
||||||
{
|
{
|
||||||
FilesystemNode dir(myBrowser->getResult());
|
FilesystemNode dir(myBrowser->getResult());
|
||||||
mySnapPath->setEditString(dir.getPath(false));
|
mySnapPath->setEditString(dir.getRelativePath());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case kCheatFileChosenCmd:
|
case kCheatFileChosenCmd:
|
||||||
{
|
{
|
||||||
FilesystemNode dir(myBrowser->getResult());
|
FilesystemNode dir(myBrowser->getResult());
|
||||||
myCheatFile->setEditString(dir.getPath(false));
|
myCheatFile->setEditString(dir.getRelativePath());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case kPaletteFileChosenCmd:
|
case kPaletteFileChosenCmd:
|
||||||
{
|
{
|
||||||
FilesystemNode dir(myBrowser->getResult());
|
FilesystemNode dir(myBrowser->getResult());
|
||||||
myPaletteFile->setEditString(dir.getPath(false));
|
myPaletteFile->setEditString(dir.getRelativePath());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case kPropsFileChosenCmd:
|
case kPropsFileChosenCmd:
|
||||||
{
|
{
|
||||||
FilesystemNode dir(myBrowser->getResult());
|
FilesystemNode dir(myBrowser->getResult());
|
||||||
myPropsFile->setEditString(dir.getPath(false));
|
myPropsFile->setEditString(dir.getRelativePath());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case kEEPROMDirChosenCmd:
|
case kEEPROMDirChosenCmd:
|
||||||
{
|
{
|
||||||
FilesystemNode dir(myBrowser->getResult());
|
FilesystemNode dir(myBrowser->getResult());
|
||||||
myEEPROMPath->setEditString(dir.getPath(false));
|
myEEPROMPath->setEditString(dir.getRelativePath());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case kStateDirChosenCmd:
|
case kStateDirChosenCmd:
|
||||||
{
|
{
|
||||||
FilesystemNode dir(myBrowser->getResult());
|
FilesystemNode dir(myBrowser->getResult());
|
||||||
myStatePath->setEditString(dir.getPath(false));
|
myStatePath->setEditString(dir.getRelativePath());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -293,7 +293,7 @@ void LauncherDialog::updateListing(const string& nameToSelect)
|
||||||
myPrevDirButton->setEnabled(myCurrentNode.hasParent());
|
myPrevDirButton->setEnabled(myCurrentNode.hasParent());
|
||||||
|
|
||||||
// Show current directory
|
// Show current directory
|
||||||
myDir->setLabel(myCurrentNode.getPath(false));
|
myDir->setLabel(myCurrentNode.getRelativePath());
|
||||||
|
|
||||||
// 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;
|
||||||
|
@ -583,7 +583,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.getPath(false));
|
instance().settings().setString("romdir", dir.getRelativePath());
|
||||||
// fall through to the next case
|
// fall through to the next case
|
||||||
}
|
}
|
||||||
case kRomDirChosenCmd:
|
case kRomDirChosenCmd:
|
||||||
|
|
|
@ -119,7 +119,7 @@ void LoggerDialog::saveLogFile()
|
||||||
string path = AbstractFilesystemNode::getAbsolutePath("stella", "~", "log");
|
string path = AbstractFilesystemNode::getAbsolutePath("stella", "~", "log");
|
||||||
FilesystemNode node(path);
|
FilesystemNode node(path);
|
||||||
|
|
||||||
ofstream out(node.getPath(true).c_str(), ios::out);
|
ofstream out(node.getPath().c_str(), ios::out);
|
||||||
if(out.is_open())
|
if(out.is_open())
|
||||||
{
|
{
|
||||||
out << instance().logMessages();
|
out << instance().logMessages();
|
||||||
|
|
|
@ -109,7 +109,7 @@ RomAuditDialog::~RomAuditDialog()
|
||||||
void RomAuditDialog::loadConfig()
|
void RomAuditDialog::loadConfig()
|
||||||
{
|
{
|
||||||
const string& currentdir =
|
const string& currentdir =
|
||||||
instance().launcher().currentNode().getPath(false);
|
instance().launcher().currentNode().getRelativePath();
|
||||||
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.getPath(false));
|
myRomPath->setEditString(dir.getRelativePath());
|
||||||
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.getPath(false) : "~";
|
return desktop.isDirectory() ? desktop.getRelativePath() : "~";
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,7 +61,8 @@ 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; }
|
||||||
string getDisplayName() const { return _displayName; }
|
string getDisplayName() const { return _displayName; }
|
||||||
string getName() const { return _displayName; }
|
string getName() const { return _displayName; }
|
||||||
string getPath(bool fqn) const;
|
string getPath() const { return _path; }
|
||||||
|
string getRelativePath() const;
|
||||||
bool isDirectory() const { return _isDirectory; }
|
bool isDirectory() const { return _isDirectory; }
|
||||||
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; }
|
||||||
|
@ -161,11 +162,11 @@ POSIXFilesystemNode::POSIXFilesystemNode(const string& p, bool verify)
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
string POSIXFilesystemNode::getPath(bool fqn) const
|
string POSIXFilesystemNode::getRelativePath() 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");
|
||||||
if(!fqn && home != NULL && BSPF_startsWithIgnoreCase(_path, home))
|
if(home != NULL && BSPF_startsWithIgnoreCase(_path, home))
|
||||||
{
|
{
|
||||||
string path = "~";
|
string path = "~";
|
||||||
const char* offset = _path.c_str() + strlen(home);
|
const char* offset = _path.c_str() + strlen(home);
|
||||||
|
@ -307,7 +308,7 @@ string AbstractFilesystemNode::getAbsolutePath(const string& p,
|
||||||
{
|
{
|
||||||
// Does p start with the root directory or the given startpath?
|
// Does p start with the root directory or the given startpath?
|
||||||
// If not, it isn't an absolute path
|
// If not, it isn't an absolute path
|
||||||
string path = FilesystemNode(p).getPath(false);
|
string path = FilesystemNode(p).getRelativePath();
|
||||||
if(!BSPF_startsWithIgnoreCase(p, startpath+"/") &&
|
if(!BSPF_startsWithIgnoreCase(p, startpath+"/") &&
|
||||||
!BSPF_startsWithIgnoreCase(p, "/"))
|
!BSPF_startsWithIgnoreCase(p, "/"))
|
||||||
path = startpath + "/" + p;
|
path = startpath + "/" + p;
|
||||||
|
|
|
@ -94,7 +94,8 @@ 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; }
|
||||||
string getDisplayName() const { return _displayName; }
|
string getDisplayName() const { return _displayName; }
|
||||||
string getName() const { return _displayName; }
|
string getName() const { return _displayName; }
|
||||||
string getPath(bool fqn) const;
|
string getPath() const { return _path; }
|
||||||
|
string getRelativePath() const;
|
||||||
bool isDirectory() const { return _isDirectory; }
|
bool isDirectory() const { return _isDirectory; }
|
||||||
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; }
|
||||||
|
@ -275,11 +276,11 @@ WindowsFilesystemNode::WindowsFilesystemNode(const string& p)
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
string WindowsFilesystemNode::getPath(bool fqn) const
|
string WindowsFilesystemNode::getRelativePath() 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();
|
||||||
if(!fqn && home != "" && BSPF_startsWithIgnoreCase(_path, home))
|
if(home != "" && BSPF_startsWithIgnoreCase(_path, home))
|
||||||
{
|
{
|
||||||
string path = "~";
|
string path = "~";
|
||||||
const char* offset = _path.c_str() + home.length();
|
const char* offset = _path.c_str() + home.length();
|
||||||
|
@ -409,7 +410,7 @@ string AbstractFilesystemNode::getAbsolutePath(const string& p,
|
||||||
{
|
{
|
||||||
// Does p start with a drive letter or the given startpath?
|
// Does p start with a drive letter or the given startpath?
|
||||||
// If not, it isn't an absolute path
|
// If not, it isn't an absolute path
|
||||||
string path = FilesystemNode(p).getPath(false);
|
string path = FilesystemNode(p).getRelativePath();
|
||||||
bool startsWithDrive = path.length() >= 2 && path[1] == ':';
|
bool startsWithDrive = path.length() >= 2 && path[1] == ':';
|
||||||
if(!BSPF_startsWithIgnoreCase(p, startpath+"\\") && !startsWithDrive)
|
if(!BSPF_startsWithIgnoreCase(p, startpath+"\\") && !startsWithDrive)
|
||||||
path = startpath + "\\" + p;
|
path = startpath + "\\" + p;
|
||||||
|
|
|
@ -52,38 +52,59 @@ class HomeFinder
|
||||||
|
|
||||||
/** Wrapper for SHGetFolderPathA, returning the 'HOME/User' folder
|
/** Wrapper for SHGetFolderPathA, returning the 'HOME/User' folder
|
||||||
(or an empty string if the folder couldn't be determined. */
|
(or an empty string if the folder couldn't be determined. */
|
||||||
string getHomePath() const
|
const string& getHomePath() const
|
||||||
|
{
|
||||||
|
if(ourHomePath == "")
|
||||||
|
{
|
||||||
|
if(!myFolderPathFunc)
|
||||||
|
ourHomePath = "";
|
||||||
|
else
|
||||||
{
|
{
|
||||||
if(!myFolderPathFunc) return "";
|
|
||||||
char folder_path[MAX_PATH];
|
char folder_path[MAX_PATH];
|
||||||
HRESULT const result = (myFolderPathFunc)
|
HRESULT const result = (myFolderPathFunc)
|
||||||
(NULL, CSIDL_PROFILE | CSIDL_FLAG_CREATE, NULL, 0, folder_path);
|
(NULL, CSIDL_PROFILE | CSIDL_FLAG_CREATE, NULL, 0, folder_path);
|
||||||
|
ourHomePath = (result == 0) ? folder_path : "";
|
||||||
return (result == 0) ? folder_path : "";
|
}
|
||||||
|
}
|
||||||
|
return ourHomePath;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Wrapper for SHGetFolderPathA, returning the 'APPDATA' folder
|
/** Wrapper for SHGetFolderPathA, returning the 'APPDATA' folder
|
||||||
(or an empty string if the folder couldn't be determined. */
|
(or an empty string if the folder couldn't be determined. */
|
||||||
string getAppDataPath() const
|
const string& getAppDataPath() const
|
||||||
|
{
|
||||||
|
if(ourAppDataPath == "")
|
||||||
|
{
|
||||||
|
if(!myFolderPathFunc)
|
||||||
|
ourAppDataPath = "";
|
||||||
|
else
|
||||||
{
|
{
|
||||||
if(!myFolderPathFunc) return "";
|
|
||||||
char folder_path[MAX_PATH];
|
char folder_path[MAX_PATH];
|
||||||
HRESULT const result = (myFolderPathFunc)
|
HRESULT const result = (myFolderPathFunc)
|
||||||
(NULL, CSIDL_APPDATA | CSIDL_FLAG_CREATE, NULL, 0, folder_path);
|
(NULL, CSIDL_APPDATA | CSIDL_FLAG_CREATE, NULL, 0, folder_path);
|
||||||
|
ourAppDataPath = (result == 0) ? folder_path : "";
|
||||||
return (result == 0) ? folder_path : "";
|
}
|
||||||
|
}
|
||||||
|
return ourAppDataPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Wrapper for SHGetFolderPathA, returning the 'DESKTOPDIRECTORY' folder
|
/** Wrapper for SHGetFolderPathA, returning the 'DESKTOPDIRECTORY' folder
|
||||||
(or an empty string if the folder couldn't be determined. */
|
(or an empty string if the folder couldn't be determined. */
|
||||||
string getDesktopPath() const
|
const string& getDesktopPath() const
|
||||||
|
{
|
||||||
|
if(ourDesktopPath == "")
|
||||||
|
{
|
||||||
|
if(!myFolderPathFunc)
|
||||||
|
ourDesktopPath = "";
|
||||||
|
else
|
||||||
{
|
{
|
||||||
if(!myFolderPathFunc) return "";
|
|
||||||
char folder_path[MAX_PATH];
|
char folder_path[MAX_PATH];
|
||||||
HRESULT const result = (myFolderPathFunc)
|
HRESULT const result = (myFolderPathFunc)
|
||||||
(NULL, CSIDL_DESKTOPDIRECTORY | CSIDL_FLAG_CREATE, NULL, 0, folder_path);
|
(NULL, CSIDL_DESKTOPDIRECTORY | CSIDL_FLAG_CREATE, NULL, 0, folder_path);
|
||||||
|
ourDesktopPath = (result == 0) ? folder_path : "";
|
||||||
return (result == 0) ? folder_path : "";
|
}
|
||||||
|
}
|
||||||
|
return ourDesktopPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -91,6 +112,12 @@ class HomeFinder
|
||||||
|
|
||||||
HMODULE myFolderModule;
|
HMODULE myFolderModule;
|
||||||
function_pointer myFolderPathFunc;
|
function_pointer myFolderPathFunc;
|
||||||
|
|
||||||
|
static string ourHomePath, ourAppDataPath, ourDesktopPath;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
__declspec(selectany) string HomeFinder::ourHomePath = "";
|
||||||
|
__declspec(selectany) string HomeFinder::ourAppDataPath = "";
|
||||||
|
__declspec(selectany) string HomeFinder::ourDesktopPath = "";
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -72,7 +72,7 @@ OSystemWin32::OSystemWin32()
|
||||||
FilesystemNode appdata(homefinder.getAppDataPath());
|
FilesystemNode appdata(homefinder.getAppDataPath());
|
||||||
if(appdata.isDirectory())
|
if(appdata.isDirectory())
|
||||||
{
|
{
|
||||||
basedir = appdata.getPath(false);
|
basedir = appdata.getRelativePath();
|
||||||
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.getPath(false) : "~";
|
return desktop.isDirectory() ? desktop.getRelativePath() : "~";
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
|
|
Loading…
Reference in New Issue