5#include "RabbitCommonDir.h"
6#include <QStandardPaths>
8#include <QCoreApplication>
9#include <QLoggingCategory>
13static Q_LOGGING_CATEGORY(dirLog,
"RabbitCommon.Dir")
18 m_szDocumentPath = QStandardPaths::writableLocation(
19 QStandardPaths::DocumentsLocation)
20 + QDir::separator() +
"Rabbit"
21 + QDir::separator() + QCoreApplication::applicationName();
22 qInfo(dirLog) <<
"Document path:" << m_szDocumentPath;
24 if(!d.exists(m_szDocumentPath))
25 if(!d.mkpath(m_szDocumentPath))
26 qCritical(dirLog) <<
"mkdir documents dir fail:" << m_szDocumentPath;
28 m_szApplicationDir = QCoreApplication::applicationDirPath();
29 qInfo(dirLog) <<
"Application dir:" << m_szApplicationDir;
30#if defined (Q_OS_ANDROID)
31 m_szApplicationRootDir =
"assets:";
33 if(m_szApplicationDir.isEmpty())
34 m_szApplicationRootDir =
"..";
36 m_szApplicationRootDir = m_szApplicationDir + QDir::separator() +
"..";
38 qInfo(dirLog) <<
"Application root dir:" << m_szApplicationRootDir;
43 static CDir* p =
nullptr;
49QString CDir::GetDirApplication()
52 return m_szApplicationDir;
55int CDir::SetDirApplication(
const QString &szPath)
57 m_szApplicationDir = szPath;
61QString CDir::GetDirApplicationInstallRoot()
63 return m_szApplicationRootDir;
66int CDir::SetDirApplicationInstallRoot(
const QString &szPath)
68 m_szApplicationRootDir = szPath;
72QString CDir::GetDirConfig(
bool bReadOnly)
76#if defined (Q_OS_ANDROID)
80 szPath = GetDirUserDocument() + QDir::separator() +
"root" + QDir::separator() +
"etc";
89 szPath = GetDirApplicationInstallRoot() + QDir::separator() +
"etc";
97QString CDir::GetDirLog()
100#if defined (Q_OS_ANDROID)
101 szPath = GetDirUserDocument() + QDir::separator() +
"root" + QDir::separator() +
"log";
103 if(!d.exists(szPath))
110 szPath = GetDirApplicationInstallRoot() + QDir::separator() +
"log";
112 if(!d.exists(szPath))
122#if defined (Q_OS_ANDROID)
124 return "assets:/share";
125 szPath = GetDirUserDocument() + QDir::separator() +
"root" + QDir::separator() +
"share";
127 if(!d.exists(szPath))
134 szPath = GetDirApplicationInstallRoot() + QDir::separator() +
"share";
136 if(!d.exists(szPath))
144 QString szPath =
GetDirData(bReadOnly) + QDir::separator() +
"doc";
145 if(!szProjectName.isEmpty())
146 szPath += QDir::separator() + szProjectName;
150QString CDir::GetDirDatabase(
bool bReadOnly)
152 QString szPath =
GetDirData(bReadOnly) + QDir::separator() +
"db";
154 if(!d.exists(szPath))
159QString CDir::GetDirDatabaseFile(
const QString &szFile,
bool bReadOnly)
162 return GetDirDatabase(bReadOnly) + QDir::separator() +
"database.db";
163 return GetDirDatabase(bReadOnly) + QDir::separator() + szFile;
166QString CDir::GetDirApplicationXml(
bool bReadOnly)
168 QString szPath = GetDirConfig(bReadOnly) + QDir::separator() +
"xml";
170 if(!d.exists(szPath))
175QString CDir::GetDirPlugins(
const QString &szDir)
178#if defined (Q_OS_ANDROID)
179 szPath = GetDirApplication();
181 szPath = GetDirApplicationInstallRoot() + QDir::separator() +
"plugins";
184 szPath += QDir::separator() + szDir;
188QString CDir::GetDirUserDocument()
190 return m_szDocumentPath;
193int CDir::SetDirUserDocument(QString szPath)
195 m_szDocumentPath = szPath;
197 if(!d.exists(szPath))
202QString CDir::GetDirUserConfig()
204 QString szPath = GetDirUserDocument() + QDir::separator() +
"etc";
207 if(!d.exists(szPath))
214QString CDir::GetDirUserData()
216 QString szPath = GetDirUserDocument() + QDir::separator() +
"share";
219 if(!d.exists(szPath))
226QString CDir::GetDirUserDatabase()
228 QString szPath = GetDirUserData() + QDir::separator() +
"db";
230 if(!d.exists(szPath))
235QString CDir::GetDirUserDatabaseFile(
const QString &szFile)
238 return GetDirUserDatabase() + QDir::separator() +
"database.db";
239 return GetDirUserDatabase() + QDir::separator() + szFile;
242QString CDir::GetDirUserXml()
244 QString szPath = GetDirUserData() + QDir::separator() +
"xml";
246 if(!d.exists(szPath))
251QString CDir::GetDirUserImage()
253 QString szPath = GetDirUserData() + QDir::separator() +
"image";
255 if(!d.exists(szPath))
262#if defined(_DEBUG) || defined(DEBUG)
263 return ":/share/translations";
265 QString szPath(szPrefix);
270 return szPath + QDir::separator() +
"translations";
273QString CDir::GetDirIcons(
bool bReadOnly)
275 return GetDirData(bReadOnly) + QDir::separator() +
"icons";
278QString CDir::GetDirPluginsTranslation(QString szDir)
280#if defined(_DEBUG) || defined(DEBUG)
281 return ":/" + szDir +
"/translations";
282#elif defined (Q_OS_ANDROID)
283 return "assets:/" + szDir +
"/translations";
286 return GetDirApplicationInstallRoot() + QDir::separator()
287 + szDir + QDir::separator() +
"translations";
290QString CDir::GetFileApplicationConfigure(
bool bReadOnly)
292 return GetDirConfig(bReadOnly) + QDir::separator()
293 + QCoreApplication::applicationName() +
".conf";
296QString CDir::GetFileUserConfigure()
298 QString szName = GetDirUserDocument() + QDir::separator()
299 + QCoreApplication::applicationName() +
".conf";
303int CDir::CopyDirectory(
const QString &fromDir,
const QString &toDir,
bool bCoverIfFileExists)
305 QDir formDir_(fromDir);
310 if(!toDir_.mkpath(toDir_.absolutePath()))
314 QFileInfoList fileInfoList = formDir_.entryInfoList();
315 foreach(QFileInfo fileInfo, fileInfoList)
317 if(fileInfo.fileName() ==
"."|| fileInfo.fileName() ==
"..")
322 if(!CopyDirectory(fileInfo.filePath(),
323 toDir_.filePath(fileInfo.fileName()),
329 if(bCoverIfFileExists && toDir_.exists(fileInfo.fileName()))
331 toDir_.remove(fileInfo.fileName());
333 if(!QFile::copy(fileInfo.filePath(), toDir_.filePath(fileInfo.fileName())))
QString GetDirData(bool bReadOnly=false)
Get data directory.
QString GetDirDocument(QString szProjectName=QString(), bool bReadOnly=false)
GetDirDocument.
QString GetDirTranslations(QString szPrefix=QString())