Compare commits

...

10 Commits

Author SHA1 Message Date
Mike Solar c0f45de00b 完成下载功能 2023-09-18 21:35:41 +08:00
Mike Solar 7493ac4d2e 导航栏按钮 2023-09-09 16:11:02 +08:00
Mike Solar ede78c640b 修复打不开自行添加的应用 2023-09-06 21:22:06 +08:00
Mike Solar a96f802b85 修复全名重复 2023-08-29 11:45:11 +08:00
Mike Solar fd525fb8d1 阶段性完成,还差独立浏览器和几个别的需求。 2023-08-26 22:13:39 +08:00
Mike Solar 9ee232cead 解决兼容性问题 2023-08-21 15:10:19 +08:00
Mike Solar 5ec58b3bfb 除了win7的问题外全修复了 2023-08-18 20:51:05 +08:00
Mike Solar b728e697fb 几乎完成 2023-08-18 19:09:55 +08:00
Mike Solar bc3b3f69a7 准备整理代码 2023-08-17 01:10:27 +08:00
Mike Solar 94017995bc 关了VS,重新提交 2023-08-15 20:13:27 +08:00
46 changed files with 1912 additions and 1566 deletions

View File

@ -1,4 +1,4 @@
// //
// Created by HW on 2023/07/26. // Created by HW on 2023/07/26.
// //
#include "MyButton.h" #include "MyButton.h"
@ -10,6 +10,7 @@ MyButton::MyButton(ButtonStruct &buttonStruct,int width,int height,QList<MyButto
this->height2=height; this->height2=height;
this->text=buttonStruct.text; this->text=buttonStruct.text;
this->op = buttonStruct.op; this->op = buttonStruct.op;
this->orig_name = buttonStruct.orig_name;
this->func = buttonStruct.func; this->func = buttonStruct.func;
this->url = buttonStruct.url; this->url = buttonStruct.url;
this->path = buttonStruct.path; this->path = buttonStruct.path;
@ -43,7 +44,7 @@ void MyButton::paintEvent(QPaintEvent *e) {
setContentsMargins(0,0,0,0); setContentsMargins(0,0,0,0);
QFont ft; QFont ft;
ft.setPixelSize(TEXT_SIZE); ft.setPixelSize(TEXT_SIZE);
//别问我为啥乘3我也不知道 //别问我为啥乘3我也不知道
int text_x=(width()-TEXT_SIZE*text.length()*scale*3)/2; int text_x=(width()-TEXT_SIZE*text.length()*scale*3)/2;
int text_y=(logo_width+logo_y+10); int text_y=(logo_width+logo_y+10);
QRectF logo_rect(logo_x, logo_y, logo_width, logo_width); QRectF logo_rect(logo_x, logo_y, logo_width, logo_width);
@ -91,6 +92,6 @@ void MyButton::mouseReleaseEvent(QMouseEvent *event) {
checked=false; checked=false;
else else
checked=true; checked=true;
emit clicked1(op, func, url, path, initial_position); emit clicked1(orig_name,op, func, url, path, initial_position);
} }

View File

@ -1,4 +1,4 @@
// //
// Created by HW on 2023/07/26. // Created by HW on 2023/07/26.
// //
@ -16,7 +16,7 @@
class MyButton: public QPushButton{ class MyButton: public QPushButton{
Q_OBJECT Q_OBJECT
signals: signals:
void clicked1(QString op, QString func, QString url, QString path, QString initial_position); void clicked1(QString orig_name,QString op, QString func, QString url, QString path, QString initial_position);
public: public:
MyButton(ButtonStruct &buttonStruct,int width,int height,QList<MyButton *> *buttons,QWidget *parent=nullptr); MyButton(ButtonStruct &buttonStruct,int width,int height,QList<MyButton *> *buttons,QWidget *parent=nullptr);
~MyButton() override; ~MyButton() override;
@ -57,6 +57,7 @@ private:
QImage *logo_cover; QImage *logo_cover;
QVBoxLayout *layout; QVBoxLayout *layout;
QString text; QString text;
QString orig_name;
QString url; QString url;
QString op; QString op;
QString path; QString path;

View File

@ -102,6 +102,7 @@
<QtRcc Include="OfficeAssistant_msvc.qrc" /> <QtRcc Include="OfficeAssistant_msvc.qrc" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<QtMoc Include="userimprove.h" />
<QtMoc Include="applicationmanager.h" /> <QtMoc Include="applicationmanager.h" />
<QtMoc Include="addapp.h" /> <QtMoc Include="addapp.h" />
<QtMoc Include="addcategory.h" /> <QtMoc Include="addcategory.h" />
@ -139,6 +140,7 @@
<ClCompile Include="netio.cpp" /> <ClCompile Include="netio.cpp" />
<ClCompile Include="qminiblink.cpp" /> <ClCompile Include="qminiblink.cpp" />
<ClCompile Include="sqlitehelper.cpp" /> <ClCompile Include="sqlitehelper.cpp" />
<ClCompile Include="userimprove.cpp" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<QtUic Include="addapp.ui" /> <QtUic Include="addapp.ui" />
@ -152,6 +154,7 @@
<QtUic Include="mysettingsdialog.ui" /> <QtUic Include="mysettingsdialog.ui" />
<QtUic Include="navbar.ui" /> <QtUic Include="navbar.ui" />
<QtUic Include="qminiblink.ui" /> <QtUic Include="qminiblink.ui" />
<QtUic Include="userimprove.ui" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ResourceCompile Include="logo.rc" /> <ResourceCompile Include="logo.rc" />

View File

@ -85,6 +85,9 @@
<QtMoc Include="applicationmanagerpage.h"> <QtMoc Include="applicationmanagerpage.h">
<Filter>Header Files</Filter> <Filter>Header Files</Filter>
</QtMoc> </QtMoc>
<QtMoc Include="userimprove.h">
<Filter>Header Files</Filter>
</QtMoc>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="mainscreen.cpp"> <ClCompile Include="mainscreen.cpp">
@ -123,15 +126,18 @@
<ClCompile Include="minibutton.cpp"> <ClCompile Include="minibutton.cpp">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="addapp.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="addcategory.cpp"> <ClCompile Include="addcategory.cpp">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="applicationmanagerpage.cpp"> <ClCompile Include="applicationmanagerpage.cpp">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="userimprove.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="addapp.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<QtUic Include="navbar.ui"> <QtUic Include="navbar.ui">
@ -167,6 +173,9 @@
<QtUic Include="applicationmanagerpage.ui"> <QtUic Include="applicationmanagerpage.ui">
<Filter>Form Files</Filter> <Filter>Form Files</Filter>
</QtUic> </QtUic>
<QtUic Include="userimprove.ui">
<Filter>Form Files</Filter>
</QtUic>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ResourceCompile Include="logo.rc"> <ResourceCompile Include="logo.rc">

View File

@ -1,13 +1,17 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LocalDebuggerCommandArguments>79c86fb12b36dfa33d1a537c9af100b4c7928a9c</LocalDebuggerCommandArguments> <LocalDebuggerCommandArguments>autostart</LocalDebuggerCommandArguments>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LocalDebuggerCommandArguments>$(QmlDebug)</LocalDebuggerCommandArguments>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor> <DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Label="QtSettings" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> <PropertyGroup Label="QtSettings" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<QtLastBackgroundBuild>2023-08-12T03:22:21.9071424Z</QtLastBackgroundBuild> <QtLastBackgroundBuild>2023-09-18T12:55:53.6703998Z</QtLastBackgroundBuild>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Label="QtSettings" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> <PropertyGroup Label="QtSettings" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<QtLastBackgroundBuild>2023-08-12T03:22:23.0360904Z</QtLastBackgroundBuild> <QtLastBackgroundBuild>2023-09-18T12:55:55.7491129Z</QtLastBackgroundBuild>
</PropertyGroup> </PropertyGroup>
</Project> </Project>

View File

@ -1,4 +1,4 @@
#include "addapp.h" #include "addapp.h"
#include <QFileDialog> #include <QFileDialog>
#include <QProcessEnvironment> #include <QProcessEnvironment>
#include <QMessageBox> #include <QMessageBox>
@ -18,39 +18,43 @@ AddApp::AddApp(bool isEdit, Record2 *row , QWidget* parent)
ui.setupUi(this); ui.setupUi(this);
this->row=row; this->row=row;
SQLiteHelper sqlite_helper; SQLiteHelper sqlite_helper;
setFixedSize(450, 450); setFixedSize(450, 600);
Record2 record; Record2 record;
sqlite_helper.get_a_software(row->orig_name, &record);
setWindowFlags(Qt::WindowCloseButtonHint); setWindowFlags(Qt::WindowCloseButtonHint);
form = new QFormLayout; form = new QFormLayout;
name = new QLineEdit; name = new QLineEdit;
form->addRow(QString::fromLocal8Bit("名称"), name); if(isEdit)
if (isEdit)
{ {
name_label = new QLabel(orig_name_str); record=*row;//最初为啥这么写我也忘了
form->addRow(QString::fromLocal8Bit("全名"), name_label);
if (!record.orig_name.isEmpty())
{
name_label->setText(record.orig_name);
}
orig_name_str = record.orig_name;
} }
else
{
orig_name = new QLineEdit;
form->addRow(QString::fromLocal8Bit("全名"), orig_name);
}
if (record.orig_name.isEmpty()) if (record.orig_name.isEmpty())
{ {
path = new QPushButton(QString::fromLocal8Bit("浏览")); path = new QPushButton(QString::fromLocal8Bit("浏览"));
connect(path, &QPushButton::clicked, this, &AddApp::broswer_exe); connect(path, &QPushButton::clicked, this, &AddApp::broswer_exe);
form->addRow(QString::fromLocal8Bit("路径"), path); form->addRow(QString::fromLocal8Bit("路径"), path);
if (isEdit)
{
sqlite_helper.get_a_software(row->orig_name, &record);
name_label = new QLabel(orig_name_str);
form->addRow(QString::fromLocal8Bit("全名"), name_label);
if (!record.orig_name.isEmpty())
{
name_label->setText(record.orig_name);
}
orig_name_str = record.orig_name;
}
else
{
orig_name = new QLineEdit;
form->addRow(QString::fromLocal8Bit("全名"), orig_name);
}
form->addRow(QString::fromLocal8Bit("名称"), name);
sort = new QLineEdit; sort = new QLineEdit;
sort->setValidator(new QIntValidator(10, 100)); sort->setValidator(new QIntValidator(10, 100));
form->addRow(QString::fromLocal8Bit("排序"), sort); sort->setText("50");
form->addRow(QString::fromLocal8Bit("排序"), sort);
QList<Categrory> categrories; QList<Categrory> categrories;
layout_inner = new QVBoxLayout; layout_inner = new QVBoxLayout;
sqlite_helper.get_category(categrories, true); sqlite_helper.get_category(categrories, true);
@ -62,8 +66,8 @@ AddApp::AddApp(bool isEdit, Record2 *row , QWidget* parent)
layout_inner->addWidget(check_box); layout_inner->addWidget(check_box);
categories_list.insert(category.id, check_box); categories_list.insert(category.id, check_box);
} }
form->addRow(QString::fromLocal8Bit("类别"), layout_inner); form->addRow(QString::fromLocal8Bit("类别"), layout_inner);
submit_btn = new QPushButton(QString::fromLocal8Bit("提交")); submit_btn = new QPushButton(QString::fromLocal8Bit("提交"));
form->addWidget(submit_btn); form->addWidget(submit_btn);
this->setLayout(form); this->setLayout(form);
connect(path, &QPushButton::click, this, &AddApp::broswer_exe); connect(path, &QPushButton::click, this, &AddApp::broswer_exe);
@ -75,15 +79,36 @@ AddApp::AddApp(bool isEdit, Record2 *row , QWidget* parent)
name->setText(record.name); name->setText(record.name);
name_str = record.name; name_str = record.name;
sort_str = QString::number(record.sort); sort_str = QString::number(record.sort);
path = new QPushButton(QString::fromLocal8Bit("浏览")); path = new QPushButton(QString::fromLocal8Bit("浏览"));
path_str = record.exe_file; path_str = record.exe_file;
path->setText(QString::fromWCharArray(fs::path(path_str.toStdWString()).filename().c_str())); path->setText(QString::fromWCharArray(fs::path(path_str.toStdWString()).filename().c_str()));
connect(path, &QPushButton::clicked, this, &AddApp::broswer_exe); connect(path, &QPushButton::clicked, this, &AddApp::broswer_exe);
form->addRow(QString::fromLocal8Bit("路径"), path); if (record.op == "soft")
{
form->addRow(QString::fromLocal8Bit("路径"), path);
}
if (isEdit)
{
sqlite_helper.get_a_software(row->orig_name, &record);
name_label = new QLabel(orig_name_str);
form->addRow(QString::fromLocal8Bit("全名"), name_label);
if (!record.orig_name.isEmpty())
{
name_label->setText(record.orig_name);
}
orig_name_str = record.orig_name;
}
else
{
orig_name = new QLineEdit;
form->addRow(QString::fromLocal8Bit("全名"), orig_name);
}
form->addRow(QString::fromLocal8Bit("名称"), name);
sort = new QLineEdit; sort = new QLineEdit;
sort->setText(QString::number(record.sort)); sort->setText(QString::number(record.sort));
sort->setValidator(new QIntValidator(10, 100)); sort->setValidator(new QIntValidator(10, 100));
form->addRow(QString::fromLocal8Bit("排序"), sort); form->addRow(QString::fromLocal8Bit("排序"), sort);
QList<Categrory> categrories; QList<Categrory> categrories;
layout_inner = new QVBoxLayout; layout_inner = new QVBoxLayout;
sqlite_helper.get_category(categrories, true); sqlite_helper.get_category(categrories, true);
@ -98,15 +123,14 @@ AddApp::AddApp(bool isEdit, Record2 *row , QWidget* parent)
layout_inner->addWidget(check_box); layout_inner->addWidget(check_box);
categories_list.insert(category.id, check_box); categories_list.insert(category.id, check_box);
} }
form->addRow(QString::fromLocal8Bit("类别"), layout_inner); form->addRow(QString::fromLocal8Bit("类别"), layout_inner);
submit_btn = new QPushButton(QString::fromLocal8Bit("提交")); submit_btn = new QPushButton(QString::fromLocal8Bit("提交"));
form->addWidget(submit_btn); form->addWidget(submit_btn);
this->setLayout(form); this->setLayout(form);
connect(path, &QPushButton::click, this, &AddApp::broswer_exe); connect(path, &QPushButton::click, this, &AddApp::broswer_exe);
connect(submit_btn, &QPushButton::clicked, this, &AddApp::submit); connect(submit_btn, &QPushButton::clicked, this, &AddApp::submit);
this->isEdit = isEdit; this->isEdit = isEdit;
} }
} }
AddApp::~AddApp() AddApp::~AddApp()
@ -130,42 +154,42 @@ void AddApp::broswer_exe(){
QString path_str_old = path_str; QString path_str_old = path_str;
if(path_str.isEmpty()) if(path_str.isEmpty())
{ {
path_str = QFileDialog::getOpenFileName(this, QString::fromLocal8Bit("选择程序"), path_str = QFileDialog::getOpenFileName(this, QString::fromLocal8Bit("选择程序"),
QApplication::applicationDirPath(), QString::fromLocal8Bit("应用程序 (*.exe)")); QApplication::applicationDirPath(), QString::fromLocal8Bit("应用程序 (*.exe)"));
} }
else else
{ {
path_str = QFileDialog::getOpenFileName(this, QString::fromLocal8Bit("选择程序"), path_str = QFileDialog::getOpenFileName(this, QString::fromLocal8Bit("选择程序"),
path_str, QString::fromLocal8Bit("应用程序 (*.exe)")); path_str, QString::fromLocal8Bit("应用程序 (*.exe)"));
} }
if (path_str.isEmpty()) { if (path_str.isEmpty()) {
path_str = path_str_old; path_str = path_str_old;
} }
fs::path file(path_str.toStdWString()); fs::path file(path_str.toStdWString());
path->setText(QString::fromStdWString(file.filename().c_str())); path->setText(QString::fromStdWString(file.filename().c_str()));
if(!isEdit)
{
orig_name->setText(QString::fromStdWString(file.filename().c_str()));
}
} }
void AddApp::submit() { void AddApp::submit() {
if(isEdit) if(sort->text().toInt()<10||sort->text().toInt()>100)
{ {
if (!path->text().isEmpty()) QMessageBox::critical(this, QString::fromLocal8Bit("错误"), QString::fromLocal8Bit("排序必须在10-100之间"));
{ return;
QString name_str_old = name_str; }
QString sort_str_old = sort_str; if (isEdit)
name_str = name->text(); {
sort_str = sort->text(); QString name_str_old = name_str;
if (name_str.isEmpty()) { QString sort_str_old = sort_str;
name_str = name_str_old; name_str = name->text();
} sort_str = sort->text();
if (sort_str.isEmpty()) { if (name_str.isEmpty()) {
sort_str = sort_str_old; name_str = name_str_old;
}
} }
else if (sort_str.isEmpty()) {
{ sort_str = sort_str_old;
QMessageBox::critical(this, QString::fromLocal8Bit("错误"), QString::fromLocal8Bit("未填写路径"));
return;
} }
} }
else else
@ -184,27 +208,21 @@ void AddApp::submit() {
} }
else else
{ {
QMessageBox::critical(this, QString::fromLocal8Bit("错误"), QString::fromLocal8Bit("未填写全名或路径")); QMessageBox::critical(this, QString::fromLocal8Bit("错误"), QString::fromLocal8Bit("未填写全名或路径"));
return; return;
} }
} }
categories = new bool[8]; categories = new bool[8];
for (int i = 0; i < 8; i++) { for (int i = 0; i < CATEGORIES_NUM; i++) {
categories[i] = false; categories[i] = false;
} }
categories[ALL-1] = true; categories[ALL-1] = true;
if (row->op == "soft") {
categories[SOFT-1] = true;
}
else if (row->op == "app") {
categories[INNER-1] = true;
}
for(auto key:categories_list.keys()) for(auto key:categories_list.keys())
{ {
categories[key - 1] = categories_list[key]->checkState(); categories[key - 1] = categories_list[key]->checkState();
} }
for (int i = 0; i < 8; i++) { for (int i = 0; i < CATEGORIES_NUM; i++) {
qDebug() << categories[i]; qDebug() << categories[i];
} }

View File

