改进部分代码
This commit is contained in:
@@ -66,7 +66,8 @@ bool App::SelectAllWebServer = true;
|
||||
|
||||
void App::readConfig()
|
||||
{
|
||||
if (!checkConfig()) {
|
||||
if (!QUIHelper::checkIniFile(App::ConfigFile)) {
|
||||
writeConfig();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -218,43 +219,6 @@ void App::writeConfig()
|
||||
set.endGroup();
|
||||
}
|
||||
|
||||
bool App::checkConfig()
|
||||
{
|
||||
//如果配置文件大小为0,则以初始值继续运行,并生成配置文件
|
||||
QFile file(App::ConfigFile);
|
||||
if (file.size() == 0) {
|
||||
writeConfig();
|
||||
return false;
|
||||
}
|
||||
|
||||
//如果配置文件不完整,则以初始值继续运行,并生成配置文件
|
||||
if (file.open(QFile::ReadOnly)) {
|
||||
bool ok = true;
|
||||
while (!file.atEnd()) {
|
||||
QString line = file.readLine();
|
||||
line = line.replace("\r", "");
|
||||
line = line.replace("\n", "");
|
||||
QStringList list = line.split("=");
|
||||
if (list.count() == 2) {
|
||||
if (list.at(1) == "") {
|
||||
ok = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!ok) {
|
||||
writeConfig();
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
writeConfig();
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
QStringList App::Intervals = QStringList();
|
||||
QStringList App::Datas = QStringList();
|
||||
QStringList App::Keys = QStringList();
|
||||
|
||||
@@ -78,7 +78,6 @@ public:
|
||||
//读写配置参数及其他操作
|
||||
static void readConfig(); //读取配置参数
|
||||
static void writeConfig(); //写入配置参数
|
||||
static bool checkConfig(); //校验配置文件
|
||||
|
||||
static QStringList Intervals;
|
||||
static QStringList Datas;
|
||||
|
||||
@@ -2186,6 +2186,42 @@ void QUIHelper::initFile(const QString &sourceName, const QString &targetName)
|
||||
}
|
||||
}
|
||||
|
||||
bool QUIHelper::checkIniFile(const QString &iniFile)
|
||||
{
|
||||
//如果配置文件大小为0,则以初始值继续运行,并生成配置文件
|
||||
QFile file(iniFile);
|
||||
if (file.size() == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
//如果配置文件不完整,则以初始值继续运行,并生成配置文件
|
||||
if (file.open(QFile::ReadOnly)) {
|
||||
bool ok = true;
|
||||
while (!file.atEnd()) {
|
||||
QString line = file.readLine();
|
||||
line = line.replace("\r", "");
|
||||
line = line.replace("\n", "");
|
||||
QStringList list = line.split("=");
|
||||
|
||||
if (list.count() == 2) {
|
||||
if (list.at(1) == "") {
|
||||
qDebug() << TIMEMS << "ini node no value" << list.at(0);
|
||||
ok = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!ok) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void QUIHelper::setIconBtn(QAbstractButton *btn, const QString &png, const QChar &str)
|
||||
{
|
||||
int size = 16;
|
||||
@@ -3016,7 +3052,7 @@ QString QUIHelper::byteArrayToAsciiStr(const QByteArray &data)
|
||||
QString temp;
|
||||
int len = data.size();
|
||||
|
||||
for (int i = 0; i < len; i++) {
|
||||
for (int i = 0; i < len; i++) {
|
||||
char byte = data.at(i);
|
||||
QString value = listChar.value(byte);
|
||||
if (!value.isEmpty()) {
|
||||
@@ -3245,26 +3281,29 @@ bool QUIHelper::ipLive(const QString &ip, int port, int timeout)
|
||||
|
||||
QString QUIHelper::getHtml(const QString &url)
|
||||
{
|
||||
QNetworkAccessManager *manager = new QNetworkAccessManager();
|
||||
QNetworkReply *reply = manager->get(QNetworkRequest(QUrl(url)));
|
||||
QByteArray responseData;
|
||||
QNetworkAccessManager manager;
|
||||
QNetworkReply *reply = manager.get(QNetworkRequest(QUrl(url)));
|
||||
QEventLoop eventLoop;
|
||||
QObject::connect(manager, SIGNAL(finished(QNetworkReply *)), &eventLoop, SLOT(quit()));
|
||||
QObject::connect(&manager, SIGNAL(finished(QNetworkReply *)), &eventLoop, SLOT(quit()));
|
||||
eventLoop.exec();
|
||||
responseData = reply->readAll();
|
||||
return QString(responseData);
|
||||
QByteArray data = reply->readAll();
|
||||
reply->deleteLater();
|
||||
return QString(data);
|
||||
}
|
||||
|
||||
QString QUIHelper::getNetIP(const QString &webCode)
|
||||
QString QUIHelper::getNetIP(const QString &html)
|
||||
{
|
||||
QString web = webCode;
|
||||
web = web.replace(' ', "");
|
||||
web = web.replace("\r", "");
|
||||
web = web.replace("\n", "");
|
||||
QStringList list = web.split("<br/>");
|
||||
QString tar = list.at(3);
|
||||
QStringList ip = tar.split("=");
|
||||
return ip.at(1);
|
||||
QString ip;
|
||||
QStringList list = html.split(" ");
|
||||
foreach (QString str, list) {
|
||||
//value=\"101.86.197.178\">
|
||||
if (str.contains("value=")) {
|
||||
QStringList temp = str.split("\"");
|
||||
ip = temp.at(1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return ip;
|
||||
}
|
||||
|
||||
QString QUIHelper::getLocalIP()
|
||||
@@ -3335,8 +3374,8 @@ QString QUIHelper::getValue(quint8 value)
|
||||
|
||||
bool QUIHelper::isWebOk()
|
||||
{
|
||||
//能接通百度IP说明可以通外网
|
||||
return ipLive("115.239.211.112", 80);
|
||||
//能接通百度IP 115.239.211.112 说明可以通外网
|
||||
return ipLive("www.baidu.com", 80);
|
||||
}
|
||||
|
||||
void QUIHelper::initTableView(QTableView *tableView, int rowHeight, bool headVisible, bool edit, bool stretchLast)
|
||||
|
||||
@@ -601,6 +601,9 @@ public:
|
||||
//初始化文件,不存在则拷贝
|
||||
static void initFile(const QString &sourceName, const QString &targetName);
|
||||
|
||||
//检查ini配置文件
|
||||
static bool checkIniFile(const QString &iniFile);
|
||||
|
||||
//设置图标到按钮
|
||||
static void setIconBtn(QAbstractButton *btn, const QString &png, const QChar &str);
|
||||
|
||||
@@ -756,7 +759,7 @@ public:
|
||||
//获取网页所有源代码
|
||||
static QString getHtml(const QString &url);
|
||||
//获取本机公网IP地址
|
||||
static QString getNetIP(const QString &webCode);
|
||||
static QString getNetIP(const QString &html);
|
||||
//获取本机IP
|
||||
static QString getLocalIP();
|
||||
//获取本机IP地址集合
|
||||
|
||||
@@ -28,6 +28,11 @@ void frmTcpClient::initForm()
|
||||
|
||||
ui->cboxInterval->addItems(App::Intervals);
|
||||
ui->cboxData->addItems(App::Datas);
|
||||
|
||||
#ifndef emsdk
|
||||
QString ip = QUIHelper::getNetIP(QUIHelper::getHtml("http://whois.pconline.com.cn/"));
|
||||
append(1, QString("外网IP -> %1").arg(ip));
|
||||
#endif
|
||||
}
|
||||
|
||||
void frmTcpClient::initConfig()
|
||||
|
||||
@@ -33,7 +33,7 @@ void frmWebClient::initForm()
|
||||
connect(timer, SIGNAL(timeout()), this, SLOT(on_btnSend_clicked()));
|
||||
|
||||
ui->cboxInterval->addItems(App::Intervals);
|
||||
ui->cboxData->addItems(App::Datas);
|
||||
ui->cboxData->addItems(App::Datas);
|
||||
}
|
||||
|
||||
void frmWebClient::initConfig()
|
||||
|
||||
Reference in New Issue
Block a user