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 #include "serverapi/server.h"
29 
30 DClass<WadFindResult>
31 {
32  public:
33  QString alias;
34  QString path;
35 };
36 
37 DPointered(WadFindResult)
38 
40 {
41 }
42 
43 WadFindResult::~WadFindResult()
44 {
45 }
46 
47 const QString &WadFindResult::alias() const
48 {
49  return d->alias;
50 }
51 
52 void WadFindResult::setAlias(const QString &val)
53 {
54  d->alias = val;
55 }
56 
57 bool WadFindResult::isAlias() const
58 {
59  return isValid() && !d->alias.isEmpty();
60 }
61 
62 bool WadFindResult::isValid() const
63 {
64  return !d->path.isEmpty();
65 }
66 
67 const QString &WadFindResult::path() const
68 {
69  return d->path;
70 }
71 
72 void WadFindResult::setPath(const QString &val)
73 {
74  d->path = val;
75 }
77 DClass<WadPathFinder>
78 {
79  public:
80  QList<FileAlias> aliases;
81  PathFinder pathFinder;
82 };
83 
84 DPointered(WadPathFinder)
85 
86 WadPathFinder::WadPathFinder(const PathFinder &pathFinder)
87 {
88  d->aliases = gConfig.doomseeker.wadAliases();
89  d->pathFinder = pathFinder;
90 }
91 
92 WadPathFinder::~WadPathFinder()
93 {
94 }
95 
96 QStringList WadPathFinder::aliases(const QString &name) const
97 {
98  foreach (const FileAlias &candidate, d->aliases)
99  {
100  if (candidate.name().compare(name, Qt::CaseInsensitive) == 0)
101  {
102  return candidate.aliases();
103  }
104  }
105  return QStringList();
106 }
107 
108 WadFindResult WadPathFinder::find(const QString &name)
109 {
110  {
111  QString path = d->pathFinder.findFile(name);
112  if (!path.isEmpty())
113  {
114  WadFindResult result;
115  result.setPath(path);
116  return result;
117  }
118  }
119  foreach (const QString &alias, aliases(name))
120  {
121  QString path = d->pathFinder.findFile(alias);
122  if (!path.isEmpty())
123  {
124  WadFindResult result;
125  result.setPath(path);
126  result.setAlias(alias);
127  return result;
128  }
129  }
130  return WadFindResult();
131 }
133 WadFindResult findWad(ServerPtr server, const QString &wadName)
134 {
135  PathFinder pathFinder = server->wadPathFinder();
136  WadPathFinder wadFinder(pathFinder);
137  return wadFinder.find(wadName);
138 }
Performs a case-insensitive (OS independent) file searches.
Definition: pathfinder.h:81
Wrapper for PathFinder that specializes in findings WADs.
Definition: wadpathfinder.h:55