Skip to content

Commit

Permalink
Fixed indentation and comments
Browse files Browse the repository at this point in the history
  • Loading branch information
sgourdas committed Sep 9, 2024
1 parent a69db03 commit 0ae1ab4
Showing 1 changed file with 28 additions and 30 deletions.
58 changes: 28 additions & 30 deletions src/kiwixapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,38 +142,36 @@ void KiwixApp::newTab()

QString KiwixApp::findLibraryDirectory()
{
// Check for library.xml in the same directory than the executable (portable kiwix-desktop)
auto currentDataDir = QString::fromStdString(kiwix::removeLastPathElement(kiwix::getExecutablePath()));
auto libraryFile = QFileInfo(currentDataDir, "library.xml");
if (libraryFile.exists())
return currentDataDir;

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

// There is no library.xml in default dataDirectory.
// Either, it is a first launch, or user used a pre-release version with wrong directory.
// Let's try to move data from old directory to new one if needed.
auto oldDataDir = QDir(currentDataDir);
oldDataDir.cdUp();
libraryFile = QFileInfo(oldDataDir, "library.xml");
if (libraryFile.exists()) {
// We have to move all zims file and xml file to the new dataDir
for (auto& fileInfo: oldDataDir.entryInfoList({"*.zim", "library*.xml"})) {
auto newFileInfo = QFileInfo(currentDataDir, fileInfo.fileName());
QFile::rename(fileInfo.absoluteFilePath(), newFileInfo.absoluteFilePath());
}
// Aria2 store informations about the current download using absolute path.
// Let's remove everything. User will loose its ongoing download but it should be pretty rare.
for (auto& fileInfo: oldDataDir.entryInfoList({"*.aria2", "*.meta4", "kiwix.session"})) {
QFile::remove(fileInfo.absoluteFilePath());
auto currentDataDir = QString::fromStdString(kiwix::removeLastPathElement(kiwix::getExecutablePath()));
// Check for library.xml in the same directory as the executable.
auto libraryFile = QFileInfo(currentDataDir, "library.xml");
if (libraryFile.exists())
return currentDataDir;

// 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.
auto oldDataDir = QDir(currentDataDir);
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());
QFile::rename(fileInfo.absoluteFilePath(), newFileInfo.absoluteFilePath());
}
// Aria2 stores information about the current download using absolute path.
// Let's remove everything. User will lose its ongoing download but it should be pretty rare.
for (auto& fileInfo: oldDataDir.entryInfoList({"*.aria2", "*.meta4", "kiwix.session"}))
QFile::remove(fileInfo.absoluteFilePath());
}
}

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

void KiwixApp::restoreTabs()
Expand Down

0 comments on commit 0ae1ab4

Please sign in to comment.