gamefile.h
1 //------------------------------------------------------------------------------
2 // gamefile.h
3 //------------------------------------------------------------------------------
4 //
5 // This library is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation; either
8 // version 2.1 of the License, or (at your option) any later version.
9 //
10 // This library 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 GNU
13 // Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with this library; 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) 2015 "Zalewa" <zalewapl@gmail.com>
22 //------------------------------------------------------------------------------
23 #ifndef idc66bde0f_a415_4f5a_8dcb_34697293515c
24 #define idc66bde0f_a415_4f5a_8dcb_34697293515c
25 
26 #include "dptr.h"
27 #include "global.h"
28 #include <QList>
29 #include <QString>
30 
72 class MAIN_EXPORT GameFile
73 {
74 public:
79  enum ExecType
80  {
81  Client = 0x1,
82  Server = 0x2,
83  Offline = 0x4,
84  Cso = Client | Server | Offline,
85  CreateGame = Server | Offline,
86  };
87 
88  GameFile();
89  GameFile(const GameFile &other);
90  virtual ~GameFile();
91  GameFile &operator=(const GameFile &other);
92 
96  bool isSameFile(const QString &otherFileName);
97 
101  bool isValid() const;
102 
106  int executable() const;
107  GameFile &setExecutable(int flags);
108 
112  const QString &configName() const;
113  GameFile &setConfigName(const QString &name);
114 
120  const QString &fileName() const;
121  GameFile &setFileName(const QString &name);
122 
127  const QString &niceName() const;
128  GameFile &setNiceName(const QString &name);
129 
135  QStringList &searchSuffixes() const;
136  GameFile &setSearchSuffixes(const QStringList &suffixes);
137 
138 private:
139  DPtr<GameFile> d;
140 };
141 
142 
147 class MAIN_EXPORT GameFileList
148 {
149  friend MAIN_EXPORT GameFileList &operator<<(GameFileList &list, const GameFile &gameFile);
150  friend MAIN_EXPORT GameFileList &operator<<(GameFileList &list, const GameFileList &other);
151 
152 public:
153  GameFileList();
154  virtual ~GameFileList();
155 
156  GameFileList &append(const GameFile &gameFile);
157  GameFileList &append(const GameFileList &list);
158  QList<GameFile> asQList() const;
159  void clear();
160  GameFile findByConfigName(const QString &configName);
161  GameFile first() const;
162  bool isEmpty() const;
163  GameFileList &prepend(const GameFile &gameFile);
164 
165 private:
167 };
168 
169 namespace GameFiles
170 {
171 GameFileList allCreateGameExecutables(const GameFileList &list);
172 GameFileList allClientExecutables(const GameFileList &list);
173 GameFileList allServerExecutables(const GameFileList &list);
174 
179 GameFileList allFlagMatchExecutables(const GameFileList &list, int execs);
180 
181 GameFile defaultClientExecutable(const GameFileList &list);
182 GameFile defaultOfflineExecutable(const GameFileList &list);
183 GameFile defaultServerExecutable(const GameFileList &list);
184 
185 GameFile preferredOfflineExecutable(const GameFileList &list);
186 }
187 
188 #endif