源url连通性检测

This commit is contained in:
JackLee_CN 2024-10-20 19:24:21 +08:00
parent f3dc14698d
commit 35dd8cb465
8 changed files with 107 additions and 23 deletions

View File

@ -2,6 +2,9 @@
<qresource prefix="/">
<file>res/img/btn/btn_setting.png</file>
<file>res/img/btn/btn_about.png</file>
<file>res/img/btn/net_ok.png</file>
<file>res/img/btn/net_error.png</file>
<file>res/img/btn/net_wait.png</file>
<file>res/img/xsteam.ico</file>
<file>res/img/xsteam.png</file>
<file>res/bin/luapacka.exe</file>

BIN
res/img/btn/net_error.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB

BIN
res/img/btn/net_ok.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

BIN
res/img/btn/net_wait.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

View File

@ -2,17 +2,19 @@
xsteam_curl::xsteam_curl()
{
curl=nullptr;
curl = nullptr;
}
xsteam_curl::~xsteam_curl()
{
}
void xsteam_curl::init_curl(){
if(curl!=nullptr){
void xsteam_curl::init_curl()
{
if (curl != nullptr)
{
curl_easy_cleanup(curl);
curl=nullptr;
curl = nullptr;
}
curl=curl_easy_init();
curl = curl_easy_init();
}
size_t call_info_data(void *buffer, size_t sz, size_t nmemb, void *writer)
{
@ -27,10 +29,10 @@ size_t call_write_data(void *ptr, size_t size, size_t nmemb, void *stream)
size_t written = fwrite(ptr, size, nmemb, (FILE *)stream);
return written;
}
std::string xsteam_curl::get_steam_id_info(std::string api_url,std::string _c_uid)
std::string xsteam_curl::get_steam_id_info(std::string api_url, std::string _c_uid)
{
std::string u_str = api_url + _c_uid;
std::string strRsp;
std::string u_str = api_url + _c_uid;
std::string strRsp;
init_curl();
CURLcode res = CURLE_QUOTE_ERROR;
int retry = 3;
@ -78,13 +80,14 @@ std::string xsteam_curl::get_steam_id_info(std::string api_url,std::string _c_ui
return strRsp;
}
bool xsteam_curl::get_steam_header_ico(std::string logo_url,std::string _c_uid)
bool xsteam_curl::get_steam_header_ico(std::string logo_url, std::string _c_uid)
{
std::string base_str=QDir::currentPath().toStdString();
std::string base_str = QDir::currentPath().toStdString();
QDir dir(QString::fromStdString(base_str + "/save/img"));
std::string u_str = logo_url + _c_uid + "/header.jpg";
std::string s_str = base_str + "/save/img/" + _c_uid + ".jpg";
if(!dir.exists()){
std::string u_str = logo_url + _c_uid + "/header.jpg";
std::string s_str = base_str + "/save/img/" + _c_uid + ".jpg";
if (!dir.exists())
{
QDir().mkpath(QString::fromStdString(base_str + "/save/img"));
}
init_curl();
@ -118,7 +121,47 @@ bool xsteam_curl::get_steam_header_ico(std::string logo_url,std::string _c_uid)
return true;
}
catch (std::runtime_error &e)
{
{
return false;
}
}
bool xsteam_curl::get_url_state(std::string url)
{
CURL *curl;
CURLcode res;
curl_global_init(CURL_GLOBAL_DEFAULT);
curl = curl_easy_init();
std::string strTmpStr;
std::string strRsp;
int retry = 3;
if (curl)
{
curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
curl_easy_setopt(curl, CURLOPT_CONNECT_ONLY, 1L);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &strTmpStr);
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1);
res = curl_easy_perform(curl);
if (strTmpStr.data() == nullptr)
{
if (retry == 0)
{
return false;
}
res = curl_easy_perform(curl);
retry--;
}
if (QString::fromStdString(strTmpStr).contains(QStringLiteral("404"), Qt::CaseSensitive) ||
QString::fromStdString(strTmpStr).contains(QStringLiteral("500"), Qt::CaseSensitive) ||
QString::fromStdString(strTmpStr).contains(QStringLiteral("403"), Qt::CaseSensitive) ||
QString::fromStdString(strTmpStr).contains(QStringLiteral("502"), Qt::CaseSensitive) ||
res == CURLE_QUOTE_ERROR)
{
return false;
}else{
return true;
}
curl_easy_cleanup(curl);
}
curl_global_cleanup();
return false;
}

View File

@ -20,6 +20,7 @@ public:
~xsteam_curl();
std::string get_steam_id_info(std::string,std::string _c_uid);
bool get_steam_header_ico(std::string,std::string _c_uid);
bool get_url_state(std::string url);
private:
void init_curl();
CURL *curl;

View File

@ -37,8 +37,8 @@ void xsteam_ui::xsteam_init_main_layout()
}
void xsteam_ui::xsteam_init_info_layout()
{
info_layout=new QHBoxLayout();
info_txt_tag=new QLabel(tr("本工具建议配合SteamTools和Steam++使用"));
info_layout = new QHBoxLayout();
info_txt_tag = new QLabel(tr("本工具建议配合SteamTools和Steam++使用"));
info_layout->addItem(sparcer_item);
info_layout->addWidget(info_txt_tag);
info_layout->addItem(sparcer_item);
@ -49,6 +49,7 @@ void xsteam_ui::xsteam_init_mind_layout()
server_tag = new QLabel(tr("源数据:"));
server_tag->setObjectName("SRC_SERVER");
server_txt = new QComboBox();
server_state=new QLabel();
btn_server_edit = new QPushButton(tr("编辑源"));
btn_server_edit->setObjectName("EDIT");
btn_fetch_src_data = new QPushButton(tr("拉取"));
@ -59,11 +60,12 @@ void xsteam_ui::xsteam_init_mind_layout()
btn_run_steam->setObjectName("RUN_STEAM");
btn_run_steamdb = new QPushButton(tr("SteamDB"));
btn_run_steamdb->setObjectName("STEAM_DB");
btn_push_manifest=new QPushButton(tr("清单分享"));
btn_push_manifest = new QPushButton(tr("清单分享"));
btn_push_manifest->setObjectName("PUSH_MANIFEST");
server_layout->addWidget(server_tag);
server_layout->addWidget(server_txt);
server_layout->addWidget(server_state);
server_layout->addWidget(btn_fetch_src_data);
server_layout->addWidget(btn_server_edit);
server_layout->addWidget(btn_run_steam);
@ -135,7 +137,7 @@ void xsteam_ui::xsteam_init_mind_layout()
ip_data_layout->setStretch(0, 8);
ip_data_layout->setStretch(1, 2);
mind_layout->addLayout(server_layout);
mind_layout->addLayout(info_layout);
mind_layout->addLayout(ip_data_layout);
@ -201,6 +203,38 @@ void xsteam_ui::xsteam_init_connect()
connect(ip_in_dlc_table, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(slots_rightMenu(QPoint)));
connect(btn_dlc_push, SIGNAL(clicked()), this, SLOT(slots_get_uid_dlcs()));
connect(btn_push_manifest, SIGNAL(clicked()), this, SLOT(slots_push_manifest()));
connect(server_txt, SIGNAL(currentIndexChanged(int)), this, SLOT(slots_change_src_state(int)));
}
void xsteam_ui::slots_change_src_state(int index)
{
QPixmap xs_pixmap;
std::string url;
xs_pixmap.load(":res/img/btn/net_wait.png");
xs_pixmap = xs_pixmap.scaled(25,25,Qt::KeepAspectRatio);
server_state->setPixmap(xs_pixmap);
for (auto &i : _data.s_data)
{
if (i.src_name == server_txt->itemText(index))
{
url = i.src_url;
break;
}
}
if (url != "")
{
QFuture<void> future = QtConcurrent::run([=](std::string _url,QPixmap _pixmap) {
xsteam_curl* xs_curl=new xsteam_curl();
if(xs_curl->get_url_state(_url)){
_pixmap.load(":/res/img/btn/net_ok.png");
}else{
_pixmap.load(":/res/img/btn/net_error.png");
}
_pixmap=_pixmap.scaled(25,25,Qt::KeepAspectRatio);
server_state->setPixmap(_pixmap);
delete xs_curl;
xs_curl=nullptr;
},url,xs_pixmap);
}
}
void xsteam_ui::slots_get_uid_dlcs()
{
@ -421,9 +455,9 @@ void xsteam_ui::slots_server_combobox_load_data()
server_txt->setCurrentIndex(0);
}
void xsteam_ui::table_load_ui_data()
{
{
for (auto x : _data.u_data)
{
{
ip_uid_table->item_append(x, VIEW_MODE::UID_INFO);
}
}
@ -440,9 +474,10 @@ void xsteam_ui::slots_run_steam_steamtools()
xsteam_run_steam_steamtools(RUN_MODE::STEAMTOOLS);
}
}
void xsteam_ui::slots_push_manifest(){
void xsteam_ui::slots_push_manifest()
{
xs_push_manifest = xsteam_push_manifest::Instance();
xs_push_manifest->setMaximumSize(((QWidget *)this->parent())->width(), ((QWidget *)this->parent())->height()-25);
xs_push_manifest->setMaximumSize(((QWidget *)this->parent())->width(), ((QWidget *)this->parent())->height() - 25);
xs_push_manifest->setGeometry(((QWidget *)this->parent())->geometry());
xs_push_manifest->exec();
}

View File

@ -41,6 +41,7 @@ private:
QHBoxLayout* server_layout;
QLabel* server_tag;
QComboBox* server_txt;
QLabel* server_state;
QPushButton* btn_server_edit;
QPushButton* btn_fetch_src_data;
QPushButton* btn_run_steam;
@ -106,6 +107,7 @@ private slots:
void slots_in_dlc_delete();
void slots_in_dlc_add();
void slots_imput_update_uid_push();
void slots_change_src_state(int);
signals:
void signals_src_combobox_update();
};