Skip to content

Commit

Permalink
修复因路径问题造成开机自启无法读取配置文件。
Browse files Browse the repository at this point in the history
  • Loading branch information
CHN-STUDENT authored Dec 3, 2017
1 parent 4ccf5e1 commit 46f3119
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
29 changes: 18 additions & 11 deletions srun-3k-ui/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ void MainWindow::Start(void)
"QPushButton:pressed {border-image: url(:/titleButtons/advanced_pressed);}");
AboutButton->hide();//在获取公告前隐藏这两个按钮
AdvancedButton->hide();
QFile open("server.json");
QString serverconfig=QCoreApplication::applicationDirPath()+"/server.json";
QFile open(serverconfig);
if(open.open(QIODevice::ReadOnly))
{//打开服务器信息文件
QByteArray OPEN_CONFIG=open.readAll();
Expand Down Expand Up @@ -167,16 +168,17 @@ void MainWindow::GetServerInfo(void)
GetINFOManager->get(QNetworkRequest(QUrl(login_server+"/cgi-bin/rad_user_info")));
connect(GetINFOManager, SIGNAL(finished(QNetworkReply*)),this,SLOT(GET_INFO_Finished(QNetworkReply*)));
/*自动读取用户信息*/
QFile open("config.json");
if(open.open(QIODevice::ReadOnly))
QString userconfig=QCoreApplication::applicationDirPath()+"/config.json";
QFile u(userconfig);
if(u.open(QIODevice::ReadOnly))
{
file_state=1;
QByteArray OPEN_INFO=open.readAll();
open.close();
QJsonDocument INFO=QJsonDocument::fromJson(OPEN_INFO);
if(INFO.isObject())
QByteArray OPEN_USERINFO=u.readAll();
u.close();
QJsonDocument USERINFO=QJsonDocument::fromJson(OPEN_USERINFO);
if(USERINFO.isObject())
{
QJsonObject obj=INFO.object();
QJsonObject obj=USERINFO.object();
if(obj.contains("username"))
{ ui->NAME_INPUT->setText(obj.value("username").toString());}
if(obj.contains("password"))
Expand Down Expand Up @@ -207,7 +209,8 @@ void MainWindow::GetServerInfo(void)
QString all = codec->toUnicode(reply->readAll());
ui->Message_show->setText(all);
/*自动读取上次公告*/
QFile m("lastservermessage.txt");
QString servermessage=QCoreApplication::applicationDirPath()+"/lastservermessage.txt";
QFile m(servermessage);
if(m.open(QIODevice::ReadWrite))
{//读取上次公告文件
QString ServerMessage=m.readAll();
Expand All @@ -219,6 +222,8 @@ void MainWindow::GetServerInfo(void)
m.write(all.toUtf8());
m.close();
}
else
m.close();
}
else
{//如果读取不到上次公告文件
Expand Down Expand Up @@ -598,7 +603,8 @@ void MainWindow::on_LoginButton_clicked()
info.insert("auto_start",auto_start);
QJsonDocument SAVE_INFO;
SAVE_INFO.setObject(info);
QFile save("config.json");
QString userconfig=QCoreApplication::applicationDirPath()+"/config.json";
QFile save(userconfig);
if(!save.open(QIODevice::WriteOnly))
{
ui->ShowState->setText("错误!文件保存失败!");
Expand Down Expand Up @@ -704,7 +710,8 @@ void MainWindow::on_advanced_save_clicked()
pop=QString(ui->pop->text());
QJsonDocument SAVE_CONFIG;
SAVE_CONFIG.setObject(config);
QFile save("server.json");
QString serverconfig=QCoreApplication::applicationDirPath()+"/server.json";
QFile save(serverconfig);
if(!save.open(QIODevice::WriteOnly))
{
ui->ShowState->setText("错误!文件保存失败!");
Expand Down
3 changes: 2 additions & 1 deletion srun-3k-ui/mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -1131,7 +1131,7 @@ border: 1px solid #D9D9D6;
<html><head><meta name="qrichtext" content="1" /><style type="text/css">
p, li { white-space: pre-wrap; }
</style></head><body style=" font-family:'SimSun'; font-size:9pt; font-weight:400; font-style:normal;">
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">校园网登录器 V1.03.2</p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">校园网登录器 V1.03.3</p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">By CHN-STUDENT</p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Copyright(C) 2017</p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">-----------------------</p>
Expand All @@ -1157,6 +1157,7 @@ p, li { white-space: pre-wrap; }
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">-----------------------</p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">更新日志:</p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">V1.03.3修复开机自启无法读取配置文件的BUG。(感谢 Noisky 大佬)</p>
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">V1.03.2密码加密存储,修复V1.02.3的自动登陆功能失效。</p>
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p>
Expand Down

0 comments on commit 46f3119

Please sign in to comment.