diff options
author | Andrei Karas <akaras@inbox.ru> | 2017-04-02 06:23:19 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2017-04-03 18:44:58 +0300 |
commit | 49631972db5b965413d4bbe36983a8d5bd203183 (patch) | |
tree | cb31545521cb4b33e65f8e94e7f2d5cd33e9e7a1 /src | |
parent | be7786e70668c014b19263895a6c8f507ed8161d (diff) | |
download | manaplus-49631972db5b965413d4bbe36983a8d5bd203183.tar.gz manaplus-49631972db5b965413d4bbe36983a8d5bd203183.tar.bz2 manaplus-49631972db5b965413d4bbe36983a8d5bd203183.tar.xz manaplus-49631972db5b965413d4bbe36983a8d5bd203183.zip |
Use pathJoin for concatinate some paths.
Diffstat (limited to 'src')
-rw-r--r-- | src/being/actorsprite.cpp | 10 | ||||
-rw-r--r-- | src/chatlogger.cpp | 7 | ||||
-rw-r--r-- | src/client.cpp | 37 | ||||
-rw-r--r-- | src/configmanager.cpp | 2 | ||||
-rw-r--r-- | src/dirs.cpp | 66 | ||||
-rw-r--r-- | src/dyetool/client.cpp | 18 | ||||
-rw-r--r-- | src/fs/virtfs/virtfstools.cpp | 16 | ||||
-rw-r--r-- | src/gui/popups/itempopup.cpp | 2 | ||||
-rw-r--r-- | src/gui/theme.cpp | 7 | ||||
-rw-r--r-- | src/gui/windows/mailviewwindow.cpp | 2 | ||||
-rw-r--r-- | src/gui/windows/minimap.cpp | 4 | ||||
-rw-r--r-- | src/gui/windows/npcdialog.cpp | 4 | ||||
-rw-r--r-- | src/resources/item/item.cpp | 10 | ||||
-rw-r--r-- | src/resources/map/map.cpp | 4 | ||||
-rw-r--r-- | src/resources/sprite/spritedef.cpp | 2 | ||||
-rw-r--r-- | src/test/testlauncher.cpp | 4 | ||||
-rw-r--r-- | src/test/testmain.cpp | 4 | ||||
-rw-r--r-- | src/textcommand.cpp | 2 | ||||
-rw-r--r-- | src/utils/fuzzer.cpp | 2 |
19 files changed, 101 insertions, 102 deletions
diff --git a/src/being/actorsprite.cpp b/src/being/actorsprite.cpp index 0cbb88d99..fc4850e32 100644 --- a/src/being/actorsprite.cpp +++ b/src/being/actorsprite.cpp @@ -438,7 +438,7 @@ void ActorSprite::setupSpriteDisplay(const SpriteDisplay &display, { if (!*it) continue; - const std::string file = paths.getStringValue("sprites").append( + const std::string file = pathJoin(paths.getStringValue("sprites"), combineDye3((*it)->sprite, color)); const int variant = (*it)->variant; @@ -450,8 +450,8 @@ void ActorSprite::setupSpriteDisplay(const SpriteDisplay &display, { if (display.image.empty()) { - addSprite(AnimatedSprite::delayedLoad( - paths.getStringValue("sprites").append( + addSprite(AnimatedSprite::delayedLoad(pathJoin( + paths.getStringValue("sprites"), paths.getStringValue("spriteErrorFile")))); } else @@ -461,11 +461,11 @@ void ActorSprite::setupSpriteDisplay(const SpriteDisplay &display, { case 0: default: - imagePath = paths.getStringValue("itemIcons").append( + imagePath = pathJoin(paths.getStringValue("itemIcons"), display.image); break; case 1: - imagePath = paths.getStringValue("itemIcons").append( + imagePath = pathJoin(paths.getStringValue("itemIcons"), display.floor); break; } diff --git a/src/chatlogger.cpp b/src/chatlogger.cpp index ff803ef2b..1b0b7052d 100644 --- a/src/chatlogger.cpp +++ b/src/chatlogger.cpp @@ -185,11 +185,10 @@ void ChatLogger::setServerName(const std::string &serverName) secureName(mServerName); if (!mLogDir.empty()) { - const char *const name = (std::string(mLogDir).append(dirSeparator) - .append(mServerName)).c_str(); - DIR *const dir = opendir(name); + const std::string name = pathJoin(mLogDir, mServerName); + DIR *const dir = opendir(name.c_str()); if (!dir) - mkdir_r(name); + mkdir_r(name.c_str()); else closedir(dir); } diff --git a/src/client.cpp b/src/client.cpp index 6715290ff..d15aa240a 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -298,9 +298,14 @@ void Client::gameInit() // Configure logger if (!settings.options.logFileName.empty()) + { settings.logFileName = settings.options.logFileName; + } else - settings.logFileName = settings.localDataDir + "/manaplus.log"; + { + settings.logFileName = pathJoin(settings.localDataDir, + "manaplus.log"); + } logger->log("Log file: " + settings.logFileName); logger->setLogFile(settings.logFileName); @@ -1092,15 +1097,13 @@ int Client::gameExec() if (!settings.options.skipUpdate) { VirtFs::searchAndRemoveArchives( - settings.updatesDir + - "/local/", + pathJoin(settings.updatesDir, "local/"), "zip"); - VirtFs::unmountDirSilent( - settings.localDataDir + - dirSeparator + - settings.updatesDir + - "/local/"); + VirtFs::unmountDirSilent(pathJoin( + settings.localDataDir, + settings.updatesDir, + "local/")); } resourceManager->clearCache(); @@ -1277,16 +1280,15 @@ int Client::gameExec() } else if (loginData.updateType & UpdateType::Skip) { - settings.oldUpdates = settings.localDataDir - + dirSeparator + settings.updatesDir; + settings.oldUpdates = pathJoin(settings.localDataDir, + settings.updatesDir); UpdaterWindow::loadLocalUpdates(settings.oldUpdates); mState = State::LOAD_DATA; } else { - settings.oldUpdates = settings.localDataDir + - dirSeparator + - settings.updatesDir; + settings.oldUpdates = pathJoin(settings.localDataDir, + settings.updatesDir); CREATEWIDGETV(mCurrentDialog, UpdaterWindow, settings.updateHost, settings.oldUpdates, @@ -1319,11 +1321,10 @@ int Client::gameExec() "zip", Append_false); - VirtFs::mountDir( - settings.localDataDir + - dirSeparator + - settings.updatesDir + - "/local/", + VirtFs::mountDir(pathJoin( + settings.localDataDir, + settings.updatesDir, + "local/"), Append_false); } diff --git a/src/configmanager.cpp b/src/configmanager.cpp index 78182477c..f1232235a 100644 --- a/src/configmanager.cpp +++ b/src/configmanager.cpp @@ -55,7 +55,7 @@ static void setDefaultOption(const char *const name, */ void ConfigManager::initServerConfig(const std::string &serverName) { - settings.serverConfigDir = settings.configDir + dirSeparator + serverName; + settings.serverConfigDir = pathJoin(settings.configDir, serverName); if (mkdir_r(settings.serverConfigDir.c_str())) { diff --git a/src/dirs.cpp b/src/dirs.cpp index 765a498a6..d72881545 100644 --- a/src/dirs.cpp +++ b/src/dirs.cpp @@ -163,8 +163,8 @@ void Dirs::updateDataPath() } else { - settings.options.dataPath = branding.getDirectory().append( - dirSeparator) + branding.getStringValue("dataPath"); + settings.options.dataPath = pathJoin(branding.getDirectory(), + branding.getStringValue("dataPath")); } settings.options.skipUpdate = true; } @@ -327,26 +327,28 @@ void Dirs::initLocalDataDir() { #ifdef __APPLE__ // Use Application Directory instead of .mana - settings.localDataDir = std::string(VirtFs::getUserDir()) + - "/Library/Application Support/" + - branding.getValue("appName", "ManaPlus"); + settings.localDataDir = pathJoin(VirtFs::getUserDir(), + "Library/Application Support", + branding.getValue("appName", "ManaPlus")); #elif defined __HAIKU__ - settings.localDataDir = std::string(VirtFs::getUserDir()) + - "/config/data/Mana"; + settings.localDataDir = pathJoin(VirtFs::getUserDir(), + "config/data/Mana"); #elif defined WIN32 settings.localDataDir = getSpecialFolderLocation(CSIDL_LOCAL_APPDATA); if (settings.localDataDir.empty()) - settings.localDataDir = std::string(VirtFs::getUserDir()); - settings.localDataDir.append("/Mana"); + settings.localDataDir = VirtFs::getUserDir(); + settings.localDataDir = pathJoin(settings.localDataDir, + "Mana"); #elif defined __ANDROID__ - settings.localDataDir = getSdStoragePath() + branding.getValue( - "appShort", "ManaPlus") + "/local"; + settings.localDataDir = pathJoin(getSdStoragePath(), + branding.getValue("appShort", "ManaPlus"), + "local"); #elif defined __native_client__ - settings.localDataDir = _nacl_dir.append("/local"); + settings.localDataDir = pathJoin(_nacl_dir, "local"); #else // __APPLE__ - settings.localDataDir = std::string(VirtFs::getUserDir()) + - ".local/share/mana"; + settings.localDataDir = pathJoin(VirtFs::getUserDir(), + ".local/share/mana"); #endif // __APPLE__ } @@ -357,13 +359,13 @@ void Dirs::initLocalDataDir() "Exiting."), settings.localDataDir.c_str())); } #ifdef USE_PROFILER - Perfomance::init(settings.localDataDir + "/profiler.log"); + Perfomance::init(pathJoin(settings.localDataDir, "profiler.log")); #endif // USE_PROFILER } void Dirs::initTempDir() { - settings.tempDir = settings.localDataDir + dirSeparator + "temp"; + settings.tempDir = pathJoin(settings.localDataDir, "temp"); if (mkdir_r(settings.tempDir.c_str())) { @@ -381,12 +383,12 @@ void Dirs::initConfigDir() if (settings.configDir.empty()) { #ifdef __APPLE__ - settings.configDir = settings.localDataDir + dirSeparator - + branding.getValue("appShort", "mana"); + settings.configDir = pathJoin(settings.localDataDir, + branding.getValue("appShort", "mana")); #elif defined __HAIKU__ - settings.configDir = std::string(VirtFs::getUserDir()) + - "/config/settings/Mana" + - branding.getValue("appName", "ManaPlus"); + settings.configDir = pathJoin(VirtFs::getUserDir(), + "config/settings/Mana", + branding.getValue("appName", "ManaPlus")); #elif defined WIN32 settings.configDir = getSpecialFolderLocation(CSIDL_APPDATA); if (settings.configDir.empty()) @@ -402,7 +404,7 @@ void Dirs::initConfigDir() settings.configDir = getSdStoragePath() + branding.getValue( "appShort", "ManaPlus").append("/config"); #elif defined __native_client__ - settings.configDir = _nacl_dir.append("/config"); + settings.configDir = pathJoin(_nacl_dir, "config"); #else // __APPLE__ settings.configDir = std::string(VirtFs::getUserDir()).append( @@ -490,17 +492,8 @@ void Dirs::initUpdatesDir() if (!VirtFs::mkdir(updateDir)) { #if defined WIN32 - std::string newDir = settings.localDataDir + - "\\" + - settings.updatesDir; - size_t loc = newDir.find("/", 0); - - while (loc != std::string::npos) - { - newDir.replace(loc, 1, "\\"); - loc = newDir.find("/", loc); - } - + std::string newDir = pathJoin(settings.localDataDir, + settings.updatesDir); if (!CreateDirectory(newDir.c_str(), nullptr) && GetLastError() != ERROR_ALREADY_EXISTS) { @@ -513,7 +506,8 @@ void Dirs::initUpdatesDir() #else // defined WIN32 logger->log("Error: %s/%s can't be made, but doesn't exist!", - settings.localDataDir.c_str(), settings.updatesDir.c_str()); + settings.localDataDir.c_str(), + settings.updatesDir.c_str()); // TRANSLATORS: update server initialisation error errorMessage = _("Error creating updates directory!"); client->setState(State::ERROR); @@ -544,7 +538,7 @@ void Dirs::initScreenshotDir() else if (settings.screenshotDir.empty()) { #ifdef __native_client__ - settings.screenshotDir = _nacl_dir + "/screenshots/"; + settings.screenshotDir = pathJoin(_nacl_dir, "screenshots/"); #else // __native_client__ settings.screenshotDir = decodeBase64String( config.getStringValue("screenshotDirectory3")); @@ -571,7 +565,7 @@ void Dirs::initScreenshotDir() if (!configScreenshotSuffix.empty()) { - settings.screenshotDir.append(dirSeparator).append( + settings.screenshotDir = pathJoin(settings.screenshotDir, configScreenshotSuffix); } } diff --git a/src/dyetool/client.cpp b/src/dyetool/client.cpp index 8be7b125e..f618db321 100644 --- a/src/dyetool/client.cpp +++ b/src/dyetool/client.cpp @@ -159,9 +159,14 @@ void Client::gameInit() // Configure logger if (!settings.options.logFileName.empty()) + { settings.logFileName = settings.options.logFileName; + } else - settings.logFileName = settings.localDataDir + "/manaplus.log"; + { + settings.logFileName = pathJoin(settings.localDataDir, + "manaplus.log"); + } logger->setLogFile(settings.logFileName); #ifdef USE_FUZZER @@ -640,14 +645,15 @@ int Client::gameExec() if (!settings.options.skipUpdate) { - VirtFs::searchAndAddArchives( - settings.updatesDir + "/local/", + VirtFs::searchAndAddArchives(pathJoin( + settings.updatesDir, "local/"), "zip", Append_false); - VirtFs::mountDir( - settings.localDataDir - + dirSeparator + settings.updatesDir + "/local/", + VirtFs::mountDir(pathJoin( + settings.localDataDir, + settings.updatesDir, + "local/"), Append_false); } diff --git a/src/fs/virtfs/virtfstools.cpp b/src/fs/virtfs/virtfstools.cpp index 8bcc0d065..ca65bbdf2 100644 --- a/src/fs/virtfs/virtfstools.cpp +++ b/src/fs/virtfs/virtfstools.cpp @@ -51,8 +51,7 @@ namespace VirtFs { const std::string file = path + str; const std::string realPath = VirtFs::getRealDir(file); - VirtFs::mountZip(std::string(realPath).append( - dirSeparator).append(file), append); + VirtFs::mountZip(pathJoin(realPath, file), append); } } VirtFs::freeList(list); @@ -71,10 +70,7 @@ namespace VirtFs { const std::string file = path + str; const std::string realPath = VirtFs::getRealDir(file); - VirtFs::unmountZip(std::string( - realPath).append( - dirSeparator).append( - file)); + VirtFs::unmountZip(pathJoin(realPath, file)); } } VirtFs::freeList(list); @@ -114,7 +110,7 @@ namespace VirtFs VirtList *const fonts = VirtFs::enumerateFiles(path); FOR_EACH (StringVectCIter, i, fonts->names) { - if (!VirtFs::isDirectory(path + dirSeparator + *i)) + if (!VirtFs::isDirectory(pathJoin(path, *i))) list.push_back(*i); } VirtFs::freeList(fonts); @@ -125,7 +121,7 @@ namespace VirtFs VirtList *const fonts = VirtFs::enumerateFiles(path); FOR_EACH (StringVectCIter, i, fonts->names) { - if (VirtFs::isDirectory(path + dirSeparator + *i)) + if (VirtFs::isDirectory(pathJoin(path, *i))) list.push_back(*i); } VirtFs::freeList(fonts); @@ -140,7 +136,7 @@ namespace VirtFs // if the file is not in the search path, then its empty if (!tmp.empty()) { - path = std::string(tmp).append(dirSeparator).append(file); + path = pathJoin(tmp, file); #if defined __native_client__ std::string dataZip = "/http/data.zip/"; if (path.substr(0, dataZip.length()) == dataZip) @@ -150,7 +146,7 @@ namespace VirtFs else { // if not found in search path return the default path - path = getPackageDir().append(dirSeparator).append(file); + path = pathJoin(getPackageDir(), file); } return path; diff --git a/src/gui/popups/itempopup.cpp b/src/gui/popups/itempopup.cpp index 5cdc1dd20..34e583f7a 100644 --- a/src/gui/popups/itempopup.cpp +++ b/src/gui/popups/itempopup.cpp @@ -182,7 +182,7 @@ void ItemPopup::setItem(const ItemInfo &item, if (showImage) { Image *const image = Loader::getImage(combineDye2( - paths.getStringValue("itemIcons").append(item.getDisplay().image), + pathJoin(paths.getStringValue("itemIcons"), item.getDisplay().image), item.getDyeIconColorsString(color))); mIcon->setImage(image); diff --git a/src/gui/theme.cpp b/src/gui/theme.cpp index bffd212f7..b68fa011d 100644 --- a/src/gui/theme.cpp +++ b/src/gui/theme.cpp @@ -1004,7 +1004,7 @@ void Theme::loadColors(std::string file) if (file.empty()) file = "colors.xml"; else - file.append("/colors.xml"); + file = pathJoin(file, "colors.xml"); XML::Document *const doc = Loader::getXml(resolveThemePath(file), UseVirtFs_true, @@ -1211,8 +1211,9 @@ ThemeInfo *Theme::loadInfo(const std::string &themeName) } else { - path = std::string(defaultThemePath).append( - themeName).append("/info.xml"); + path = pathJoin(defaultThemePath, + themeName, + "info.xml"); } logger->log("loading: " + path); XML::Document *const doc = Loader::getXml(path, diff --git a/src/gui/windows/mailviewwindow.cpp b/src/gui/windows/mailviewwindow.cpp index 879fa804a..54c3edca7 100644 --- a/src/gui/windows/mailviewwindow.cpp +++ b/src/gui/windows/mailviewwindow.cpp @@ -112,7 +112,7 @@ MailViewWindow::MailViewWindow(const MailMessage *const message) : const ItemInfo &item = ItemDB::get(message->itemId); // +++ need use message->cards and ItemColorManager for colors Image *const image = Loader::getImage(combineDye2( - paths.getStringValue("itemIcons").append( + pathJoin(paths.getStringValue("itemIcons"), item.getDisplay().image), item.getDyeIconColorsString(ItemColor_one))); diff --git a/src/gui/windows/minimap.cpp b/src/gui/windows/minimap.cpp index e43ea4138..2a2d6830a 100644 --- a/src/gui/windows/minimap.cpp +++ b/src/gui/windows/minimap.cpp @@ -186,8 +186,8 @@ void Minimap::setMap(const Map *const map) if (minimapName.empty()) { - tempname = std::string("graphics/minimaps/").append( - map->getFilename()).append(".png"); + tempname = pathJoin("graphics/minimaps", + std::string(map->getFilename()).append(".png")); if (VirtFs::exists(tempname)) minimapName = tempname; } diff --git a/src/gui/windows/npcdialog.cpp b/src/gui/windows/npcdialog.cpp index 1c7fca17e..e1b139bd8 100644 --- a/src/gui/windows/npcdialog.cpp +++ b/src/gui/windows/npcdialog.cpp @@ -717,8 +717,8 @@ void NpcDialog::parseListItems(const std::string &itemString) else { mItems.push_back(tmp.substr(pos + 1)); - Image *const img = Loader::getImage(std::string( - path).append(tmp.substr(0, pos)).append(".png")); + Image *const img = Loader::getImage(pathJoin(path, + std::string(tmp.substr(0, pos)).append(".png"))); mImages.push_back(img); } } diff --git a/src/resources/item/item.cpp b/src/resources/item/item.cpp index 99fed928d..d738ca0e3 100644 --- a/src/resources/item/item.cpp +++ b/src/resources/item/item.cpp @@ -97,15 +97,15 @@ void Item::setId(const int id, const ItemInfo &info = getInfo(); mTags = info.getTags(); - const std::string dye = combineDye2(paths.getStringValue( - "itemIcons").append(info.getDisplay().image), + const std::string dye = combineDye2(pathJoin( + paths.getStringValue("itemIcons"), info.getDisplay().image), info.getDyeIconColorsString(color)); mImage = Loader::getImage(dye); if (!mImage) { mImage = Theme::getImageFromTheme(paths.getValue("unknownItemFile", - "unknown-item.png")); + "unknown-item.png")); } } @@ -121,8 +121,8 @@ Image *Item::getImage(const int id, const ItemColor color) { const ItemInfo &info = ItemDB::get(id); - Image *image = Loader::getImage(combineDye2(paths.getStringValue( - "itemIcons").append(info.getDisplay().image), + Image *image = Loader::getImage(combineDye2(pathJoin(paths.getStringValue( + "itemIcons"), info.getDisplay().image), info.getDyeIconColorsString(color))); if (!image) diff --git a/src/resources/map/map.cpp b/src/resources/map/map.cpp index 571b19abd..b7e5d1fca 100644 --- a/src/resources/map/map.cpp +++ b/src/resources/map/map.cpp @@ -1250,8 +1250,8 @@ void Map::saveExtraLayer() const restrict2 std::string Map::getUserMapDirectory() const restrict2 { - return settings.serverConfigDir + - dirSeparator + getProperty("_realfilename"); + return pathJoin(settings.serverConfigDir, + getProperty("_realfilename")); } void Map::addRange(const std::string &restrict name, diff --git a/src/resources/sprite/spritedef.cpp b/src/resources/sprite/spritedef.cpp index fc168b53f..59ac9d9f4 100644 --- a/src/resources/sprite/spritedef.cpp +++ b/src/resources/sprite/spritedef.cpp @@ -477,7 +477,7 @@ void SpriteDef::includeSprite(XmlNodeConstPtr includeNode, const int variant) if (filename.empty()) return; - filename = paths.getStringValue("sprites").append(filename); + filename = pathJoin(paths.getStringValue("sprites"), filename); if (mProcessedFiles.find(filename) != mProcessedFiles.end()) { diff --git a/src/test/testlauncher.cpp b/src/test/testlauncher.cpp index b05091ddd..ffb183cd0 100644 --- a/src/test/testlauncher.cpp +++ b/src/test/testlauncher.cpp @@ -33,6 +33,8 @@ #include "gui/fonts/font.h" +#include "utils/stringutils.h" + #include "render/graphics.h" #include "render/vertexes/imagecollection.h" @@ -65,7 +67,7 @@ TestLauncher::TestLauncher(std::string test) : mTest(test), file() { - file.open((settings.localDataDir + std::string("/test.log")).c_str(), + file.open(pathJoin(settings.localDataDir, "test.log").c_str(), std::ios::out); } diff --git a/src/test/testmain.cpp b/src/test/testmain.cpp index fad34dbb0..540ec5cf5 100644 --- a/src/test/testmain.cpp +++ b/src/test/testmain.cpp @@ -40,7 +40,7 @@ TestMain::TestMain() : mConfig() { fileName = getSelfName(); - log->setLogFile(settings.localDataDir + std::string("/manaplustest.log")); + log->setLogFile(pathJoin(settings.localDataDir, "manaplustest.log")); } TestMain::~TestMain() @@ -320,7 +320,7 @@ int TestMain::readValue(const int ver, int def) std::string tmp; int var; std::ifstream file; - file.open((settings.localDataDir + std::string("/test.log")).c_str(), + file.open(pathJoin(settings.localDataDir, "test.log").c_str(), std::ios::in); if (!getline(file, tmp)) { diff --git a/src/textcommand.cpp b/src/textcommand.cpp index 64b70d5df..5e2570f0f 100644 --- a/src/textcommand.cpp +++ b/src/textcommand.cpp @@ -129,7 +129,7 @@ void TextCommand::loadImage() return; const SpriteDisplay display = ItemDB::get(getIcon()).getDisplay(); - mImage = Loader::getImage(paths.getStringValue("itemIcons").append( + mImage = Loader::getImage(pathJoin(paths.getStringValue("itemIcons"), display.image)); if (!mImage) diff --git a/src/utils/fuzzer.cpp b/src/utils/fuzzer.cpp index 962b96972..d11d61de3 100644 --- a/src/utils/fuzzer.cpp +++ b/src/utils/fuzzer.cpp @@ -39,7 +39,7 @@ namespace void Fuzzer::init() { fuzz = new Logger; - fuzz->setLogFile(settings.localDataDir + "/fuzzer.log"); + fuzz->setLogFile(pathJoin(settings.localDataDir, "fuzzer.log")); unsigned int sr = time(nullptr); fuzz->log("Srand: %u", sr); |