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 <QSqlDatabase>
#include <QSqlQuery>
#include <mainwindow.h>
#include "mainwindow.h"
#include <QDebug>
#include <QSqlError>
#include <QFile>

View File

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

View File

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

View File

@ -4,22 +4,31 @@
#include <QMessageBox>
#include <QProcess>
#include "mainwindow.h"
#include <QDir>
bool validationCheck(QString path)
{
QString output = "";
QProcess process;
process.start("v2ray", QStringList() << "-test" << "-config" << path, QIODevice::ReadWrite | QIODevice::Text);
if(!process.waitForFinished()) {
qDebug() << "executing program failed with exit code" << process.exitCode();
} else {
output = QString(process.readAllStandardOutput());
if (!output.contains("Configuration OK")) {
QMessageBox::critical(0, "Error in configuration", output.mid(output.indexOf("anti-censorship.") + 17), QMessageBox::Ok | QMessageBox::Default, 0);
return false;
if (QFileInfo("v2ray").exists() && QFileInfo("geoip.dat").exists() && QFileInfo("geosite.dat").exists() ) {
QString output = "";
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);
if(!process.waitForFinished()) {
qDebug() << "executing program failed with exit code" << process.exitCode();
} else {
output = QString(process.readAllStandardOutput());
if (!output.contains("Configuration OK")) {
QMessageBox::critical(0, "Error in configuration", output.mid(output.indexOf("anti-censorship.") + 17), QMessageBox::Ok | QMessageBox::Default, 0);
return false;
}
}
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;
}
return true;
}
v2Instance::v2Instance()
{
@ -33,12 +42,16 @@ v2Instance::~v2Instance()
void v2Instance::start(MainWindow *parent)
{
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
env.insert("V2RAY_LOCATION_ASSET", "./");
this->v2Process->setProcessEnvironment(env);
this->v2Process->start("v2ray", QStringList() << "-config" << "config.json", QIODevice::ReadWrite | QIODevice::Text);
this->v2Process->waitForStarted();
QObject::connect(v2Process, SIGNAL(readyReadStandardOutput()), parent, SLOT(updateLog()));
if (QFileInfo("v2ray").exists() && QFileInfo("geoip.dat").exists() && QFileInfo("geosite.dat").exists() ) {
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
env.insert("V2RAY_LOCATION_ASSET", QDir::currentPath());
this->v2Process->setProcessEnvironment(env);
this->v2Process->start("./v2ray", QStringList() << "-config" << "config.json", QIODevice::ReadWrite | QIODevice::Text);
this->v2Process->waitForStarted();
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()

View File

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

View File

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