Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop library from prioritizing executable directory #1208

Merged
merged 1 commit into from
Sep 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 7 additions & 15 deletions src/kiwixapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,30 +142,22 @@ void KiwixApp::newTab()

QString KiwixApp::findLibraryDirectory()
{
auto currentDataDir = QString::fromStdString(kiwix::removeLastPathElement(kiwix::getExecutablePath()));

auto dataDir = getDataDirectory();
if (isPortableMode())
return currentDataDir + QDir::separator() + "data";
return dataDir;

// Check for library.xml in the same directory as the executable.
auto libraryFile = QFileInfo(currentDataDir, "library.xml");
auto libraryFile = QFileInfo(dataDir, "library.xml");
if (libraryFile.exists())
return currentDataDir;

// Check for default dataDirectory.
currentDataDir = getDataDirectory();
libraryFile = QFileInfo(currentDataDir, "library.xml");
if (libraryFile.exists())
return currentDataDir;
return dataDir;

// Check if this is a pre-release version with wrong directory.
auto oldDataDir = QDir(currentDataDir);
auto oldDataDir = QDir(dataDir);
oldDataDir.cdUp();
libraryFile = QFileInfo(oldDataDir, "library.xml");
if (libraryFile.exists()) {
// We have to move all zim files and xml file to the new dataDir
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());
}
// Aria2 stores information about the current download using absolute path.
Expand All @@ -175,7 +167,7 @@ QString KiwixApp::findLibraryDirectory()
}

// This is a first launch
return currentDataDir;
return dataDir;
}

void KiwixApp::restoreTabs()
Expand Down
Loading