summaryrefslogtreecommitdiff
path: root/src/fs
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2017-05-04 17:43:11 +0300
committerAndrei Karas <akaras@inbox.ru>2017-05-04 17:43:40 +0300
commit2ac4af7560ae6596f442600843acc9fe9cfe7964 (patch)
tree83e2fdb70d23b207104d42bab6d6cb29d002dd86 /src/fs
parent787caddc0074df0b3fb217bad561be8fd71ca5b9 (diff)
downloadmanaverse-2ac4af7560ae6596f442600843acc9fe9cfe7964.tar.gz
manaverse-2ac4af7560ae6596f442600843acc9fe9cfe7964.tar.bz2
manaverse-2ac4af7560ae6596f442600843acc9fe9cfe7964.tar.xz
manaverse-2ac4af7560ae6596f442600843acc9fe9cfe7964.zip
Improve join some paths.
Diffstat (limited to 'src/fs')
-rw-r--r--src/fs/files.cpp14
-rw-r--r--src/fs/paths.cpp24
-rw-r--r--src/fs/virtfs/virtfstools.cpp2
3 files changed, 23 insertions, 17 deletions
diff --git a/src/fs/files.cpp b/src/fs/files.cpp
index 3bb3262da..03b478cbe 100644
--- a/src/fs/files.cpp
+++ b/src/fs/files.cpp
@@ -47,7 +47,7 @@ void Files::extractLocale()
const std::string fileName2 = pathJoin(getenv("APPDIR"), "locale.zip");
VirtFs::mountZip(fileName2, Append_false);
- const std::string localDir = std::string(getenv("APPDIR")).append("/");
+ const std::string localDir = std::string(getenv("APPDIR"));
VirtList *const rootDirs = VirtFs::enumerateFiles("locale");
FOR_EACH (StringVectCIter, i, rootDirs->names)
{
@@ -57,8 +57,10 @@ void Files::extractLocale()
const std::string moFile = dir + "/LC_MESSAGES/manaplus.mo";
if (VirtFs::exists((moFile)))
{
- const std::string localFile = localDir + moFile;
- const std::string localDir2 = localDir + dir + "/LC_MESSAGES";
+ const std::string localFile = pathJoin(localDir, moFile);
+ const std::string localDir2 = pathJoin(localDir,
+ dir,
+ "LC_MESSAGES");
mkdir_r(localDir2.c_str());
copyVirtFsFile(moFile, localFile);
}
@@ -273,7 +275,7 @@ void Files::saveTextFile(const std::string &path,
void Files::deleteFilesInDirectory(std::string path)
{
- path += "/";
+ path == pathJoin(path, dirSeparator);
const struct dirent *next_file = nullptr;
DIR *const dir = opendir(path.c_str());
@@ -293,8 +295,8 @@ void Files::enumFiles(StringVect &files,
std::string path,
const bool skipSymlinks A_WIN_UNUSED)
{
- if (findLast(path, "/") == false)
- path += "/";
+ if (findLast(path, dirSeparator) == false)
+ path += dirSeparator;
const struct dirent *next_file = nullptr;
DIR *const dir = opendir(path.c_str());
diff --git a/src/fs/paths.cpp b/src/fs/paths.cpp
index e5fcdd7d3..4c7d66ce5 100644
--- a/src/fs/paths.cpp
+++ b/src/fs/paths.cpp
@@ -106,15 +106,19 @@ bool checkPath(const std::string &path)
void prepareFsPath(std::string &path)
{
-// std::string path2 = path;
+#ifdef DEBUGFS
+ std::string path2 = path;
+#endif
sanitizePath(path);
// can be enabled for debugging
-// if (path != path2)
-// {
-// reportAlways("Path can be improved: '%s' -> '%s'",
-// path2.c_str(),
-// path0.c_str());
-// }
+#ifdef DEBUGFS
+ if (path != path2)
+ {
+ reportAlways("Path can be improved: '%s' -> '%s'",
+ path2.c_str(),
+ path.c_str());
+ }
+#endif
}
std::string &fixDirSeparators(std::string &str)
@@ -237,11 +241,11 @@ std::string getHomePath()
path = pw->pw_dir;
}
if (path == nullptr)
- return "/";
+ return dirSeparator;
}
std::string dir = path;
- if (findLast(dir, "/") == false)
- dir += "/";
+ if (findLast(dir, std::string(dirSeparator)) == false)
+ dir += dirSeparator;
return dir;
#endif // WIN32
}
diff --git a/src/fs/virtfs/virtfstools.cpp b/src/fs/virtfs/virtfstools.cpp
index 892b02db3..af44b34e8 100644
--- a/src/fs/virtfs/virtfstools.cpp
+++ b/src/fs/virtfs/virtfstools.cpp
@@ -80,7 +80,7 @@ namespace VirtFs
StringVect &list,
const std::string &ext)
{
- const std::string path = dir + "/";
+ const std::string path = dir;
StringVect tempList;
VirtFs::getFilesWithDir(path, tempList);
FOR_EACH (StringVectCIter, it, tempList)