Stop library from prioritizing executable dir

This commit is contained in:
sgourdas 2024-09-13 12:02:55 +03:00 committed by Kelson
parent 93ebec0b39
commit 4bb69389aa

View File

@ -142,30 +142,22 @@ void KiwixApp::newTab()
QString KiwixApp::findLibraryDirectory() QString KiwixApp::findLibraryDirectory()
{ {
auto currentDataDir = QString::fromStdString(kiwix::removeLastPathElement(kiwix::getExecutablePath())); auto dataDir = getDataDirectory();
if (isPortableMode()) if (isPortableMode())
return currentDataDir + QDir::separator() + "data"; return dataDir;
// Check for library.xml in the same directory as the executable. auto libraryFile = QFileInfo(dataDir, "library.xml");
auto libraryFile = QFileInfo(currentDataDir, "library.xml");
if (libraryFile.exists()) if (libraryFile.exists())
return currentDataDir; return dataDir;
// Check for default dataDirectory.
currentDataDir = getDataDirectory();
libraryFile = QFileInfo(currentDataDir, "library.xml");
if (libraryFile.exists())
return currentDataDir;
// Check if this is a pre-release version with wrong directory. // Check if this is a pre-release version with wrong directory.
auto oldDataDir = QDir(currentDataDir); auto oldDataDir = QDir(dataDir);
oldDataDir.cdUp(); oldDataDir.cdUp();
libraryFile = QFileInfo(oldDataDir, "library.xml"); libraryFile = QFileInfo(oldDataDir, "library.xml");
if (libraryFile.exists()) { if (libraryFile.exists()) {
// We have to move all zim files and xml file to the new dataDir // We have to move all zim files and xml file to the new dataDir
for (auto& fileInfo: oldDataDir.entryInfoList({"*.zim", "library*.xml"})) { for (auto& fileInfo: oldDataDir.entryInfoList({"*.zim", "library*.xml"})) {
auto newFileInfo = QFileInfo(currentDataDir, fileInfo.fileName()); auto newFileInfo = QFileInfo(dataDir, fileInfo.fileName());
QFile::rename(fileInfo.absoluteFilePath(), newFileInfo.absoluteFilePath()); QFile::rename(fileInfo.absoluteFilePath(), newFileInfo.absoluteFilePath());
} }
// Aria2 stores information about the current download using absolute path. // Aria2 stores information about the current download using absolute path.
@ -175,7 +167,7 @@ QString KiwixApp::findLibraryDirectory()
} }
// This is a first launch // This is a first launch
return currentDataDir; return dataDir;
} }
void KiwixApp::restoreTabs() void KiwixApp::restoreTabs()