Override inbounds.

This commit is contained in:
Hork 2019-05-10 13:09:31 +08:00
parent 69b44c28cc
commit 0f24b32b7e
3 changed files with 22 additions and 2 deletions

View File

@ -11,8 +11,8 @@ QJsonObject switchJsonArrayObject(QJsonObject obj, QString value)
{ {
QJsonObject returnObj; QJsonObject returnObj;
returnObj = obj.value(value).isNull() returnObj = obj.value(value).isNull()
? obj.value(value).toObject() ? obj.value(value).toObject()
: obj.value(value).toArray().first().toObject(); : obj.value(value).toArray().first().toObject();
return returnObj; return returnObj;
} }
@ -63,3 +63,21 @@ void alterMessage(QString title, QString text)
{ {
QMessageBox::critical(nullptr, title, text, QMessageBox::Ok | QMessageBox::Default, 0); QMessageBox::critical(nullptr, title, text, QMessageBox::Ok | QMessageBox::Default, 0);
} }
void overrideInbounds(QString path)
{
QFile confFile(path);
confFile.open(QIODevice::ReadOnly);
QByteArray conf = confFile.readAll();
confFile.close();
QJsonDocument v2conf(QJsonDocument::fromJson(conf));
QJsonObject rootObj = v2conf.object();
QJsonArray modifiedIn = getInbounds();
rootObj.remove("inbounds");
rootObj.insert("inbounds", QJsonValue(modifiedIn));
v2conf.setObject(rootObj);
conf = v2conf.toJson(QJsonDocument::Indented);
confFile.open(QIODevice::WriteOnly | QIODevice::Truncate);
confFile.write(conf);
confFile.close();
}

View File

@ -8,5 +8,6 @@ QJsonObject loadRootObjFromConf();
QJsonArray getInbounds(); QJsonArray getInbounds();
bool testCoreFiles(); bool testCoreFiles();
void alterMessage(QString title, QString text); void alterMessage(QString title, QString text);
void overrideInbounds(QString path);
#endif // UTILS_H #endif // UTILS_H

View File

@ -45,6 +45,7 @@ void vmess::on_buttonBox_accepted()
if(QFile::exists(QCoreApplication::applicationDirPath() + "/config.json.tmp")) { if(QFile::exists(QCoreApplication::applicationDirPath() + "/config.json.tmp")) {
importConf *im = new importConf(this->parentWidget()); importConf *im = new importConf(this->parentWidget());
if (validationCheck(QCoreApplication::applicationDirPath() + "/config.json.tmp")) { if (validationCheck(QCoreApplication::applicationDirPath() + "/config.json.tmp")) {
overrideInbounds(QCoreApplication::applicationDirPath() + "/config.json.tmp");
im->savefromFile("config.json.tmp", alias); im->savefromFile("config.json.tmp", alias);
} }
QFile::remove("config.json.tmp"); QFile::remove("config.json.tmp");