62 QDir wDir(QCoreApplication::applicationDirPath());
65 qWarning() <<
"Unable to use prefix one level up from " << wDir.path();
68 cachedPrefix.emplace(wDir);
72 cachedApplicationSwordDir.emplace(wDir);
73 if (!cachedApplicationSwordDir->cd(QStringLiteral(
"share/sword"))) {
74 qWarning() <<
"Cannot find sword directory relative to"
75 << QCoreApplication::applicationDirPath();
79 cachedSharedSwordDir.emplace(qEnvironmentVariable(
"ProgramData"));
80 if (!cachedSharedSwordDir->cd(SWORD_DIR)) {
81 if (!cachedSharedSwordDir->mkdir(SWORD_DIR)
82 || !cachedSharedSwordDir->cd(SWORD_DIR))
84 qWarning() <<
"Cannot find " << cachedSharedSwordDir->absolutePath() <<
" \\Sword";
91 ::qunsetenv(
"SWORD_PATH");
93 cachedPicsDir.emplace(wDir);
94 if (!cachedPicsDir->cd(QStringLiteral(
"share/bibletime/pics"))) {
95 qWarning() <<
"Cannot find pics directory relative to"
96 << wDir.absolutePath();
100 cachedLocaleDir.emplace(wDir);
101 if (!cachedLocaleDir->cd(QStringLiteral(
"share/bibletime/locale"))) {
102 qWarning() <<
"Cannot find locale directory relative to"
103 << wDir.absolutePath();
107 cachedDisplayTemplatesDir.emplace(wDir);
108 if (!cachedDisplayTemplatesDir->cd(
109 QStringLiteral(
"share/bibletime/display-templates/")))
111 qWarning() <<
"Cannot find display template directory relative to"
112 << wDir.absolutePath();
117 cachedUserHomeDir.emplace();
118#elif defined (Q_OS_WIN) && !defined(Q_OS_WIN32)
119 cachedUserHomeDir.emplace(QCoreApplication::applicationDirPath());
120#elif defined Q_OS_WIN32
121 cachedUserHomeDir.emplace(qEnvironmentVariable(
"APPDATA"));
123 cachedUserHomeDir.emplace(qgetenv(
"HOME"));
126 cachedUserBaseDir.emplace(*cachedUserHomeDir);
127 if (!cachedUserBaseDir->cd(BIBLETIME)) {
128 if (!cachedUserBaseDir->mkpath(BIBLETIME)
129 || !cachedUserBaseDir->cd(BIBLETIME))
131 qWarning() <<
"Could not create user settings directory relative to"
132 << cachedUserHomeDir->absolutePath();
137 cachedUserHomeSwordDir.emplace(*cachedUserHomeDir);
138#if !defined(Q_OS_WIN) || defined(Q_OS_WIN32)
139 if (!cachedUserHomeSwordDir->cd(SWORD_DIR)) {
140 if (!cachedUserHomeSwordDir->mkpath(SWORD_DIR)
141 || !cachedUserHomeSwordDir->cd(SWORD_DIR))
143 qWarning() <<
"Could not create user home " << SWORD_DIR
151 auto userHomeSwordModsDir = *cachedUserHomeSwordDir;
152 static auto const modsDir = QStringLiteral(
"mods.d");
153 if (!userHomeSwordModsDir.cd(modsDir)) {
154 if (!userHomeSwordModsDir.mkdir(modsDir)
155 || !userHomeSwordModsDir.cd(modsDir))
157 qWarning() <<
"Could not create user home " << SWORD_DIR
158 <<
" mods.d directory.";
164 cachedUserCacheDir.emplace(*cachedUserBaseDir);
166 static auto const cacheDir = QStringLiteral(
"cache");
167 if (!cachedUserCacheDir->cd(cacheDir)) {
168 if (!cachedUserCacheDir->mkdir(cacheDir)
169 || !cachedUserCacheDir->cd(cacheDir))
171 qWarning() <<
"Could not create user cache directory.";
177 cachedUserIndexDir.emplace(*cachedUserBaseDir);
179 static auto const indicesDir = QStringLiteral(
"indices");
180 if (!cachedUserIndexDir->cd(indicesDir)) {
181 if (!cachedUserIndexDir->mkdir(indicesDir)
182 || !cachedUserIndexDir->cd(indicesDir))
184 qWarning() <<
"Could not create user indices directory.";
190 cachedUserDisplayTemplatesDir.emplace(*cachedUserBaseDir);
192 static auto const displayTemplatesDir =
193 QStringLiteral(
"display-templates");
194 if (!cachedUserDisplayTemplatesDir->cd(displayTemplatesDir)) {
195 if (!cachedUserDisplayTemplatesDir->mkdir(displayTemplatesDir)
196 || !cachedUserDisplayTemplatesDir->cd(displayTemplatesDir))
198 qWarning() <<
"Could not create user display templates "
257 static QDir
const cachedDocDir(
cachedPrefix->filePath(BT_RUNTIME_DOCDIR));
259 if (
auto dir = cachedDocDir; dir.cd(docName)) {
260 QStringList tryLanguages;
261 tryLanguages.append(QLocale().name());
263 auto const & localeName = tryLanguages.back();
264 if (localeName.contains(
'_'))
265 tryLanguages.append(localeName.section(
'_', 0, 0));
267 tryLanguages.append(QStringLiteral(
"en"));
269 [&dir,&tryLanguages](QString
const & type,
270 QString
const & filename) -> QString
273 for (
auto const & tryLanguage : tryLanguages) {
274 if (dir.cd(tryLanguage)) {
275 if (dir.exists(filename))
276 return dir.absoluteFilePath(filename);
284 r = tryDoc(QStringLiteral(
"html"), QStringLiteral(
"index.html"));
286 r = tryDoc(QStringLiteral(
"pdf"), docName + QStringLiteral(
".pdf"));