wadpathfinder.cpp
1 //------------------------------------------------------------------------------
2 // wadpathfinder.cpp
3 //------------------------------------------------------------------------------
4 //
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 // 02110-1301, USA.
19 //
20 //------------------------------------------------------------------------------
21 // Copyright (C) 2014 "Zalewa" <zalewapl@gmail.com>
22 //------------------------------------------------------------------------------
23 #include "wadpathfinder.h"
24 
25 #include "configuration/doomseekerconfig.h"
26 #include "pathfinder/filealias.h"
27 #include "pathfinder/pathfinder.h"
28 
29 DClass<WadFindResult>
30 {
31  public:
32  QString alias;
33  QString path;
34 };
35 
36 DPointered(WadFindResult)
37 
39 {
40 }
41 
42 WadFindResult::~WadFindResult()
43 {
44 }
45 
46 const QString &WadFindResult::alias() const
47 {
48  return d->alias;
49 }
50 
51 void WadFindResult::setAlias(const QString &val)
52 {
53  d->alias = val;
54 }
55 
56 bool WadFindResult::isAlias() const
57 {
58  return isValid() && !d->alias.isEmpty();
59 }
60 
61 bool WadFindResult::isValid() const
62 {
63  return !d->path.isEmpty();
64 }
65 
66 const QString &WadFindResult::path() const
67 {
68  return d->path;
69 }
70 
71 void WadFindResult::setPath(const QString &val)
72 {
73  d->path = val;
74 }
76 DClass<WadPathFinder>
77 {
78  public:
79  QList<FileAlias> aliases;
80  PathFinder pathFinder;
81 };
82 
83 DPointered(WadPathFinder)
84 
85 WadPathFinder::WadPathFinder(const PathFinder &pathFinder)
86 {
87  d->aliases = gConfig.doomseeker.wadAliases();
88  d->pathFinder = pathFinder;
89 }
90 
91 WadPathFinder::~WadPathFinder()
92 {
93 }
94 
95 QStringList WadPathFinder::aliases(const QString &name) const
96 {
97  foreach (const FileAlias &candidate, d->aliases)
98  {
99  if (candidate.name().compare(name, Qt::CaseInsensitive) == 0)
100  {
101  return candidate.aliases();
102  }
103  }
104  return QStringList();
105 }
106 
107 WadFindResult WadPathFinder::find(const QString &name)
108 {
109  {
110  QString path = d->pathFinder.findFile(name);
111  if (!path.isEmpty())
112  {
113  WadFindResult result;
114  result.setPath(path);
115  return result;
116  }
117  }
118  foreach (const QString &alias, aliases(name))
119  {
120  QString path = d->pathFinder.findFile(alias);
121  if (!path.isEmpty())
122  {
123  WadFindResult result;
124  result.setPath(path);
125  result.setAlias(alias);
126  return result;
127  }
128  }
129  return WadFindResult();
130 }
Performs a case-insensitive (OS independent) file searches.
Definition: pathfinder.h:81
Wrapper for PathFinder that specializes in findings WADs.
Definition: wadpathfinder.h:54