doomseekerfilepaths.cpp
1 //------------------------------------------------------------------------------
2 // doomseekerfilepaths.cpp
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) 2010 "Zalewa" <zalewapl@gmail.com>
22 //------------------------------------------------------------------------------
23 #include "doomseekerfilepaths.h"
24 
25 #include "datapaths.h"
26 #include "strings.hpp"
27 #include <QFile>
28 
29 static const QString DATA_SEARCH_PREFIX = "data";
30 
31 DataPaths* DoomseekerFilePaths::pDataPaths = NULL;
32 
33 const QString DoomseekerFilePaths::CACERTS_FILENAME = "cacerts.pem";
34 const QString DoomseekerFilePaths::IP2C_DATABASE_FILENAME = "IpToCountry.dat";
35 const QString DoomseekerFilePaths::IP2C_QT_SEARCH_PATH = DATA_SEARCH_PREFIX + ":" + IP2C_DATABASE_FILENAME;
36 const QString DoomseekerFilePaths::TEMP_SERVER_CONFIG_FILENAME = "tmpserver.cfg";
37 const QString DoomseekerFilePaths::INI_FILENAME = "doomseeker.ini";
38 const QString DoomseekerFilePaths::IRC_INI_FILENAME = "doomseeker-irc.ini";
39 const QString DoomseekerFilePaths::PASSWORD_INI_FILENAME = "doomseeker-password.ini";
40 
41 QString DoomseekerFilePaths::cacerts()
42 {
43  QStringList paths = pDataPaths->staticDataSearchDirs(CACERTS_FILENAME);
44  foreach (const QString &path, paths)
45  {
46  if (QFile(path).exists())
47  return path;
48  }
49  return QString();
50 }
51 
52 QString DoomseekerFilePaths::ini()
53 {
54  return joinIfNeitherEmpty(pDataPaths->programsDataDirectoryPath(), INI_FILENAME);
55 }
56 
57 QString DoomseekerFilePaths::ircIni()
58 {
59  return joinIfNeitherEmpty(pDataPaths->programsDataDirectoryPath(), IRC_INI_FILENAME);
60 }
61 
63 {
64  foreach(const QString &searchPath, QDir::searchPaths(DATA_SEARCH_PREFIX))
65  {
66  QString path = Strings::combinePaths(searchPath, IP2C_DATABASE_FILENAME);
67  if (QFile(path).exists())
68  return path;
69  }
70  return QString();
71 }
72 
74 {
75  return joinIfNeitherEmpty(pDataPaths->localDataLocationPath(), IP2C_DATABASE_FILENAME);
76 }
77 
78 QString DoomseekerFilePaths::joinIfNeitherEmpty(const QString &left, const QString &right)
79 {
80  if (left.trimmed().isEmpty() || right.trimmed().isEmpty())
81  {
82  return QString();
83  }
84  return left + "/" + right;
85 }
86 
87 QString DoomseekerFilePaths::passwordIni()
88 {
89  return joinIfNeitherEmpty(pDataPaths->programsDataDirectoryPath(), PASSWORD_INI_FILENAME);
90 }
91 
92 QString DoomseekerFilePaths::tempServerConfig()
93 {
94  return joinIfNeitherEmpty(pDataPaths->programsDataDirectoryPath(), TEMP_SERVER_CONFIG_FILENAME);
95 }
96 
97 QString DoomseekerFilePaths::updatePackagesStorageDir()
98 {
99  return pDataPaths->localDataLocationPath(DataPaths::UPDATE_PACKAGES_DIR_NAME);
100 }
static QString combinePaths(QString pathFront, QString pathEnd)
Definition: strings.cpp:147
static QString ip2cDatabaseAny()
QString programsDataDirectoryPath() const
Path to directory where this concrete application should store its data.
Definition: datapaths.cpp:413
Represents directories used by Doomseeker to store data.
Definition: datapaths.h:82
static const QString IP2C_QT_SEARCH_PATH
static QString ip2cDatabase()
QString localDataLocationPath(const QString &subpath=QString()) const
Path to the directory where large data should be saved.
Definition: datapaths.cpp:334
static QStringList staticDataSearchDirs(const QString &subdir=QString())
Paths to directories where program should search for its static data.
Definition: datapaths.cpp:423