Merge branch '138-toggle-free-look-with-hotkey' into main/gingo-test
[ryzomcore.git] / ryzom / client / src / interface_v3 / add_on_manager.cpp
blobc696ffd03f7fcbf0321cbfc1fc7a25c9cd6d30f4
1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 #include "stdpch.h"
18 #include "add_on_manager.h"
21 using namespace NLMISC;
22 using namespace std;
24 // ***************************************************************************
25 CAddOnManager InterfaceAddOnManager;
28 // ***************************************************************************
29 CAddOnManager::CAddOnManager()
34 // ***************************************************************************
35 void CAddOnManager::addSearchFiles(const std::string &path, const std::string &posFilterList, const std::string &negFilterList, NLMISC::IProgressCallback *progressCallBack)
38 NB: this is mainly a copy of CPath::addSearchPath(), with filter added.
41 // *** Build filter list
42 std::vector<std::string> posFilters, negFilters;
43 splitString(posFilterList, ";", posFilters);
44 splitString(negFilterList, ";", negFilters);
45 if(posFilters.empty())
46 return;
49 // *** AddSearch Path, with Filter features
50 // Progress bar
51 if (progressCallBack)
53 progressCallBack->progress (0);
54 progressCallBack->pushCropedValues (0, 0.5f);
57 // find all files in the path and subpaths
58 string newPath = CPath::standardizePath(path);
59 vector<string> filesToProcess;
60 CPath::getPathContent (newPath, true, false, true, filesToProcess, progressCallBack);
62 // Progress bar
63 if (progressCallBack)
65 progressCallBack->popCropedValues ();
66 progressCallBack->progress (0.5);
67 progressCallBack->pushCropedValues (0.5f, 1);
70 // add them in the map
71 for (uint f = 0; f < filesToProcess.size(); f++)
73 // Progress bar
74 if (progressCallBack)
76 progressCallBack->progress ((float)f/(float)filesToProcess.size());
77 progressCallBack->pushCropedValues ((float)f/(float)filesToProcess.size(), (float)(f+1)/(float)filesToProcess.size());
80 string filename = CFile::getFilename (filesToProcess[f]);
81 string filepath = CFile::getPath (filesToProcess[f]);
83 // positive Filter
84 bool ok= false;
85 for(uint i=0;i<posFilters.size();i++)
87 if(testWildCard(filename, posFilters[i]))
89 ok= true;
90 break;
94 // negative filter
95 if(ok)
97 for(uint i=0;i<negFilters.size();i++)
99 if(testWildCard(filename, negFilters[i]))
101 ok= false;
102 break;
107 // If ok, add it to set and to path
108 if(ok)
110 _FileSet.insert(filename);
111 CPath::addSearchFile (filesToProcess[f], false, "", progressCallBack);
114 // Progress bar
115 if (progressCallBack)
117 progressCallBack->popCropedValues ();
121 // Progress bar
122 if (progressCallBack)
124 progressCallBack->popCropedValues ();
129 // ***************************************************************************
130 void CAddOnManager::getFiles(const std::string &filterList, std::vector<std::string> &files)
132 files.clear();
134 // get wildcard list
135 std::vector<string> wildcards;
136 splitString(filterList, ";", wildcards);
137 if(wildcards.empty())
138 return;
140 // test all files
141 std::set<std::string>::const_iterator it= _FileSet.begin();
142 for(;it!=_FileSet.end();it++)
144 // if only one wildcard match, ok
145 for(uint i=0;i<wildcards.size();i++)
147 if(testWildCard(*it, wildcards[i]))
149 files.push_back(*it);
150 break;