diff options
author | Andrei Karas <akaras@inbox.ru> | 2016-01-25 18:40:05 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2016-01-25 18:40:05 +0300 |
commit | 2157b8c6629cea79801566244fc3f1d8491e91be (patch) | |
tree | fb999e7d464c70511f13472da0fba86749b8d737 /src | |
parent | e89fb908638196c9484a2038e3f3eb18db6ef4ee (diff) | |
download | mv-2157b8c6629cea79801566244fc3f1d8491e91be.tar.gz mv-2157b8c6629cea79801566244fc3f1d8491e91be.tar.bz2 mv-2157b8c6629cea79801566244fc3f1d8491e91be.tar.xz mv-2157b8c6629cea79801566244fc3f1d8491e91be.zip |
Add file utils function getFilesInDir.
Diffstat (limited to 'src')
28 files changed, 62 insertions, 23 deletions
diff --git a/src/effectmanager.cpp b/src/effectmanager.cpp index 1a9901beb..e74c102bb 100644 --- a/src/effectmanager.cpp +++ b/src/effectmanager.cpp @@ -32,6 +32,8 @@ #include "resources/beingcommon.h" +#include "utils/files.h" + #include "debug.h" EffectManager *effectManager = nullptr; diff --git a/src/gui/windows/questswindow.cpp b/src/gui/windows/questswindow.cpp index 3bea8577f..284aabc22 100644 --- a/src/gui/windows/questswindow.cpp +++ b/src/gui/windows/questswindow.cpp @@ -46,6 +46,7 @@ #include "utils/delete2.h" #include "utils/dtor.h" +#include "utils/files.h" #include "utils/gettext.h" #include "utils/translation/podict.h" diff --git a/src/gui/windows/skilldialog.cpp b/src/gui/windows/skilldialog.cpp index b80f6d5fe..9fc386499 100644 --- a/src/gui/windows/skilldialog.cpp +++ b/src/gui/windows/skilldialog.cpp @@ -52,6 +52,7 @@ #include "net/skillhandler.h" #include "utils/dtor.h" +#include "utils/files.h" #include "utils/gettext.h" #include "utils/timer.h" diff --git a/src/resources/beingcommon.cpp b/src/resources/beingcommon.cpp index 999b19980..67aeea4fb 100644 --- a/src/resources/beingcommon.cpp +++ b/src/resources/beingcommon.cpp @@ -82,22 +82,6 @@ void BeingCommon::readBasicAttributes(BeingInfo *const info, info->setBlockWalkMask(static_cast<unsigned char>(block ^ allFlags)); } -void BeingCommon::getIncludeFiles(const std::string &dir, - StringVect &list, - const std::string &ext) -{ - const std::string path = dir + "/"; - StringVect tempList; - Files::getFilesWithDir(path, tempList); - FOR_EACH (StringVectCIter, it, tempList) - { - const std::string &str = *it; - if (findLast(str, ext)) - list.push_back(str); - } - std::sort(list.begin(), list.end()); -} - bool BeingCommon::readObjectNodes(XmlNodePtrConst &spriteNode, SpriteDisplay &display, BeingInfo *const currentInfo, diff --git a/src/resources/beingcommon.h b/src/resources/beingcommon.h index 273c95e11..04551092f 100644 --- a/src/resources/beingcommon.h +++ b/src/resources/beingcommon.h @@ -34,7 +34,7 @@ struct SpriteDisplay; #define loadXmlDir(name, function) \ { \ StringVect listVect; \ - BeingCommon::getIncludeFiles(paths.getStringValue( \ + Files::getFilesInDir(paths.getStringValue( \ name), listVect, ".xml"); \ FOR_EACH (StringVectCIter, itVect, listVect) \ function(*itVect); \ @@ -43,7 +43,7 @@ struct SpriteDisplay; #define loadXmlDir2(name, function, ext) \ { \ StringVect listVect; \ - BeingCommon::getIncludeFiles(name, listVect, ext); \ + Files::getFilesInDir(name, listVect, ext); \ FOR_EACH (StringVectCIter, itVect, listVect) \ function(*itVect); \ } diff --git a/src/resources/db/avatardb.cpp b/src/resources/db/avatardb.cpp index 5b377b173..d11e8ab63 100644 --- a/src/resources/db/avatardb.cpp +++ b/src/resources/db/avatardb.cpp @@ -30,6 +30,7 @@ #include "resources/sprite/spritereference.h" #include "utils/dtor.h" +#include "utils/files.h" #include "utils/gettext.h" #include "configuration.h" diff --git a/src/resources/db/badgesdb.cpp b/src/resources/db/badgesdb.cpp index ccaa1dc3d..de8f48499 100644 --- a/src/resources/db/badgesdb.cpp +++ b/src/resources/db/badgesdb.cpp @@ -24,6 +24,7 @@ #include "resources/beingcommon.h" +#include "utils/files.h" #include "utils/xmlutils.h" #include "debug.h" @@ -57,7 +58,7 @@ static void loadDB(const std::string &name, BadgesInfos &arr) name, arr); StringVect listVect; - BeingCommon::getIncludeFiles(paths.getStringValue( + Files::getFilesInDir(paths.getStringValue( "badgesPatchDir"), listVect, ".xml"); FOR_EACH (StringVectCIter, itVect, listVect) loadXmlFile(*itVect, name, arr); diff --git a/src/resources/db/colordb.cpp b/src/resources/db/colordb.cpp index 6b4ae2cd1..674f70ef6 100644 --- a/src/resources/db/colordb.cpp +++ b/src/resources/db/colordb.cpp @@ -26,6 +26,8 @@ #include "resources/beingcommon.h" +#include "utils/files.h" + #include "debug.h" namespace @@ -48,7 +50,7 @@ void ColorDB::load() loadHair(paths.getStringValue("hairColorFile"), colors); loadHair(paths.getStringValue("hairColorPatchFile"), colors); StringVect list; - BeingCommon::getIncludeFiles(paths.getStringValue( + Files::getFilesInDir(paths.getStringValue( "hairColorPatchDir"), list, ".xml"); FOR_EACH (StringVectCIter, it2, list) loadHair(*it2, colors); diff --git a/src/resources/db/commandsdb.cpp b/src/resources/db/commandsdb.cpp index 335627c53..daf347473 100644 --- a/src/resources/db/commandsdb.cpp +++ b/src/resources/db/commandsdb.cpp @@ -28,6 +28,8 @@ #include "resources/beingcommon.h" +#include "utils/files.h" + #include "debug.h" namespace diff --git a/src/resources/db/deaddb.cpp b/src/resources/db/deaddb.cpp index a2a6a6494..ce77aa6b4 100644 --- a/src/resources/db/deaddb.cpp +++ b/src/resources/db/deaddb.cpp @@ -23,6 +23,7 @@ #include "configuration.h" #include "logger.h" +#include "utils/files.h" #include "utils/translation/podict.h" #include "resources/beingcommon.h" diff --git a/src/resources/db/emotedb.cpp b/src/resources/db/emotedb.cpp index b2f9a0581..32679a9dc 100644 --- a/src/resources/db/emotedb.cpp +++ b/src/resources/db/emotedb.cpp @@ -32,6 +32,8 @@ #include "resources/sprite/animatedsprite.h" +#include "utils/files.h" + #include "debug.h" namespace diff --git a/src/resources/db/homunculusdb.cpp b/src/resources/db/homunculusdb.cpp index e8d2f723e..6f8164742 100644 --- a/src/resources/db/homunculusdb.cpp +++ b/src/resources/db/homunculusdb.cpp @@ -28,6 +28,7 @@ #include "resources/beinginfo.h" #include "utils/dtor.h" +#include "utils/files.h" #include "configuration.h" diff --git a/src/resources/db/horsedb.cpp b/src/resources/db/horsedb.cpp index 27987c657..99139fb21 100644 --- a/src/resources/db/horsedb.cpp +++ b/src/resources/db/horsedb.cpp @@ -28,6 +28,7 @@ #include "resources/horseinfo.h" #include "utils/dtor.h" +#include "utils/files.h" #include "debug.h" diff --git a/src/resources/db/itemdb.cpp b/src/resources/db/itemdb.cpp index 6a3766cc6..620367bd1 100644 --- a/src/resources/db/itemdb.cpp +++ b/src/resources/db/itemdb.cpp @@ -41,6 +41,7 @@ #include "utils/delete2.h" #include "utils/dtor.h" +#include "utils/files.h" #include "utils/stringmap.h" #include "debug.h" @@ -250,7 +251,7 @@ void ItemDB::load() loadXmlFile(paths.getStringValue("itemsPatchFile"), tagNum); StringVect list; - BeingCommon::getIncludeFiles(paths.getStringValue("itemsPatchDir"), + Files::getFilesInDir(paths.getStringValue("itemsPatchDir"), list, ".xml"); FOR_EACH (StringVectCIter, it, list) diff --git a/src/resources/db/mapdb.cpp b/src/resources/db/mapdb.cpp index 6d31c69f2..521d7ac84 100644 --- a/src/resources/db/mapdb.cpp +++ b/src/resources/db/mapdb.cpp @@ -26,6 +26,8 @@ #include "resources/beingcommon.h" +#include "utils/files.h" + #include "debug.h" namespace diff --git a/src/resources/db/mercenarydb.cpp b/src/resources/db/mercenarydb.cpp index 26476892d..bc5374f51 100644 --- a/src/resources/db/mercenarydb.cpp +++ b/src/resources/db/mercenarydb.cpp @@ -28,6 +28,7 @@ #include "resources/beinginfo.h" #include "utils/dtor.h" +#include "utils/files.h" #include "configuration.h" diff --git a/src/resources/db/moddb.cpp b/src/resources/db/moddb.cpp index 3a803a9af..051fe09e5 100644 --- a/src/resources/db/moddb.cpp +++ b/src/resources/db/moddb.cpp @@ -28,6 +28,7 @@ #include "resources/beingcommon.h" #include "utils/dtor.h" +#include "utils/files.h" #include "utils/gettext.h" #include "debug.h" diff --git a/src/resources/db/monsterdb.cpp b/src/resources/db/monsterdb.cpp index 133b2545d..1c18ada0b 100644 --- a/src/resources/db/monsterdb.cpp +++ b/src/resources/db/monsterdb.cpp @@ -28,6 +28,7 @@ #include "resources/beinginfo.h" #include "utils/dtor.h" +#include "utils/files.h" #include "utils/gettext.h" #include "configuration.h" diff --git a/src/resources/db/npcdb.cpp b/src/resources/db/npcdb.cpp index 1827cd859..dff7b4c70 100644 --- a/src/resources/db/npcdb.cpp +++ b/src/resources/db/npcdb.cpp @@ -31,6 +31,7 @@ #include "resources/sprite/spritereference.h" #include "utils/dtor.h" +#include "utils/files.h" #include "utils/gettext.h" #include "debug.h" diff --git a/src/resources/db/npcdialogdb.cpp b/src/resources/db/npcdialogdb.cpp index 772a64a45..610925864 100644 --- a/src/resources/db/npcdialogdb.cpp +++ b/src/resources/db/npcdialogdb.cpp @@ -27,6 +27,7 @@ #include "resources/npcdialoginfo.h" #include "utils/dtor.h" +#include "utils/files.h" #include "debug.h" diff --git a/src/resources/db/petdb.cpp b/src/resources/db/petdb.cpp index 160306d71..17ffba502 100644 --- a/src/resources/db/petdb.cpp +++ b/src/resources/db/petdb.cpp @@ -30,8 +30,9 @@ #include "resources/sprite/spritereference.h" -#include "utils/gettext.h" #include "utils/dtor.h" +#include "utils/files.h" +#include "utils/gettext.h" #include "debug.h" diff --git a/src/resources/db/skillunitdb.cpp b/src/resources/db/skillunitdb.cpp index 30d0b3918..6ffcfbe18 100644 --- a/src/resources/db/skillunitdb.cpp +++ b/src/resources/db/skillunitdb.cpp @@ -30,8 +30,9 @@ #include "resources/sprite/spritereference.h" -#include "utils/gettext.h" #include "utils/dtor.h" +#include "utils/files.h" +#include "utils/gettext.h" #include "debug.h" diff --git a/src/resources/db/sounddb.cpp b/src/resources/db/sounddb.cpp index 238e17b51..955a20d1f 100644 --- a/src/resources/db/sounddb.cpp +++ b/src/resources/db/sounddb.cpp @@ -27,6 +27,8 @@ #include "resources/beingcommon.h" +#include "utils/files.h" + #include "debug.h" namespace diff --git a/src/resources/mapreader.cpp b/src/resources/mapreader.cpp index 9da094d54..f55551982 100644 --- a/src/resources/mapreader.cpp +++ b/src/resources/mapreader.cpp @@ -50,6 +50,7 @@ #include "utils/base64.h" #include "utils/delete2.h" +#include "utils/files.h" #include "utils/stringmap.h" #include <zlib.h> diff --git a/src/statuseffect.cpp b/src/statuseffect.cpp index f4b1ce4e9..f628cd7ae 100644 --- a/src/statuseffect.cpp +++ b/src/statuseffect.cpp @@ -37,6 +37,8 @@ #include "resources/sprite/animatedsprite.h" +#include "utils/files.h" + #include "debug.h" static void unloadMap(std::map<int, StatusEffect *> &map); diff --git a/src/units.cpp b/src/units.cpp index 6d7e2a49c..28e21e7e5 100644 --- a/src/units.cpp +++ b/src/units.cpp @@ -27,6 +27,8 @@ #include "resources/beingcommon.h" +#include "utils/files.h" + #include <climits> #include "debug.h" diff --git a/src/utils/files.cpp b/src/utils/files.cpp index e694a2b9e..0a3f3eb92 100644 --- a/src/utils/files.cpp +++ b/src/utils/files.cpp @@ -31,7 +31,9 @@ #include "utils/mkdir.h" #include "utils/paths.h" #include "utils/physfstools.h" +#include "utils/stringutils.h" +#include <algorithm> #include <dirent.h> #include <fstream> #include <sstream> @@ -363,3 +365,19 @@ void Files::deleteFilesInDirectory(std::string path) if (dir) closedir(dir); } + +void Files::getFilesInDir(const std::string &dir, + StringVect &list, + const std::string &ext) +{ + const std::string path = dir + "/"; + StringVect tempList; + Files::getFilesWithDir(path, tempList); + FOR_EACH (StringVectCIter, it, tempList) + { + const std::string &str = *it; + if (findLast(str, ext)) + list.push_back(str); + } + std::sort(list.begin(), list.end()); +} diff --git a/src/utils/files.h b/src/utils/files.h index 80ecb9a43..8123a5949 100644 --- a/src/utils/files.h +++ b/src/utils/files.h @@ -77,6 +77,11 @@ namespace Files const std::string &restrict text); void deleteFilesInDirectory(std::string path); + + void getFilesInDir(const std::string &dir, + StringVect &list, + const std::string &ext); + } // namespace Files #endif // UTILS_FILES_H |