mirror of
https://github.com/kiwix/kiwix-desktop.git
synced 2025-09-23 03:58:56 -04:00
Use data directory in portable mode
This commit is contained in:
parent
380c3ae672
commit
78a50cfe76
@ -143,6 +143,10 @@ void KiwixApp::newTab()
|
|||||||
QString KiwixApp::findLibraryDirectory()
|
QString KiwixApp::findLibraryDirectory()
|
||||||
{
|
{
|
||||||
auto currentDataDir = QString::fromStdString(kiwix::removeLastPathElement(kiwix::getExecutablePath()));
|
auto currentDataDir = QString::fromStdString(kiwix::removeLastPathElement(kiwix::getExecutablePath()));
|
||||||
|
|
||||||
|
if (isPortableMode())
|
||||||
|
return currentDataDir + QDir::separator() + "data";
|
||||||
|
|
||||||
// Check for library.xml in the same directory as the executable.
|
// 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())
|
||||||
|
@ -9,6 +9,11 @@
|
|||||||
|
|
||||||
QString getDataDirectory()
|
QString getDataDirectory()
|
||||||
{
|
{
|
||||||
|
if (isPortableMode()) {
|
||||||
|
auto currentDataDir = QString::fromStdString(kiwix::removeLastPathElement(kiwix::getExecutablePath()));
|
||||||
|
return currentDataDir + QDir::separator() + "data";
|
||||||
|
}
|
||||||
|
|
||||||
QString dataDir = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
|
QString dataDir = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
|
||||||
|
|
||||||
if (!dataDir.isEmpty() && QDir().mkpath(dataDir))
|
if (!dataDir.isEmpty() && QDir().mkpath(dataDir))
|
||||||
@ -17,9 +22,30 @@ QString getDataDirectory()
|
|||||||
return QString::fromStdString(kiwix::getCurrentDirectory());
|
return QString::fromStdString(kiwix::getCurrentDirectory());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool isPortableMode()
|
||||||
|
{
|
||||||
|
auto currentDataDir = QString::fromStdString(kiwix::removeLastPathElement(kiwix::getExecutablePath()));
|
||||||
|
auto portableFile = QFileInfo(currentDataDir, ".portable");
|
||||||
|
|
||||||
|
return portableFile.exists();
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
QString getSettingsConfPath()
|
||||||
|
{
|
||||||
|
QString confDirectory = isPortableMode() ?
|
||||||
|
getDataDirectory() :
|
||||||
|
QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation);
|
||||||
|
|
||||||
|
return confDirectory + QDir::separator() + "Kiwix-desktop.conf";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
SettingsManager::SettingsManager(QObject *parent)
|
SettingsManager::SettingsManager(QObject *parent)
|
||||||
: QObject(parent),
|
: QObject(parent),
|
||||||
m_settings("Kiwix", "Kiwix-desktop"),
|
m_settings(getSettingsConfPath(), QSettings::NativeFormat),
|
||||||
m_view(nullptr)
|
m_view(nullptr)
|
||||||
{
|
{
|
||||||
initSettings();
|
initSettings();
|
||||||
@ -162,7 +188,8 @@ void SettingsManager::initSettings()
|
|||||||
{
|
{
|
||||||
m_kiwixServerPort = m_settings.value("localKiwixServer/port", 8080).toInt();
|
m_kiwixServerPort = m_settings.value("localKiwixServer/port", 8080).toInt();
|
||||||
m_zoomFactor = m_settings.value("view/zoomFactor", 1).toDouble();
|
m_zoomFactor = m_settings.value("view/zoomFactor", 1).toDouble();
|
||||||
m_downloadDir = m_settings.value("download/dir", getDataDirectory()).toString();
|
QString dataDir = getDataDirectory();
|
||||||
|
m_downloadDir = isPortableMode() ? dataDir : m_settings.value("download/dir", dataDir).toString();
|
||||||
m_kiwixServerIpAddress = m_settings.value("localKiwixServer/ipAddress", QString("0.0.0.0")).toString();
|
m_kiwixServerIpAddress = m_settings.value("localKiwixServer/ipAddress", QString("0.0.0.0")).toString();
|
||||||
m_monitorDir = m_settings.value("monitor/dir", QString("")).toString();
|
m_monitorDir = m_settings.value("monitor/dir", QString("")).toString();
|
||||||
m_moveToTrash = m_settings.value("moveToTrash", true).toBool();
|
m_moveToTrash = m_settings.value("moveToTrash", true).toBool();
|
||||||
|
@ -78,4 +78,6 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
QString getDataDirectory();
|
QString getDataDirectory();
|
||||||
|
bool isPortableMode();
|
||||||
|
|
||||||
#endif // SETTINGSMANAGER_H
|
#endif // SETTINGSMANAGER_H
|
||||||
|
Loading…
x
Reference in New Issue
Block a user