Skip to content

Commit

Permalink
os/filesystem/*FileSystem: some improvements, need to test with MSC
Browse files Browse the repository at this point in the history
  • Loading branch information
andreasdr committed Nov 2, 2023
1 parent c4d677b commit 5ced965
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
5 changes: 4 additions & 1 deletion src/tdme/os/filesystem/ArchiveFileSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,7 @@ const string ArchiveFileSystem::getCanonicalPath(const string& pathName, const s
string unixPathName = StringTools::replace(pathName, "\\", "/");
string unixFileName = StringTools::replace(fileName, "\\", "/");

//
auto pathString = getFileName(unixPathName, unixFileName);

// separate into path components
Expand Down Expand Up @@ -372,12 +373,14 @@ const string ArchiveFileSystem::getCanonicalPath(const string& pathName, const s
}

// add cwd if required
auto canonicalPathString = canonicalPath;
auto canonicalPathString = canonicalPath.empty() == true?"/":canonicalPath;
/*
if (canonicalPathString.length() == 0 ||
(StringTools::startsWith(canonicalPathString, "/") == false &&
StringTools::regexMatch(canonicalPathString, "^[a-zA-Z]\\:.*$") == false)) {
canonicalPathString = getCurrentWorkingPathName() + "/" + canonicalPathString;
}
*/

//
return canonicalPathString;
Expand Down
14 changes: 11 additions & 3 deletions src/tdme/os/filesystem/StandardFileSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,13 @@ const string StandardFileSystem::getFileName(const string& pathName, const strin
void StandardFileSystem::list(const string& pathName, vector<string>& files, FileNameFilter* filter, bool addDrives)
{
auto _pathName = pathName;
if (StringTools::endsWith(pathName, "/") == false) _pathName+= "/";
if (StringTools::endsWith(_pathName, "/") == false) _pathName+= "/";

try {
for (const auto& entry: std::filesystem::directory_iterator(std::filesystem::u8path(_pathName))) {
auto u8FileName = entry.path().filename().u8string();
string fileName(u8FileName.size(), 0);
for (auto i = 0; i < u8FileName.size(); i++) fileName[i] = u8FileName[i];
if (fileName == ".") continue;
try {
if (filter != nullptr && filter->accept(pathName, fileName) == false) continue;
} catch (Exception& exception) {
Expand All @@ -70,8 +69,14 @@ void StandardFileSystem::list(const string& pathName, vector<string>& files, Fil
throw FileSystemException("Unable to list path: " + pathName + ": " + string(exception.what()));
}

//
sort(files.begin(), files.end());

//
if (isDrive(_pathName) == false && _pathName.empty() == false && _pathName != "/") {
files.insert(files.begin(), "..");
}

#if defined(_WIN32)
if (addDrives == true) {
for (char drive = 'A'; drive <= 'Z'; drive++) {
Expand Down Expand Up @@ -227,6 +232,7 @@ const string StandardFileSystem::getCanonicalPath(const string& pathName, const
string unixPathName = StringTools::replace(pathName, "\\", "/");
string unixFileName = StringTools::replace(fileName, "\\", "/");

//
auto pathString = getFileName(unixPathName, unixFileName);

// separate into path components
Expand Down Expand Up @@ -270,12 +276,14 @@ const string StandardFileSystem::getCanonicalPath(const string& pathName, const
}

// add cwd if required
auto canonicalPathString = canonicalPath;
auto canonicalPathString = canonicalPath.empty() == true?"/":canonicalPath;
/*
if (canonicalPathString.length() == 0 ||
(StringTools::startsWith(canonicalPathString, "/") == false &&
StringTools::regexMatch(canonicalPathString, "^[a-zA-Z]\\:.*$") == false)) {
canonicalPathString = getCurrentWorkingPathName() + "/" + canonicalPathString;
}
*/

//
return canonicalPathString;
Expand Down

0 comments on commit 5ced965

Please sign in to comment.