summaryrefslogtreecommitdiff
path: root/src
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
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')
-rw-r--r--src/dirs.cpp4
-rw-r--r--src/fs/files.cpp14
-rw-r--r--src/fs/paths.cpp24
-rw-r--r--src/fs/virtfs/virtfstools.cpp2
-rw-r--r--src/gui/windows/updaterwindow.cpp6
5 files changed, 28 insertions, 22 deletions
diff --git a/src/dirs.cpp b/src/dirs.cpp
index 85383543a..31af61165 100644
--- a/src/dirs.cpp
+++ b/src/dirs.cpp
@@ -510,8 +510,8 @@ void Dirs::initUpdatesDir()
#endif // defined WIN32
}
}
- const std::string updateLocal = updateDir + "/local";
- const std::string updateFix = updateDir + "/fix";
+ const std::string updateLocal = pathJoin(updateDir, "local");
+ const std::string updateFix = pathJoin(updateDir, "fix");
if (!VirtFs::isDirectory(updateLocal))
VirtFs::mkdir(updateLocal);
if (!VirtFs::isDirectory(updateFix))
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)
diff --git a/src/gui/windows/updaterwindow.cpp b/src/gui/windows/updaterwindow.cpp
index 13e16627d..823a92c3d 100644
--- a/src/gui/windows/updaterwindow.cpp
+++ b/src/gui/windows/updaterwindow.cpp
@@ -603,7 +603,7 @@ void UpdaterWindow::download()
if (mDownloadStatus == UpdateDownloadStatus::UPDATE_LIST2 ||
mDownloadStatus == UpdateDownloadStatus::UPDATE_RESOURCES2)
{
- const std::string str = mUpdateServerPath + "/" + mCurrentFile;
+ const std::string str = urlJoin(mUpdateServerPath, mCurrentFile);
mDownload->addMirror(updateServer3 + str);
mDownload->addMirror(updateServer4 + str);
mDownload->addMirror(updateServer5 + str);
@@ -1176,7 +1176,7 @@ void UpdaterWindow::loadDirMods(const std::string &dir)
const std::string &localDir = mod->getLocalDir();
if (!localDir.empty())
{
- VirtFs::mountDir(dir + "/" + localDir,
+ VirtFs::mountDir(pathJoin(dir, localDir),
Append_false);
}
}
@@ -1200,7 +1200,7 @@ void UpdaterWindow::unloadMods(const std::string &dir)
{
const std::string &localDir = mod->getLocalDir();
if (!localDir.empty())
- VirtFs::unmountDir(dir + "/" + localDir);
+ VirtFs::unmountDir(pathJoin(dir, localDir));
}
}
}