Fix some bugs.

This commit is contained in:
Hork 2019-04-17 08:49:12 +08:00
parent 4e91b727ee
commit 5e28486386
6 changed files with 40 additions and 22 deletions

View File

@ -3,7 +3,7 @@
#include <iostream> #include <iostream>
#include <QSqlDatabase> #include <QSqlDatabase>
#include <QSqlQuery> #include <QSqlQuery>
#include <mainwindow.h> #include "mainwindow.h"
#include <QDebug> #include <QDebug>
#include <QSqlError> #include <QSqlError>
#include <QFile> #include <QFile>

View File

@ -15,7 +15,7 @@ void init()
QDir().mkdir(confDir); QDir().mkdir(confDir);
qDebug() << "Conf directory created."; qDebug() << "Conf directory created.";
} }
QFileInfo confDb(confDatabase); QFileInfo confDb(QDir::currentPath() + confDatabase);
if (!confDb.exists()) { if (!confDb.exists()) {
QSqlDatabase database; QSqlDatabase database;
if (QSqlDatabase::contains("qt_sql_default_connection")) { if (QSqlDatabase::contains("qt_sql_default_connection")) {

View File

@ -2,7 +2,7 @@
#include "ui_mainwindow.h" #include "ui_mainwindow.h"
#include "confedit.h" #include "confedit.h"
#include "importconf.h" #include "importconf.h"
#include <vinteract.h> #include "vinteract.h"
#include <QHeaderView> #include <QHeaderView>
#include <QStandardItemModel> #include <QStandardItemModel>
#include <QDebug> #include <QDebug>

View File

@ -4,11 +4,16 @@
#include <QMessageBox> #include <QMessageBox>
#include <QProcess> #include <QProcess>
#include "mainwindow.h" #include "mainwindow.h"
#include <QDir>
bool validationCheck(QString path) bool validationCheck(QString path)
{ {
if (QFileInfo("v2ray").exists() && QFileInfo("geoip.dat").exists() && QFileInfo("geosite.dat").exists() ) {
QString output = ""; QString output = "";
QProcess process; QProcess process;
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
env.insert("V2RAY_LOCATION_ASSET", QDir::currentPath());
process.setProcessEnvironment(env);
process.start("v2ray", QStringList() << "-test" << "-config" << path, QIODevice::ReadWrite | QIODevice::Text); process.start("v2ray", QStringList() << "-test" << "-config" << path, QIODevice::ReadWrite | QIODevice::Text);
if(!process.waitForFinished()) { if(!process.waitForFinished()) {
qDebug() << "executing program failed with exit code" << process.exitCode(); qDebug() << "executing program failed with exit code" << process.exitCode();
@ -20,6 +25,10 @@ bool validationCheck(QString path)
} }
} }
return true; return true;
} else {
QMessageBox::critical(0, "v2ray core not found", "V2ray core files not found. Please download the latest version of v2ray and extract it into the current folder.", QMessageBox::Ok | QMessageBox::Default, 0);
return false;
}
} }
v2Instance::v2Instance() v2Instance::v2Instance()
{ {
@ -33,12 +42,16 @@ v2Instance::~v2Instance()
void v2Instance::start(MainWindow *parent) void v2Instance::start(MainWindow *parent)
{ {
if (QFileInfo("v2ray").exists() && QFileInfo("geoip.dat").exists() && QFileInfo("geosite.dat").exists() ) {
QProcessEnvironment env = QProcessEnvironment::systemEnvironment(); QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
env.insert("V2RAY_LOCATION_ASSET", "./"); env.insert("V2RAY_LOCATION_ASSET", QDir::currentPath());
this->v2Process->setProcessEnvironment(env); this->v2Process->setProcessEnvironment(env);
this->v2Process->start("v2ray", QStringList() << "-config" << "config.json", QIODevice::ReadWrite | QIODevice::Text); this->v2Process->start("./v2ray", QStringList() << "-config" << "config.json", QIODevice::ReadWrite | QIODevice::Text);
this->v2Process->waitForStarted(); this->v2Process->waitForStarted();
QObject::connect(v2Process, SIGNAL(readyReadStandardOutput()), parent, SLOT(updateLog())); QObject::connect(v2Process, SIGNAL(readyReadStandardOutput()), parent, SLOT(updateLog()));
} else {
QMessageBox::critical(0, "v2ray core not found", "V2ray core files not found. Please download the latest version of v2ray and extract it into the current folder.", QMessageBox::Ok | QMessageBox::Default, 0);
}
} }
void v2Instance::stop() void v2Instance::stop()

View File

@ -6,7 +6,8 @@
#pragma pop_macro("slots") #pragma pop_macro("slots")
#include <QDebug> #include <QDebug>
#include "importconf.h" #include "importconf.h"
#include<QFile> #include <QFile>
#include "vinteract.h"
vmess::vmess(QWidget *parent) : vmess::vmess(QWidget *parent) :
QDialog(parent), QDialog(parent),
@ -39,6 +40,8 @@ void vmess::on_buttonBox_accepted()
PyObject_CallObject(pFunc, arg); PyObject_CallObject(pFunc, arg);
Py_Finalize(); Py_Finalize();
importConf *im = new importConf(this->parentWidget()); importConf *im = new importConf(this->parentWidget());
if (validationCheck(QCoreApplication::applicationDirPath() + "/tmp.config.json")) {
im->savefromFile("tmp.config.json", alias); im->savefromFile("tmp.config.json", alias);
}
QFile::remove("tmp.config.json"); QFile::remove("tmp.config.json");
} }

View File

@ -1,4 +1,6 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
#Imported and modified from "https://github.com/boypt/vmess2json.git", thanks to the author boypt.
import os import os
import sys import sys
import json import json