Fixed indentation and comments

This commit is contained in:
sgourdas 2024-08-23 23:14:33 +03:00 committed by Kelson
parent f383bea78c
commit 380c3ae672

View File

@ -142,38 +142,36 @@ void KiwixApp::newTab()
QString KiwixApp::findLibraryDirectory() 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 currentDataDir = QString::fromStdString(kiwix::removeLastPathElement(kiwix::getExecutablePath())); // Check for library.xml in the same directory as the executable.
auto libraryFile = QFileInfo(currentDataDir, "library.xml"); auto libraryFile = QFileInfo(currentDataDir, "library.xml");
if (libraryFile.exists()) if (libraryFile.exists())
return currentDataDir; return currentDataDir;
// Check for default dataDirectory. // Check for default dataDirectory.
currentDataDir = getDataDirectory(); currentDataDir = getDataDirectory();
libraryFile = QFileInfo(currentDataDir, "library.xml"); libraryFile = QFileInfo(currentDataDir, "library.xml");
if (libraryFile.exists()) if (libraryFile.exists())
return currentDataDir; return currentDataDir;
// There is no library.xml in default dataDirectory. // Check if this is a pre-release version with wrong directory.
// Either, it is a first launch, or user used a pre-release version with wrong directory. auto oldDataDir = QDir(currentDataDir);
// Let's try to move data from old directory to new one if needed. oldDataDir.cdUp();
auto oldDataDir = QDir(currentDataDir); libraryFile = QFileInfo(oldDataDir, "library.xml");
oldDataDir.cdUp(); if (libraryFile.exists()) {
libraryFile = QFileInfo(oldDataDir, "library.xml"); // We have to move all zim files and xml file to the new dataDir
if (libraryFile.exists()) { for (auto& fileInfo: oldDataDir.entryInfoList({"*.zim", "library*.xml"})) {
// We have to move all zims file and xml file to the new dataDir auto newFileInfo = QFileInfo(currentDataDir, fileInfo.fileName());
for (auto& fileInfo: oldDataDir.entryInfoList({"*.zim", "library*.xml"})) { QFile::rename(fileInfo.absoluteFilePath(), newFileInfo.absoluteFilePath());
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());
} }
// 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());
}
}
return currentDataDir; // This is a first launch
return currentDataDir;
} }
void KiwixApp::restoreTabs() void KiwixApp::restoreTabs()