1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
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.
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/>.
18 #include "add_on_manager.h"
21 using namespace NLMISC
;
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())
49 // *** AddSearch Path, with Filter features
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
);
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
++)
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
]);
85 for(uint i
=0;i
<posFilters
.size();i
++)
87 if(testWildCard(filename
, posFilters
[i
]))
97 for(uint i
=0;i
<negFilters
.size();i
++)
99 if(testWildCard(filename
, negFilters
[i
]))
107 // If ok, add it to set and to path
110 _FileSet
.insert(filename
);
111 CPath::addSearchFile (filesToProcess
[f
], false, "", progressCallBack
);
115 if (progressCallBack
)
117 progressCallBack
->popCropedValues ();
122 if (progressCallBack
)
124 progressCallBack
->popCropedValues ();
129 // ***************************************************************************
130 void CAddOnManager::getFiles(const std::string
&filterList
, std::vector
<std::string
> &files
)
135 std::vector
<string
> wildcards
;
136 splitString(filterList
, ";", wildcards
);
137 if(wildcards
.empty())
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
);