@ -1,4 +1,4 @@
#pragma once #pragma once
#include <QDialog> #include <QDialog>
#include <QLineEdit> #include <QLineEdit>
@ -16,7 +16,7 @@ class AddApp : public QDialog
Q_OBJECT Q_OBJECT
public: public:
AddApp(bool isEdit = false, Record2 *orig_name_str=nullptr,QWidget* parent = nullptr); AddApp(bool isEdit = false, Record2 *row=nullptr,QWidget* parent = nullptr);
~AddApp(); ~AddApp();
QString get_exe_path() QString get_exe_path()
{ {

View File

@ -1,5 +1,8 @@
#include "addcategory.h" #include "addcategory.h"
#include <QString> #include <QString>
#include "config.h"
AddCategory::AddCategory(QWidget* parent) AddCategory::AddCategory(QWidget* parent)
: QDialog(parent) : QDialog(parent)
{ {
@ -9,21 +12,21 @@ AddCategory::AddCategory(QWidget* parent)
//connect(ui.submit, &QPushButton::click, this, &AddCategory::submit); //connect(ui.submit, &QPushButton::click, this, &AddCategory::submit);
QStringList title; QStringList title;
ui.tableWidget->setColumnCount(3); ui.tableWidget->setColumnCount(3);
title << QString::fromLocal8Bit("名称") << QString::fromLocal8Bit("显示") << QString::fromLocal8Bit("排序"); title << QString::fromLocal8Bit("名称") << QString::fromLocal8Bit("显示") << QString::fromLocal8Bit("排序");
ui.tableWidget->setHorizontalHeaderLabels(title); ui.tableWidget->setHorizontalHeaderLabels(title);
sqlite_helper.get_category(categrories,false); sqlite_helper.get_category(categrories,true);
ui.tableWidget->setRowCount(categrories.count()); ui.tableWidget->setRowCount(categrories.count());
int i = 0; int i = 0;
for(auto category : categrories) for(auto category : categrories)
{ {
ui.tableWidget->setItem(i, 0, new QTableWidgetItem(category.name)); ui.tableWidget->setItem(i, 0, new QTableWidgetItem(category.name));
if(category.id==1&&category.id==8) if(category.id==ALL||category.id==OTHERS||category.id==ELITE)
{ {
ui.tableWidget->item(i, 0)->setFlags(ui.tableWidget->item(i, 0)->flags() & (~Qt::ItemIsEditable)); ui.tableWidget->item(i, 0)->setFlags(ui.tableWidget->item(i, 0)->flags() & (~Qt::ItemIsEditable));
} }
QComboBox* combo_box = new QComboBox; QComboBox* combo_box = new QComboBox;
combo_box->addItem(QString::fromLocal8Bit("显示"), true); combo_box->addItem(QString::fromLocal8Bit("显示"), true);
combo_box->addItem(QString::fromLocal8Bit("不显示"), false); combo_box->addItem(QString::fromLocal8Bit("不显示"), false);
if(category.display==true) if(category.display==true)
{ {
combo_box->setCurrentIndex(0); combo_box->setCurrentIndex(0);
@ -36,7 +39,7 @@ AddCategory::AddCategory(QWidget* parent)
combo_boxes << combo_box; combo_boxes << combo_box;
i++; i++;
} }
//submit_btn = new QPushButton(QString::fromLocal8Bit("提交")); //submit_btn = new QPushButton(QString::fromLocal8Bit("提交"));
connect(ui.submit, &QPushButton::clicked, this, &AddCategory::submit); connect(ui.submit, &QPushButton::clicked, this, &AddCategory::submit);
} }
AddCategory::~AddCategory() AddCategory::~AddCategory()
@ -60,7 +63,7 @@ void AddCategory::submit()
categrory.sort = ui.tableWidget->item(i, 2)->text().toInt(&ok, 10); categrory.sort = ui.tableWidget->item(i, 2)->text().toInt(&ok, 10);
if(!ok) if(!ok)
{ {
QMessageBox::critical(this, QString::fromLocal8Bit("错误"), QString::fromLocal8Bit("排序列中有一行不是数字")); QMessageBox::critical(this, QString::fromLocal8Bit("错误"), QString::fromLocal8Bit("排序列中有一行不是数字"));
return; return;
} }
categrories_new << categrory; categrories_new << categrory;

View File

@ -1,30 +1,36 @@
#include "applicationmanager.h" #include "applicationmanager.h"
#include "applicationmanagerpage.h" #include "applicationmanagerpage.h"
#include "config.h" #include "config.h"
#include "addapp.h" #include "addapp.h"
#include "addcategory.h" #include "addcategory.h"
#include "sqlitehelper.h" #include "sqlitehelper.h"
#include "userimprove.h"
#include "globalvariables.h"
#include "netio.h"
#include <ctime> #include <ctime>
#include "globalvariables.h" #include "globalvariables.h"
#include "mainwindowlayout.h"
#include "MyButton.h"
ApplicationManager::ApplicationManager(QWidget *parent) ApplicationManager::ApplicationManager(QWidget *parent)
: QWidget(parent) : QWidget(parent)
{ {
application_manager = this;
ui.setupUi(this); ui.setupUi(this);
connect(this, &ApplicationManager::clickButton, mainWindowLayout, &MainWindowLayout::clickButton);
resize(parent->width(), parent->height()); resize(parent->width(), parent->height());
this->parent = parent; this->parent = parent;
miniblink = new QMiniBlink(this);
miniblink->init();
miniblink->show();
connect(this, &ApplicationManager::changeUrl, miniblink, &QMiniBlink::switchUrl);
layout = new QVBoxLayout(this); layout = new QVBoxLayout(this);
layout_top = new QHBoxLayout(this); layout_top_right = new QHBoxLayout(this);
layout_top->setAlignment(Qt::AlignRight); layout_top_right->setAlignment(Qt::AlignRight);
layout_top->setMargin(5); layout_top_right->setMargin(5);
layout_top= new QHBoxLayout(this);
layout_top_left = new QHBoxLayout(this);
layout_top_left->setMargin(0);
layout_top_left->setAlignment(Qt::AlignLeft);
layout_bottom = new QHBoxLayout(this); layout_bottom = new QHBoxLayout(this);
QList<Categrory> categrories; QList<Categrory> categrories;
sqlite_helper.get_category(categrories,false,true); sqlite_helper.get_category(categrories,false);
sqlite_helper.get_buttons(button_structs); sqlite_helper.get_buttons(button_structs);
for (auto button_struct : button_structs) for (auto button_struct : button_structs)
{ {
@ -36,8 +42,8 @@ ApplicationManager::ApplicationManager(QWidget *parent)
button->setMaximumHeight(TEXT_SIZE * scale * 3 + 20); button->setMaximumHeight(TEXT_SIZE * scale * 3 + 20);
//button->resize(TEXT_SIZE * button->text().length() * scale * 3 + 20, TEXT_SIZE * scale * 3 + 10); //button->resize(TEXT_SIZE * button->text().length() * scale * 3 + 20, TEXT_SIZE * scale * 3 + 10);
buttons << button; buttons << button;
layout_top->addWidget(button, 1); layout_top_right->addWidget(button, 1);
connect(button, &MiniButton::click0, button, &MiniButton::onclick1); connect(button, &MiniButton::clicked, button, &MiniButton::onclick1);
connect(button, &MiniButton::click1, this, &ApplicationManager::onclick1); connect(button, &MiniButton::click1, this, &ApplicationManager::onclick1);
} }
//ui.tabWidget->setStyleSheet("border:none;"); //ui.tabWidget->setStyleSheet("border:none;");
@ -49,24 +55,29 @@ ApplicationManager::ApplicationManager(QWidget *parent)
tab_bar = new QTabBar(this); tab_bar = new QTabBar(this);
layout_bottom_top = new QVBoxLayout; layout_bottom_top = new QVBoxLayout;
for(int i=1;i<=8;i++) for(int i=0;i<categrories.length();i++)
{ {
tab_bar->addTab(categrories[i - 1].name + "(" + QString::number(categrories[i - 1].total) + ")"); tab_bar->addTab(categrories[i].name + "(" + QString::number(categrories[i].total) + ")");
map2.insert(i, categrories[i].id);
} }
layout_bottom_top->addWidget(tab_bar, 1); layout_top_left->addWidget(tab_bar, 1);
layout_top->addLayout(layout_top_left, 7);
layout_top->addLayout(layout_top_right, 3);
application_manager_page_all = new ApplicationManagerPage(ALL, this, this); application_manager_page_all = new ApplicationManagerPage(ALL, this, this);
connect(this, &ApplicationManager::refresh, application_manager_page_all, &ApplicationManagerPage::refresh); connect(this, &ApplicationManager::refresh, application_manager_page_all, &ApplicationManagerPage::refresh);
layout_bottom_top->addWidget(application_manager_page_all, 19); layout_bottom_top->addWidget(application_manager_page_all, 19);
map.insert(1, application_manager_page_all); map.insert(ALL, application_manager_page_all);
for(int i=2;i<=8;i++) for(int i=2;i<=CATEGORIES_NUM;i++)
{ {
ApplicationManagerPage* application_manager_page = new ApplicationManagerPage(i, this, this); ApplicationManagerPage* application_manager_page = new ApplicationManagerPage(i, this, this);
connect(this, &ApplicationManager::refresh, application_manager_page, &ApplicationManagerPage::refresh); connect(this, &ApplicationManager::refresh, application_manager_page, &ApplicationManagerPage::refresh);
layout_bottom_top->addWidget(application_manager_page, 19); layout_bottom_top->addWidget(application_manager_page, 1);
application_manager_page->setHidden(true); application_manager_page->setHidden(true);
map.insert(i, application_manager_page); map.insert(i, application_manager_page);
} }
connect(this,&ApplicationManager::refresh,this,&ApplicationManager::onNumChange); //先不刷新创建完navbar再刷新
//emit refresh();
connect(this,&ApplicationManager::refresh_tab,this,&ApplicationManager::onNumChange);
tab_bar->setCurrentIndex(0); tab_bar->setCurrentIndex(0);
connect(tab_bar, &QTabBar::currentChanged, this, &ApplicationManager::tabChange); connect(tab_bar, &QTabBar::currentChanged, this, &ApplicationManager::tabChange);
QString style = "QTabBar::tab{height:80;width:150; border:2px} QTabBar::tab:hover{ border:2px;height:80;width:150;color:"; QString style = "QTabBar::tab{height:80;width:150; border:2px} QTabBar::tab:hover{ border:2px;height:80;width:150;color:";
@ -76,63 +87,7 @@ ApplicationManager::ApplicationManager(QWidget *parent)
style += ";}"; style += ";}";
tab_bar->setStyleSheet(style); tab_bar->setStyleSheet(style);
tab_bar->setDrawBase(false); tab_bar->setDrawBase(false);
/*ApplicationManagerPage* application_manager_page_all = new ApplicationManagerPage(ALL,this);
QHBoxLayout *application_manager_page_all_layout = new QHBoxLayout;
application_manager_page_all_layout->addWidget(application_manager_page_all);
pages.insert(application_manager_page_all_layout, application_manager_page_all);
ui.tab_1->setLayout(application_manager_page_all_layout);
ui.tabWidget->setTabText(0,QString::fromLocal8Bit("全部"));
ApplicationManagerPage* application_manager_page_elite = new ApplicationManagerPage(ELITE,this);
QHBoxLayout* application_manager_page_elite_layout = new QHBoxLayout;
application_manager_page_elite_layout->addWidget(application_manager_page_elite);
ui.tab_2->setLayout(application_manager_page_elite_layout);
pages.insert(application_manager_page_elite_layout, application_manager_page_elite);
ui.tabWidget->setTabText(1, categrories[0].name);
ApplicationManagerPage* application_manager_page_soft = new ApplicationManagerPage(SOFT,this);
QHBoxLayout* application_manager_page_soft_layout = new QHBoxLayout;
application_manager_page_soft_layout->addWidget(application_manager_page_soft);
pages.insert(application_manager_page_soft_layout, application_manager_page_soft);
ui.tab_3->setLayout(application_manager_page_soft_layout);
ui.tabWidget->setTabText(2, categrories[1].name);
ApplicationManagerPage* application_manager_page_system = new ApplicationManagerPage(SYSTEM,this);
QHBoxLayout* application_manager_page_system_layout = new QHBoxLayout;
application_manager_page_system_layout->addWidget(application_manager_page_system);
pages.insert(application_manager_page_system_layout, application_manager_page_system);
ui.tab_4->setLayout(application_manager_page_system_layout);
ui.tabWidget->setTabText(3, categrories[2].name);
ApplicationManagerPage* application_manager_page_inner = new ApplicationManagerPage(INNER,this);
QHBoxLayout* application_manager_page_inner_layout = new QHBoxLayout;
application_manager_page_inner_layout->addWidget(application_manager_page_inner);
pages.insert(application_manager_page_inner_layout, application_manager_page_inner);
ui.tab_5->setLayout(application_manager_page_inner_layout);
ui.tabWidget->setTabText(4, categrories[3].name);
ApplicationManagerPage* application_manager_page_custom_1 = new ApplicationManagerPage(CUSTOM_1, this);
QHBoxLayout* application_manager_page_custom_1_layout = new QHBoxLayout;
application_manager_page_custom_1_layout->addWidget(application_manager_page_custom_1);
pages.insert(application_manager_page_custom_1_layout, application_manager_page_custom_1);
ui.tab_6->setLayout(application_manager_page_custom_1_layout);
ui.tabWidget->setTabText(5, categrories[4].name);
ApplicationManagerPage* application_manager_page_custom_2 = new ApplicationManagerPage(CUSTOM_2, this);
QHBoxLayout* application_manager_page_custom_2_layout = new QHBoxLayout;
application_manager_page_custom_2_layout->addWidget(application_manager_page_custom_2);
pages.insert(application_manager_page_custom_2_layout, application_manager_page_custom_2);
ui.tab_7->setLayout(application_manager_page_custom_2_layout);
ui.tabWidget->setTabText(6, categrories[5].name);
ApplicationManagerPage* application_manager_page_others = new ApplicationManagerPage(OTHERS,this);
QHBoxLayout* application_manager_page_others_layout = new QHBoxLayout;
application_manager_page_others_layout->addWidget(application_manager_page_others);
pages.insert(application_manager_page_others_layout, application_manager_page_others);
ui.tab_8->setLayout(application_manager_page_others_layout);
ui.tabWidget->setTabText(7, categrories[6].name);*/
layout_bottom->addLayout(layout_bottom_top,7); layout_bottom->addLayout(layout_bottom_top,7);
layout_bottom->addWidget(miniblink, 3);
layout->addLayout(layout_top, 1); layout->addLayout(layout_top, 1);
layout->addLayout(layout_bottom, 9); layout->addLayout(layout_bottom, 9);
setLayout(layout); setLayout(layout);
@ -149,7 +104,8 @@ ApplicationManager::~ApplicationManager()
delete pages[layout]; delete pages[layout];
delete layout; delete layout;
} }
delete miniblink; delete layout_top_left;
delete layout_top_right;
delete layout_top; delete layout_top;
delete layout_bottom; delete layout_bottom;
delete layout; delete layout;
@ -165,97 +121,115 @@ void ApplicationManager::onclick1(QString op, QString func, QString path, QStrin
add_app.exec(); add_app.exec();
if(add_app.changed) if(add_app.changed)
{ {
bool ok = sqlite_helper.insert_software(add_app.get_name(), add_app.get_orig_name(), add_app.get_exe_path(), int ok = sqlite_helper.insert_software(add_app.get_name(), add_app.get_orig_name(), add_app.get_exe_path(),
add_app.get_sort(), add_app.get_categories()); add_app.get_sort(), add_app.get_categories());
if (!ok) if (!ok)
{ {
QMessageBox::critical(this, QString::fromLocal8Bit("错误"), QString::fromLocal8Bit("插入失败")); QMessageBox::critical(this, QString::fromLocal8Bit("错误"), QString::fromLocal8Bit("插入失败。"));
} }else if(ok==FIND)
emit refresh();
/*table->insertRow(table->rowCount()-1);
table->setItem(table->rowCount(), 0, new QTableWidgetItem(add_app.get_name()));
table->setItem(table->rowCount(), 1, new QTableWidgetItem(add_app.get_orig_name()));
Record2 record2;
srand(time(nullptr));
int id = rand();
if(id<RAND_MAX-100000)
{ {
id += 100000; QMessageBox::critical(this, QString::fromLocal8Bit("错误"), QString::fromLocal8Bit("已存在。"));
} }
record2.settings = new MiniButton(id, "settings"); emit refresh_tab();
record2.settings->setText(QString::fromLocal8Bit("设置"));
connect(record2.settings, &MiniButton::click0, record2.settings, &MiniButton::onclick2);
connect(record2.settings, &MiniButton::click2, this, &ApplicationManager::onclick2);
record2.open = new MiniButton(id, "open");
record2.open->setText(QString::fromLocal8Bit("打开"));
connect(record2.open, &MiniButton::click0, record2.open, &MiniButton::onclick2);
connect(record2.open, &MiniButton::click2, this, &ApplicationManager::onclick2);
record2.exe_file = add_app.get_exe_path();
record2.orig_name = add_app.get_orig_name();
table->setCellWidget(table->rowCount(), 4, record2.settings);
table->setCellWidget(table->rowCount(), 5, record2.open);
rows.insert(id, record2);*/
} }
} }
else if (func == "app_update") else if (func == "app_update")
{ {
bool software_ok = sqlite_helper.update_software(); bool software_ok = sqlite_helper.update_software();
bool app_ok = sqlite_helper.update_app(); bool app_ok = sqlite_helper.update_app();
if(software_ok&&app_ok) QFile file(QApplication::applicationDirPath() + DEFAULT_FILE);
if(file.open(QIODevice::ReadOnly))
{ {
QMessageBox::information(this, QString::fromLocal8Bit("提示"), QString::fromLocal8Bit("更新成功")); QByteArray ba = file.readAll();
file.close();
QJsonParseError json_error;
QJsonDocument jsonDoc(QJsonDocument::fromJson(ba, &json_error));
if (json_error.error == QJsonParseError::NoError)
{
QJsonObject rootObj = jsonDoc.object();
agree=rootObj.value("agree").toBool();
}
else
{
QMessageBox::critical(this, QString::fromLocal8Bit("错误"), QString::fromLocal8Bit("配置文件损坏"));
}
}else
{
UserImprove user_improve;
user_improve.exec();
if(file.open(QIODevice::WriteOnly|QIODevice::Text))
{
QJsonObject rootObj;
rootObj.insert("agree", agree);
QJsonDocument jsonDoc;
jsonDoc.setObject(rootObj);
file.write(jsonDoc.toJson());
file.close();
}
}
if(agree)
{
DeviceRequest *device_request = new DeviceRequest;//构造函数里面会自动发送请求
delete device_request;
}
if (software_ok && app_ok)
{
QMessageBox::information(this, QString::fromLocal8Bit("提示"), QString::fromLocal8Bit("更新成功"));
emit refresh_tab();
} }
else else
{ {
QMessageBox::critical(this, QString::fromLocal8Bit("错误"), QString::fromLocal8Bit("更新部分或全部失败")); QMessageBox::critical(this, QString::fromLocal8Bit("错误"), QString::fromLocal8Bit("更新部分或全部失败,全名是否重名?"));
} }
emit refresh();
}else if(func=="app_category") }else if(func=="app_category")
{ {
AddCategory add_category; AddCategory add_category;
add_category.exec(); add_category.exec();
if(add_category.changed) if(add_category.changed)
{ {
for(int i=0;i<7;i++) for(int i=0;i<add_category.categrories.length();i++)
{ {
tab_bar->setTabText(i + 1, add_category.categrories[i].name); tab_bar->setTabText(i + 1, add_category.categrories[i].name);
} }
bool ok = sqlite_helper.set_category(add_category.categrories); bool ok = sqlite_helper.set_category(add_category.categrories);
if (!ok) if (!ok)
{ {
QMessageBox::critical(this, QString::fromLocal8Bit("错误"), QString::fromLocal8Bit("添加失败")); QMessageBox::critical(this, QString::fromLocal8Bit("错误"), QString::fromLocal8Bit("添加失败,分类是否重名?"));
} }
emit refresh(); emit refresh_tab();
} }
} }
}else if(op=="soft") }else if(op=="soft")
{ {
emit changeUrl(url); emit clickButton("",op,func,url,path,"");
ShellExecute(GetDesktopWindow(), L"open", path.toStdWString().c_str(), L"", L"", SW_SHOW); //ShellExecute(GetDesktopWindow(), L"open", path.toStdWString().c_str(), L"", L"", SW_SHOW);
}else if(op=="app") }else if(op=="app")
{ {
emit changeUrl(url); emit clickButton("", op, func, url, path, "");
QString str = QApplication::applicationDirPath() + path; //QString str = QApplication::applicationDirPath() + path;
ShellExecute(GetDesktopWindow(), L"open",str.toStdWString().c_str(), L"", L"", SW_SHOW); //ShellExecute(GetDesktopWindow(), L"open",str.toStdWString().c_str(), L"", L"", SW_SHOW);
}else if(op=="url") }else if(op=="url")
{ {
emit changeUrl(url); //emit clickButton("", op, func, url, path, "");
emit clickButton("", op, func, url, path, "");
} }
} }
void ApplicationManager::onclick2(QString orig_name, QString op) void ApplicationManager::onclick2(QString orig_name, QString op)
{ {
sqlite_helper.use_software(orig_name);
if (op == "app") if (op == "app")
{ {
if (application_manager_page_all->rows[orig_name].func == "openwechat") { if (application_manager_page_all->rows[orig_name].func == "openwechat") {
emit application_manager_page_all->onclick3(application_manager_page_all->rows[orig_name].op, application_manager_page_all->rows[orig_name].func, application_manager_page_all->rows[orig_name].exe_file, application_manager_page_all->rows[orig_name].url); emit application_manager_page_all->onclick3(orig_name,application_manager_page_all->rows[orig_name].op, application_manager_page_all->rows[orig_name].func, application_manager_page_all->rows[orig_name].exe_file, application_manager_page_all->rows[orig_name].url);
} }
else { else {
emit changeUrl(application_manager_page_all->rows[orig_name].url); //emit changeUrl(application_manager_page_all->rows[orig_name].url);
WinExec((QApplication::applicationDirPath()+application_manager_page_all->rows[orig_name].exe_file).toStdString().c_str(), SW_SHOW); //WinExec((QApplication::applicationDirPath()+application_manager_page_all->rows[orig_name].exe_file).toStdString().c_str(), SW_SHOW);
emit clickButton("", op, application_manager_page_all->rows[orig_name].func, application_manager_page_all->rows[orig_name].url, application_manager_page_all->rows[orig_name].exe_file, "");
} }
} }
else if (op == "settings") else if (op == "settings")
@ -267,14 +241,14 @@ void ApplicationManager::onclick2(QString orig_name, QString op)
bool ok = sqlite_helper.edit_software(add_app.get_name(), add_app.get_orig_name(), add_app.get_exe_path(), add_app.get_sort(), add_app.get_categories()); bool ok = sqlite_helper.edit_software(add_app.get_name(), add_app.get_orig_name(), add_app.get_exe_path(), add_app.get_sort(), add_app.get_categories());
if (!ok) if (!ok)
{ {
QMessageBox::critical(this, QString::fromLocal8Bit("错误"), QString::fromLocal8Bit("编辑失败")); QMessageBox::critical(this, QString::fromLocal8Bit("错误"), QString::fromLocal8Bit("编辑失败"));
} }
emit refresh(); emit refresh_tab();
} }
} }
else { else {
emit application_manager_page_all->onclick3(application_manager_page_all->rows[orig_name].op, emit application_manager_page_all->onclick3(orig_name,application_manager_page_all->rows[orig_name].op,
application_manager_page_all->rows[orig_name].func, application_manager_page_all->rows[orig_name].func,
application_manager_page_all->rows[orig_name].url, application_manager_page_all->rows[orig_name].url,
application_manager_page_all->rows[orig_name].exe_file application_manager_page_all->rows[orig_name].exe_file
@ -289,13 +263,42 @@ void ApplicationManager::tabChange(int index)
{ {
map[i]->setHidden(true); map[i]->setHidden(true);
} }
map[index + 1]->setHidden(false); map[map2[index]]->setHidden(false);
} }
void ApplicationManager::onNumChange() { void ApplicationManager::onNumChange() {
QList<Categrory> categrories; int count = tab_bar->count();
sqlite_helper.get_category(categrories, false, true); disconnect(tab_bar, &QTabBar::currentChanged, this, &ApplicationManager::tabChange);
for (int i = 0; i < categrories.size(); i++) { for(int i=0;i<count;i++)
tab_bar->setTabText(i, categrories[i].name + "(" + QString::number(categrories[i].total) + ")"); {
tab_bar->removeTab(0);
} }
} for(auto i:map.values())
{
delete i;
}
application_manager_page_all = new ApplicationManagerPage(ALL, this, this);
connect(this, &ApplicationManager::refresh, application_manager_page_all, &ApplicationManagerPage::refresh);
layout_bottom_top->addWidget(application_manager_page_all, 19);
map.insert(ALL, application_manager_page_all);
for (int i = 2; i <= CATEGORIES_NUM; i++)
{
ApplicationManagerPage* application_manager_page = new ApplicationManagerPage(i, this, this);
connect(this, &ApplicationManager::refresh, application_manager_page, &ApplicationManagerPage::refresh);
layout_bottom_top->addWidget(application_manager_page, 1);
application_manager_page->setHidden(true);
map.insert(i, application_manager_page);
}
QList<Categrory> categories;
map2.clear();
sqlite_helper.get_category(categories,false);
for (int i = 0; i < categories.size(); i++) {
tab_bar->addTab(categories[i].name + "(" + QString::number(categories[i].total) + ")");
map2.insert(i, categories[i].id);
}
connect(tab_bar, &QTabBar::currentChanged, this, &ApplicationManager::tabChange);
tab_bar->setCurrentIndex(0);
emit refresh();
}
ApplicationManager *application_manager;

View File

@ -1,4 +1,4 @@
#pragma once #pragma once
#include <QWidget> #include <QWidget>
#include "sqlitehelper.h" #include "sqlitehelper.h"
@ -16,6 +16,8 @@
#include "ui_applicationmanager.h" #include "ui_applicationmanager.h"
#include <QTabBar> #include <QTabBar>
#include <QCheckBox> #include <QCheckBox>
#include "config.h"
class ApplicationManagerPage; class ApplicationManagerPage;
struct Record2 struct Record2
@ -24,7 +26,7 @@ struct Record2
QLabel *orig_name; QLabel *orig_name;
QLabel *dev; QLabel *dev;
QLabel *use_time;*/ QLabel *use_time;*/
QSvgWidget* icon; QLabel* icon;
MiniButton* settings; MiniButton* settings;
MiniButton * open; MiniButton * open;
QString op; QString op;
@ -33,9 +35,10 @@ struct Record2
QString orig_name; QString orig_name;
QString exe_file; QString exe_file;
QCheckBox *check_box; QCheckBox *check_box;
bool is_locked;
int sort; int sort;
QString url; QString url;
bool categories[8]; bool categories[CATEGORIES_NUM];
}; };
struct Title struct Title
@ -50,9 +53,11 @@ class ApplicationManager : public QWidget
{ {
Q_OBJECT Q_OBJECT
signals: signals:
void changeUrl(QString url); void clickButton(QString orig_name, QString op, QString func, QString url, QString path, QString initial_position);
void refresh(); void refresh();
void refresh_tab();
public: public:
QList<MiniButton*> buttons;
ApplicationManager(QWidget *parent = nullptr); ApplicationManager(QWidget *parent = nullptr);
~ApplicationManager(); ~ApplicationManager();
QWidget* parent; QWidget* parent;
@ -61,14 +66,16 @@ private:
QVBoxLayout* layout; QVBoxLayout* layout;
QTabBar *tab_bar; QTabBar *tab_bar;
QMap<int, ApplicationManagerPage*> map; QMap<int, ApplicationManagerPage*> map;
QMap<int,int> map2;
QHBoxLayout* layout_top; QHBoxLayout* layout_top;
QHBoxLayout* layout_bottom; QHBoxLayout* layout_bottom;
QMiniBlink* miniblink; QMiniBlink* miniblink;
QList<MiniButton*> buttons;
QList<Record> softwares; QList<Record> softwares;
QList<ButtonStruct> button_structs; QList<ButtonStruct> button_structs;
ApplicationManagerPage* application_manager_page_all; ApplicationManagerPage* application_manager_page_all;
Ui::ApplicationManagerClass ui; Ui::ApplicationManagerClass ui;
QHBoxLayout* layout_top_left;
QHBoxLayout* layout_top_right;
SQLiteHelper sqlite_helper; SQLiteHelper sqlite_helper;
QVBoxLayout *layout_bottom_top; QVBoxLayout *layout_bottom_top;
QTableWidget *table; QTableWidget *table;

View File

@ -1,4 +1,4 @@
#include "applicationmanagerpage.h" #include "applicationmanagerpage.h"
#include <QSvgRenderer> #include <QSvgRenderer>
#include <QPainter> #include <QPainter>
@ -12,20 +12,21 @@ ApplicationManagerPage::ApplicationManagerPage(int category, ApplicationManager
{ {
ui.setupUi(this); ui.setupUi(this);
this->category = category; this->category = category;
this->parent = parent;
this->application_manager = application_manager; this->application_manager = application_manager;
sqlite_helper.get_buttons(button_structs); sqlite_helper.get_buttons(button_structs);
layout = new QVBoxLayout; layout = new QVBoxLayout;
sqlite_helper.get_all_software(softwares, category); sqlite_helper.get_all_software(softwares, category);
table = new QTableWidget(this); table = new QTableWidget(this);
table->setColumnCount(8); table->setColumnCount(9);
QStringList titles; QStringList titles;
titles<< QString::fromLocal8Bit("图标") << QString::fromLocal8Bit("名称") << QString::fromLocal8Bit("全名") << QString::fromLocal8Bit("开发者") << QString::fromLocal8Bit("最后使用日期") << QString::fromLocal8Bit("添加到导航条") <<QString::fromLocal8Bit("设置") << QString::fromLocal8Bit("打开"); titles<< QString::fromLocal8Bit("图标") << QString::fromLocal8Bit("名称") << QString::fromLocal8Bit("全名") << QString::fromLocal8Bit("开发者") << QString::fromLocal8Bit("最后使用日期")<<QString::fromLocal8Bit("排序") << QString::fromLocal8Bit("添加到导航条") <<QString::fromLocal8Bit("设置") << QString::fromLocal8Bit("打开");
table->setHorizontalHeaderLabels(titles); table->setHorizontalHeaderLabels(titles);
table->setEditTriggers(QAbstractItemView::NoEditTriggers); table->setEditTriggers(QAbstractItemView::NoEditTriggers);
table->setStyleSheet("QTableWidget{border:1px;outline:1px;align: center;} QQTableWidget::widget QTableWidget::item {text-align: center;}"); table->setStyleSheet("QTableWidget{border:1px;outline:1px;align: center;} QQTableWidget::widget QTableWidget::item {text-align: center;}");
table->horizontalHeader()->setDefaultAlignment(Qt::AlignHCenter | Qt::AlignVCenter); table->horizontalHeader()->setDefaultAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
int i = 0; int i = 0;
for (i = 0; i < 8; i++) for (i = 0; i < 9; i++)
{ {
table->horizontalHeader()->setSectionResizeMode(i, QHeaderView::Stretch); table->horizontalHeader()->setSectionResizeMode(i, QHeaderView::Stretch);
@ -34,92 +35,6 @@ ApplicationManagerPage::ApplicationManagerPage(int category, ApplicationManager
QTableWidgetItem* item = new QTableWidgetItem; QTableWidgetItem* item = new QTableWidgetItem;
item->setTextAlignment(Qt::AlignCenter); item->setTextAlignment(Qt::AlignCenter);
table->setItemPrototype(item); table->setItemPrototype(item);
for (auto software : softwares)
{
table->insertRow(i);
table->setItem(i, 1, new QTableWidgetItem(software.name));
table->setItem(i, 2, new QTableWidgetItem(software.orig_name));
table->setItem(i, 3, new QTableWidgetItem(software.dev));
QString date;
std::tm* time;
time = std::localtime(&software.use_time);
date = QString::number(1900 + time->tm_year, 10);
date += "/";
date += QString::number(1 + time->tm_mon, 10);
date += "/";
date += QString::number(time->tm_mday, 10);
if (software.use_time == 0) {
date.clear();
}
table->setItem(i, 4, new QTableWidgetItem(date));
Record2 record2;
record2.name = software.name;
record2.icon = new QSvgWidget;
QFile file(software.logo);
if(file.exists())
{
record2.icon->load(software.logo);
}
else {
record2.icon->load(QApplication::applicationDirPath() + DEFAULT_IMAGE);
}
record2.icon->setMaximumSize(80, 80);
table->setCellWidget(i, 0, record2.icon);
record2.settings = new MiniButton(software.orig_name, "settings");
record2.settings->setText(QString::fromLocal8Bit("设置"));
record2.settings->setMaximumSize(60, 40);
connect(record2.settings, &MiniButton::click0, record2.settings, &MiniButton::onclick2);
connect(record2.settings, &MiniButton::click2, application_manager, &ApplicationManager::onclick2);
record2.open = new MiniButton(software.orig_name,software.op);
record2.open->setText(QString::fromLocal8Bit("打开"));
record2.open->setMaximumSize(60, 40);
connect(record2.open, &MiniButton::click0, record2.open, &MiniButton::onclick2);
connect(record2.open, &MiniButton::click2, application_manager, &ApplicationManager::onclick2);
record2.exe_file = software.path;
record2.orig_name = software.orig_name;
record2.url = software.url;
record2.op = software.op;
record2.func = software.func;
connect(this, &ApplicationManagerPage::onclick3, (MainWindowLayout*)((MainScreen*)application_manager->parent)->parent, &MainWindowLayout::clickButton);
for(int i=0;i<8;i++)
{
record2.categories[i] = false;
}
for(int i=0;i<8;i++)
{
if (software.category_id.contains(QString::number(i+1)))
{
record2.categories[i] = true;
}
}
record2.sort = software.sort;
record2.check_box = new QCheckBox;
if(software.type=="navbar")
{
record2.check_box->setCheckState(Qt::Checked);
checked.insert(software.orig_name, true);
}
else
{
record2.check_box->setCheckState(Qt::Unchecked);
checked.insert(software.orig_name, false);
}
connect(record2.check_box, &QCheckBox::clicked, this, &ApplicationManagerPage::onclicked);
QTableWidgetItem* check_box_item = new QTableWidgetItem;
table->setItem(i, 5, check_box_item);
table->setCellWidget(i, 5, record2.check_box);
check_box_item->setTextAlignment(Qt::AlignCenter);
table->setCellWidget(i, 6, record2.settings);
//table->item(i, 5)->setTextAlignment(Qt::AlignCenter);
table->setCellWidget(i, 7, record2.open);
//table->item(i, 6)->setTextAlignment(Qt::AlignCenter);
rows.insert(software.orig_name, record2);
table->resizeColumnToContents(0);
//table->item(i, 0)->setTextAlignment(Qt::AlignCenter);
//table->verticalHeader()->setSectionResizeMode(i, QHeaderView::ResizeToContents);
i++;
}
layout->addWidget(table); layout->addWidget(table);
setLayout(layout); setLayout(layout);
@ -134,11 +49,11 @@ ApplicationManagerPage::~ApplicationManagerPage()
delete layout; delete layout;
} }
void ApplicationManagerPage::onclicked() void ApplicationManagerPage::onclicked(int state)
{ {
for(int i=0;i<table->rowCount();i++) for(int i=0;i<table->rowCount();i++)
{ {
if(((QCheckBox *)table->cellWidget(i,5))->checkState()==Qt::Checked) if(((QCheckBox *)table->cellWidget(i,6))->checkState()==Qt::Checked)
{ {
if(!checked[table->item(i,2)->text()]) if(!checked[table->item(i,2)->text()])
{ {
@ -146,9 +61,10 @@ void ApplicationManagerPage::onclicked()
bool ok=sqlite_helper.edit_software(table->item(i, 1)->text(), orig_name, rows[orig_name].exe_file, QString::number(rows[orig_name].sort), rows[orig_name].categories,"navbar"); bool ok=sqlite_helper.edit_software(table->item(i, 1)->text(), orig_name, rows[orig_name].exe_file, QString::number(rows[orig_name].sort), rows[orig_name].categories,"navbar");
if(!ok) if(!ok)
{ {
QMessageBox::critical(this, QString::fromLocal8Bit("错误"), QString::fromLocal8Bit("更新部分或全部失败")); QMessageBox::critical(this, QString::fromLocal8Bit("错误"), QString::fromLocal8Bit("更新部分或全部失败"));
break; break;
} }
checked[table->item(i, 2)->text()] = true;
} }
}else }else
{ {
@ -158,18 +74,27 @@ void ApplicationManagerPage::onclicked()
bool ok = sqlite_helper.edit_software(table->item(i, 1)->text(), orig_name, rows[orig_name].exe_file, QString::number(rows[orig_name].sort), rows[orig_name].categories, "app"); bool ok = sqlite_helper.edit_software(table->item(i, 1)->text(), orig_name, rows[orig_name].exe_file, QString::number(rows[orig_name].sort), rows[orig_name].categories, "app");
if (!ok) if (!ok)
{ {
QMessageBox::critical(this, QString::fromLocal8Bit("错误"), QString::fromLocal8Bit("更新部分或全部失败")); QMessageBox::critical(this, QString::fromLocal8Bit("错误"), QString::fromLocal8Bit("更新部分或全部失败"));
break; break;
} }
checked[table->item(i, 2)->text()] = false;
} }
} }
} }
emit application_manager->refresh(); //在后面refresh避免因为refresh导致信号和槽断开
} }
//刷新页面
void ApplicationManagerPage::refresh() void ApplicationManagerPage::refresh()
{ {
for(auto button:application_manager->buttons)
{
button->update();
}
int rowcount = table->rowCount(); int rowcount = table->rowCount();
for(auto i : connections)
{
disconnect(i);
}
for(int i=0;i<rowcount;i++) for(int i=0;i<rowcount;i++)
{ {
table->removeRow(0); table->removeRow(0);
@ -197,37 +122,56 @@ void ApplicationManagerPage::refresh()
date += QString::number(time->tm_mday, 10); date += QString::number(time->tm_mday, 10);
table->setItem(i, 4, new QTableWidgetItem(date)); table->setItem(i, 4, new QTableWidgetItem(date));
} }
else
{
table->setItem(i, 4, new QTableWidgetItem(QString::fromLocal8Bit("从未使用")));
}
Record2 record2; Record2 record2;
record2.name = software.name; record2.name = software.name;
record2.icon = new QSvgWidget; record2.icon = new QLabel;
QFile file(software.logo); QFile file(software.img);
record2.icon->setMaximumSize(50, 50);
record2.icon->setScaledContents(true);
if (file.exists()) if (file.exists())
{ {
record2.icon->load(software.logo); QPixmap pixmap(software.img);
//pixmap.scaled(40, 40);
record2.icon->setPixmap(pixmap);
} }
else { else {
record2.icon->load(QApplication::applicationDirPath() + DEFAULT_IMAGE); QPixmap pixmap(QApplication::applicationDirPath() + DEFAULT_PNG);
//pixmap.scaled(40, 40);
record2.icon->setPixmap(pixmap);
} }
record2.icon->setMaximumSize(80, 80);
table->setCellWidget(i, 0, record2.icon); table->setCellWidget(i, 0, record2.icon);
record2.settings = new MiniButton(software.orig_name, "settings");
record2.settings->setText(QString::fromLocal8Bit("设置")); if(!software.locked)
record2.settings->setMaximumSize(60, 40); {
connect(record2.settings, &MiniButton::click0, record2.settings, &MiniButton::onclick2); record2.settings = new MiniButton(software.orig_name, "settings");
connect(record2.settings, &MiniButton::click2, application_manager, &ApplicationManager::onclick2); record2.settings->setText(QString::fromLocal8Bit("设置"));
record2.settings->setMaximumSize(60, 40);
QMetaObject::Connection connect1 = connect(record2.settings, &MiniButton::clicked, record2.settings, &MiniButton::onclick2);
connections << connect1;
QMetaObject::Connection connect2 = connect(record2.settings, &MiniButton::click2, application_manager, &ApplicationManager::onclick2);
connections << connect2;
table->setCellWidget(i, 7, record2.settings);
}
record2.open = new MiniButton(software.orig_name, "open"); record2.open = new MiniButton(software.orig_name, "open");
record2.open->setText(QString::fromLocal8Bit("打开")); record2.open->setText(QString::fromLocal8Bit("打开"));
record2.open->setMaximumSize(60, 40); record2.open->setMaximumSize(60, 40);
connect(record2.open, &MiniButton::click0, record2.open, &MiniButton::onclick2); QMetaObject::Connection connect3=connect(record2.open, &MiniButton::clicked, record2.open, &MiniButton::onclick2);
connect(record2.open, &MiniButton::click2, application_manager, &ApplicationManager::onclick2); connections << connect3;
QMetaObject::Connection connect4=connect(record2.open, &MiniButton::click2, application_manager, &ApplicationManager::onclick2);
connections << connect4;
record2.exe_file = software.path; record2.exe_file = software.path;
record2.orig_name = software.orig_name; record2.orig_name = software.orig_name;
record2.url = software.url; record2.url = software.url;
for (int i = 0; i < 8; i++) for (int i = 0; i < CATEGORIES_NUM; i++)
{ {
record2.categories[i] = false; record2.categories[i] = false;
} }
for (int i = 0; i < 8; i++) for (int i = 0; i < CATEGORIES_NUM; i++)
{ {
if (software.category_id.contains(QString::number(i+1))) if (software.category_id.contains(QString::number(i+1)))
{ {
@ -236,10 +180,11 @@ void ApplicationManagerPage::refresh()
} }
record2.op = software.op; record2.op = software.op;
record2.func = software.func; record2.func = software.func;
connect(this, &ApplicationManagerPage::onclick3, (MainWindowLayout*)((MainScreen*)application_manager->parent)->parent, &MainWindowLayout::clickButton); QMetaObject::Connection connect5 = connect(this, &ApplicationManagerPage::onclick3, (MainWindowLayout*)((MainScreen*)application_manager->parent)->parent, &MainWindowLayout::clickButton);
connections<<connect5;
record2.sort = software.sort; record2.sort = software.sort;
record2.check_box = new QCheckBox; record2.check_box = new QCheckBox;
if (software.type == "navbar") if (software.is_navbar)
{ {
record2.check_box->setCheckState(Qt::Checked); record2.check_box->setCheckState(Qt::Checked);
checked.insert(software.orig_name, true); checked.insert(software.orig_name, true);
@ -249,19 +194,27 @@ void ApplicationManagerPage::refresh()
record2.check_box->setCheckState(Qt::Unchecked); record2.check_box->setCheckState(Qt::Unchecked);
checked.insert(software.orig_name, false); checked.insert(software.orig_name, false);
} }
connect(record2.check_box, &QCheckBox::clicked, this, &ApplicationManagerPage::onclicked); if(software.locked)
{
record2.check_box->setEnabled(false);
}
else
{
record2.check_box->setEnabled(true);
}
QMetaObject::Connection connect6 = connect(record2.check_box, &QCheckBox::stateChanged, this, &ApplicationManagerPage::onclicked);
connections << connect6;
QMetaObject::Connection connect7 = connect(record2.check_box, &QCheckBox::stateChanged, mainWindowLayout->navBar, &NavBar::refresh);
connections << connect7;
table->setItem(i, 5, new QTableWidgetItem(QString::number(software.sort)));
QTableWidgetItem* check_box_item = new QTableWidgetItem; QTableWidgetItem* check_box_item = new QTableWidgetItem;
table->setItem(i, 5, check_box_item); table->setItem(i, 6, check_box_item);
table->setCellWidget(i, 5, record2.check_box); table->setCellWidget(i, 6, record2.check_box);
check_box_item->setTextAlignment(Qt::AlignCenter); check_box_item->setTextAlignment(Qt::AlignCenter);
table->setCellWidget(i, 6, record2.settings); table->setCellWidget(i, 8, record2.open);
//table->item(i, 5)->setTextAlignment(Qt::AlignCenter);
table->setCellWidget(i, 7, record2.open);
//table->item(i, 6)->setTextAlignment(Qt::AlignCenter);
rows.insert(software.orig_name, record2); rows.insert(software.orig_name, record2);
table->resizeColumnToContents(0); table->resizeColumnToContents(0);
//table->item(i, 0)->setTextAlignment(Qt::AlignCenter);
//table->verticalHeader()->setSectionResizeMode(i, QHeaderView::ResizeToContents);
i++; i++;
} }
} }

View File

@ -1,4 +1,4 @@
#pragma once #pragma once
#include <QTableWidget> #include <QTableWidget>
#include <QVBoxLayout> #include <QVBoxLayout>
@ -17,7 +17,7 @@ class ApplicationManagerPage : public QWidget
{ {
Q_OBJECT Q_OBJECT
signals: signals:
void onclick3(QString op, QString func, QString url, QString path,QString initial_position=""); void onclick3(QString orig_name,QString op, QString func, QString url, QString path,QString initial_position="");
public: public:
ApplicationManagerPage(int category, ApplicationManager *application_manager,QWidget *parent = nullptr); ApplicationManagerPage(int category, ApplicationManager *application_manager,QWidget *parent = nullptr);
~ApplicationManagerPage(); ~ApplicationManagerPage();
@ -28,6 +28,7 @@ private:
QVBoxLayout* layout; QVBoxLayout* layout;
QHBoxLayout* layout_top; QHBoxLayout* layout_top;
QHBoxLayout* layout_bottom; QHBoxLayout* layout_bottom;
QList<QMetaObject::Connection> connections;
QMiniBlink* miniblink; QMiniBlink* miniblink;
QList<MiniButton*> buttons; QList<MiniButton*> buttons;
QList<Record> softwares; QList<Record> softwares;
@ -39,7 +40,8 @@ private:
ApplicationManager* application_manager; ApplicationManager* application_manager;
Title *title; Title *title;
int category; int category;
QWidget *parent;
public slots: public slots:
void refresh(); void refresh();
void onclicked(); void onclicked(int state);
}; };

View File

@ -1,4 +1,4 @@
// //
// Created by HW on 2023/07/26. // Created by HW on 2023/07/26.
// //
@ -9,6 +9,7 @@
typedef struct taButtonStruct{ typedef struct taButtonStruct{
QImage *image; QImage *image;
QImage *image_cover; QImage *image_cover;
QImage *png;
QString text; QString text;
QString orig_name; QString orig_name;
QString url; QString url;

View File

@ -1,37 +1,39 @@
//
// Created by 孙羽 on 2023/07/27.
// //
// Created by 孙羽 on 2023/07/27. //说明:没有注释的项请勿修改
//
//说明:没有注释的项请勿修改
#ifndef OFFICEASSISTANT_CONFIG_H #ifndef OFFICEASSISTANT_CONFIG_H
#define OFFICEASSISTANT_CONFIG_H #define OFFICEASSISTANT_CONFIG_H
#define CONFIG_URL "http://softapi.s103.y01.cn/addons/Kmdsoft/Index/config" //获取导航栏信息的地址 #define CONFIG_URL "http://softapi.s103.y01.cn/addons/Kmdsoft/Index/config" //获取导航栏信息的地址
#define OP_URL "http://softapi.s103.y01.cn/addons/Kmdsoft/Index/op" //上传是否设置开机启动、是否建立桌面快捷方式的地址 #define OP_URL "http://softapi.s103.y01.cn/addons/Kmdsoft/Index/op" //上传是否设置开机启动、是否建立桌面快捷方式的地址
#define DEVICE_URL "http://softapi.s103.y01.cn/addons/Kmdsoft/Index/device" //上传设备信息的地址 #define DEVICE_URL "http://softapi.s103.y01.cn/addons/Kmdsoft/Index/device" //上传设备信息的地址
#define WECHAT_URL " http://softapi.s103.y01.cn/addons/Kmdsoft/Wxdk/open" #define WECHAT_URL "http://softapi.s103.y01.cn/addons/Kmdsoft/Wxdk/open"
#define BASE_URL "http://softapi.s103.y01.cn/" //域名 #define BASE_URL "http://softapi.s103.y01.cn/" //域名
#define DEFAULT_FILE "/config/config.kmd" //默认配置文件位置 #define DEFAULT_FILE "/config/config.kmd" //默认配置文件位置
#define DEFAULT_NAVBAR_FILLE "/config/default_navbar.kmd" #define DEFAULT_NAVBAR_FILLE "/config/default_navbar.kmd"
#define KEY "3b046cfe4a2a3e62141a4840f2006210a3224e3615312bef6e19f4983921abe0" //Key #define KEY "3b046cfe4a2a3e62141a4840f2006210a3224e3615312bef6e19f4983921abe0" //Key
#define NAME "办公助手" //中文名 #define NAME "办公助手" //中文名
#define LOGO_TITLEBAR "/images/icon/logo_navbar.png" //标题栏图标 #define LOGO_TITLEBAR "/images/logo_titlebar.png" //标题栏图标
#define ENG_NAME "OfficeAssistant" //英文名 #define ENG_NAME "OfficeAssistant" //英文名
#define LENG_NAME L"OfficeAssistant" //英文名(宽字符) #define LENG_NAME L"OfficeAssistant" //英文名(宽字符)
#define ADD_AUTOSTART 1 #define ADD_AUTOSTART 1
#define ADD_SHORTCUT 2 #define ADD_SHORTCUT 2
#define VERSION "1.0.0" //软件版本 #define VERSION "1.0.0" //软件版本
#define RELEASE "20230801" //Release #define RELEASE "20230801" //Release
#define SOFTWARE_URL "http://softapi.s103.y01.cn/addons/Kmdsoft/App/update/type/add" #define SOFTWARE_URL "http://softapi.s103.y01.cn/addons/Kmdsoft/App/update/type/add"
#define DEFAULT_BACKGROUND_COLOR "#333332" //默认背景色,若从服务器读不到即使用这个 #define DEFAULT_BACKGROUND_COLOR "#333332" //默认背景色,若从服务器读不到即使用这个
#define DEFAULT_COLOR "#3399FF" // #define DEFAULT_COLOR "#3399FF" //
#define DEFAULT_TEXT_COLOR "#FFFFFF" //默认文字颜色 #define DEFAULT_TEXT_COLOR "#FFFFFF" //默认文字颜色
#define DEFAULT_COVER_COLOR "#0033FF" //鼠标指向后变成的颜色,也是“添加应用”等几个按钮的默认颜色 #define DEFAULT_COVER_COLOR "#0033FF" //鼠标指向后变成的颜色,也是“添加应用”等几个按钮的默认颜色
#define DEFAULT_IMAGE "/images/svg/default.svg" //默认图标 #define DEFAULT_IMAGE "/images/svg/default.svg" //默认图标
#define DEFAULT_SVG_PATH "/images/svg/" #define DEFAULT_SVG_PATH "/images/svg/"
#define DEFAULT_LOGO "/images/logo.png" //logo路径 #define DEFAULT_LOGO "/images/logo.png" //logo路径
#define TITLE " " //标题栏 #define DEFAULT_PNG_PATH "/images/png/" //png路径
#define TEXT_SIZE 7 //字体大小。不是所有字体受此项控制 #define TITLE " " //标题栏
#define TEXT_SIZE 7 //字体大小。不是所有字体受此项控制
#define DEFAULT_PNG "/images/png/default.png" //默认PNG图标
#define TEXT_SIZE_BIG 10 #define TEXT_SIZE_BIG 10
//分类 //分类
#define ALL 1 #define ALL 1
#define ELITE 2 #define ELITE 2
#define SOFT 3 #define SOFT 3
@ -40,4 +42,7 @@
#define CUSTOM_1 6 #define CUSTOM_1 6
#define CUSTOM_2 7 #define CUSTOM_2 7
#define OTHERS 8 #define OTHERS 8
#define CATEGORIES_NUM 8
#define FIND 2
#endif //OFFICEASSISTANT_CONFIG_H #endif //OFFICEASSISTANT_CONFIG_H

View File

@ -1,10 +1,11 @@
// //
// Created by HW on 2023/07/27. // Created by HW on 2023/07/27.
// //
#ifndef OFFICEASSISTANT_GLOBALVARIABLES_H #ifndef OFFICEASSISTANT_GLOBALVARIABLES_H
#define OFFICEASSISTANT_GLOBALVARIABLES_H #define OFFICEASSISTANT_GLOBALVARIABLES_H
#include "exitmanager.h" #include "exitmanager.h"
class ApplicationManager;
class MainWindowLayout; class MainWindowLayout;
extern ExitManager exit_manager; extern ExitManager exit_manager;
extern double scale; extern double scale;
@ -12,4 +13,8 @@ extern MainWindowLayout *mainWindowLayout;
extern QString url_param; extern QString url_param;
extern bool autostart; extern bool autostart;
extern bool agree; extern bool agree;
extern QString background_color;
extern QString text_color;
extern QString text_cover_color;
extern ApplicationManager *application_manager;
#endif //OFFICEASSISTANT_GLOBALVARIABLES_H #endif //OFFICEASSISTANT_GLOBALVARIABLES_H

Binary file not shown.

View File

@ -1,4 +1,4 @@
// //
// Created by HW on 2023/07/27. // Created by HW on 2023/07/27.
// //
@ -34,7 +34,7 @@ MainScreen::MainScreen(QWidget *parent) :
button->setStyleSheet("border-style:none;padding:10px;border-radius:5px;background-color:#09bb07;color:white;font-family:SimHei"); button->setStyleSheet("border-style:none;padding:10px;border-radius:5px;background-color:#09bb07;color:white;font-family:SimHei");
//Plus Math icon by Icons8 //Plus Math icon by Icons8
QString dir = QApplication::applicationDirPath(); QString dir = QApplication::applicationDirPath();
button->setText(QString::fromLocal8Bit("打开微信")); button->setText(QString::fromLocal8Bit("打开微信"));
//button->setStyleSheet("text-color:white"); //button->setStyleSheet("text-color:white");
layout = new QHBoxLayout; layout = new QHBoxLayout;
miniblink = new QMiniBlink(this); miniblink = new QMiniBlink(this);
@ -80,31 +80,43 @@ MainScreen::~MainScreen() {
void MainScreen::firstUrl(QString url) void MainScreen::firstUrl(QString url)
{ {
QString url_full; QString url_full;
if (url.contains("http")) if (url.isEmpty())
{ {
url_full = url; url_full = "";
}
else if (url.contains("?"))
{
url_full = BASE_URL + url + url_param;
emit changeUrl(url_full);
} }
else else
{ {
url_full = BASE_URL + url + url_param; url_full = BASE_URL + url + "?" + url_param;
emit changeUrl(url_full);
} }
emit changeUrl(url_full);
} }
void MainScreen::clickButton1(QString op,QString url) { void MainScreen::clickButton1(QString op,QString url) {
QString url_full; QString url_full;
if(url.contains("http")) if (url.isEmpty())
{ {
url_full = url; url_full = "";
}else }
else if (url.contains("?"))
{ {
url_full = BASE_URL + url + url_param; url_full = BASE_URL + url + url_param;
emit changeUrl(url_full);
}
else
{
url_full = BASE_URL + url + "?" + url_param;
emit changeUrl(url_full);
} }
if (op == "openwechat") { if (op == "openwechat") {
OpenWeChatRequest open_wechat_request; OpenWeChatRequest open_wechat_request;
QString msg = open_wechat_request.sendRequest(); QString msg = open_wechat_request.sendRequest();
if(msg!="ok") if(msg!="ok")
{ {
QMessageBox::information(this, QString::fromLocal8Bit("提示"), msg); QMessageBox::information(this, QString::fromLocal8Bit("提示"), msg);
return; return;
} }
widget->setHidden(false); widget->setHidden(false);

View File

@ -1,4 +1,4 @@
// //
// Created by HW on 2023/07/27. // Created by HW on 2023/07/27.
// //
@ -27,6 +27,7 @@ public:
explicit MainScreen(QWidget *parent = nullptr); explicit MainScreen(QWidget *parent = nullptr);
~MainScreen() override; ~MainScreen() override;
QWidget* parent; QWidget* parent;
ApplicationManager* application_manager;
public slots: public slots:
void clickButton1(QString op, QString url); void clickButton1(QString op, QString url);
void firstUrl(QString url); void firstUrl(QString url);
@ -38,7 +39,6 @@ private:
QVBoxLayout *layout_left; QVBoxLayout *layout_left;
QPushButton *button; QPushButton *button;
QIcon *icon; QIcon *icon;
ApplicationManager* application_manager;
QWidget *broswer; QWidget *broswer;
static bool isInited(); static bool isInited();
QWidget *widget; QWidget *widget;

View File

@ -1,4 +1,4 @@
// //
// Created by HW on 2023/07/26. // Created by HW on 2023/07/26.
// //
@ -25,92 +25,7 @@ MainWindow::MainWindow(QWidget *parent) :
icon = new QIcon(path); icon = new QIcon(path);
setWindowIcon(*icon); setWindowIcon(*icon);
setStyleSheet("*{font-family:SimHei;}"); setStyleSheet("*{font-family:SimHei;}");
QFile file(QApplication::applicationDirPath() + DEFAULT_FILE);
if(!file.open(QIODevice::Text|QIODevice::ReadOnly))
{
QMessageBox::warning(nullptr, QString::fromLocal8Bit("错误"), QString::fromLocal8Bit("无法打开配置文件"));
exit_manager.exit(1);
}
QByteArray buffer;
buffer = file.readAll();
file.close();
QJsonDocument document = QJsonDocument::fromJson(buffer);
if(document.isObject())
{
if(document.object().value("agree").isUndefined())
{
QMessageBox msg;
msg.setWindowTitle(QString::fromLocal8Bit("用户体验改善计划"));
msg.setText(QString::fromLocal8Bit("为改善我们的服务质量,我们将向服务器发送以下信息:\n"
"1.您的计算机配置;\n"
"2.您计算机上的软件安装列表;\n"
"3.您是否设置了开机启动,以及是不是通过开机启动的方式启动本软件。\n"
"第二项信息是我们提供服务所必需的,如您选择不同意但继续使用本软件,则第二项数据将正常发送,但第一项和第三项数据不会发送。选择不同意不影响您使用本软件。"));
msg.addButton(QString::fromLocal8Bit("同意"), QMessageBox::AcceptRole);
msg.addButton(QString::fromLocal8Bit("不同意"), QMessageBox::RejectRole);
int ret = msg.exec();
if(ret==QMessageBox::AcceptRole)
{
QJsonObject obj_root = document.object();
obj_root.insert("agree", true);
document.setObject(obj_root);
agree = true;
DeviceRequest* device_request = new DeviceRequest;//构造函数直接发出去数据了
delete device_request;
}else
{
QJsonObject obj_root = document.object();
obj_root.insert("agree", false);
document.setObject(obj_root);
agree = false;
}
if(file.open(QIODevice::WriteOnly|QIODevice::Text))
{
file.write(document.toJson());
file.close();
}
}
else if(document.object().value("agree").toBool())
{
agree = true;
DeviceRequest* device_request = new DeviceRequest;
delete device_request;
}
}
else
{
QMessageBox msg;
msg.setWindowTitle(QString::fromLocal8Bit("用户体验改善计划"));
msg.setText(QString::fromLocal8Bit("为改善我们的服务质量,我们将向服务器发送以下信息:\n"
"1.您的计算机配置;\n"
"2.您计算机上的软件安装列表;\n"
"3.您是否设置了开机启动,以及是不是通过开机启动的方式启动本软件。\n"
"第二项信息是我们提供服务所必需的,如您选择不同意但继续使用本软件,则第二项数据将正常发送,但第一项和第三项数据不会发送。选择不同意不影响您使用本软件。"));
msg.addButton(QString::fromLocal8Bit("同意"), QMessageBox::AcceptRole);
msg.addButton(QString::fromLocal8Bit("不同意"), QMessageBox::RejectRole);
int ret = msg.exec();
if (ret == QMessageBox::AcceptRole)
{
QJsonObject obj_root;
obj_root.insert("agree", true);
document.setObject(obj_root);
agree = true;
DeviceRequest* device_request = new DeviceRequest;//构造函数直接发出去数据了
delete device_request;
}
else
{
QJsonObject obj_root;
obj_root.insert("agree", false);
document.setObject(obj_root);
agree = false;
}
if (file.open(QIODevice::WriteOnly | QIODevice::Text))
{
file.write(document.toJson());
file.close();
}
}
} }
MainWindow::~MainWindow() { MainWindow::~MainWindow() {

View File

@ -1,4 +1,4 @@
// //
// Created by HW on 2023/07/26. // Created by HW on 2023/07/26.
// //
@ -17,14 +17,11 @@ MainWindowLayout::MainWindowLayout(QWidget *parent) :
mainWindowLayout = this; mainWindowLayout = this;
QList<ButtonStruct> list; QList<ButtonStruct> list;
mainScreen = new MainScreen(this); mainScreen = new MainScreen(this);
navBar=new NavBar(mainScreen,this); navBar = new NavBar(mainScreen, this);
emit mainScreen->application_manager->refresh_tab();
navBar->setMinimumHeight(0); navBar->setMinimumHeight(0);
navBar->setMaximumHeight(this->height() / 8); navBar->setMaximumHeight(this->height() / 8);
mainScreen->setMinimumHeight(0); mainScreen->setMinimumHeight(0);
//navBar->setAttribute(Qt::WA_DeleteOnClose);
//QSizePolicy sizePolicy(QSizePolicy::Policy::Fixed, QSizePolicy::QSizePolicy::Fixed);
//navBar->setSizePolicy(sizePolicy);
//layout->setContentsMargins(0, 0, 0, 0);
layout->addWidget(navBar,1); layout->addWidget(navBar,1);
layout->addWidget(mainScreen,7); layout->addWidget(mainScreen,7);
layout->setMargin(0); layout->setMargin(0);
@ -48,7 +45,10 @@ void MainWindowLayout::resizeEvent(QResizeEvent *event) {
//layout->setAlignment(Qt::AlignmentFlag::AlignHCenter); //layout->setAlignment(Qt::AlignmentFlag::AlignHCenter);
} }
void MainWindowLayout::clickButton(QString op, QString func, QString url,QString path,QString initial_position) { void MainWindowLayout::clickButton(QString orig_name,QString op, QString func, QString url,QString path,QString initial_position) {
SQLiteHelper sqlite_helper;
sqlite_helper.use_software(orig_name);
emit mainScreen->application_manager->refresh();
QString root_path = QApplication::applicationDirPath(); QString root_path = QApplication::applicationDirPath();
if(op=="app") if(op=="app")
{ {
@ -59,7 +59,7 @@ void MainWindowLayout::clickButton(QString op, QString func, QString url,QString
{ {
path = root_path + path; path = root_path + path;
path.replace("/", "\\"); path.replace("/", "\\");
WinExec(path.toStdString().c_str(), SW_SHOW); ShellExecute(GetDesktopWindow(), L"open", path.toStdWString().c_str(), L"", initial_position.toStdWString().c_str(), SW_SHOW);
emit clickButton1(op, url); emit clickButton1(op, url);
} }
} }
@ -76,7 +76,9 @@ void MainWindowLayout::clickButton(QString op, QString func, QString url,QString
} }
} }
else if(op=="soft"){ else if(op=="soft"){
ShellExecute(GetDesktopWindow(), L"open",path.toStdWString().c_str(),L"",initial_position.toStdWString().c_str(),SW_SHOW); path.replace("/", "\\");
initial_position.replace("/", "\\");
WinExec(path.toStdString().c_str(), SW_SHOW);
emit clickButton1(op, url); emit clickButton1(op, url);
}else }else
{ {

View File

@ -1,4 +1,4 @@

// //
// Created by HW on 2023/07/26. // Created by HW on 2023/07/26.
// //
@ -22,10 +22,10 @@ signals:
void clickButton1(QString op,QString url); void clickButton1(QString op,QString url);
public: public:
explicit MainWindowLayout(QWidget *parent = nullptr); explicit MainWindowLayout(QWidget *parent = nullptr);
NavBar* navBar;
~MainWindowLayout() override; ~MainWindowLayout() override;
public slots: public slots:
void clickButton(QString op, QString func, QString url, QString path, QString initial_position); void clickButton(QString orig_name,QString op, QString func, QString url, QString path, QString initial_position);
protected: protected:
void resizeEvent(QResizeEvent *event) override; void resizeEvent(QResizeEvent *event) override;
//void paintEvent(QPaintEvent *event) override; //void paintEvent(QPaintEvent *event) override;
@ -34,7 +34,6 @@ private:
Ui::MainWindowLayout *ui; Ui::MainWindowLayout *ui;
QVBoxLayout *layout; QVBoxLayout *layout;
//QList<ButtonStruct *> list; //QList<ButtonStruct *> list;
NavBar *navBar;
ButtonStruct *buttons; ButtonStruct *buttons;
MainScreen *mainScreen; MainScreen *mainScreen;
ConfigResponse *configResponse; ConfigResponse *configResponse;

View File

@ -1,4 +1,4 @@
#include "minibutton.h" #include "minibutton.h"
#include <QPainter> #include <QPainter>
#include "config.h" #include "config.h"
#include "globalvariables.h" #include "globalvariables.h"
@ -6,7 +6,6 @@
MiniButton::MiniButton(QString orig_name, QString op, QWidget* parent) MiniButton::MiniButton(QString orig_name, QString op, QWidget* parent)
{ {
this->orig_name = orig_name; this->orig_name = orig_name;
q_color.setNamedColor(DEFAULT_BACKGROUND_COLOR);
this->op = op; this->op = op;
connect(this, &MiniButton::click, this, &MiniButton::onclick2); connect(this, &MiniButton::click, this, &MiniButton::onclick2);
@ -15,11 +14,6 @@ MiniButton::MiniButton(ButtonStruct button_struct, QWidget *parent)
: QPushButton(parent) : QPushButton(parent)
{ {
ui.setupUi(this); ui.setupUi(this);
q_color.setNamedColor(DEFAULT_COVER_COLOR);
QString style_sheet = "MiniButton:{background-color:";
style_sheet += DEFAULT_TEXT_COLOR;
style_sheet += ";}";
setStyleSheet(style_sheet);
connect(this, &MiniButton::click, this, &MiniButton::onclick1); connect(this, &MiniButton::click, this, &MiniButton::onclick1);
this->button_struct = button_struct; this->button_struct = button_struct;
} }
@ -33,22 +27,19 @@ void MiniButton::paintEvent(QPaintEvent* event)
setContentsMargins(0, 0, 0, 0); setContentsMargins(0, 0, 0, 0);
QRect rect(0, 0, this->width(), this->height()); QRect rect(0, 0, this->width(), this->height());
QPainter painter(this); QPainter painter(this);
q_color.setNamedColor(background_color);
painter.fillRect(rect, q_color); painter.fillRect(rect, q_color);
int text_x = (width() - TEXT_SIZE * text().length() * scale * 3) / 2; int text_x = (width() - TEXT_SIZE * text().length() * scale * 3) / 2;
int text_y = (height()- TEXT_SIZE * scale * 3)/2; int text_y = (height()- TEXT_SIZE * scale * 3)/2;
QFont ft; QFont ft;
ft.setPixelSize(TEXT_SIZE); ft.setPixelSize(TEXT_SIZE);
QRectF text_rect(text_x, text_y, TEXT_SIZE * text().length() * scale * 3, TEXT_SIZE * scale * 3); QRectF text_rect(text_x, text_y, TEXT_SIZE * text().length() * scale * 3, TEXT_SIZE * scale * 3);
painter.setPen(DEFAULT_TEXT_COLOR); painter.setPen(text_color);
painter.drawText(text_rect, Qt::AlignCenter, text()); painter.drawText(text_rect, Qt::AlignCenter, text());
} }
void MiniButton::mouseReleaseEvent(QMouseEvent* event)
{
emit click0();
}
void MiniButton::onclick1() void MiniButton::onclick1()
{ {

View File

@ -1,4 +1,4 @@
#pragma once #pragma once
#include <QPushButton> #include <QPushButton>
@ -18,7 +18,6 @@ public:
~MiniButton(); ~MiniButton();
protected: protected:
void paintEvent(QPaintEvent* event) override; void paintEvent(QPaintEvent* event) override;
void mouseReleaseEvent(QMouseEvent* event) override;
private: private:
QString orig_name; QString orig_name;
QString op; QString op;

View File

@ -1,4 +1,4 @@
#include "mysettingsdialog.h" #include "mysettingsdialog.h"
#include <Windows.h> #include <Windows.h>
#include <QClipBoard> #include <QClipBoard>
#include "netio.h" #include "netio.h"
@ -12,9 +12,9 @@ MySettingsDialog::MySettingsDialog(QWidget *parent)
setWindowFlags(Qt::WindowCloseButtonHint); setWindowFlags(Qt::WindowCloseButtonHint);
this->setFixedSize(width(), height()); this->setFixedSize(width(), height());
HKEY hRoot = HKEY_CURRENT_USER; HKEY hRoot = HKEY_CURRENT_USER;
wchar_t *szSubKey = (wchar_t *)"Software\\Microsoft\\Windows\\CurrentVersion\\Run"; wchar_t *szSubKey = L"Software\\Microsoft\\Windows\\CurrentVersion\\Run";
HKEY hKey; HKEY hKey;
DWORD dwDisposition = REG_OPENED_EXISTING_KEY; // 如果不存在不创建 DWORD dwDisposition = REG_OPENED_EXISTING_KEY; // 如果不存在不创建
LONG lRet = RegCreateKeyEx(hRoot, szSubKey, 0, NULL, LONG lRet = RegCreateKeyEx(hRoot, szSubKey, 0, NULL,
REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, &dwDisposition); REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, &dwDisposition);
if (lRet != ERROR_SUCCESS) { if (lRet != ERROR_SUCCESS) {
@ -22,9 +22,10 @@ MySettingsDialog::MySettingsDialog(QWidget *parent)
} }
QString app = QApplication::applicationFilePath(); QString app = QApplication::applicationFilePath();
app.replace("/", "\\"); app.replace("/", "\\");
DWORD size=128+sizeof(wchar_t); app += " autostart";
char reg[128] = { 0 }; DWORD size=256*sizeof(wchar_t);
lRet = RegQueryValueEx(hKey, L"OfficeAssistant", NULL, NULL,(LPBYTE)reg, &size); wchar_t reg[256] = { 0 };
lRet = RegQueryValueEx(hKey, LENG_NAME, NULL, NULL,(LPBYTE)reg, &size);
if (lRet==0) { if (lRet==0) {
ui.autostart->setChecked(true); ui.autostart->setChecked(true);
} }
@ -47,11 +48,11 @@ void MySettingsDialog::autoStart(int state)
HKEY hRoot = HKEY_CURRENT_USER; HKEY hRoot = HKEY_CURRENT_USER;
wchar_t *szSubKey = (wchar_t*)L"Software\\Microsoft\\Windows\\CurrentVersion\\Run"; wchar_t *szSubKey = (wchar_t*)L"Software\\Microsoft\\Windows\\CurrentVersion\\Run";
HKEY hKey; HKEY hKey;
DWORD dwDisposition = REG_OPENED_EXISTING_KEY; // 如果不存在不创建 DWORD dwDisposition = REG_OPENED_EXISTING_KEY; // 如果不存在不创建
LONG lRet = RegCreateKeyEx(hRoot, szSubKey, 0, NULL, LONG lRet = RegCreateKeyEx(hRoot, szSubKey, 0, NULL,
REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, &dwDisposition); REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, &dwDisposition);
if (lRet != ERROR_SUCCESS) { if (lRet != ERROR_SUCCESS) {
QMessageBox::critical(this, QString::fromLocal8Bit("提示"), QString::fromLocal8Bit("创建开机启动项失败")); QMessageBox::critical(this, QString::fromLocal8Bit("提示"), QString::fromLocal8Bit("创建开机启动项失败"));
return; return;
} }
QString app = QApplication::applicationFilePath(); QString app = QApplication::applicationFilePath();
@ -61,7 +62,7 @@ void MySettingsDialog::autoStart(int state)
lRet = RegSetValueEx(hKey, LENG_NAME, 0, REG_SZ, (BYTE*)app.toStdWString().c_str(), app.length()*sizeof(wchar_t)); lRet = RegSetValueEx(hKey, LENG_NAME, 0, REG_SZ, (BYTE*)app.toStdWString().c_str(), app.length()*sizeof(wchar_t));
if (lRet == ERROR_SUCCESS) if (lRet == ERROR_SUCCESS)
{ {
QMessageBox::information(this, QString::fromLocal8Bit("提示"), QString::fromLocal8Bit("创建开机启动项成功")); QMessageBox::information(this, QString::fromLocal8Bit("提示"), QString::fromLocal8Bit("创建开机启动项成功"));
} }
RegCloseKey(hKey); RegCloseKey(hKey);
if(agree) if(agree)
@ -78,14 +79,14 @@ void MySettingsDialog::autoStart(int state)
LONG lRet = RegCreateKeyEx(hRoot, szSubKey, 0, NULL, LONG lRet = RegCreateKeyEx(hRoot, szSubKey, 0, NULL,
REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, &dwDisposition); REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, &dwDisposition);
if (lRet != ERROR_SUCCESS) { if (lRet != ERROR_SUCCESS) {
QMessageBox::critical(this, QString::fromLocal8Bit("提示"), QString::fromLocal8Bit("移除开机启动项失败。")); QMessageBox::critical(this, QString::fromLocal8Bit("提示"), QString::fromLocal8Bit("移除开机启动项失败。"));
return; return;
} }
QString app = QApplication::applicationFilePath(); QString app = QApplication::applicationFilePath();
lRet = RegDeleteValue(hKey, LENG_NAME); lRet = RegDeleteValue(hKey, LENG_NAME);
if (lRet == ERROR_SUCCESS) if (lRet == ERROR_SUCCESS)
{ {
QMessageBox::information(this, QString::fromLocal8Bit("提示"), QString::fromLocal8Bit("移除开机启动项成功。")); QMessageBox::information(this, QString::fromLocal8Bit("提示"), QString::fromLocal8Bit("移除开机启动项成功。"));
} }
RegCloseKey(hKey); RegCloseKey(hKey);
if(agree) if(agree)
@ -116,9 +117,9 @@ void MySettingsDialog::createShortcut() {
QString srcFile = QApplication::applicationFilePath(); QString srcFile = QApplication::applicationFilePath();
bool succeed=QFile::link(srcFile, deskTopPath); bool succeed=QFile::link(srcFile, deskTopPath);
if (succeed) { if (succeed) {
QMessageBox::information(this, QString::fromLocal8Bit("提示"), QString::fromLocal8Bit("创建快捷方式成功。")); QMessageBox::information(this, QString::fromLocal8Bit("提示"), QString::fromLocal8Bit("创建快捷方式成功。"));
} }
else { else {
QMessageBox::information(this, QString::fromLocal8Bit("提示"), QString::fromLocal8Bit("创建快捷方式失败。")); QMessageBox::information(this, QString::fromLocal8Bit("提示"), QString::fromLocal8Bit("创建快捷方式失败。"));
} }
} }

View File

@ -1,4 +1,4 @@
// //
// Created by HW on 2023/07/26. // Created by HW on 2023/07/26.
// //
@ -42,6 +42,7 @@ void ConvertImageToTransparent(QImage &img)
NavBar::NavBar(MainScreen *mainScreen,QWidget *parent) : NavBar::NavBar(MainScreen *mainScreen,QWidget *parent) :
QWidget(parent), ui(new Ui::NavBar) { QWidget(parent), ui(new Ui::NavBar) {
ui->setupUi(this); ui->setupUi(this);
this->parent = parent;
//this->setAttribute(Qt::WA_DeleteOnClose); //this->setAttribute(Qt::WA_DeleteOnClose);
buffer = new QByteArray; buffer = new QByteArray;
/*QString style = "background-color:"; /*QString style = "background-color:";
@ -55,18 +56,18 @@ NavBar::NavBar(MainScreen *mainScreen,QWidget *parent) :
config_request.sendRequest(&config_response); config_request.sendRequest(&config_response);
SQLiteHelper sqlite_helper; SQLiteHelper sqlite_helper;
sqlite_helper.get_software(&buttonStructs, &config_response); sqlite_helper.get_software(&buttonStructs, &config_response);
if(!config_response.succeed) if(!config_response.succeed)
{ {
qColor.setNamedColor(buttonStructs[0].background_color); qColor.setNamedColor(background_color);
}else }else
{ {
qColor.setNamedColor(config_response.basic.backgroud_color); qColor.setNamedColor(background_color);
} }
layout2 = new QHBoxLayout; layout2 = new QHBoxLayout;
layout_right = new QHBoxLayout; layout_right = new QHBoxLayout;
layout_left = new QHBoxLayout; layout_left = new QHBoxLayout;
getLogoFromInternet(&config_response);
logo_label = new QLabel(this); logo_label = new QLabel(this);
logo_label->setAttribute(Qt::WA_TranslucentBackground); logo_label->setAttribute(Qt::WA_TranslucentBackground);
//*logo = logo->scaled(this->width() / (5 / scale), this->height()); //*logo = logo->scaled(this->width() / (5 / scale), this->height());
@ -85,7 +86,7 @@ NavBar::NavBar(MainScreen *mainScreen,QWidget *parent) :
MyButton *myButton = new MyButton(buttonStruct, height(), height(), &buttons,this); MyButton *myButton = new MyButton(buttonStruct, height(), height(), &buttons,this);
myButton->setMaximumHeight(parent->height() / 8); myButton->setMaximumHeight(parent->height() / 8);
layout_right->addWidget(myButton); layout_right->addWidget(myButton);
//myButton->show(); myButton->show();
connect(myButton, &MyButton::clicked1, mainWindowLayout, &MainWindowLayout::clickButton); connect(myButton, &MyButton::clicked1, mainWindowLayout, &MainWindowLayout::clickButton);
buttons << myButton; buttons << myButton;
} }
@ -138,9 +139,7 @@ void NavBar::resizeEvent(QResizeEvent *event) {
} }
logo_label->setMaximumSize(event->size().width() / 5, event->size().height()); logo_label->setMaximumSize(event->size().width() / 5, event->size().height());
} }
/*void NavBar::getLogoFromInternet(ConfigResponse *configResponse) { void NavBar::getLogoFromInternet(ConfigResponse *configResponse) {
qColor.setNamedColor(configResponse->basic.backgroud_color);
QUrl url_logo(configResponse->basic.logo_url); QUrl url_logo(configResponse->basic.logo_url);
QNetworkRequest *request_logo = new QNetworkRequest(url_logo); QNetworkRequest *request_logo = new QNetworkRequest(url_logo);
manager = new QNetworkAccessManager; manager = new QNetworkAccessManager;
@ -153,20 +152,21 @@ void NavBar::resizeEvent(QResizeEvent *event) {
timer.stop(); timer.stop();
buffer = new QByteArray; buffer = new QByteArray;
delete request_logo; delete request_logo;
reply->close();
if (downloadSuccess == true) { if (downloadSuccess == true&& reply->error() == QNetworkReply::NoError) {
*buffer = reply->readAll(); *buffer = reply->readAll();
logo = new ; QFile logo(QApplication::applicationDirPath() + DEFAULT_LOGO);
logo->loadFromData(*buffer); if (logo.open(QIODevice::WriteOnly)) {
logo.write(*buffer);
logo.close();
}
buffer->clear(); buffer->clear();
}else reply->close();
{
getLogoFromLocal();
} }
delete manager; delete manager;
manager = nullptr; manager = nullptr;
}
}*/
void NavBar::storeToBuffer() { void NavBar::storeToBuffer() {
buffer = new QByteArray; buffer = new QByteArray;
@ -178,31 +178,24 @@ void NavBar::cancelDownload() {
downloadSuccess = false; downloadSuccess = false;
} }
/*void NavBar::getLogoFromLocal() { void NavBar::refresh(int state)
QString dir = QApplication::applicationDirPath(); {
QFile file(dir + DEFAULT_FILE); SQLiteHelper sqlite_helper;
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { buttonStructs.clear();
QMessageBox::warning(nullptr, QString::fromLocal8Bit("错误"), QString::fromLocal8Bit("无法打开配置文件")); sqlite_helper.get_software(&buttonStructs, background_color,text_color,text_cover_color);
exit(1); for(auto button:buttons)
{
layout_right->removeWidget(button);
delete button;
buttons.removeOne(button);
} }
buffer->clear(); for (auto buttonStruct : buttonStructs) {
*buffer = file.readAll(); MyButton* myButton = new MyButton(buttonStruct, height(), height(), &buttons, this);
file.close(); myButton->setMaximumHeight(parent->height() / 8);
QJsonDocument *qJsonDocument = new QJsonDocument; layout_right->addWidget(myButton);
*qJsonDocument = QJsonDocument::fromJson(*buffer); //myButton->show();
QJsonObject *obj_root = new QJsonObject; connect(myButton, &MyButton::clicked1, mainWindowLayout, &MainWindowLayout::clickButton);
if (qJsonDocument->isObject()) { buttons << myButton;
*obj_root = qJsonDocument->object();
delete qJsonDocument;
QString logo_path = obj_root->value("basic").toObject().value("logo").toString();
logo = new QPixmap(logo_path);
QJsonArray *array = new QJsonArray;
} }
else { emit application_manager->refresh();//在这里refresh避免因为refresh导致信号和槽断开
QMessageBox::warning(nullptr, QString::fromLocal8Bit("错误"), QString::fromLocal8Bit("配置文件损坏")); }
delete obj_root;
exit(1);
}
delete obj_root;
}*/

View File

@ -1,4 +1,4 @@
// //
// Created by HW on 2023/07/26. // Created by HW on 2023/07/26.
// //
@ -28,6 +28,8 @@ class NavBar : public QWidget {
Q_OBJECT Q_OBJECT
signals: signals:
void firstUrl(QString url); void firstUrl(QString url);
public slots:
void refresh(int state);
public: public:
NavBar(MainScreen *mainScreen,QWidget *parent = nullptr); NavBar(MainScreen *mainScreen,QWidget *parent = nullptr);
@ -37,6 +39,8 @@ protected:
void resizeEvent(QResizeEvent *event) override; void resizeEvent(QResizeEvent *event) override;
void getLogoFromInternet(ConfigResponse* configResponse);
private: private:
Ui::NavBar *ui; Ui::NavBar *ui;
@ -46,13 +50,13 @@ private:
QByteArray *buffer; QByteArray *buffer;
int width2; int width2;
int height2; int height2;
QWidget* parent;
QNetworkAccessManager *manager; QNetworkAccessManager *manager;
QNetworkReply *reply; QNetworkReply *reply;
QEventLoop eventLoop; QEventLoop eventLoop;
QPixmap *logo; QPixmap *logo;
QLabel *logo_label; QLabel *logo_label;
bool downloadSuccess=true; bool downloadSuccess=true;
//void getLogoFromInternet(ConfigResponse *configResponse);
//void getLogoFromLocal(); //void getLogoFromLocal();
MainScreen *mainScreen; MainScreen *mainScreen;
QHBoxLayout *layout_left; QHBoxLayout *layout_left;

View File

@ -1,4 +1,4 @@
// //
// Created by HW on 2023/07/27. // Created by HW on 2023/07/27.
// //
@ -31,11 +31,14 @@
#pragma comment(lib, "Qt5Network.lib") #pragma comment(lib, "Qt5Network.lib")
#endif #endif
#pragma comment(lib,"comsuppw.lib") #pragma comment(lib,"comsuppw.lib")
//读取注册表获取MachineUUID QString background_color;
QString text_color;
QString text_cover_color;
//读取注册表获取MachineUUID
bool IsWin11AndLater() bool IsWin11AndLater()
{ {
//Windows 10 从内部版本 10240 开始,以内部版本 19044 结束。Windows 11 从内部版本 22000 开始,那么: //Windows 10 从内部版本 10240 开始,以内部版本 19044 结束。Windows 11 从内部版本 22000 开始,那么:
//Environment.OSVersion.Version.Build >= 22000; //Environment.OSVersion.Version.Build >= 22000;
NTSTATUS(WINAPI * RtlGetVersion)(LPOSVERSIONINFOEXW); NTSTATUS(WINAPI * RtlGetVersion)(LPOSVERSIONINFOEXW);
OSVERSIONINFOEXW osInfo; OSVERSIONINFOEXW osInfo;
@ -54,40 +57,40 @@ RequestBodyBase::RequestBodyBase(){
wchar_t unix_time[65]={0}; wchar_t unix_time[65]={0};
wsprintf(unix_time,L"%ld",std::time(0)); wsprintf(unix_time,L"%ld",std::time(0));
QString request_id=QString::fromWCharArray(unix_time); QString request_id=QString::fromWCharArray(unix_time);
//打开配置文件 //打开配置文件
QString dir=QApplication::applicationDirPath(); QString dir=QApplication::applicationDirPath();
QFile *infFile=new QFile(dir+"/config/information.kmd"); QFile *infFile=new QFile(dir+"/config/information.kmd");
if(!infFile->open(QIODevice::ReadOnly|QIODevice::Text)){ if(!infFile->open(QIODevice::ReadOnly|QIODevice::Text)){
QMessageBox::critical(nullptr,QString::fromLocal8Bit("错误"), QString::fromLocal8Bit("无法打开配置文件")); QMessageBox::critical(nullptr,QString::fromLocal8Bit("错误"), QString::fromLocal8Bit("无法打开配置文件"));
delete infFile; delete infFile;
exit_manager.exit(1); exit_manager.exit(1);
} }
//读取配置文件 //读取配置文件
QByteArray bytes; QByteArray bytes;
bytes=infFile->readAll(); bytes=infFile->readAll();
infFile->close(); infFile->close();
delete infFile; delete infFile;
//转化为json //转化为json
qJsonDocument=QJsonDocument::fromJson(bytes); qJsonDocument=QJsonDocument::fromJson(bytes);
if(qJsonDocument.isObject()){ if(qJsonDocument.isObject()){
//读取数据,写入对应字段 //读取数据,写入对应字段
QJsonObject obj_root=qJsonDocument.object(); QJsonObject obj_root=qJsonDocument.object();
if(obj_root.value("product")==QJsonValue::Undefined){ if(obj_root.value("product")==QJsonValue::Undefined){
QMessageBox::critical(nullptr, QString::fromLocal8Bit("错误"), QString::fromLocal8Bit("配置文件损坏")); QMessageBox::critical(nullptr, QString::fromLocal8Bit("错误"), QString::fromLocal8Bit("配置文件损坏"));
exit_manager.exit(1); exit_manager.exit(1);
} }
product=obj_root.value("product").toString(); product=obj_root.value("product").toString();
if(obj_root.value("partner_id")==QJsonValue::Undefined){ if(obj_root.value("partner_id")==QJsonValue::Undefined){
QMessageBox::critical(nullptr , QString::fromLocal8Bit("错误"), QString::fromLocal8Bit("配置文件损坏")); QMessageBox::critical(nullptr , QString::fromLocal8Bit("错误"), QString::fromLocal8Bit("配置文件损坏"));
exit_manager.exit(1); exit_manager.exit(1);
} }
parter_id=obj_root.value("partner_id").toString(); parter_id=obj_root.value("partner_id").toString();
}else{ }else{
//处理错误 //处理错误
QMessageBox::critical(nullptr, QString::fromLocal8Bit("错误"), QString::fromLocal8Bit("配置文件损坏")); QMessageBox::critical(nullptr, QString::fromLocal8Bit("错误"), QString::fromLocal8Bit("配置文件损坏"));
exit_manager.exit(1); exit_manager.exit(1);
} }
//获取操作系统版本 //获取操作系统版本
this->os="Windows"; this->os="Windows";
OSVERSIONINFOEXW os; OSVERSIONINFOEXW os;
os.dwOSVersionInfoSize=sizeof(os); os.dwOSVersionInfoSize=sizeof(os);
@ -96,12 +99,12 @@ RequestBodyBase::RequestBodyBase(){
*(FARPROC*)&RtlGetVersion = GetProcAddress(GetModuleHandleA("ntdll"), "RtlGetVersion"); *(FARPROC*)&RtlGetVersion = GetProcAddress(GetModuleHandleA("ntdll"), "RtlGetVersion");
if (RtlGetVersion != nullptr) { if (RtlGetVersion != nullptr) {
RtlGetVersion(&os); RtlGetVersion(&os);
switch (os.dwMajorVersion) {//主版本号 switch (os.dwMajorVersion) {//主版本号
case 5: //不兼容Windows 2000因此5.x一定是Windows XP case 5: //不兼容Windows 2000因此5.x一定是Windows XP
os_version = "Windows XP"; os_version = "Windows XP";
break; break;
case 6: case 6:
switch (os.dwMinorVersion) { //次版本号 switch (os.dwMinorVersion) { //次版本号
case 0: case 0:
os_version = "Windows Vista or Windows Server 2008"; os_version = "Windows Vista or Windows Server 2008";
break; break;
@ -117,7 +120,7 @@ RequestBodyBase::RequestBodyBase(){
default: default:
os_version = "Unknown"; os_version = "Unknown";
} }
case 10: //这几个系统都是10.0 case 10: //这几个系统都是10.0
if (IsWin11AndLater()) { if (IsWin11AndLater()) {
os_version = "Windows 11 or Windows Server 2022"; os_version = "Windows 11 or Windows Server 2022";
} }
@ -135,10 +138,10 @@ RequestBodyBase::RequestBodyBase(){
this->release = RELEASE; this->release = RELEASE;
this->version = VERSION; this->version = VERSION;
//读取MachineGUID并取MD5作为device_id //读取MachineGUID并取MD5作为device_id
QByteArray hash = QCryptographicHash::hash(getMachineGUID().toUtf8(), QCryptographicHash::Md5); QByteArray hash = QCryptographicHash::hash(getMachineGUID().toUtf8(), QCryptographicHash::Md5);
device_id = hash.toHex(); device_id = hash.toHex();
//加入json序列 //加入json序列
QJsonValue value = device_id; QJsonValue value = device_id;
QJsonObject obj_root = qJsonDocument.object(); QJsonObject obj_root = qJsonDocument.object();
obj_root.insert("device_id", value); obj_root.insert("device_id", value);
@ -156,16 +159,15 @@ RequestBodyBase::RequestBodyBase(){
QJsonValue sign_json(sign); QJsonValue sign_json(sign);
QJsonValue requestId_json=QJsonValue(request_id); QJsonValue requestId_json=QJsonValue(request_id);
obj_root=qJsonDocument.object(); obj_root=qJsonDocument.object();
//插入request_id //插入request_id
obj_root.insert(QString::fromLocal8Bit("request_id"),requestId_json); obj_root.insert(QString::fromLocal8Bit("request_id"),requestId_json);
obj_root.insert(QString::fromLocal8Bit("os"), os_json); obj_root.insert(QString::fromLocal8Bit("os"), os_json);
obj_root.insert(QString::fromLocal8Bit("os_version"), os_version_json); obj_root.insert(QString::fromLocal8Bit("os_version"), os_version_json);
obj_root.insert(QString::fromLocal8Bit("sign"), sign_json); obj_root.insert(QString::fromLocal8Bit("sign"), sign_json);
qJsonDocument.setObject(obj_root); qJsonDocument.setObject(obj_root);
url_param = "?"; url_param = "&product=";
url_param += "product=";
url_param += product; url_param += product;
url_param += "&parter_id="; url_param += "&partner_id=";
url_param += parter_id; url_param += parter_id;
url_param += "&os="; url_param += "&os=";
url_param += this->os; url_param += this->os;
@ -188,29 +190,26 @@ RequestBodyBase::RequestBodyBase(){
void ConfigRequest::sendRequest(ConfigResponse *configResponse) { void ConfigRequest::sendRequest(ConfigResponse *configResponse) {
timer = new QTimer(this); timer = new QTimer(this);
if(agree) QJsonObject obj_root = qJsonDocument.object();
{ obj_root.insert("autostart", autostart);
QJsonObject obj_root = qJsonDocument.object(); qJsonDocument.setObject(obj_root);
obj_root.insert("autostart", autostart);
qJsonDocument.setObject(obj_root);
}
QNetworkAccessManager *httpMgr = new QNetworkAccessManager(); QNetworkAccessManager *httpMgr = new QNetworkAccessManager();
QNetworkRequest requestInfo; QNetworkRequest requestInfo;
//HTTP请求 //HTTP请求
//请求头 //请求头
QString url = CONFIG_URL; QString url = CONFIG_URL;
requestInfo.setUrl(QUrl(CONFIG_URL)); requestInfo.setUrl(QUrl(CONFIG_URL));
requestInfo.setHeader(QNetworkRequest::ContentTypeHeader,QVariant("application/json")); requestInfo.setHeader(QNetworkRequest::ContentTypeHeader,QVariant("application/json"));
//保存响应的变量 //保存响应的变量
reply = httpMgr->post(requestInfo,qJsonDocument.toJson()); reply = httpMgr->post(requestInfo,qJsonDocument.toJson());
qDebug() << qJsonDocument.toJson(); qDebug() << qJsonDocument.toJson();
//开启一个循环,直到超时或者获取到数据为止 //开启一个循环,直到超时或者获取到数据为止
connect(reply,&QNetworkReply::finished, &eventLoop, &QEventLoop::quit); connect(reply,&QNetworkReply::finished, &eventLoop, &QEventLoop::quit);
//设置定时器防止超时 //设置定时器防止超时
connect(timer,&QTimer::timeout,this,&ConfigRequest::cancelDownload); connect(timer,&QTimer::timeout,this,&ConfigRequest::cancelDownload);
timer->start(5000); timer->start(5000);
//启动循环 //启动循环
eventLoop.exec(); eventLoop.exec();
timer->stop(); timer->stop();
//delete httpMgr; //delete httpMgr;
@ -219,11 +218,11 @@ void ConfigRequest::sendRequest(ConfigResponse *configResponse) {
configResponse->succeed = false; configResponse->succeed = false;
//memset(configResponse,0,sizeof(*configResponse)); //memset(configResponse,0,sizeof(*configResponse));
auto error = reply->error(); auto error = reply->error();
//如果没有错误 //如果没有错误
if(reply->error() == QNetworkReply::NoError) { if(reply->error() == QNetworkReply::NoError) {
buffer = reply->readAll(); buffer = reply->readAll();
}else{ }else{
//如果有错误 //如果有错误
configResponse->succeed=false; configResponse->succeed=false;
//delete reply; //delete reply;
delete timer; delete timer;
@ -232,13 +231,20 @@ void ConfigRequest::sendRequest(ConfigResponse *configResponse) {
} }
//qDebug() << result.toJson(); //qDebug() << result.toJson();
result = QJsonDocument::fromJson(buffer); result = QJsonDocument::fromJson(buffer);
//如果数据完整 //如果数据完整
if(result.isObject()){ if(result.isObject()){
QJsonObject obj_root=result.object(); QJsonObject obj_root=result.object();
QJsonArray array; QJsonArray array;
array = obj_root.value("data").toObject().value("menu").toArray(); array = obj_root.value("data").toObject().value("menu").toArray();
QJsonObject obj_basic = obj_root.value("data").toObject().value("basic").toObject(); QJsonObject obj_data = obj_root.value("data").toObject();
if(!obj_data.value("basic").isObject())
{
configResponse->succeed=false;
delete timer;
return;
}
QJsonObject obj_basic=obj_data.value("basic").toObject();
configResponse->basic.logo_url = obj_basic.value("logo").toString(); configResponse->basic.logo_url = obj_basic.value("logo").toString();
configResponse->basic.device_id = obj_basic.value("device_id").toString(); configResponse->basic.device_id = obj_basic.value("device_id").toString();
configResponse->basic.dev_id = obj_basic.value("dev_id").toString(); configResponse->basic.dev_id = obj_basic.value("dev_id").toString();
@ -246,18 +252,29 @@ void ConfigRequest::sendRequest(ConfigResponse *configResponse) {
configResponse->basic.backgroud_color = obj_basic.value("backgroud_color").toString(); configResponse->basic.backgroud_color = obj_basic.value("backgroud_color").toString();
configResponse->basic.title_color = obj_basic.value("title_color").toString(); configResponse->basic.title_color = obj_basic.value("title_color").toString();
configResponse->basic.title_cover_color = obj_basic.value("title_cover_color").toString(); configResponse->basic.title_cover_color = obj_basic.value("title_cover_color").toString();
auto i=0; auto i=0;
for(auto value:array){ for(auto value:array){
QJsonObject object=value.toObject(); QJsonObject object=value.toObject();
Button button; Button button;
button.img=object.value("img").toString(); button.img = object.value("logo").toString();
button.orig_name= object.value("orig_name").toString(); button.png = object.value("img").toString();
// button.img_cover=object.value("img_cover").toString(); button.img_name = object.value("img_name").toString();
button.title=object.value("title").toString(); button.name = object.value("name").toString();
button.categroy_id = object.value("category_id").toString(); button.type = object.value("type").toString();
button.sort = object.value("sort").toInt();
button.status = object.value("status").toInt();
button.is_navbar = object.value("is_navbar").toBool();
button.is_elite = object.value("is_elite").toBool();
button.orig_name = object.value("orig_name").toString();
button.categroy_id = object.value("categroy_id").toString();
button.op = object.value("op").toString(); button.op = object.value("op").toString();
button.func=object.value("func").toString(); button.func = object.value("func").toString();
button.url=object.value("url").toString(); button.url = object.value("url").toString();
button.dev = object.value("dev").toString();
button.locked = object.value("locked").toBool();
button.is_delete = object.value("is_delete").toBool();
button.version = object.value("version").toString();
configResponse->buttons << button; configResponse->buttons << button;
i++; i++;
} }
@ -269,7 +286,7 @@ void ConfigRequest::sendRequest(ConfigResponse *configResponse) {
file.close(); file.close();
} }
}else{ }else{
//数据不完整 //数据不完整
configResponse->succeed=false; configResponse->succeed=false;
//delete reply; //delete reply;
delete timer; delete timer;
@ -288,18 +305,18 @@ void RequestBodyBase::sendRequest() {
timer = new QTimer(this); timer = new QTimer(this);
QNetworkAccessManager *httpMgr = new QNetworkAccessManager(); QNetworkAccessManager *httpMgr = new QNetworkAccessManager();
QNetworkRequest requestInfo; QNetworkRequest requestInfo;
//HTTP请求 //HTTP请求
//请求头 //请求头
requestInfo.setUrl(QUrl(OP_URL)); requestInfo.setUrl(QUrl(OP_URL));
requestInfo.setHeader(QNetworkRequest::ContentTypeHeader,QVariant("application/json")); requestInfo.setHeader(QNetworkRequest::ContentTypeHeader,QVariant("application/json"));
//保存响应的变量 //保存响应的变量
reply = httpMgr->post(requestInfo,qJsonDocument.toJson()); reply = httpMgr->post(requestInfo,qJsonDocument.toJson());
//开启一个循环,直到超时或者获取到数据为止 //开启一个循环,直到超时或者获取到数据为止
connect(reply,&QNetworkReply::finished, this, &RequestBodyBase::cancelDownload); connect(reply,&QNetworkReply::finished, this, &RequestBodyBase::cancelDownload);
//设置定时器防止超时 //设置定时器防止超时
connect(timer,&QTimer::timeout,&eventLoop,&QEventLoop::quit); connect(timer,&QTimer::timeout,&eventLoop,&QEventLoop::quit);
timer->start(5000); timer->start(5000);
//启动循环 //启动循环
eventLoop.exec(); eventLoop.exec();
delete timer; delete timer;
delete httpMgr; delete httpMgr;
@ -308,70 +325,23 @@ void RequestBodyBase::sendRequest() {
DeviceRequest::DeviceRequest() : RequestBodyBase() { DeviceRequest::DeviceRequest() : RequestBodyBase() {
//CPU //内存大小
QString cpu = QSysInfo::currentCpuArchitecture();
//内存大小
MEMORYSTATUSEX status; MEMORYSTATUSEX status;
status.dwLength = sizeof(status); status.dwLength = sizeof(status);
GlobalMemoryStatusEx(&status); GlobalMemoryStatusEx(&status);
int ram = status.ullTotalPhys / 1024 / 1024; int ram = status.ullTotalPhys / 1024 / 1024;
//硬盘大小 //硬盘大小
QStorageInfo storage = QStorageInfo::root(); QStorageInfo storage = QStorageInfo::root();
int disk = storage.bytesTotal() / static_cast<qulonglong>(1024 * 1024 * 1024); int disk = storage.bytesTotal() / static_cast<qulonglong>(1024 * 1024 * 1024);
//显卡型号
QStringList gpus; //WMI获取网卡型号
BOOL success; HRESULT hr = CoInitializeEx(0, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);
DWORD deviceIndex = 0;
DISPLAY_DEVICE displayDevice;
displayDevice.cb = sizeof(displayDevice);
while (EnumDisplayDevices(NULL, deviceIndex, &displayDevice, 0)) {
WCHAR valueName[128];
DWORD valueSize;
DWORD valueType;
BYTE valueData[MAX_PATH];
HKEY hKey;
WCHAR keyName[128];
wsprintf(keyName, L"SYSTEM\\CurrentControlSet\\Control\\Video\\%s\\HardwareInformation",
displayDevice.DeviceID);
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, keyName, 0, KEY_READ, &hKey) == ERROR_SUCCESS) {
valueSize = sizeof(valueData);
wsprintf(valueName, L"HardwareInformation.AdapterString");
if (RegQueryValueEx(hKey, valueName, NULL, &valueType, valueData, &valueSize) == ERROR_SUCCESS) {
Q_ASSERT(valueType == REG_SZ);
QString adapterString = QString::fromWCharArray((wchar_t *) valueData, valueSize / sizeof(wchar_t) - 1);
gpus.append(adapterString);
}
RegCloseKey(hKey);
}
deviceIndex++;
displayDevice.cb = sizeof(displayDevice);
}
//主板型号
QString motherboard = QSysInfo::prettyProductName();
//WMI获取网卡型号
HRESULT hr = CoInitializeEx(0, COINIT_MULTITHREADED);
if (FAILED(hr)) { if (FAILED(hr)) {
std::cerr << "Failed to initialize COM library." << std::endl; std::cerr << "Failed to initialize COM library." << std::endl;
return; return;
} }
QStringList netCards; QStringList netCards;
hr = CoInitializeSecurity(
NULL,
-1,
NULL,
NULL,
RPC_C_AUTHN_LEVEL_DEFAULT,
RPC_C_IMP_LEVEL_IMPERSONATE,
NULL,
EOAC_NONE,
NULL
);
if (FAILED(hr)) {
std::cerr << "Failed to initialize security." << std::endl;
CoUninitialize();
return;
}
IWbemLocator* pLoc = NULL; IWbemLocator* pLoc = NULL;
hr = CoCreateInstance( hr = CoCreateInstance(
CLSID_WbemLocator, CLSID_WbemLocator,
@ -425,7 +395,7 @@ DeviceRequest::DeviceRequest() : RequestBodyBase() {
IEnumWbemClassObject* pEnumerator = NULL; IEnumWbemClassObject* pEnumerator = NULL;
hr = pSvc->ExecQuery( hr = pSvc->ExecQuery(
_bstr_t("WQL"), _bstr_t("WQL"),
_bstr_t("SELECT * FROM Win32_NetworkAdapter WHERE PhysicalAdapter = TRUE AND NetConnectionStatus = 3"), _bstr_t("SELECT * FROM Win32_NetworkAdapter WHERE PhysicalAdapter = TRUE"),
WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY, WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY,
NULL, NULL,
&pEnumerator &pEnumerator
@ -455,7 +425,79 @@ DeviceRequest::DeviceRequest() : RequestBodyBase() {
pClassObj->Release(); pClassObj->Release();
} }
//WMI获取声卡型号 pEnumerator->Release();
pEnumerator = nullptr;
// 获取 CPU 信息
hr = pSvc->ExecQuery(bstr_t("WQL"), bstr_t("SELECT * FROM Win32_Processor"), WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY, NULL, &pEnumerator);
IWbemClassObject* pclsObj = NULL;
uReturn = 0;
QString cpu;
while (pEnumerator) {
HRESULT hr = pEnumerator->Next(WBEM_INFINITE, 1, &pclsObj, &uReturn);
if (0 == uReturn) break;
VARIANT vtProp;
hr = pclsObj->Get(L"Name", 0, &vtProp, 0, 0);
if (SUCCEEDED(hr)) {
cpu=QString::fromWCharArray(vtProp.bstrVal);
VariantClear(&vtProp);
}
pclsObj->Release();
}
// 获取主板信息
QString motherboard;
hr = pSvc->ExecQuery(bstr_t("WQL"), bstr_t("SELECT * FROM Win32_BaseBoard"), WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY, NULL, &pEnumerator);
while (pEnumerator) {
HRESULT hr = pEnumerator->Next(WBEM_INFINITE, 1, &pclsObj, &uReturn);
if (0 == uReturn) break;
VARIANT vtProp;
hr = pclsObj->Get(L"Product", 0, &vtProp, 0, 0);
if (SUCCEEDED(hr)) {
motherboard=QString::fromWCharArray(vtProp.bstrVal);
VariantClear(&vtProp);
}
pclsObj->Release();
}
pEnumerator->Release();
pEnumerator=nullptr;
//WMI获取显卡型号
hr = pSvc->ExecQuery(
bstr_t("WQL"),
bstr_t("SELECT * FROM Win32_VideoController"),
WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY,
NULL,
&pEnumerator);
if (FAILED(hr))
{
std::cerr << "Query failed." << std::endl;
pSvc->Release();
pLoc->Release();
CoUninitialize();
return;
}
QStringList graphicsCards;
pclsObj->Release();
pclsObj = NULL;
uReturn = 0;
while (pEnumerator)
{
HRESULT hr = pEnumerator->Next(WBEM_INFINITE, 1, &pclsObj, &uReturn);
if (0 == uReturn) break;
VARIANT vtProp;
hr = pclsObj->Get(L"Name", 0, &vtProp, 0, 0);
if (SUCCEEDED(hr))
{
graphicsCards<< QString::fromWCharArray(vtProp.bstrVal);
VariantClear(&vtProp);
}
pclsObj->Release();
}
//WMI获取声卡型号
hr = pSvc->ExecQuery( hr = pSvc->ExecQuery(
_bstr_t("WQL"), _bstr_t("WQL"),
_bstr_t("SELECT * FROM Win32_SoundDevice"), _bstr_t("SELECT * FROM Win32_SoundDevice"),
@ -515,7 +557,7 @@ DeviceRequest::DeviceRequest() : RequestBodyBase() {
hr = pClassObj->Get(L"Manufacturer", 0, &vtProp, 0, 0); hr = pClassObj->Get(L"Manufacturer", 0, &vtProp, 0, 0);
if (SUCCEEDED(hr)) if (SUCCEEDED(hr))
{ {
std::wcout << "Manufacturer: " << vtProp.bstrVal << std::endl; RAMModel<<QString::fromWCharArray(vtProp.bstrVal);
VariantClear(&vtProp); VariantClear(&vtProp);
} }
@ -531,20 +573,43 @@ DeviceRequest::DeviceRequest() : RequestBodyBase() {
pSvc->Release(); pSvc->Release();
pLoc->Release(); pLoc->Release();
CoUninitialize(); CoUninitialize();
DISPLAY_DEVICE d = { sizeof(DISPLAY_DEVICE) };
::EnumDisplayDevices(NULL, 0, &d, 0); DISPLAY_DEVICE dd;
QString monitor=QString::fromWCharArray(d.DeviceString, wcslen(d.DeviceString)); ZeroMemory(&dd, sizeof(dd));
//发送 dd.cb = sizeof(dd);
//构造JSON int deviceIndex = 0;
QStringList monitors;
// 枚举显卡设备
while (EnumDisplayDevices(0, deviceIndex, &dd, 0))
{
DISPLAY_DEVICE monitor;
ZeroMemory(&monitor, sizeof(monitor));
monitor.cb = sizeof(monitor);
int monitorIndex = 0;
// 对每个显卡枚举其连接的显示器
while (EnumDisplayDevices(dd.DeviceName, monitorIndex, &monitor, 0))
{
// 打印显示器型号
monitors<<QString::fromWCharArray(monitor.DeviceString);
monitorIndex++;
}
deviceIndex++;
}
//发送
//构造JSON
QJsonDocument *device=new QJsonDocument; QJsonDocument *device=new QJsonDocument;
QJsonObject *object=new QJsonObject; QJsonObject *object=new QJsonObject;
object->insert("CPU",QJsonValue(cpu)); object->insert("CPU",QJsonValue(cpu));
object->insert("RAM",QJsonValue(ram)); object->insert("RAM",QJsonValue(ram));
object->insert("Hard_Disk",QJsonValue(disk)); object->insert("Hard_Disk",QJsonValue(disk));
QJsonArray *gpu_array=new QJsonArray; QJsonArray *gpu_array=new QJsonArray;
for(auto gpu:gpus) {
gpu_array->append(gpu); for(auto gpu:graphicsCards)
} {
gpu_array->append(gpu);
}
object->insert("GPU",*gpu_array); object->insert("GPU",*gpu_array);
delete gpu_array; delete gpu_array;
object->insert("Mother_Board",motherboard); object->insert("Mother_Board",motherboard);
@ -566,7 +631,13 @@ DeviceRequest::DeviceRequest() : RequestBodyBase() {
} }
object->insert("Audio_Card",*audioCards_json); object->insert("Audio_Card",*audioCards_json);
delete audioCards_json; delete audioCards_json;
object->insert("Monitor",monitor); QJsonArray *monitors_json=new QJsonArray;
for(auto monitor:monitors)
{
monitors_json->append(monitor);
}
object->insert("Monitor",*monitors_json);
delete monitors_json;
device->setObject(*object); device->setObject(*object);
delete object; delete object;
QJsonObject obj_root=qJsonDocument.object(); QJsonObject obj_root=qJsonDocument.object();
@ -576,19 +647,22 @@ DeviceRequest::DeviceRequest() : RequestBodyBase() {
timer = new QTimer(this); timer = new QTimer(this);
QNetworkAccessManager *httpMgr = new QNetworkAccessManager(); QNetworkAccessManager *httpMgr = new QNetworkAccessManager();
QNetworkRequest requestInfo; QNetworkRequest requestInfo;
//HTTP请求 //HTTP请求
//请求头 //请求头
requestInfo.setUrl(QUrl(DEVICE_URL)); requestInfo.setUrl(QUrl(DEVICE_URL));
requestInfo.setHeader(QNetworkRequest::ContentTypeHeader,QVariant("application/json")); requestInfo.setHeader(QNetworkRequest::ContentTypeHeader,QVariant("application/json"));
//保存响应的变量 //保存响应的变量
qDebug()<<qJsonDocument.toJson();
reply = httpMgr->post(requestInfo,qJsonDocument.toJson()); reply = httpMgr->post(requestInfo,qJsonDocument.toJson());
//开启一个循环,直到超时或者获取到数据为止 //开启一个循环,直到超时或者获取到数据为止
connect(reply,&QNetworkReply::finished, &eventLoop, &QEventLoop::quit); connect(reply,&QNetworkReply::finished, &eventLoop, &QEventLoop::quit);
//设置定时器防止超时 //设置定时器防止超时
connect(timer,&QTimer::timeout,this,&DeviceRequest::cancelDownload); connect(timer,&QTimer::timeout,this,&DeviceRequest::cancelDownload);
timer->start(5000); timer->start(5000);
//启动循环 //启动循环
eventLoop.exec(); eventLoop.exec();
qDebug()<<reply->error();
qDebug()<<reply->readAll();
delete httpMgr; delete httpMgr;
} }
bool SoftwareRequest::sendRequest(QHash<QString,QString>&startMenu, QHash<QString, Record> *records, QJsonArray &software_exists) bool SoftwareRequest::sendRequest(QHash<QString,QString>&startMenu, QHash<QString, Record> *records, QJsonArray &software_exists)
@ -596,8 +670,8 @@ bool SoftwareRequest::sendRequest(QHash<QString,QString>&startMenu, QHash<QStrin
timer = new QTimer(this); timer = new QTimer(this);
QNetworkAccessManager* httpMgr = new QNetworkAccessManager(); QNetworkAccessManager* httpMgr = new QNetworkAccessManager();
QNetworkRequest requestInfo; QNetworkRequest requestInfo;
//HTTP请求 //HTTP请求
//请求头 //请求头
QJsonArray array; QJsonArray array;
for(auto record : *records) for(auto record : *records)
{ {
@ -618,40 +692,41 @@ bool SoftwareRequest::sendRequest(QHash<QString,QString>&startMenu, QHash<QStrin
QJsonObject object; QJsonObject object;
object.insert("reg", array); object.insert("reg", array);
object.insert("start", menu_list); object.insert("start", menu_list);
object.insert("exists", software_exists); object.insert("app", software_exists);
obj_root.insert("data", object); obj_root.insert("data", object);
obj_root.insert("type", "update"); obj_root.insert("type", "update");
qJsonDocument.setObject(obj_root); qJsonDocument.setObject(obj_root);
QString url = SOFTWARE_URL; QString url = SOFTWARE_URL;
requestInfo.setUrl(url); requestInfo.setUrl(url);
requestInfo.setHeader(QNetworkRequest::ContentTypeHeader, QVariant("application/json")); requestInfo.setHeader(QNetworkRequest::ContentTypeHeader, QVariant("application/json"));
//保存响应的变量 //保存响应的变量
reply = httpMgr->post(requestInfo, qJsonDocument.toJson()); reply = httpMgr->post(requestInfo, qJsonDocument.toJson());
qDebug() << qJsonDocument.toJson(); qDebug() << qJsonDocument.toJson();
//开启一个循环,直到超时或者获取到数据为止 //开启一个循环,直到超时或者获取到数据为止
connect(reply, &QNetworkReply::finished, &eventLoop, &QEventLoop::quit); connect(reply, &QNetworkReply::finished, &eventLoop, &QEventLoop::quit);
//设置定时器防止超时 //设置定时器防止超时
connect(timer, &QTimer::timeout, this, &SoftwareRequest::cancelDownload); connect(timer, &QTimer::timeout, this, &SoftwareRequest::cancelDownload);
timer->start(5000); timer->start(5000);
//启动循环 //启动循环
eventLoop.exec(); eventLoop.exec();
timer->stop(); timer->stop();
delete timer; delete timer;
QJsonDocument result; QJsonDocument result;
// auto error = reply->error(); // auto error = reply->error();
//如果没有错误 //如果没有错误
qDebug() << reply->error(); qDebug() << reply->error();
auto result2=reply->readAll();
if (reply->error() == QNetworkReply::NoError) { if (reply->error() == QNetworkReply::NoError) {
result = QJsonDocument::fromJson(reply->readAll()); result = QJsonDocument::fromJson(result2);
} }
else { else {
//如果有错误 //如果有错误
delete httpMgr; delete httpMgr;
return false; return false;
} }
//qDebug() << result.toJson(); //qDebug() << result.toJson();
records->clear();
//如果数据完整 //如果数据完整
if (result.isObject()) { if (result.isObject()) {
QJsonObject obj_root2 = result.object(); QJsonObject obj_root2 = result.object();
QJsonArray array = obj_root2.value("data").toObject().value("menu").toArray(); QJsonArray array = obj_root2.value("data").toObject().value("menu").toArray();
@ -687,21 +762,30 @@ bool SoftwareRequest::sendRequest(QHash<QString,QString>&startMenu, QHash<QStrin
file.close(); file.close();
} }
} }
Record record;
(*records)[orig_name].logo = dir + orig_name + ".svg"; record.orig_name = orig_name;
(*records)[orig_name].name = object.value("name").toString(); record.path = object.value("path").toString();
(*records)[orig_name].locked = object.value("locked").toBool(); record.img = dir + orig_name + ".svg";
(*records)[orig_name].url = object.value("url").toString(); record.name = object.value("name").toString();
(*records)[orig_name].path = object.value("path").toString(); record.version = object.value("version").toString();
if ((*records)[orig_name].path.isEmpty()) record.app_id=object.value("app_id").toString();
{ record.locked=object.value("locked").toBool();
delete httpMgr; record.type=object.value("type").toString();
return false; record.category_id=object.value("category_id").toString();
} record.status=object.value("status").toBool();
record.op=object.value("op").toString();
record.func=object.value("func").toString();
record.initial_position=object.value("initial_position").toString();
record.url=object.value("url").toString();
record.logo=object.value("logo").toString();
record.img=object.value("img").toString();
record.is_navbar=object.value("is_navbar").toBool();
record.is_elite=object.value("is_elite").toBool();
records->insert(orig_name, record);
} }
} }
else { else {
//数据不完整 //数据不完整
//delete reply; //delete reply;
delete httpMgr; delete httpMgr;
return false; return false;
@ -718,23 +802,25 @@ QString OpenWeChatRequest::sendRequest(bool notuse)
timer = new QTimer(this); timer = new QTimer(this);
QNetworkAccessManager* httpMgr = new QNetworkAccessManager(); QNetworkAccessManager* httpMgr = new QNetworkAccessManager();
QNetworkRequest requestInfo; QNetworkRequest requestInfo;
//HTTP请求 //HTTP请求
//请求头 //请求头
requestInfo.setUrl(QUrl(WECHAT_URL)); requestInfo.setUrl(QUrl(WECHAT_URL));
requestInfo.setHeader(QNetworkRequest::ContentTypeHeader, QVariant("application/json")); requestInfo.setHeader(QNetworkRequest::ContentTypeHeader, QVariant("application/json"));
//保存响应的变量 //保存响应的变量
reply = httpMgr->post(requestInfo, qJsonDocument.toJson()); reply = httpMgr->post(requestInfo, qJsonDocument.toJson());
//开启一个循环,直到超时或者获取到数据为止 //开启一个循环,直到超时或者获取到数据为止
connect(reply, &QNetworkReply::finished, this, &OpenWeChatRequest::cancelDownload); connect(reply, &QNetworkReply::finished, this, &OpenWeChatRequest::cancelDownload);
//设置定时器防止超时 //设置定时器防止超时
connect(timer, &QTimer::timeout, &eventLoop, &QEventLoop::quit); connect(timer, &QTimer::timeout, &eventLoop, &QEventLoop::quit);
timer->start(5000); timer->start(5000);
//启动循环 //启动循环
eventLoop.exec(); eventLoop.exec();
timer->stop(); timer->stop();
qDebug() << reply->error();
QByteArray buffer = reply->readAll(); QByteArray buffer = reply->readAll();
QJsonDocument reply_json = QJsonDocument::fromJson(buffer); QJsonDocument reply_json = QJsonDocument::fromJson(buffer);
if(!reply_json.isObject())
if(!reply_json.isObject())
{ {
delete timer; delete timer;
delete httpMgr; delete httpMgr;
@ -743,7 +829,6 @@ QString OpenWeChatRequest::sendRequest(bool notuse)
} }
delete timer; delete timer;
delete httpMgr; delete httpMgr;
delete reply;
return reply_json.object().value("msg").toString(); return reply_json.object().value("msg").toString();
} }
@ -755,18 +840,18 @@ void OpRequest::sendRequest()
qJsonDocument.setObject(object); qJsonDocument.setObject(object);
QNetworkAccessManager* httpMgr = new QNetworkAccessManager(); QNetworkAccessManager* httpMgr = new QNetworkAccessManager();
QNetworkRequest requestInfo; QNetworkRequest requestInfo;
//HTTP请求 //HTTP请求
//请求头 //请求头
requestInfo.setUrl(QUrl(OP_URL)); requestInfo.setUrl(QUrl(OP_URL));
requestInfo.setHeader(QNetworkRequest::ContentTypeHeader, QVariant("application/json")); requestInfo.setHeader(QNetworkRequest::ContentTypeHeader, QVariant("application/json"));
//保存响应的变量 //保存响应的变量
reply = httpMgr->post(requestInfo, qJsonDocument.toJson()); reply = httpMgr->post(requestInfo, qJsonDocument.toJson());
//开启一个循环,直到超时或者获取到数据为止 //开启一个循环,直到超时或者获取到数据为止
connect(reply, &QNetworkReply::finished, this, &OpRequest::cancelDownload); connect(reply, &QNetworkReply::finished, this, &OpRequest::cancelDownload);
//设置定时器防止超时 //设置定时器防止超时
connect(timer, &QTimer::timeout, &eventLoop, &QEventLoop::quit); connect(timer, &QTimer::timeout, &eventLoop, &QEventLoop::quit);
timer->start(5000); timer->start(5000);
//启动循环 //启动循环
eventLoop.exec(); eventLoop.exec();
timer->stop(); timer->stop();
delete timer; delete timer;

View File

@ -1,4 +1,4 @@
// //
// Created by HW on 2023/07/27. // Created by HW on 2023/07/27.
// //
@ -17,13 +17,24 @@
typedef struct { typedef struct {
QString img; QString img;
QString img_cover; QString png;
QString title; QString img_name;
QString name;
QString type;
int sort;
int status;
bool is_navbar;
bool is_elite;
QString orig_name; QString orig_name;
QString categroy_id; QString categroy_id;
QString op; QString op;
QString func; QString func;
QString url; QString url;
QString dev;
bool locked;
bool is_delete;
QString version;
} Button; } Button;
struct ConfigResponse { struct ConfigResponse {
bool succeed; bool succeed;
@ -126,6 +137,13 @@ class OpenWeChatRequest:public RequestBodyBase
{ {
public: public:
OpenWeChatRequest():RequestBodyBase(){} OpenWeChatRequest():RequestBodyBase(){}
QString sendRequest(bool notuse=false/*为了构成函数重载,凑数的*/); QString sendRequest(bool notuse=false/*为了构成函数重载,凑数的*/);
};
class OpenAppRequest:public RequestBodyBase
{
public:
OpenAppRequest():RequestBodyBase(){}
QString sendRequest(QString app_name);
}; };
#endif //OFFICEASSISTANT_NETIO_H #endif //OFFICEASSISTANT_NETIO_H

View File

@ -1,8 +1,82 @@
#include "qminiblink.h" #include "qminiblink.h"
#include <functional>
#include <QThread> #include <QThread>
#include <QDebug> #include <QDebug>
#include <thread>
#pragma comment (lib,"Comctl32.lib") #pragma comment (lib,"Comctl32.lib")
struct DownInfo {
std::string url;
size_t recvSize;
size_t allSize;
};
void MB_CALL_TYPE onNetJobDataRecvCallback(void* ptr, mbNetJob job, const char* data, int length)
{
DownInfo* info = (DownInfo*)ptr;
info->recvSize += length;
char* output = (char*)malloc(0x1000);
sprintf_s(output, 0x990, "onNetJobDataRecvCallback: %d %d, %f\n", info->allSize, info->recvSize, info->recvSize / (info->allSize + 1.0));
OutputDebugStringA(output);
free(output);
}
unsigned int __stdcall msgBoxThread(void* param)
{
std::function<void(void)>* callback = (std::function<void(void)>*)param;
(*callback)();
delete callback;
return 0;
}
void MB_CALL_TYPE onNetJobDataFinishCallback(void* ptr, mbNetJob job, mbLoadingResult result)
{
OutputDebugStringA("onNetJobDataFinishCallback\n");
std::wstring* title = new std::wstring;
*title += L" 下载完成:";
std::function<void(void)>* callback = new std::function<void(void)>([title, result] {
LPCWSTR lpCaption = (result == MB_LOADING_SUCCEEDED ? L"下载成功" : L"下载失败");
MessageBoxW(nullptr, title->c_str(), lpCaption, MB_OK);
delete title;
});
unsigned int threadId = 0; // 为了不卡blink线程messagbox放到另外个线程弹出
std::thread msgBox(msgBoxThread, callback);
msgBox.detach();
}
static mbDownloadOpt MB_CALL_TYPE onDownloadCallback(mbWebView webView,
void* param,
size_t expectedContentLength,
const char* url,
const char* mime,
const char* disposition,
mbNetJob job,
mbNetJobDataBind* dataBind)
{
char* output = (char*)malloc(0x8000);
sprintf_s(output, 0x7990, "onDownloadCallback: %d %s\n", expectedContentLength, url);
OutputDebugStringA(output);
free(output);
DownInfo* info = new DownInfo();
info->url = url;
info->recvSize = 0;
info->allSize = expectedContentLength;
mbDownloadBind bind = { 0 };
bind.param = info;
bind.recvCallback = onNetJobDataRecvCallback;
bind.finishCallback = onNetJobDataFinishCallback;
bind.saveNameCallback = nullptr;
return mbPopupDialogAndDownload(webView, nullptr, expectedContentLength, url, mime, disposition, job, dataBind, &bind);
//return mbDownloadByPath(webView, nullptr, L"P:\\", expectedContentLength, url, mime, disposition, job, dataBind, &bind);
}
QMiniBlink::QMiniBlink(QWidget *parent) QMiniBlink::QMiniBlink(QWidget *parent)
: QWidget(parent){ : QWidget(parent){
@ -26,6 +100,7 @@ void QMiniBlink::init() {
mbMoveWindow(this->mbView, 0, 0, rect.right - rect.left, rect.bottom - rect.top); mbMoveWindow(this->mbView, 0, 0, rect.right - rect.left, rect.bottom - rect.top);
//while(this->firstUrl.isEmpty()){} //while(this->firstUrl.isEmpty()){}
//mbLoadURL(this->mbView, this->firstUrl.toStdString().c_str()); //mbLoadURL(this->mbView, this->firstUrl.toStdString().c_str());
mbOnDownloadInBlinkThread(mbView,onDownloadCallback, nullptr);
SetWindowSubclass((HWND)this->winId(), subClassProc, 0, (DWORD_PTR)this); SetWindowSubclass((HWND)this->winId(), subClassProc, 0, (DWORD_PTR)this);
//mbRunMessageLoop(); //mbRunMessageLoop();
} }

View File

@ -6,13 +6,52 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>1142</width> <width>600</width>
<height>806</height> <height>400</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
<string>QMiniBlink</string> <string>QMiniBlink</string>
</property> </property>
<widget class="QCheckBox" name="checkBox">
<property name="geometry">
<rect>
<x>110</x>
<y>130</y>
<width>401</width>
<height>61</height>
</rect>
</property>
<property name="text">
<string>我同意加入用户体验改善计划</string>
</property>
</widget>
<widget class="QPushButton" name="detail">
<property name="geometry">
<rect>
<x>70</x>
<y>280</y>
<width>150</width>
<height>46</height>
</rect>
</property>
<property name="text">
<string>查看详情</string>
</property>
</widget>
<widget class="QPushButton" name="submit">
<property name="geometry">
<rect>
<x>370</x>
<y>280</y>
<width>150</width>
<height>46</height>
</rect>
</property>
<property name="text">
<string>确定</string>
</property>
</widget>
</widget> </widget>
<layoutdefault spacing="6" margin="11"/> <layoutdefault spacing="6" margin="11"/>
<resources/> <resources/>

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +1,4 @@
#pragma once #pragma once
#include <QtSql/QSqlDatabase> #include <QtSql/QSqlDatabase>
#include <QtSql/QSqlError> #include <QtSql/QSqlError>
#include <QtSql/QSqlQuery> #include <QtSql/QSqlQuery>
@ -14,11 +14,15 @@ class SoftwareRequest;
typedef struct tagRecord{ typedef struct tagRecord{
int id; int id;
int sort; int sort;
QString initial_position;
QString app_id; QString app_id;
bool locked; bool locked;
bool is_navbar;
bool is_elite;
QString type; QString type;
QString category_id; QString category_id;
QString logo; QString logo;
QString img;
QString name; QString name;
QString orig_name; QString orig_name;
QString version; QString version;
@ -47,15 +51,20 @@ class SQLiteHelper : public QObject
public: public:
SQLiteHelper(QObject *parent = nullptr); SQLiteHelper(QObject *parent = nullptr);
bool update_software(); bool update_software();
bool insert_software(QString name, QString orig_name, QString path, QString sort, bool* categories); bool insert_software(QString name, QString orig_name, QString path, QString sort, bool* categories, QString logo, QString img,QString type,bool locked,QString op,QString func,QString url,bool is_navbar,bool is_elite,QString dev);
int insert_software(QString name, QString orig_name, QString path, QString sort, bool* categories);
bool edit_software(QString name, QString orig_name, QString path, QString sort, bool* categories,QString type=""); bool edit_software(QString name, QString orig_name, QString path, QString sort, bool* categories,QString type="");
bool get_software(QList<ButtonStruct>* buttons, ConfigResponse* config_response); bool get_software(QList<ButtonStruct>* buttons, ConfigResponse* config_response);
bool get_software(QList<ButtonStruct>* button_structs,QString background_color , QString title_color, QString title_cover_color);
bool update_app(); bool update_app();
bool get_buttons(QList<ButtonStruct> &buttons); bool get_buttons(QList<ButtonStruct> &buttons);
bool get_category(QList<Categrory>& categrories, bool is_edit,bool all=false); bool get_category(QList<Categrory>& categrories, bool is_edit,bool all=false);
bool set_category(QList<Categrory>& categrories); bool set_category(QList<Categrory>& categrories);
bool get_all_software(QList<Record> &softwares,int category); bool get_all_software(QList<Record> &softwares,int category);
bool get_a_software(QString orig_name, Record2 *record); bool get_a_software(QString orig_name, Record2 *record);
bool update_total();//警告:这个函数必须用于事务中
bool use_software(QString orig_name);
QSqlDatabase db; QSqlDatabase db;
~SQLiteHelper(); ~SQLiteHelper();
@ -64,6 +73,8 @@ private:
QNetworkReply* reply; QNetworkReply* reply;
QEventLoop eventLoop; QEventLoop eventLoop;
bool downloadSuccess; bool downloadSuccess;
bool delete_software(QString orig_name);
bool execute_query(QString sql, QList<Record>& softwares);
void cancelDownload(); void cancelDownload();
}; };

View File

@ -0,0 +1,35 @@
#include "userimprove.h"
#include "globalvariables.h"
UserImprove::UserImprove(QWidget* parent)
: QDialog(parent)
{
ui.setupUi(this);
connect(ui.submit, &QPushButton::clicked, this, &UserImprove::submit);
connect(ui.detail, &QPushButton::clicked, this, &UserImprove::showDetail);
setFixedSize(600, 400);
}
UserImprove::~UserImprove()
{
}
void UserImprove::submit()
{
if (ui.checkBox->checkState() == Qt::Checked)
{
agree = true;
}
else
{
agree = false;
}
close();
}
void UserImprove::showDetail()
{
QString path = QApplication::applicationDirPath();
QString license = path + "/detail.txt";
license.replace("/", "\\");
ShellExecute(GetDesktopWindow(), L"open", L"notepad.exe", license.toStdWString().c_str(), nullptr, SW_SHOW);
}

View File

@ -0,0 +1,18 @@
#pragma once
#include <QDialog>
#include "ui_userimprove.h"
class UserImprove : public QDialog
{
Q_OBJECT
public:
UserImprove(QWidget *parent = nullptr);
~UserImprove();
private slots:
void submit();
void showDetail();
private:
Ui::UserImproveClass ui;
};

View File

@ -0,0 +1,59 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>UserImproveClass</class>
<widget class="QDialog" name="UserImproveClass">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>600</width>
<height>400</height>
</rect>
</property>
<property name="windowTitle">
<string>用户体验改善计划</string>
</property>
<widget class="QPushButton" name="detail">
<property name="geometry">
<rect>
<x>80</x>
<y>310</y>
<width>150</width>
<height>46</height>
</rect>
</property>
<property name="text">
<string>查看详情</string>
</property>
</widget>
<widget class="QPushButton" name="submit">
<property name="geometry">
<rect>
<x>330</x>
<y>310</y>
<width>150</width>
<height>46</height>
</rect>
</property>
<property name="text">
<string>确定</string>
</property>
</widget>
<widget class="QCheckBox" name="checkBox">
<property name="geometry">
<rect>
<x>110</x>
<y>170</y>
<width>371</width>
<height>28</height>
</rect>
</property>
<property name="text">
<string>我同意加入用户体验改善计划</string>
</property>
</widget>
</widget>
<layoutdefault spacing="6" margin="11"/>
<resources/>
<connections/>
</ui>

3
config/config.kmd Normal file
View File

@ -0,0 +1,3 @@
{
"agree": true
}

Binary file not shown.

BIN
images/app.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

View File

@ -1 +0,0 @@
<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg t="1691497575694" class="icon" viewBox="0 0 1243 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="4021" xmlns:xlink="http://www.w3.org/1999/xlink" width="242.7734375" height="200"><path d="M839.68 323.584c13.312 0 26.624 1.243 39.863 2.414-35.62-166.62-214.309-291.109-417.865-291.109-227.62 0.805-414.135 155.868-414.135 352.768 0 113.518 62.171 207.14 165.449 279.625l-41.691 124.343 144.969-72.411c51.931 10.24 93.623 20.48 144.896 20.48 13.312 0 25.965-0.585 38.62-1.756a318.61 318.61 0 0 1-12.655-87.04c0.586-180.516 155.795-327.24 352.622-327.24zM616.887 211.383c31.451 0 51.931 20.48 51.931 51.931 0 30.72-20.48 51.932-51.931 51.932-30.793 0-62.172-20.553-62.172-51.932 0-31.451 31.379-51.931 62.172-51.931zM327.022 315.246c-30.72 0-62.172-20.553-62.172-51.932 0-31.451 31.452-51.931 62.172-51.931 30.793 0 51.931 20.48 51.931 51.931 0 30.72-20.48 51.932-51.931 51.932z m890.807 331.337c0-165.45-165.45-300.69-352.11-300.69-196.828 0-352.037 135.24-352.037 300.69 0 166.034 155.21 300.763 352.037 300.763 41.106 0 82.798-10.24 124.416-20.553l113.518 62.172-31.379-103.278c83.383-63.342 145.555-146.14 145.555-239.104zM751.616 594.65c-20.48 0-41.691-20.48-41.691-41.691 0-20.48 21.211-41.691 41.691-41.691 31.451 0 51.931 20.553 51.931 41.691 0 21.211-20.48 41.691-51.931 41.691z m227.694 0c-20.553 0-41.107-20.48-41.107-41.691 0-20.48 20.48-41.691 41.107-41.691 31.378 0 51.931 20.553 51.931 41.691 0 21.211-20.553 41.691-51.931 41.691z" fill="#00CE12" p-id="4022"></path></svg>

Before

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.8 KiB

After

Width:  |  Height:  |  Size: 7.7 KiB

BIN
images/logo_titlebar.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

View File

@ -1,72 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>发生错误</title>
<meta name="robots" content="noindex,nofollow" />
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
<link rel="shortcut icon" href="/assets/img/favicon.ico" />
<style>
* {-moz-box-sizing:border-box;-webkit-box-sizing:border-box;box-sizing:border-box;}
html,body,div,span,object,iframe,h1,h2,h3,h4,h5,h6,p,blockquote,pre,abbr,address,cite,code,del,dfn,em,img,ins,kbd,q,samp,small,strong,sub,sup,var,b,i,dl,dt,dd,ol,ul,li,fieldset,form,label,legend,caption,article,aside,canvas,details,figcaption,figure,footer,header,hgroup,menu,nav,section,summary,time,mark,audio,video {margin:0;padding:0;border:0;outline:0;vertical-align:baseline;background:transparent;}
article,aside,details,figcaption,figure,footer,header,hgroup,nav,section {display:block;}
html {font-size:16px;line-height:24px;width:100%;height:100%;-webkit-text-size-adjust:100%;-ms-text-size-adjust:100%;overflow-y:scroll;overflow-x:hidden;}
img {vertical-align:middle;max-width:100%;height:auto;border:0;-ms-interpolation-mode:bicubic;}
body {min-height:100%;background:#f4f6f8;text-rendering:optimizeLegibility;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale;font-family:"Helvetica Neue",Helvetica,"PingFang SC","Hiragino Sans GB","Microsoft YaHei",微软雅黑,Arial,sans-serif;}
.clearfix {clear:both;zoom:1;}
.clearfix:before,.clearfix:after {content:"\0020";display:block;height:0;visibility:hidden;}
.clearfix:after {clear:both;}
body.error-page-wrapper,.error-page-wrapper.preview {background-position:center center;background-repeat:no-repeat;background-size:cover;position:relative;}
.error-page-wrapper .content-container {border-radius:2px;text-align:center;box-shadow:0 0 30px rgba(99,99,99,0.06);padding:50px;background-color:#fff;width:100%;max-width:560px;position:absolute;left:50%;top:50%;margin-top:-220px;margin-left:-280px;}
.error-page-wrapper .content-container.in {left:0px;opacity:1;}
.error-page-wrapper .head-line {transition:color .2s linear;font-size:40px;line-height:60px;letter-spacing:-1px;margin-bottom:20px;color:#777;}
.error-page-wrapper .subheader {transition:color .2s linear;font-size:32px;line-height:46px;color:#494949;}
.error-page-wrapper .hr {height:1px;background-color:#eee;width:80%;max-width:350px;margin:25px auto;}
.error-page-wrapper .context {transition:color .2s linear;font-size:16px;line-height:27px;color:#aaa;}
.error-page-wrapper .context p {margin:0;}
.error-page-wrapper .context p:nth-child(n+2) {margin-top:16px;}
.error-page-wrapper .buttons-container {margin-top:35px;overflow:hidden;}
.error-page-wrapper .buttons-container a {transition:text-indent .2s ease-out,color .2s linear,background-color .2s linear;text-indent:0px;font-size:14px;text-transform:uppercase;text-decoration:none;color:#fff;background-color:#2ecc71;border-radius:99px;padding:8px 0 8px;text-align:center;display:inline-block;overflow:hidden;position:relative;width:45%;}
.error-page-wrapper .buttons-container a:hover {text-indent:15px;}
.error-page-wrapper .buttons-container a:nth-child(1) {float:left;}
.error-page-wrapper .buttons-container a:nth-child(2) {float:right;}
@media screen and (max-width:580px) {
.error-page-wrapper {padding:30px 5%;}
.error-page-wrapper .content-container {padding:37px;position:static;left:0;margin-top:0;margin-left:0;}
.error-page-wrapper .head-line {font-size:36px;}
.error-page-wrapper .subheader {font-size:27px;line-height:37px;}
.error-page-wrapper .hr {margin:30px auto;width:215px;}
}
@media screen and (max-width:450px) {
.error-page-wrapper {padding:30px;}
.error-page-wrapper .head-line {font-size:32px;}
.error-page-wrapper .hr {margin:25px auto;width:180px;}
.error-page-wrapper .context {font-size:15px;line-height:22px;}
.error-page-wrapper .context p:nth-child(n+2) {margin-top:10px;}
.error-page-wrapper .buttons-container {margin-top:29px;}
.error-page-wrapper .buttons-container a {float:none !important;width:65%;margin:0 auto;font-size:13px;padding:9px 0;}
.error-page-wrapper .buttons-container a:nth-child(2) {margin-top:12px;}
}
</style>
</head>
<body class="error-page-wrapper">
<div class="content-container">
<div class="head-line">
<img src="/assets/img/error.svg" alt="" width="120"/>
</div>
<div class="subheader">
你所浏览的页面暂时无法访问{"s":"\/assets\/addons\/kmdsoft\/images\/wxdk\/menu\/hao123.svg"} </div>
<div class="hr"></div>
<div class="context">
<p>
你可以返回上一页重试 </p>
</div>
<div class="buttons-container">
<a href="/">返回主页</a>
<a href="javascript:" onclick="history.go(-1)">返回上一页</a>
</div>
</div>
</body>
</html>

1
images/svg/default.svg Normal file
View File

@ -0,0 +1 @@
<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg t="1691679612388" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="1664" xmlns:xlink="http://www.w3.org/1999/xlink" width="200" height="200"><path d="M541.696 86.308571l316.952381 140.775619A73.142857 73.142857 0 0 1 902.095238 293.936762v436.126476a73.142857 73.142857 0 0 1-43.446857 66.852572l-316.952381 140.751238a73.142857 73.142857 0 0 1-59.392 0l-316.952381-140.751238A73.142857 73.142857 0 0 1 121.904762 730.063238V293.936762a73.142857 73.142857 0 0 1 43.446857-66.852572l316.952381-140.751238a73.142857 73.142857 0 0 1 59.392 0zM195.047619 362.788571v367.274667l286.476191 127.21981V485.546667L195.047619 362.788571z m633.904762 2.633143l-274.285714 117.516191V851.870476L828.952381 730.063238V365.421714zM512 153.185524L207.335619 288.475429l307.760762 131.900952 304.591238-130.56L512 153.185524z" p-id="1665"></path></svg>

After

Width:  |  Height:  |  Size: 1019 B

View File

@ -1,294 +1,294 @@
#define KEY "79c86fb12b36dfa33d1a537c9af100b4c7928a9c" #define KEY "79c86fb12b36dfa33d1a537c9af100b4c7928a9c"
#include "openwechat.h" #include "openwechat.h"
#include <string> #include <string>
#include <wchar.h> #include <wchar.h>
#include <cstring> #include <cstring>
#include <vector> #include <vector>
#include <tlhelp32.h> #include <tlhelp32.h>
ZWQUERYSYSTEMINFORMATION ZwQuerySystemInformation = (ZWQUERYSYSTEMINFORMATION)GetProcAddress(GetModuleHandleA("ntdll.dll"), "ZwQuerySystemInformation"); ZWQUERYSYSTEMINFORMATION ZwQuerySystemInformation = (ZWQUERYSYSTEMINFORMATION)GetProcAddress(GetModuleHandleA("ntdll.dll"), "ZwQuerySystemInformation");
NTQUERYOBJECT NtQueryObject = (NTQUERYOBJECT)GetProcAddress( NTQUERYOBJECT NtQueryObject = (NTQUERYOBJECT)GetProcAddress(
GetModuleHandleA("ntdll.dll"), "NtQueryObject"); GetModuleHandleA("ntdll.dll"), "NtQueryObject");
BOOL IsTargetPid(DWORD Pid, std::vector<DWORD> Pids, int num) BOOL IsTargetPid(DWORD Pid, std::vector<DWORD> Pids, int num)
{ {
for (auto pid:Pids) for (auto pid:Pids)
{ {
if (Pid == pid) if (Pid == pid)
{ {
return TRUE; return TRUE;
} }
} }
return FALSE; return FALSE;
} }
HANDLE DuplicateHandleEx(DWORD pid, HANDLE h, DWORD flags) HANDLE DuplicateHandleEx(DWORD pid, HANDLE h, DWORD flags)
{ {
HANDLE hHandle = NULL; HANDLE hHandle = NULL;
HANDLE hProc = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid); HANDLE hProc = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid);
if (hProc) if (hProc)
{ {
if (!DuplicateHandle(hProc, if (!DuplicateHandle(hProc,
(HANDLE)h, GetCurrentProcess(), (HANDLE)h, GetCurrentProcess(),
&hHandle, 0, FALSE, /*DUPLICATE_SAME_ACCESS*/flags)) &hHandle, 0, FALSE, /*DUPLICATE_SAME_ACCESS*/flags))
{ {
hHandle = NULL; hHandle = NULL;
} }
} }
CloseHandle(hProc); CloseHandle(hProc);
return hHandle; return hHandle;
} }
typedef struct _SYSTEM_HANDLE_TABLE_ENTRY_INFO { typedef struct _SYSTEM_HANDLE_TABLE_ENTRY_INFO {
USHORT UniqueProcessId; USHORT UniqueProcessId;
USHORT CreatorBackTraceIndex; USHORT CreatorBackTraceIndex;
UCHAR ObjectTypeIndex; UCHAR ObjectTypeIndex;
UCHAR HandleAttributes; UCHAR HandleAttributes;
USHORT HandleValue; USHORT HandleValue;
PVOID Object; PVOID Object;
ULONG GrantedAccess; ULONG GrantedAccess;
} SYSTEM_HANDLE_TABLE_ENTRY_INFO, *PSYSTEM_HANDLE_TABLE_ENTRY_INFO; } SYSTEM_HANDLE_TABLE_ENTRY_INFO, *PSYSTEM_HANDLE_TABLE_ENTRY_INFO;
typedef struct typedef struct
{ {
USHORT Length; USHORT Length;
USHORT MaxLen; USHORT MaxLen;
USHORT *Buffer; USHORT *Buffer;
}UNICODE_STRING, *PUNICODE_STRING; }UNICODE_STRING, *PUNICODE_STRING;
typedef struct _OBJECT_NAME_INFORMATION { typedef struct _OBJECT_NAME_INFORMATION {
UNICODE_STRING Name; UNICODE_STRING Name;
} OBJECT_NAME_INFORMATION, *POBJECT_NAME_INFORMATION; } OBJECT_NAME_INFORMATION, *POBJECT_NAME_INFORMATION;
typedef struct _SYSTEM_HANDLE_INFORMATION1 { typedef struct _SYSTEM_HANDLE_INFORMATION1 {
ULONG NumberOfHandles; ULONG NumberOfHandles;
SYSTEM_HANDLE_TABLE_ENTRY_INFO Handles[1]; SYSTEM_HANDLE_TABLE_ENTRY_INFO Handles[1];
} SYSTEM_HANDLE_INFORMATION1, *PSYSTEM_HANDLE_INFORMATION1; } SYSTEM_HANDLE_INFORMATION1, *PSYSTEM_HANDLE_INFORMATION1;
DWORD qureyProcessId(std::wstring name, std::vector<DWORD> *pids) { DWORD qureyProcessId(std::wstring name, std::vector<DWORD> *pids) {
DWORD pid; DWORD pid;
PROCESSENTRY32 entry; PROCESSENTRY32 entry;
entry.dwSize = sizeof(PROCESSENTRY32); entry.dwSize = sizeof(PROCESSENTRY32);
HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL); HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL);
if (Process32First(snapshot, &entry) == TRUE) if (Process32First(snapshot, &entry) == TRUE)
{ {
while (Process32Next(snapshot, &entry) == TRUE) while (Process32Next(snapshot, &entry) == TRUE)
{ {
if (std::wstring(entry.szExeFile) == name) { if (std::wstring(entry.szExeFile) == name) {
HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, entry.th32ProcessID); HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, entry.th32ProcessID);
pid = GetProcessId(hProcess); pid = GetProcessId(hProcess);
CloseHandle(hProcess); CloseHandle(hProcess);
pids->emplace_back(pid); pids->emplace_back(pid);
} }
} }
} }
CloseHandle(snapshot); CloseHandle(snapshot);
return pid; return pid;
} }
BOOL ElevatePrivileges() BOOL ElevatePrivileges()
{ {
HANDLE hToken; HANDLE hToken;
TOKEN_PRIVILEGES tkp; TOKEN_PRIVILEGES tkp;
tkp.PrivilegeCount = 1; tkp.PrivilegeCount = 1;
if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken)) if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken))
return FALSE; return FALSE;
LookupPrivilegeValue(NULL, SE_DEBUG_NAME, &tkp.Privileges[0].Luid); LookupPrivilegeValue(NULL, SE_DEBUG_NAME, &tkp.Privileges[0].Luid);
tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
if (!AdjustTokenPrivileges(hToken, FALSE, &tkp, sizeof(TOKEN_PRIVILEGES), NULL, NULL)) if (!AdjustTokenPrivileges(hToken, FALSE, &tkp, sizeof(TOKEN_PRIVILEGES), NULL, NULL))
{ {
return FALSE; return FALSE;
} }
return TRUE; return TRUE;
} }
int PatchWeChat() int PatchWeChat()
{ {
DWORD dwSize = 0; DWORD dwSize = 0;
POBJECT_NAME_INFORMATION pNameInfo; POBJECT_NAME_INFORMATION pNameInfo;
POBJECT_NAME_INFORMATION pNameType; POBJECT_NAME_INFORMATION pNameType;
PVOID pbuffer = NULL; PVOID pbuffer = NULL;
NTSTATUS Status; NTSTATUS Status;
int nIndex = 0; int nIndex = 0;
DWORD dwFlags = 0; DWORD dwFlags = 0;
char szType[128] = { 0 }; char szType[128] = { 0 };
char szName[512] = { 0 }; char szName[512] = { 0 };
PSYSTEM_HANDLE_INFORMATION1 pHandleInfo = NULL; PSYSTEM_HANDLE_INFORMATION1 pHandleInfo = NULL;
int ret = -1; int ret = -1;
ElevatePrivileges(); ElevatePrivileges();
std::vector<DWORD> pids; std::vector<DWORD> pids;
DWORD Num = qureyProcessId(L"WeChat.exe", &pids); DWORD Num = qureyProcessId(L"WeChat.exe", &pids);
if (Num == 0) if (Num == 0)
{ {
return ret; return ret;
} }
if (!ZwQuerySystemInformation) if (!ZwQuerySystemInformation)
{ {
goto Exit0; goto Exit0;
} }
pbuffer = VirtualAlloc(NULL, 0x1000, MEM_COMMIT, PAGE_READWRITE); pbuffer = VirtualAlloc(NULL, 0x1000, MEM_COMMIT, PAGE_READWRITE);
if (!pbuffer) if (!pbuffer)
{ {
goto Exit0; goto Exit0;
} }
Status = ZwQuerySystemInformation(SystemHandleInformation, pbuffer, 0x1000, &dwSize); Status = ZwQuerySystemInformation(SystemHandleInformation, pbuffer, 0x1000, &dwSize);
if (Status<0) if (Status<0)
{ {
if ((LONG)0xC0000004L != Status) if ((LONG)0xC0000004L != Status)
{ {
goto Exit0; goto Exit0;
} }
else else
{ {
// 这里大家可以保证程序的正确性使用循环分配稍好 // 这里大家可以保证程序的正确性使用循环分配稍好
if (NULL != pbuffer) if (NULL != pbuffer)
{ {
VirtualFree(pbuffer, 0, MEM_RELEASE); VirtualFree(pbuffer, 0, MEM_RELEASE);
} }
if (dwSize * 2 > 0x4000000) // MAXSIZE if (dwSize * 2 > 0x4000000) // MAXSIZE
{ {
goto Exit0; goto Exit0;
} }
pbuffer = VirtualAlloc(NULL, dwSize * 2, MEM_COMMIT, PAGE_READWRITE); pbuffer = VirtualAlloc(NULL, dwSize * 2, MEM_COMMIT, PAGE_READWRITE);
if (!pbuffer) if (!pbuffer)
{ {
goto Exit0; goto Exit0;
} }
Status = ZwQuerySystemInformation(SystemHandleInformation, pbuffer, dwSize * 2, NULL); Status = ZwQuerySystemInformation(SystemHandleInformation, pbuffer, dwSize * 2, NULL);
if (Status<0) if (Status<0)
{ {
goto Exit0; goto Exit0;
} }
} }
} }
pHandleInfo = (PSYSTEM_HANDLE_INFORMATION1)pbuffer; pHandleInfo = (PSYSTEM_HANDLE_INFORMATION1)pbuffer;
for (nIndex = 0; nIndex < pHandleInfo->NumberOfHandles; nIndex++) for (nIndex = 0; nIndex < pHandleInfo->NumberOfHandles; nIndex++)
{ {
if (IsTargetPid(pHandleInfo->Handles[nIndex].UniqueProcessId, pids, Num)) if (IsTargetPid(pHandleInfo->Handles[nIndex].UniqueProcessId, pids, Num))
{ {
// //
HANDLE hHandle = DuplicateHandleEx(pHandleInfo->Handles[nIndex].UniqueProcessId, HANDLE hHandle = DuplicateHandleEx(pHandleInfo->Handles[nIndex].UniqueProcessId,
(HANDLE)pHandleInfo->Handles[nIndex].HandleValue, (HANDLE)pHandleInfo->Handles[nIndex].HandleValue,
DUPLICATE_SAME_ACCESS DUPLICATE_SAME_ACCESS
); );
if (hHandle == NULL) continue; if (hHandle == NULL) continue;
Status = NtQueryObject(hHandle, ObjectNameInformation, szName, 512, &dwFlags); Status = NtQueryObject(hHandle, ObjectNameInformation, szName, 512, &dwFlags);
if (Status<0) if (Status<0)
{ {
CloseHandle(hHandle); CloseHandle(hHandle);
continue; continue;
} }
Status = NtQueryObject(hHandle, ObjectTypeInformation, szType, 128, &dwFlags); Status = NtQueryObject(hHandle, ObjectTypeInformation, szType, 128, &dwFlags);
if (Status<0) if (Status<0)
{ {
CloseHandle(hHandle); CloseHandle(hHandle);
continue; continue;
} }
pNameInfo = (POBJECT_NAME_INFORMATION)szName; pNameInfo = (POBJECT_NAME_INFORMATION)szName;
pNameType = (POBJECT_NAME_INFORMATION)szType; pNameType = (POBJECT_NAME_INFORMATION)szType;
WCHAR TypName[1024] = { 0 }; WCHAR TypName[1024] = { 0 };
WCHAR Name[1024] = { 0 }; WCHAR Name[1024] = { 0 };
wcsncpy_s(TypName, (WCHAR*)pNameType->Name.Buffer, pNameType->Name.Length / 2); wcsncpy_s(TypName, (WCHAR*)pNameType->Name.Buffer, pNameType->Name.Length / 2);
wcsncpy_s(Name, (WCHAR*)pNameInfo->Name.Buffer, pNameInfo->Name.Length / 2); wcsncpy_s(Name, (WCHAR*)pNameInfo->Name.Buffer, pNameInfo->Name.Length / 2);
// 匹配是否为需要关闭的句柄名称 // 匹配是否为需要关闭的句柄名称
if (0 == wcscmp(TypName, L"Mutant")) if (0 == wcscmp(TypName, L"Mutant"))
{ {
//WeChat_aj5r8jpxt_Instance_Identity_Mutex_Name //WeChat_aj5r8jpxt_Instance_Identity_Mutex_Name
//if (wcsstr(Name, L"_WeChat_App_Instance_Identity_Mutex_Name")) //if (wcsstr(Name, L"_WeChat_App_Instance_Identity_Mutex_Name"))
if (wcsstr(Name, L"_WeChat_") && if (wcsstr(Name, L"_WeChat_") &&
wcsstr(Name, L"_Instance_Identity_Mutex_Name")) wcsstr(Name, L"_Instance_Identity_Mutex_Name"))
{ {
CloseHandle(hHandle); CloseHandle(hHandle);
hHandle = DuplicateHandleEx(pHandleInfo->Handles[nIndex].UniqueProcessId, hHandle = DuplicateHandleEx(pHandleInfo->Handles[nIndex].UniqueProcessId,
(HANDLE)pHandleInfo->Handles[nIndex].HandleValue, (HANDLE)pHandleInfo->Handles[nIndex].HandleValue,
DUPLICATE_CLOSE_SOURCE DUPLICATE_CLOSE_SOURCE
); );
if (hHandle) if (hHandle)
{ {
ret = ERROR_SUCCESS; ret = ERROR_SUCCESS;
CloseHandle(hHandle); CloseHandle(hHandle);
} }
else else
{ {
ret = GetLastError(); ret = GetLastError();
} }
//goto Exit0; //goto Exit0;
} }
} }
CloseHandle(hHandle); CloseHandle(hHandle);
} }
} }
Exit0: Exit0:
if (NULL != pbuffer) if (NULL != pbuffer)
{ {
VirtualFree(pbuffer, 0, MEM_RELEASE); VirtualFree(pbuffer, 0, MEM_RELEASE);
} }
return ret; return ret;
} }
int WINAPI WinMain( int WINAPI WinMain(
HINSTANCE hInstance, HINSTANCE hInstance,
HINSTANCE hPrevInstance, HINSTANCE hPrevInstance,
PSTR nCmdLine, PSTR nCmdLine,
int iCmdShow int iCmdShow
) { ) {
if (strcmp(nCmdLine, KEY) != 0){ if (strcmp(nCmdLine, KEY) != 0){
return 0; return 0;
} }
else { else {
int ret = 1; int ret = 1;
PatchWeChat(); PatchWeChat();
WCHAR Path[1024]; WCHAR Path[1024];
HKEY hKey = NULL; HKEY hKey = NULL;
if (ERROR_SUCCESS != RegOpenKey(HKEY_CURRENT_USER, L"Software\\Tencent\\WeChat", &hKey)) if (ERROR_SUCCESS != RegOpenKey(HKEY_CURRENT_USER, L"Software\\Tencent\\WeChat", &hKey))
{ {
return ret; return ret;
} }
DWORD Type = REG_SZ; DWORD Type = REG_SZ;
// WCHAR Path[MAX_PATH] = { 0 }; // WCHAR Path[MAX_PATH] = { 0 };
DWORD cbData = MAX_PATH * sizeof(WCHAR); DWORD cbData = MAX_PATH * sizeof(WCHAR);
if (ERROR_SUCCESS != RegQueryValueEx(hKey, L"InstallPath", 0, &Type, (LPBYTE)Path, &cbData)) if (ERROR_SUCCESS != RegQueryValueEx(hKey, L"InstallPath", 0, &Type, (LPBYTE)Path, &cbData))
{ {
ret = GetLastError(); ret = GetLastError();
if (hKey) if (hKey)
{ {
RegCloseKey(hKey); RegCloseKey(hKey);
} }
return ret; return ret;
} }
WCHAR exe[1024]; WCHAR exe[1024];
wcscpy_s(exe, Path); wcscpy_s(exe, Path);
wcscat_s(exe, L"\\WeChat.exe"); wcscat_s(exe, L"\\WeChat.exe");
ShellExecute(GetDesktopWindow(), L"open", exe, L"", Path, SW_SHOW); ShellExecute(GetDesktopWindow(), L"open", exe, L"", Path, SW_SHOW);
} }
return 0; return 0;
} }

View File

@ -1,81 +1,81 @@
#pragma once #pragma once
#include <Windows.h> #include <Windows.h>
typedef enum _SYSTEM_INFORMATION_CLASS { typedef enum _SYSTEM_INFORMATION_CLASS {
SystemBasicInformation, // 0 Y N SystemBasicInformation, // 0 Y N
SystemProcessorInformation, // 1 Y N SystemProcessorInformation, // 1 Y N
SystemPerformanceInformation, // 2 Y N SystemPerformanceInformation, // 2 Y N
SystemTimeOfDayInformation, // 3 Y N SystemTimeOfDayInformation, // 3 Y N
SystemNotImplemented1, // 4 Y N SystemNotImplemented1, // 4 Y N
SystemProcessesAndThreadsInformation, // 5 Y N SystemProcessesAndThreadsInformation, // 5 Y N
SystemCallCounts, // 6 Y N SystemCallCounts, // 6 Y N
SystemConfigurationInformation, // 7 Y N SystemConfigurationInformation, // 7 Y N
SystemProcessorTimes, // 8 Y N SystemProcessorTimes, // 8 Y N
SystemGlobalFlag, // 9 Y Y SystemGlobalFlag, // 9 Y Y
SystemNotImplemented2, // 10 Y N SystemNotImplemented2, // 10 Y N
SystemModuleInformation, // 11 Y N SystemModuleInformation, // 11 Y N
SystemLockInformation, // 12 Y N SystemLockInformation, // 12 Y N
SystemNotImplemented3, // 13 Y N SystemNotImplemented3, // 13 Y N
SystemNotImplemented4, // 14 Y N SystemNotImplemented4, // 14 Y N
SystemNotImplemented5, // 15 Y N SystemNotImplemented5, // 15 Y N
SystemHandleInformation, // 16 Y N SystemHandleInformation, // 16 Y N
SystemObjectInformation, // 17 Y N SystemObjectInformation, // 17 Y N
SystemPagefileInformation, // 18 Y N SystemPagefileInformation, // 18 Y N
SystemInstructionEmulationCounts, // 19 Y N SystemInstructionEmulationCounts, // 19 Y N
SystemInvalidInfoClass1, // 20 SystemInvalidInfoClass1, // 20
SystemCacheInformation, // 21 Y Y SystemCacheInformation, // 21 Y Y
SystemPoolTagInformation, // 22 Y N SystemPoolTagInformation, // 22 Y N
SystemProcessorStatistics, // 23 Y N SystemProcessorStatistics, // 23 Y N
SystemDpcInformation, // 24 Y Y SystemDpcInformation, // 24 Y Y
SystemNotImplemented6, // 25 Y N SystemNotImplemented6, // 25 Y N
SystemLoadImage, // 26 N Y SystemLoadImage, // 26 N Y
SystemUnloadImage, // 27 N Y SystemUnloadImage, // 27 N Y
SystemTimeAdjustment, // 28 Y Y SystemTimeAdjustment, // 28 Y Y
SystemNotImplemented7, // 29 Y N SystemNotImplemented7, // 29 Y N
SystemNotImplemented8, // 30 Y N SystemNotImplemented8, // 30 Y N
SystemNotImplemented9, // 31 Y N SystemNotImplemented9, // 31 Y N
SystemCrashDumpInformation, // 32 Y N SystemCrashDumpInformation, // 32 Y N
SystemExceptionInformation, // 33 Y N SystemExceptionInformation, // 33 Y N
SystemCrashDumpStateInformation, // 34 Y Y/N SystemCrashDumpStateInformation, // 34 Y Y/N
SystemKernelDebuggerInformation, // 35 Y N SystemKernelDebuggerInformation, // 35 Y N
SystemContextSwitchInformation, // 36 Y N SystemContextSwitchInformation, // 36 Y N
SystemRegistryQuotaInformation, // 37 Y Y SystemRegistryQuotaInformation, // 37 Y Y
SystemLoadAndCallImage, // 38 N Y SystemLoadAndCallImage, // 38 N Y
SystemPrioritySeparation, // 39 N Y SystemPrioritySeparation, // 39 N Y
SystemNotImplemented10, // 40 Y N SystemNotImplemented10, // 40 Y N
SystemNotImplemented11, // 41 Y N SystemNotImplemented11, // 41 Y N
SystemInvalidInfoClass2, // 42 SystemInvalidInfoClass2, // 42
SystemInvalidInfoClass3, // 43 SystemInvalidInfoClass3, // 43
SystemTimeZoneInformation, // 44 Y N SystemTimeZoneInformation, // 44 Y N
SystemLookasideInformation, // 45 Y N SystemLookasideInformation, // 45 Y N
SystemSetTimeSlipEvent, // 46 N Y SystemSetTimeSlipEvent, // 46 N Y
SystemCreateSession, // 47 N Y SystemCreateSession, // 47 N Y
SystemDeleteSession, // 48 N Y SystemDeleteSession, // 48 N Y
SystemInvalidInfoClass4, // 49 SystemInvalidInfoClass4, // 49
SystemRangeStartInformation, // 50 Y N SystemRangeStartInformation, // 50 Y N
SystemVerifierInformation, // 51 Y Y SystemVerifierInformation, // 51 Y Y
SystemAddVerifier, // 52 N Y SystemAddVerifier, // 52 N Y
SystemSessionProcessesInformation // 53 Y N SystemSessionProcessesInformation // 53 Y N
} SYSTEM_INFORMATION_CLASS; } SYSTEM_INFORMATION_CLASS;
typedef NTSTATUS typedef NTSTATUS
(NTAPI *ZWQUERYSYSTEMINFORMATION)( (NTAPI *ZWQUERYSYSTEMINFORMATION)(
IN SYSTEM_INFORMATION_CLASS SystemInformationClass, IN SYSTEM_INFORMATION_CLASS SystemInformationClass,
OUT PVOID SystemInformation, OUT PVOID SystemInformation,
IN ULONG SystemInformationLength, IN ULONG SystemInformationLength,
OUT PULONG ReturnLength OPTIONAL OUT PULONG ReturnLength OPTIONAL
); );
typedef enum _OBJECT_INFORMATION_CLASS { typedef enum _OBJECT_INFORMATION_CLASS {
ObjectBasicInformation, ObjectBasicInformation,
ObjectNameInformation, ObjectNameInformation,
ObjectTypeInformation, ObjectTypeInformation,
ObjectAllInformation, ObjectAllInformation,
ObjectDataInformation ObjectDataInformation
} OBJECT_INFORMATION_CLASS; } OBJECT_INFORMATION_CLASS;
typedef NTSTATUS(NTAPI *NTQUERYOBJECT)( typedef NTSTATUS(NTAPI *NTQUERYOBJECT)(
_In_opt_ HANDLE Handle, _In_opt_ HANDLE Handle,
_In_ OBJECT_INFORMATION_CLASS ObjectInformationClass, _In_ OBJECT_INFORMATION_CLASS ObjectInformationClass,
_Out_opt_ PVOID ObjectInformation, _Out_opt_ PVOID ObjectInformation,
_In_ ULONG ObjectInformationLength, _In_ ULONG ObjectInformationLength,
_Out_opt_ PULONG ReturnLength _Out_opt_ PULONG ReturnLength
); );