60 QDir wDir(QCoreApplication::applicationDirPath());
63 qWarning() <<
"Unable to use prefix one level up from " << wDir.path();
66 cachedPrefix.emplace(wDir);
70 cachedApplicationSwordDir.emplace(wDir);
71 if (!cachedApplicationSwordDir->cd(QStringLiteral(
"share/sword"))) {
72 qWarning() <<
"Cannot find sword directory relative to"
73 << QCoreApplication::applicationDirPath();
77 cachedSharedSwordDir.emplace(qEnvironmentVariable(
"ProgramData"));
78 if (!cachedSharedSwordDir->cd(SWORD_DIR)) {
79 if (!cachedSharedSwordDir->mkdir(SWORD_DIR)
80 || !cachedSharedSwordDir->cd(SWORD_DIR))
82 qWarning() <<
"Cannot find " << cachedSharedSwordDir->absolutePath() <<
" \\Sword";
89 ::qunsetenv(
"SWORD_PATH");
91 cachedPicsDir.emplace(wDir);
92 if (!cachedPicsDir->cd(QStringLiteral(
"share/bibletime/pics"))) {
93 qWarning() <<
"Cannot find pics directory relative to"
94 << wDir.absolutePath();
98 cachedLocaleDir.emplace(wDir);
99 if (!cachedLocaleDir->cd(QStringLiteral(
"share/bibletime/locale"))) {
100 qWarning() <<
"Cannot find locale directory relative to"
101 << wDir.absolutePath();
105 cachedDisplayTemplatesDir.emplace(wDir);
106 if (!cachedDisplayTemplatesDir->cd(
107 QStringLiteral(
"share/bibletime/display-templates/")))
109 qWarning() <<
"Cannot find display template directory relative to"
110 << wDir.absolutePath();
115 cachedUserHomeDir.emplace();
116#elif defined (Q_OS_WIN) && !defined(Q_OS_WIN32)
117 cachedUserHomeDir.emplace(QCoreApplication::applicationDirPath());
118#elif defined Q_OS_WIN32
119 cachedUserHomeDir.emplace(qEnvironmentVariable(
"APPDATA"));
121 cachedUserHomeDir.emplace(qgetenv(
"HOME"));
124 cachedUserBaseDir.emplace(*cachedUserHomeDir);
125 if (!cachedUserBaseDir->cd(BIBLETIME)) {
126 if (!cachedUserBaseDir->mkpath(BIBLETIME)
127 || !cachedUserBaseDir->cd(BIBLETIME))
129 qWarning() <<
"Could not create user settings directory relative to"
130 << cachedUserHomeDir->absolutePath();
135 cachedUserHomeSwordDir.emplace(*cachedUserHomeDir);
136#if !defined(Q_OS_WIN) || defined(Q_OS_WIN32)
137 if (!cachedUserHomeSwordDir->cd(SWORD_DIR)) {
138 if (!cachedUserHomeSwordDir->mkpath(SWORD_DIR)
139 || !cachedUserHomeSwordDir->cd(SWORD_DIR))
141 qWarning() <<
"Could not create user home " << SWORD_DIR
149 auto userHomeSwordModsDir = *cachedUserHomeSwordDir;
150 static auto const modsDir = QStringLiteral(
"mods.d");
151 if (!userHomeSwordModsDir.cd(modsDir)) {
152 if (!userHomeSwordModsDir.mkdir(modsDir)
153 || !userHomeSwordModsDir.cd(modsDir))
155 qWarning() <<
"Could not create user home " << SWORD_DIR
156 <<
" mods.d directory.";
162 cachedUserCacheDir.emplace(*cachedUserBaseDir);
164 static auto const cacheDir = QStringLiteral(
"cache");
165 if (!cachedUserCacheDir->cd(cacheDir)) {
166 if (!cachedUserCacheDir->mkdir(cacheDir)
167 || !cachedUserCacheDir->cd(cacheDir))
169 qWarning() <<
"Could not create user cache directory.";
175 cachedUserIndexDir.emplace(*cachedUserBaseDir);
177 static auto const indicesDir = QStringLiteral(
"indices");
178 if (!cachedUserIndexDir->cd(indicesDir)) {
179 if (!cachedUserIndexDir->mkdir(indicesDir)
180 || !cachedUserIndexDir->cd(indicesDir))
182 qWarning() <<
"Could not create user indices directory.";
188 cachedUserDisplayTemplatesDir.emplace(*cachedUserBaseDir);
190 static auto const displayTemplatesDir =
191 QStringLiteral(
"display-templates");
192 if (!cachedUserDisplayTemplatesDir->cd(displayTemplatesDir)) {
193 if (!cachedUserDisplayTemplatesDir->mkdir(displayTemplatesDir)
194 || !cachedUserDisplayTemplatesDir->cd(displayTemplatesDir))
196 qWarning() <<
"Could not create user display templates "
268 static QDir
const cachedDocDir(
cachedPrefix->filePath(BT_RUNTIME_DOCDIR));
270 if (
auto dir = cachedDocDir; dir.cd(docName)) {
271 QStringList tryLanguages;
272 tryLanguages.append(QLocale().name());
274 auto const & localeName = tryLanguages.back();
275 if (localeName.contains(
'_'))
276 tryLanguages.append(localeName.section(
'_', 0, 0));
278 tryLanguages.append(QStringLiteral(
"en"));
280 [&dir,&tryLanguages](QString
const & type,
281 QString
const & filename) -> QString
284 for (
auto const & tryLanguage : tryLanguages) {
285 if (dir.cd(tryLanguage)) {
286 if (dir.exists(filename))
287 return dir.absoluteFilePath(filename);
295 r = tryDoc(QStringLiteral(
"html"), QStringLiteral(
"index.html"));
297 r = tryDoc(QStringLiteral(
"pdf"), docName + QStringLiteral(
".pdf"));