mirror of
https://gitee.com/spark-store-project/spark-store
synced 2026-06-22 22:23:49 +08:00
新增了配置的保存,以及第一次打开程序时安装默认配置
This commit is contained in:
@@ -97,3 +97,13 @@ QVariant SpkConfig::ReadField(QString key, QVariant defaultValue)
|
||||
{
|
||||
return mSettings.value(key, defaultValue);
|
||||
}
|
||||
|
||||
void SpkConfig::SetSettings(QString key, QVariant value)
|
||||
{
|
||||
mSettings.setValue(key, value);
|
||||
}
|
||||
|
||||
void SpkConfig::Sync()
|
||||
{
|
||||
mSettings.sync();
|
||||
}
|
||||
|
||||
+3
-3
@@ -73,7 +73,7 @@ void SpkResource::ResourceDownloaded()
|
||||
.arg(reply->error()));
|
||||
// Tell ResourceContext
|
||||
if(!reply->property("outdated").toBool())
|
||||
AcquisitionFinish(id, ret);
|
||||
emit AcquisitionFinish(id, ret);
|
||||
}
|
||||
|
||||
ret.data = reply->readAll();
|
||||
@@ -102,7 +102,7 @@ void SpkResource::ResourceDownloaded()
|
||||
|
||||
// Tell ResourceContext
|
||||
if(!reply->property("outdated").toBool())
|
||||
AcquisitionFinish(id, ret);
|
||||
emit AcquisitionFinish(id, ret);
|
||||
|
||||
ContinueNext:
|
||||
// Start next possible mission
|
||||
@@ -215,7 +215,7 @@ void SpkResource::PurgeCachedResource(const QString &aPkgName, SpkResource::Reso
|
||||
{
|
||||
auto dir = QDir(mCacheDirectory + aPkgName + '/', ResourceName[aType] + '*');
|
||||
auto list = dir.entryList();
|
||||
sLog("Resource \"" + dir.absolutePath() + '/' + dir.nameFilters()[0] +
|
||||
sLog("Resource \"" + dir.absolutePath() + '/' + dir.nameFilters().constFirst() +
|
||||
"\" was requested to be removed.");
|
||||
|
||||
if(list.isEmpty())
|
||||
|
||||
+33
-23
@@ -13,7 +13,7 @@
|
||||
#include "spkutils.h"
|
||||
|
||||
SpkStore *SpkStore::Instance = nullptr;
|
||||
static void InstallDefaultConfigs();
|
||||
static bool InstallDefaultConfigs(QString configPath);
|
||||
|
||||
SpkStore::SpkStore(bool aCli, QString &aLogPath)
|
||||
{
|
||||
@@ -30,27 +30,12 @@ SpkStore::SpkStore(bool aCli, QString &aLogPath)
|
||||
mCfg = new SpkConfig(this, QDir::homePath() + "/.config/spark-store/config");
|
||||
else
|
||||
{
|
||||
mCfg = new SpkConfig(this, ":/info/default_config");
|
||||
#if 0
|
||||
bool cfgDirOk;
|
||||
if(!qgetenv("SPARK_NO_INSTALL_CONFIG").toInt())
|
||||
{
|
||||
QString path = mConfigPath.section('/', 1, -2, QString::SectionIncludeLeadingSep);
|
||||
if(!QDir().exists(path))
|
||||
{
|
||||
if(!QDir().mkpath(path))
|
||||
sErrPop(QObject::tr("Config directory \"%1\" cannot be created.").arg(path));
|
||||
else
|
||||
cfgDirOk = true;
|
||||
}
|
||||
else
|
||||
cfgDirOk = true;
|
||||
|
||||
if(cfgDirOk) // Only try copying if config dir is OK
|
||||
if(!QFile::copy(":/info/default_config", QDir::homePath() + "/.config/spark-store/config"))
|
||||
sErrPop(tr("Cannot install default config file!"));
|
||||
}
|
||||
#if 1
|
||||
if(InstallDefaultConfigs(mConfigPath))
|
||||
mCfg = new SpkConfig(this, QDir::homePath() + "/.config/spark-store/config");
|
||||
else
|
||||
#endif
|
||||
mCfg = new SpkConfig(this, ":/info/default_config");
|
||||
}
|
||||
|
||||
mNetMgr = new QNetworkAccessManager(this);
|
||||
@@ -123,7 +108,32 @@ QNetworkReply *SpkStore::SendCustomHeadRequest(QNetworkRequest req)
|
||||
return mNetMgr->head(req);
|
||||
}
|
||||
|
||||
static void InstallDefaultConfigs()
|
||||
static bool InstallDefaultConfigs(QString configPath)
|
||||
{
|
||||
//TODO:STUB
|
||||
bool cfgDirOk = false;
|
||||
if(!qEnvironmentVariableIntValue("SPARK_NO_INSTALL_CONFIG"))
|
||||
{
|
||||
cfgDirOk = SpkUtils::EnsureDirExists(SpkUtils::CutPath(configPath));
|
||||
|
||||
if(cfgDirOk) // Only try copying if config dir is OK
|
||||
{
|
||||
if(!QFile::copy(":/info/default_config", QDir::homePath() + "/.config/spark-store/config"))
|
||||
{
|
||||
sErrPop(QObject::tr("Cannot install default config file!"));
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Copying from resource to disk causes the file to be read only (444)
|
||||
// Set it to 644 manually
|
||||
QFile::setPermissions(QDir::homePath() + "/.config/spark-store/config",
|
||||
QFileDevice::WriteOwner | QFileDevice::ReadOwner |
|
||||
QFileDevice::ReadGroup | QFileDevice::ReadOther);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user