WoW Model Viewer
Your premiere tool for viewing, equipping and animating World of Warcraft models.
Loading...
Searching...
No Matches
GameFolder.cpp
Go to the documentation of this file.
1#include "GameFolder.h"
2#include <regex>
3#include "string_utils.h"
4#include "Logger.h"
5
6core::GameFolder::GameFolder(std::string path) : m_path(std::move(path))
7{
8}
9
10std::string core::GameFolder::getFullPathForFile(const std::string& file)
11{
12 const std::string lower = core::toLower(file);
13 for (const auto it : *this)
14 {
15 if (it->name() == lower)
16 return it->fullname();
17 }
18
19 return "";
20}
21
22void core::GameFolder::getFilesForFolder(std::vector<GameFile*>& fileNames, const std::string& folderPath, const std::string& extension)
23{
24 for (auto file : *this)
25 {
26 const auto& fn = file->fullname();
27 if (core::startsWithIgnoreCase(fn, folderPath) &&
28 (extension.empty() || core::endsWithIgnoreCase(fn, extension)))
29 {
30 fileNames.push_back(file);
31 }
32 }
33}
34
35void core::GameFolder::getFilteredFiles(std::set<GameFile*>& dest, const std::string& filter)
36{
37 std::regex regex;
38 try
39 {
40 regex = std::regex(filter, std::regex_constants::icase);
41 }
42 catch (const std::regex_error& e)
43 {
44 LOG_ERROR << e.what();
45 return;
46 }
47 int count = 0;
48 const int total = static_cast<int>(nbChildren());
49 for (auto it : *this)
50 {
51 if (std::regex_search(it->name(), regex))
52 {
53 dest.insert(it);
54 }
55 if (m_progressCallback && ++count % 500 == 0)
56 m_progressCallback(count, total);
57 }
58}
59
60GameFile* core::GameFolder::getFile(const std::string& filename)
61{
62 std::string lower = core::toLower(filename);
63 std::replace(lower.begin(), lower.end(), '\\', '/');
64
65 GameFile* result = nullptr;
66
67 const auto it = m_nameMap.find(lower);
68 if (it != m_nameMap.end())
69 result = it->second;
70
71 return result;
72}
73
75{
76 m_nameMap[child->fullname()] = child;
77}
78
80{
81 m_nameMap.erase(child->fullname());
82}
#define LOG_ERROR
Definition Logger.h:11
Abstract base class representing a file within the game data archive.
Definition GameFile.h:12
const std::string & fullname() const
Definition GameFile.h:56
void getFilteredFiles(std::set< GameFile * > &dest, const std::string &filter)
GameFile * getFile(const std::string &filename)
virtual void onChildRemoved(GameFile *) override
virtual void onChildAdded(GameFile *) override
void getFilesForFolder(std::vector< GameFile * > &fileNames, const std::string &folderPath, const std::string &extension="")
std::string getFullPathForFile(const std::string &file)
GameFolder(std::string path)
Definition GameFolder.cpp:6
bool startsWithIgnoreCase(const std::string &s, const std::string &prefix)
bool endsWithIgnoreCase(const std::string &s, const std::string &suffix)
std::string toLower(const std::string &s)