Updated Windows code for recent FilesystemNode class changes.

git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@2253 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba
This commit is contained in:
stephena 2011-06-11 15:59:19 +00:00
parent d1ea17711b
commit e2c736263f
2 changed files with 30 additions and 28 deletions

View File

@ -238,21 +238,11 @@ WindowsFilesystemNode::WindowsFilesystemNode()
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
WindowsFilesystemNode::WindowsFilesystemNode(const string& p) WindowsFilesystemNode::WindowsFilesystemNode(const string& p)
{ {
// Expand "~\" to the 'My Documents' directory // Expand '~\' and '.\' to the users 'home' directory
if ( p.length() >= 2 && p[0] == '~' && p[1] == '\\') if ( p.length() >= 2 && (p[0] == '~' || p[0] == '.') && p[1] == '\\')
{ {
_path = myHomeFinder.getHomePath(); _path = myHomeFinder.getHomePath();
// Skip over the tilde. We know that p contains at least // Skip over the tilde/dot. We know that p contains at least
// two chars, so this is safe:
_path += p.c_str() + 1;
}
// Expand ".\" to the current directory
else if ( p.length() >= 2 && p[0] == '.' && p[1] == '\\')
{
char path[MAX_PATH];
GetCurrentDirectory(MAX_PATH, path);
_path = path;
// Skip over the dot. We know that p contains at least
// two chars, so this is safe: // two chars, so this is safe:
_path += p.c_str() + 1; _path += p.c_str() + 1;
} }
@ -290,6 +280,7 @@ string WindowsFilesystemNode::getPath(bool fqn) 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(!fqn && 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();
if(*offset != '\\') path += '\\'; if(*offset != '\\') path += '\\';
@ -386,12 +377,6 @@ AbstractFilesystemNode* AbstractFilesystemNode::makeRootFileNode()
return new WindowsFilesystemNode(); return new WindowsFilesystemNode();
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
AbstractFilesystemNode* AbstractFilesystemNode::makeCurrentDirectoryFileNode()
{
return new WindowsFilesystemNode(".\\");
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
AbstractFilesystemNode* AbstractFilesystemNode::makeHomeDirectoryFileNode() AbstractFilesystemNode* AbstractFilesystemNode::makeHomeDirectoryFileNode()
{ {
@ -422,6 +407,23 @@ string AbstractFilesystemNode::getAbsolutePath(const string& p,
const string& startpath, const string& startpath,
const string& ext) const string& ext)
{ {
assert(false); // Does p start with a drive letter or the given startpath?
return ""; // If not, it isn't an absolute path
string path = FilesystemNode(p).getPath(false);
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;
} }

View File

@ -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.getPath(false);
if(basedir.length() > 1 && basedir[basedir.length()-1] != '\\') if(basedir.length() > 1 && basedir[basedir.length()-1] != '\\')
basedir += '\\'; basedir += '\\';
basedir += "Stella"; basedir += "Stella";