From b728e697fbeff8fd474f064d0c3c869b1bfd833b Mon Sep 17 00:00:00 2001 From: Mike Solar Date: Fri, 18 Aug 2023 19:09:55 +0800 Subject: [PATCH] =?UTF-8?q?=E5=87=A0=E4=B9=8E=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- OfficeAssistant_msvc/MyButton.cpp | 7 +- OfficeAssistant_msvc/MyButton.h | 5 +- .../OfficeAssistant_msvc.vcxproj | 3 + .../OfficeAssistant_msvc.vcxproj.filters | 9 + .../OfficeAssistant_msvc.vcxproj.user | 4 +- OfficeAssistant_msvc/addapp.cpp | 84 +-- OfficeAssistant_msvc/addapp.h | 4 +- OfficeAssistant_msvc/addcategory.cpp | 19 +- OfficeAssistant_msvc/applicationmanager.cpp | 228 +++--- OfficeAssistant_msvc/applicationmanager.h | 13 +- .../applicationmanagerpage.cpp | 185 ++--- OfficeAssistant_msvc/applicationmanagerpage.h | 8 +- OfficeAssistant_msvc/buttonstruct.h | 3 +- OfficeAssistant_msvc/config.h | 9 +- OfficeAssistant_msvc/globalvariables.h | 4 +- OfficeAssistant_msvc/mainscreen.h | 4 +- OfficeAssistant_msvc/mainwindow.cpp | 89 +-- OfficeAssistant_msvc/mainwindowlayout.cpp | 16 +- OfficeAssistant_msvc/mainwindowlayout.h | 7 +- OfficeAssistant_msvc/minibutton.cpp | 6 +- OfficeAssistant_msvc/minibutton.h | 3 +- OfficeAssistant_msvc/navbar.cpp | 50 +- OfficeAssistant_msvc/navbar.h | 6 + OfficeAssistant_msvc/netio.cpp | 69 +- OfficeAssistant_msvc/netio.h | 19 +- OfficeAssistant_msvc/qminiblink.ui | 43 +- OfficeAssistant_msvc/sqlitehelper.cpp | 711 ++++++++++-------- OfficeAssistant_msvc/sqlitehelper.h | 14 +- OfficeAssistant_msvc/userimprove.cpp | 34 + OfficeAssistant_msvc/userimprove.h | 18 + OfficeAssistant_msvc/userimprove.ui | 59 ++ wxdk/main.cpp | 586 +++++++-------- wxdk/openwechat.h | 162 ++-- 33 files changed, 1299 insertions(+), 1182 deletions(-) create mode 100644 OfficeAssistant_msvc/userimprove.cpp create mode 100644 OfficeAssistant_msvc/userimprove.h create mode 100644 OfficeAssistant_msvc/userimprove.ui diff --git a/OfficeAssistant_msvc/MyButton.cpp b/OfficeAssistant_msvc/MyButton.cpp index 3411d7b..7dbdf15 100644 --- a/OfficeAssistant_msvc/MyButton.cpp +++ b/OfficeAssistant_msvc/MyButton.cpp @@ -1,4 +1,4 @@ -// +// // Created by HW on 2023/07/26. // #include "MyButton.h" @@ -10,6 +10,7 @@ MyButton::MyButton(ButtonStruct &buttonStruct,int width,int height,QListheight2=height; this->text=buttonStruct.text; this->op = buttonStruct.op; + this->orig_name = buttonStruct.orig_name; this->func = buttonStruct.func; this->url = buttonStruct.url; this->path = buttonStruct.path; @@ -43,7 +44,7 @@ void MyButton::paintEvent(QPaintEvent *e) { setContentsMargins(0,0,0,0); QFont ft; ft.setPixelSize(TEXT_SIZE); - //Ϊɶ3Ҳ֪ + //别问我为啥乘3,我也不知道 int text_x=(width()-TEXT_SIZE*text.length()*scale*3)/2; int text_y=(logo_width+logo_y+10); QRectF logo_rect(logo_x, logo_y, logo_width, logo_width); @@ -91,6 +92,6 @@ void MyButton::mouseReleaseEvent(QMouseEvent *event) { checked=false; else checked=true; - emit clicked1(op, func, url, path, initial_position); + emit clicked1(orig_name,op, func, url, path, initial_position); } diff --git a/OfficeAssistant_msvc/MyButton.h b/OfficeAssistant_msvc/MyButton.h index c2e1967..b457d3d 100644 --- a/OfficeAssistant_msvc/MyButton.h +++ b/OfficeAssistant_msvc/MyButton.h @@ -1,4 +1,4 @@ -// +// // Created by HW on 2023/07/26. // @@ -16,7 +16,7 @@ class MyButton: public QPushButton{ Q_OBJECT 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: MyButton(ButtonStruct &buttonStruct,int width,int height,QList *buttons,QWidget *parent=nullptr); ~MyButton() override; @@ -57,6 +57,7 @@ private: QImage *logo_cover; QVBoxLayout *layout; QString text; + QString orig_name; QString url; QString op; QString path; diff --git a/OfficeAssistant_msvc/OfficeAssistant_msvc.vcxproj b/OfficeAssistant_msvc/OfficeAssistant_msvc.vcxproj index 2584906..b562b94 100644 --- a/OfficeAssistant_msvc/OfficeAssistant_msvc.vcxproj +++ b/OfficeAssistant_msvc/OfficeAssistant_msvc.vcxproj @@ -102,6 +102,7 @@ + @@ -139,6 +140,7 @@ + @@ -152,6 +154,7 @@ + diff --git a/OfficeAssistant_msvc/OfficeAssistant_msvc.vcxproj.filters b/OfficeAssistant_msvc/OfficeAssistant_msvc.vcxproj.filters index 9449889..aa843ae 100644 --- a/OfficeAssistant_msvc/OfficeAssistant_msvc.vcxproj.filters +++ b/OfficeAssistant_msvc/OfficeAssistant_msvc.vcxproj.filters @@ -85,6 +85,9 @@ Header Files + + Header Files + @@ -132,6 +135,9 @@ Source Files + + Source Files + @@ -167,6 +173,9 @@ Form Files + + Form Files + diff --git a/OfficeAssistant_msvc/OfficeAssistant_msvc.vcxproj.user b/OfficeAssistant_msvc/OfficeAssistant_msvc.vcxproj.user index ceea808..f01453d 100644 --- a/OfficeAssistant_msvc/OfficeAssistant_msvc.vcxproj.user +++ b/OfficeAssistant_msvc/OfficeAssistant_msvc.vcxproj.user @@ -5,9 +5,9 @@ WindowsLocalDebugger - 2023-08-12T03:22:21.9071424Z + 2023-08-17T22:00:04.0470850Z - 2023-08-12T03:22:23.0360904Z + 2023-08-17T22:00:04.1224923Z \ No newline at end of file diff --git a/OfficeAssistant_msvc/addapp.cpp b/OfficeAssistant_msvc/addapp.cpp index 15e375e..a3cea70 100644 --- a/OfficeAssistant_msvc/addapp.cpp +++ b/OfficeAssistant_msvc/addapp.cpp @@ -1,4 +1,4 @@ -#include "addapp.h" +#include "addapp.h" #include #include #include @@ -18,19 +18,19 @@ AddApp::AddApp(bool isEdit, Record2 *row , QWidget* parent) ui.setupUi(this); this->row=row; SQLiteHelper sqlite_helper; - setFixedSize(450, 450); + setFixedSize(450, 600); Record2 record; - sqlite_helper.get_a_software(row->orig_name, &record); setWindowFlags(Qt::WindowCloseButtonHint); form = new QFormLayout; name = new QLineEdit; - form->addRow(QString::fromLocal8Bit(""), name); + form->addRow(QString::fromLocal8Bit("名称"), name); if (isEdit) { + sqlite_helper.get_a_software(row->orig_name, &record); name_label = new QLabel(orig_name_str); - form->addRow(QString::fromLocal8Bit("ȫ"), name_label); - + form->addRow(QString::fromLocal8Bit("全名"), name_label); + record = *row;//最初为啥这么写我也忘了 if (!record.orig_name.isEmpty()) { name_label->setText(record.orig_name); @@ -40,17 +40,17 @@ AddApp::AddApp(bool isEdit, Record2 *row , QWidget* parent) else { orig_name = new QLineEdit; - form->addRow(QString::fromLocal8Bit("ȫ"), orig_name); + form->addRow(QString::fromLocal8Bit("全名"), orig_name); } if (record.orig_name.isEmpty()) { - path = new QPushButton(QString::fromLocal8Bit("")); + path = new QPushButton(QString::fromLocal8Bit("浏览")); connect(path, &QPushButton::clicked, this, &AddApp::broswer_exe); - form->addRow(QString::fromLocal8Bit("·"), path); + form->addRow(QString::fromLocal8Bit("路径"), path); sort = new QLineEdit; sort->setValidator(new QIntValidator(10, 100)); - form->addRow(QString::fromLocal8Bit(""), sort); + form->addRow(QString::fromLocal8Bit("排序"), sort); QList categrories; layout_inner = new QVBoxLayout; sqlite_helper.get_category(categrories, true); @@ -62,8 +62,8 @@ AddApp::AddApp(bool isEdit, Record2 *row , QWidget* parent) layout_inner->addWidget(check_box); categories_list.insert(category.id, check_box); } - form->addRow(QString::fromLocal8Bit(""), layout_inner); - submit_btn = new QPushButton(QString::fromLocal8Bit("ύ")); + form->addRow(QString::fromLocal8Bit("类别"), layout_inner); + submit_btn = new QPushButton(QString::fromLocal8Bit("提交")); form->addWidget(submit_btn); this->setLayout(form); connect(path, &QPushButton::click, this, &AddApp::broswer_exe); @@ -75,15 +75,18 @@ AddApp::AddApp(bool isEdit, Record2 *row , QWidget* parent) name->setText(record.name); name_str = record.name; sort_str = QString::number(record.sort); - path = new QPushButton(QString::fromLocal8Bit("")); + path = new QPushButton(QString::fromLocal8Bit("浏览")); path_str = record.exe_file; path->setText(QString::fromWCharArray(fs::path(path_str.toStdWString()).filename().c_str())); connect(path, &QPushButton::clicked, this, &AddApp::broswer_exe); - form->addRow(QString::fromLocal8Bit("·"), path); + if (record.op == "soft") + { + form->addRow(QString::fromLocal8Bit("路径"), path); + } sort = new QLineEdit; sort->setText(QString::number(record.sort)); sort->setValidator(new QIntValidator(10, 100)); - form->addRow(QString::fromLocal8Bit(""), sort); + form->addRow(QString::fromLocal8Bit("排序"), sort); QList categrories; layout_inner = new QVBoxLayout; sqlite_helper.get_category(categrories, true); @@ -98,15 +101,14 @@ AddApp::AddApp(bool isEdit, Record2 *row , QWidget* parent) layout_inner->addWidget(check_box); categories_list.insert(category.id, check_box); } - form->addRow(QString::fromLocal8Bit(""), layout_inner); - submit_btn = new QPushButton(QString::fromLocal8Bit("ύ")); + form->addRow(QString::fromLocal8Bit("类别"), layout_inner); + submit_btn = new QPushButton(QString::fromLocal8Bit("提交")); form->addWidget(submit_btn); this->setLayout(form); connect(path, &QPushButton::click, this, &AddApp::broswer_exe); connect(submit_btn, &QPushButton::clicked, this, &AddApp::submit); this->isEdit = isEdit; } - } AddApp::~AddApp() @@ -130,13 +132,13 @@ void AddApp::broswer_exe(){ QString path_str_old = path_str; if(path_str.isEmpty()) { - path_str = QFileDialog::getOpenFileName(this, QString::fromLocal8Bit("ѡ"), - QApplication::applicationDirPath(), QString::fromLocal8Bit("Ӧó (*.exe)")); + path_str = QFileDialog::getOpenFileName(this, QString::fromLocal8Bit("选择程序"), + QApplication::applicationDirPath(), QString::fromLocal8Bit("应用程序 (*.exe)")); } else { - path_str = QFileDialog::getOpenFileName(this, QString::fromLocal8Bit("ѡ"), - path_str, QString::fromLocal8Bit("Ӧó (*.exe)")); + path_str = QFileDialog::getOpenFileName(this, QString::fromLocal8Bit("选择程序"), + path_str, QString::fromLocal8Bit("应用程序 (*.exe)")); } if (path_str.isEmpty()) { path_str = path_str_old; @@ -147,25 +149,17 @@ void AddApp::broswer_exe(){ } void AddApp::submit() { - if(isEdit) + if (isEdit) { - if (!path->text().isEmpty()) - { - QString name_str_old = name_str; - QString sort_str_old = sort_str; - name_str = name->text(); - sort_str = sort->text(); - if (name_str.isEmpty()) { - name_str = name_str_old; - } - if (sort_str.isEmpty()) { - sort_str = sort_str_old; - } + QString name_str_old = name_str; + QString sort_str_old = sort_str; + name_str = name->text(); + sort_str = sort->text(); + if (name_str.isEmpty()) { + name_str = name_str_old; } - else - { - QMessageBox::critical(this, QString::fromLocal8Bit(""), QString::fromLocal8Bit("δд·")); - return; + if (sort_str.isEmpty()) { + sort_str = sort_str_old; } } else @@ -184,27 +178,21 @@ void AddApp::submit() { } else { - QMessageBox::critical(this, QString::fromLocal8Bit(""), QString::fromLocal8Bit("δдȫ·")); + QMessageBox::critical(this, QString::fromLocal8Bit("错误"), QString::fromLocal8Bit("未填写全名或路径")); return; } } categories = new bool[8]; - for (int i = 0; i < 8; i++) { + for (int i = 0; i < CATEGORIES_NUM; i++) { categories[i] = false; } 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()) { 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]; } diff --git a/OfficeAssistant_msvc/addapp.h b/OfficeAssistant_msvc/addapp.h index 3241940..fed2365 100644 --- a/OfficeAssistant_msvc/addapp.h +++ b/OfficeAssistant_msvc/addapp.h @@ -1,4 +1,4 @@ -#pragma once +#pragma once #include #include @@ -16,7 +16,7 @@ class AddApp : public QDialog Q_OBJECT public: - AddApp(bool isEdit = false, Record2 *orig_name_str=nullptr,QWidget* parent = nullptr); + AddApp(bool isEdit = false, Record2 *row=nullptr,QWidget* parent = nullptr); ~AddApp(); QString get_exe_path() { diff --git a/OfficeAssistant_msvc/addcategory.cpp b/OfficeAssistant_msvc/addcategory.cpp index cae3239..537bc58 100644 --- a/OfficeAssistant_msvc/addcategory.cpp +++ b/OfficeAssistant_msvc/addcategory.cpp @@ -1,5 +1,8 @@ -#include "addcategory.h" +#include "addcategory.h" #include + +#include "config.h" + AddCategory::AddCategory(QWidget* parent) : QDialog(parent) { @@ -9,21 +12,21 @@ AddCategory::AddCategory(QWidget* parent) //connect(ui.submit, &QPushButton::click, this, &AddCategory::submit); QStringList title; ui.tableWidget->setColumnCount(3); - title << QString::fromLocal8Bit("") << QString::fromLocal8Bit("ʾ") << QString::fromLocal8Bit(""); + title << QString::fromLocal8Bit("名称") << QString::fromLocal8Bit("显示") << QString::fromLocal8Bit("排序"); ui.tableWidget->setHorizontalHeaderLabels(title); - sqlite_helper.get_category(categrories,false); + sqlite_helper.get_category(categrories,true); ui.tableWidget->setRowCount(categrories.count()); int i = 0; for(auto category : categrories) { 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)); } QComboBox* combo_box = new QComboBox; - combo_box->addItem(QString::fromLocal8Bit("ʾ"), true); - combo_box->addItem(QString::fromLocal8Bit("ʾ"), false); + combo_box->addItem(QString::fromLocal8Bit("显示"), true); + combo_box->addItem(QString::fromLocal8Bit("不显示"), false); if(category.display==true) { combo_box->setCurrentIndex(0); @@ -36,7 +39,7 @@ AddCategory::AddCategory(QWidget* parent) combo_boxes << combo_box; i++; } - //submit_btn = new QPushButton(QString::fromLocal8Bit("ύ")); + //submit_btn = new QPushButton(QString::fromLocal8Bit("提交")); connect(ui.submit, &QPushButton::clicked, this, &AddCategory::submit); } AddCategory::~AddCategory() @@ -60,7 +63,7 @@ void AddCategory::submit() categrory.sort = ui.tableWidget->item(i, 2)->text().toInt(&ok, 10); if(!ok) { - QMessageBox::critical(this, QString::fromLocal8Bit(""), QString::fromLocal8Bit("һв")); + QMessageBox::critical(this, QString::fromLocal8Bit("错误"), QString::fromLocal8Bit("排序列中有一行不是数字")); return; } categrories_new << categrory; diff --git a/OfficeAssistant_msvc/applicationmanager.cpp b/OfficeAssistant_msvc/applicationmanager.cpp index 172c9cb..b2fcb21 100644 --- a/OfficeAssistant_msvc/applicationmanager.cpp +++ b/OfficeAssistant_msvc/applicationmanager.cpp @@ -1,30 +1,34 @@ -#include "applicationmanager.h" +#include "applicationmanager.h" #include "applicationmanagerpage.h" #include "config.h" #include "addapp.h" #include "addcategory.h" #include "sqlitehelper.h" +#include "userimprove.h" +#include "globalvariables.h" +#include "netio.h" #include #include "globalvariables.h" - +#include "MyButton.h" ApplicationManager::ApplicationManager(QWidget *parent) : QWidget(parent) { + application_manager = this; ui.setupUi(this); resize(parent->width(), parent->height()); this->parent = parent; - miniblink = new QMiniBlink(this); - miniblink->init(); - miniblink->show(); - connect(this, &ApplicationManager::changeUrl, miniblink, &QMiniBlink::switchUrl); layout = new QVBoxLayout(this); - layout_top = new QHBoxLayout(this); - layout_top->setAlignment(Qt::AlignRight); - layout_top->setMargin(5); + layout_top_right = new QHBoxLayout(this); + layout_top_right->setAlignment(Qt::AlignRight); + 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); QList categrories; - sqlite_helper.get_category(categrories,false,true); + sqlite_helper.get_category(categrories,false); sqlite_helper.get_buttons(button_structs); for (auto button_struct : button_structs) { @@ -36,8 +40,8 @@ ApplicationManager::ApplicationManager(QWidget *parent) button->setMaximumHeight(TEXT_SIZE * scale * 3 + 20); //button->resize(TEXT_SIZE * button->text().length() * scale * 3 + 20, TEXT_SIZE * scale * 3 + 10); buttons << button; - layout_top->addWidget(button, 1); - connect(button, &MiniButton::click0, button, &MiniButton::onclick1); + layout_top_right->addWidget(button, 1); + connect(button, &MiniButton::clicked, button, &MiniButton::onclick1); connect(button, &MiniButton::click1, this, &ApplicationManager::onclick1); } //ui.tabWidget->setStyleSheet("border:none;"); @@ -49,24 +53,29 @@ ApplicationManager::ApplicationManager(QWidget *parent) tab_bar = new QTabBar(this); layout_bottom_top = new QVBoxLayout; - for(int i=1;i<=8;i++) + for(int i=0;iaddTab(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); connect(this, &ApplicationManager::refresh, application_manager_page_all, &ApplicationManagerPage::refresh); layout_bottom_top->addWidget(application_manager_page_all, 19); - map.insert(1, application_manager_page_all); - for(int i=2;i<=8;i++) + 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, 19); + layout_bottom_top->addWidget(application_manager_page, 1); application_manager_page->setHidden(true); 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); 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:"; @@ -76,63 +85,7 @@ ApplicationManager::ApplicationManager(QWidget *parent) style += ";}"; tab_bar->setStyleSheet(style); 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->addWidget(miniblink, 3); layout->addLayout(layout_top, 1); layout->addLayout(layout_bottom, 9); setLayout(layout); @@ -149,7 +102,8 @@ ApplicationManager::~ApplicationManager() delete pages[layout]; delete layout; } - delete miniblink; + delete layout_top_left; + delete layout_top_right; delete layout_top; delete layout_bottom; delete layout; @@ -169,65 +123,77 @@ void ApplicationManager::onclick1(QString op, QString func, QString path, QStrin add_app.get_sort(), add_app.get_categories()); if (!ok) { - QMessageBox::critical(this, QString::fromLocal8Bit(""), QString::fromLocal8Bit("ʧ")); + QMessageBox::critical(this, QString::fromLocal8Bit("错误"), QString::fromLocal8Bit("插入失败,全名是否重名")); } 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(idsetText(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") { bool software_ok = sqlite_helper.update_software(); bool app_ok = sqlite_helper.update_app(); + QFile file(QApplication::applicationDirPath() + DEFAULT_FILE); + if(file.open(QIODevice::ReadOnly)) + { + 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)) + { + 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("³ɹ")); + QMessageBox::information(this, QString::fromLocal8Bit("提示"), QString::fromLocal8Bit("更新成功")); + emit refresh(); } else { - QMessageBox::critical(this, QString::fromLocal8Bit(""), QString::fromLocal8Bit("²ֻȫʧ")); + QMessageBox::critical(this, QString::fromLocal8Bit("错误"), QString::fromLocal8Bit("更新部分或全部失败,全名是否重名?")); } - emit refresh(); }else if(func=="app_category") { AddCategory add_category; add_category.exec(); if(add_category.changed) { - for(int i=0;i<7;i++) + for(int i=0;isetTabText(i + 1, add_category.categrories[i].name); } bool ok = sqlite_helper.set_category(add_category.categrories); if (!ok) { - QMessageBox::critical(this, QString::fromLocal8Bit(""), QString::fromLocal8Bit("ʧ")); + QMessageBox::critical(this, QString::fromLocal8Bit("错误"), QString::fromLocal8Bit("添加失败,分类是否重名?")); } - emit refresh(); + emit refresh_tab(); } } @@ -248,10 +214,11 @@ void ApplicationManager::onclick1(QString op, QString func, QString path, QStrin void ApplicationManager::onclick2(QString orig_name, QString op) { + sqlite_helper.use_software(orig_name); if (op == "app") { 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 { emit changeUrl(application_manager_page_all->rows[orig_name].url); @@ -267,14 +234,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()); if (!ok) { - QMessageBox::critical(this, QString::fromLocal8Bit(""), QString::fromLocal8Bit("༭ʧ")); + QMessageBox::critical(this, QString::fromLocal8Bit("错误"), QString::fromLocal8Bit("编辑失败")); } emit refresh(); } } 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].url, application_manager_page_all->rows[orig_name].exe_file @@ -289,13 +256,42 @@ void ApplicationManager::tabChange(int index) { map[i]->setHidden(true); } - map[index + 1]->setHidden(false); + map[map2[index]]->setHidden(false); } void ApplicationManager::onNumChange() { - QList categrories; - sqlite_helper.get_category(categrories, false, true); - for (int i = 0; i < categrories.size(); i++) { - tab_bar->setTabText(i, categrories[i].name + "(" + QString::number(categrories[i].total) + ")"); + int count = tab_bar->count(); + disconnect(tab_bar, &QTabBar::currentChanged, this, &ApplicationManager::tabChange); + for(int i=0;iremoveTab(0); } -} \ No newline at end of file + 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 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; \ No newline at end of file diff --git a/OfficeAssistant_msvc/applicationmanager.h b/OfficeAssistant_msvc/applicationmanager.h index 48e2ec1..4e6acdf 100644 --- a/OfficeAssistant_msvc/applicationmanager.h +++ b/OfficeAssistant_msvc/applicationmanager.h @@ -1,4 +1,4 @@ -#pragma once +#pragma once #include #include "sqlitehelper.h" @@ -16,6 +16,8 @@ #include "ui_applicationmanager.h" #include #include + +#include "config.h" class ApplicationManagerPage; struct Record2 @@ -24,7 +26,7 @@ struct Record2 QLabel *orig_name; QLabel *dev; QLabel *use_time;*/ - QSvgWidget* icon; + QLabel* icon; MiniButton* settings; MiniButton * open; QString op; @@ -33,9 +35,10 @@ struct Record2 QString orig_name; QString exe_file; QCheckBox *check_box; + bool is_locked; int sort; QString url; - bool categories[8]; + bool categories[CATEGORIES_NUM]; }; struct Title @@ -52,6 +55,7 @@ class ApplicationManager : public QWidget signals: void changeUrl(QString url); void refresh(); + void refresh_tab(); public: ApplicationManager(QWidget *parent = nullptr); ~ApplicationManager(); @@ -61,6 +65,7 @@ private: QVBoxLayout* layout; QTabBar *tab_bar; QMap map; + QMap map2; QHBoxLayout* layout_top; QHBoxLayout* layout_bottom; QMiniBlink* miniblink; @@ -69,6 +74,8 @@ private: QList button_structs; ApplicationManagerPage* application_manager_page_all; Ui::ApplicationManagerClass ui; + QHBoxLayout* layout_top_left; + QHBoxLayout* layout_top_right; SQLiteHelper sqlite_helper; QVBoxLayout *layout_bottom_top; QTableWidget *table; diff --git a/OfficeAssistant_msvc/applicationmanagerpage.cpp b/OfficeAssistant_msvc/applicationmanagerpage.cpp index 1989f92..0b1bd57 100644 --- a/OfficeAssistant_msvc/applicationmanagerpage.cpp +++ b/OfficeAssistant_msvc/applicationmanagerpage.cpp @@ -1,4 +1,4 @@ -#include "applicationmanagerpage.h" +#include "applicationmanagerpage.h" #include #include @@ -12,20 +12,21 @@ ApplicationManagerPage::ApplicationManagerPage(int category, ApplicationManager { ui.setupUi(this); this->category = category; + this->parent = parent; this->application_manager = application_manager; sqlite_helper.get_buttons(button_structs); layout = new QVBoxLayout; sqlite_helper.get_all_software(softwares, category); table = new QTableWidget(this); - table->setColumnCount(8); + table->setColumnCount(9); QStringList titles; - titles<< QString::fromLocal8Bit("ͼ") << QString::fromLocal8Bit("") << QString::fromLocal8Bit("ȫ") << QString::fromLocal8Bit("") << QString::fromLocal8Bit("ʹ") << QString::fromLocal8Bit("ӵ") <setHorizontalHeaderLabels(titles); table->setEditTriggers(QAbstractItemView::NoEditTriggers); table->setStyleSheet("QTableWidget{border:1px;outline:1px;align: center;} QQTableWidget::widget QTableWidget::item {text-align: center;}"); table->horizontalHeader()->setDefaultAlignment(Qt::AlignHCenter | Qt::AlignVCenter); int i = 0; - for (i = 0; i < 8; i++) + for (i = 0; i < 9; i++) { table->horizontalHeader()->setSectionResizeMode(i, QHeaderView::Stretch); @@ -34,92 +35,6 @@ ApplicationManagerPage::ApplicationManagerPage(int category, ApplicationManager QTableWidgetItem* item = new QTableWidgetItem; item->setTextAlignment(Qt::AlignCenter); 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); setLayout(layout); @@ -134,11 +49,11 @@ ApplicationManagerPage::~ApplicationManagerPage() delete layout; } -void ApplicationManagerPage::onclicked() +void ApplicationManagerPage::onclicked(int state) { for(int i=0;irowCount();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()]) { @@ -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"); if(!ok) { - QMessageBox::critical(this, QString::fromLocal8Bit(""), QString::fromLocal8Bit("²ֻȫʧ")); + QMessageBox::critical(this, QString::fromLocal8Bit("错误"), QString::fromLocal8Bit("更新部分或全部失败")); break; } + checked[table->item(i, 2)->text()] = true; } }else { @@ -158,18 +74,23 @@ 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"); if (!ok) { - QMessageBox::critical(this, QString::fromLocal8Bit(""), QString::fromLocal8Bit("²ֻȫʧ")); + QMessageBox::critical(this, QString::fromLocal8Bit("错误"), QString::fromLocal8Bit("更新部分或全部失败")); break; } + checked[table->item(i, 2)->text()] = false; } } } - emit application_manager->refresh(); + //在后面refresh,避免因为refresh导致信号和槽断开 } - +//刷新页面 void ApplicationManagerPage::refresh() { int rowcount = table->rowCount(); + for(auto i : connections) + { + disconnect(i); + } for(int i=0;iremoveRow(0); @@ -197,37 +118,51 @@ void ApplicationManagerPage::refresh() date += QString::number(time->tm_mday, 10); table->setItem(i, 4, new QTableWidgetItem(date)); } + else + { + table->setItem(i, 4, new QTableWidgetItem(QString::fromLocal8Bit("从未使用"))); + } Record2 record2; record2.name = software.name; - record2.icon = new QSvgWidget; - QFile file(software.logo); + record2.icon = new QLabel; + QFile file(software.img); + record2.icon->setMaximumSize(50, 50); + record2.icon->setScaledContents(true); if (file.exists()) { - record2.icon->load(software.logo); + QPixmap pixmap(software.img); + //pixmap.scaled(40, 40); + record2.icon->setPixmap(pixmap); } 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); record2.settings = new MiniButton(software.orig_name, "settings"); - record2.settings->setText(QString::fromLocal8Bit("")); + 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); + 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; record2.open = new MiniButton(software.orig_name, "open"); - record2.open->setText(QString::fromLocal8Bit("")); + 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); + QMetaObject::Connection connect3=connect(record2.open, &MiniButton::clicked, record2.open, &MiniButton::onclick2); + connections << connect3; + QMetaObject::Connection connect4=connect(record2.open, &MiniButton::click2, application_manager, &ApplicationManager::onclick2); + connections << connect4; record2.exe_file = software.path; record2.orig_name = software.orig_name; record2.url = software.url; - for (int i = 0; i < 8; i++) + for (int i = 0; i < CATEGORIES_NUM; i++) { 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))) { @@ -236,10 +171,11 @@ void ApplicationManagerPage::refresh() } record2.op = software.op; 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<setCheckState(Qt::Checked); checked.insert(software.orig_name, true); @@ -249,19 +185,28 @@ void ApplicationManagerPage::refresh() record2.check_box->setCheckState(Qt::Unchecked); 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; - table->setItem(i, 5, check_box_item); - table->setCellWidget(i, 5, record2.check_box); + table->setItem(i, 6, check_box_item); + table->setCellWidget(i, 6, 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); + table->setCellWidget(i, 7, record2.settings); + table->setCellWidget(i, 8, record2.open); rows.insert(software.orig_name, record2); table->resizeColumnToContents(0); - //table->item(i, 0)->setTextAlignment(Qt::AlignCenter); - //table->verticalHeader()->setSectionResizeMode(i, QHeaderView::ResizeToContents); i++; } } diff --git a/OfficeAssistant_msvc/applicationmanagerpage.h b/OfficeAssistant_msvc/applicationmanagerpage.h index 8f10698..f67e084 100644 --- a/OfficeAssistant_msvc/applicationmanagerpage.h +++ b/OfficeAssistant_msvc/applicationmanagerpage.h @@ -1,4 +1,4 @@ -#pragma once +#pragma once #include #include @@ -17,7 +17,7 @@ class ApplicationManagerPage : public QWidget { Q_OBJECT 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: ApplicationManagerPage(int category, ApplicationManager *application_manager,QWidget *parent = nullptr); ~ApplicationManagerPage(); @@ -28,6 +28,7 @@ private: QVBoxLayout* layout; QHBoxLayout* layout_top; QHBoxLayout* layout_bottom; + QList connections; QMiniBlink* miniblink; QList buttons; QList softwares; @@ -39,7 +40,8 @@ private: ApplicationManager* application_manager; Title *title; int category; + QWidget *parent; public slots: void refresh(); - void onclicked(); + void onclicked(int state); }; diff --git a/OfficeAssistant_msvc/buttonstruct.h b/OfficeAssistant_msvc/buttonstruct.h index d3392f9..08c0433 100644 --- a/OfficeAssistant_msvc/buttonstruct.h +++ b/OfficeAssistant_msvc/buttonstruct.h @@ -1,4 +1,4 @@ -// +// // Created by HW on 2023/07/26. // @@ -9,6 +9,7 @@ typedef struct taButtonStruct{ QImage *image; QImage *image_cover; + QImage *png; QString text; QString orig_name; QString url; diff --git a/OfficeAssistant_msvc/config.h b/OfficeAssistant_msvc/config.h index 578de5c..765fc42 100644 --- a/OfficeAssistant_msvc/config.h +++ b/OfficeAssistant_msvc/config.h @@ -7,7 +7,7 @@ #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 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 DEFAULT_FILE "/config/config.kmd" //默认配置文件位置 #define DEFAULT_NAVBAR_FILLE "/config/default_navbar.kmd" @@ -27,9 +27,11 @@ #define DEFAULT_COVER_COLOR "#0033FF" //鼠标指向后变成的颜色,也是“添加应用”等几个按钮的默认颜色 #define DEFAULT_IMAGE "/images/svg/default.svg" //默认图标 #define DEFAULT_SVG_PATH "/images/svg/" -#define DEFAULT_LOGO "/images/logo.png" //logo路径 +#define DEFAULT_LOGO "/images/logo.png" //logo路径 +#define DEFAULT_PNG_PATH "/images/png/" //png路径 #define TITLE " " //标题栏 -#define TEXT_SIZE 7 //字体大小。不是所有字体受此项控制 +#define TEXT_SIZE 7 //字体大小。不是所有字体受此项控制 +#define DEFAULT_PNG "/images/png/default.png" //默认PNG图标 #define TEXT_SIZE_BIG 10 //分类 #define ALL 1 @@ -40,4 +42,5 @@ #define CUSTOM_1 6 #define CUSTOM_2 7 #define OTHERS 8 +#define CATEGORIES_NUM 8 #endif //OFFICEASSISTANT_CONFIG_H diff --git a/OfficeAssistant_msvc/globalvariables.h b/OfficeAssistant_msvc/globalvariables.h index 803fe88..9488a5a 100644 --- a/OfficeAssistant_msvc/globalvariables.h +++ b/OfficeAssistant_msvc/globalvariables.h @@ -1,10 +1,11 @@ -// +// // Created by HW on 2023/07/27. // #ifndef OFFICEASSISTANT_GLOBALVARIABLES_H #define OFFICEASSISTANT_GLOBALVARIABLES_H #include "exitmanager.h" +class ApplicationManager; class MainWindowLayout; extern ExitManager exit_manager; extern double scale; @@ -12,4 +13,5 @@ extern MainWindowLayout *mainWindowLayout; extern QString url_param; extern bool autostart; extern bool agree; +extern ApplicationManager *application_manager; #endif //OFFICEASSISTANT_GLOBALVARIABLES_H diff --git a/OfficeAssistant_msvc/mainscreen.h b/OfficeAssistant_msvc/mainscreen.h index a5a633e..7851645 100644 --- a/OfficeAssistant_msvc/mainscreen.h +++ b/OfficeAssistant_msvc/mainscreen.h @@ -1,4 +1,4 @@ -// +// // Created by HW on 2023/07/27. // @@ -27,6 +27,7 @@ public: explicit MainScreen(QWidget *parent = nullptr); ~MainScreen() override; QWidget* parent; + ApplicationManager* application_manager; public slots: void clickButton1(QString op, QString url); void firstUrl(QString url); @@ -38,7 +39,6 @@ private: QVBoxLayout *layout_left; QPushButton *button; QIcon *icon; - ApplicationManager* application_manager; QWidget *broswer; static bool isInited(); QWidget *widget; diff --git a/OfficeAssistant_msvc/mainwindow.cpp b/OfficeAssistant_msvc/mainwindow.cpp index c585f10..b8af4c5 100644 --- a/OfficeAssistant_msvc/mainwindow.cpp +++ b/OfficeAssistant_msvc/mainwindow.cpp @@ -1,4 +1,4 @@ -// +// // Created by HW on 2023/07/26. // @@ -25,92 +25,7 @@ MainWindow::MainWindow(QWidget *parent) : icon = new QIcon(path); setWindowIcon(*icon); 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.Ƿ˿ԼDzͨķʽ\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.Ƿ˿ԼDzͨķʽ\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() { diff --git a/OfficeAssistant_msvc/mainwindowlayout.cpp b/OfficeAssistant_msvc/mainwindowlayout.cpp index 5631797..d92dd84 100644 --- a/OfficeAssistant_msvc/mainwindowlayout.cpp +++ b/OfficeAssistant_msvc/mainwindowlayout.cpp @@ -1,4 +1,4 @@ -// +// // Created by HW on 2023/07/26. // @@ -17,14 +17,11 @@ MainWindowLayout::MainWindowLayout(QWidget *parent) : mainWindowLayout = this; QList list; mainScreen = new MainScreen(this); - navBar=new NavBar(mainScreen,this); + navBar = new NavBar(mainScreen, this); + emit mainScreen->application_manager->refresh_tab(); navBar->setMinimumHeight(0); navBar->setMaximumHeight(this->height() / 8); 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(mainScreen,7); layout->setMargin(0); @@ -48,7 +45,10 @@ void MainWindowLayout::resizeEvent(QResizeEvent *event) { //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(); if(op=="app") { @@ -59,7 +59,7 @@ void MainWindowLayout::clickButton(QString op, QString func, QString url,QString { path = root_path + path; 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); } } diff --git a/OfficeAssistant_msvc/mainwindowlayout.h b/OfficeAssistant_msvc/mainwindowlayout.h index e6cb108..b11a1a4 100644 --- a/OfficeAssistant_msvc/mainwindowlayout.h +++ b/OfficeAssistant_msvc/mainwindowlayout.h @@ -1,4 +1,4 @@ - + // // Created by HW on 2023/07/26. // @@ -22,10 +22,10 @@ signals: void clickButton1(QString op,QString url); public: explicit MainWindowLayout(QWidget *parent = nullptr); - + NavBar* navBar; ~MainWindowLayout() override; 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: void resizeEvent(QResizeEvent *event) override; //void paintEvent(QPaintEvent *event) override; @@ -34,7 +34,6 @@ private: Ui::MainWindowLayout *ui; QVBoxLayout *layout; //QList list; - NavBar *navBar; ButtonStruct *buttons; MainScreen *mainScreen; ConfigResponse *configResponse; diff --git a/OfficeAssistant_msvc/minibutton.cpp b/OfficeAssistant_msvc/minibutton.cpp index cc9d09f..3825143 100644 --- a/OfficeAssistant_msvc/minibutton.cpp +++ b/OfficeAssistant_msvc/minibutton.cpp @@ -1,4 +1,4 @@ -#include "minibutton.h" +#include "minibutton.h" #include #include "config.h" #include "globalvariables.h" @@ -45,10 +45,6 @@ void MiniButton::paintEvent(QPaintEvent* event) } -void MiniButton::mouseReleaseEvent(QMouseEvent* event) -{ - emit click0(); -} void MiniButton::onclick1() { diff --git a/OfficeAssistant_msvc/minibutton.h b/OfficeAssistant_msvc/minibutton.h index 6bd668c..a759f3a 100644 --- a/OfficeAssistant_msvc/minibutton.h +++ b/OfficeAssistant_msvc/minibutton.h @@ -1,4 +1,4 @@ -#pragma once +#pragma once #include @@ -18,7 +18,6 @@ public: ~MiniButton(); protected: void paintEvent(QPaintEvent* event) override; - void mouseReleaseEvent(QMouseEvent* event) override; private: QString orig_name; QString op; diff --git a/OfficeAssistant_msvc/navbar.cpp b/OfficeAssistant_msvc/navbar.cpp index 4d209ef..af0fa3f 100644 --- a/OfficeAssistant_msvc/navbar.cpp +++ b/OfficeAssistant_msvc/navbar.cpp @@ -42,6 +42,7 @@ void ConvertImageToTransparent(QImage &img) NavBar::NavBar(MainScreen *mainScreen,QWidget *parent) : QWidget(parent), ui(new Ui::NavBar) { ui->setupUi(this); + this->parent = parent; //this->setAttribute(Qt::WA_DeleteOnClose); buffer = new QByteArray; /*QString style = "background-color:"; @@ -55,7 +56,9 @@ NavBar::NavBar(MainScreen *mainScreen,QWidget *parent) : config_request.sendRequest(&config_response); SQLiteHelper sqlite_helper; sqlite_helper.get_software(&buttonStructs, &config_response); - + background_color = config_response.basic.backgroud_color; + text_color = config_response.basic.title_color; + text_cover_color = config_response.basic.title_cover_color; if(!config_response.succeed) { qColor.setNamedColor(buttonStructs[0].background_color); @@ -177,31 +180,24 @@ void NavBar::cancelDownload() { downloadSuccess = false; } -/*void NavBar::getLogoFromLocal() { - QString dir = QApplication::applicationDirPath(); - QFile file(dir + DEFAULT_FILE); - if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { - QMessageBox::warning(nullptr, QString::fromLocal8Bit("错误"), QString::fromLocal8Bit("无法打开配置文件")); - exit(1); +void NavBar::refresh(int state) +{ + SQLiteHelper sqlite_helper; + buttonStructs.clear(); + sqlite_helper.get_software(&buttonStructs, background_color,text_color,text_cover_color); + for(auto button:buttons) + { + layout_right->removeWidget(button); + delete button; + buttons.removeOne(button); } - buffer->clear(); - *buffer = file.readAll(); - file.close(); - QJsonDocument *qJsonDocument = new QJsonDocument; - *qJsonDocument = QJsonDocument::fromJson(*buffer); - QJsonObject *obj_root = new QJsonObject; - if (qJsonDocument->isObject()) { - *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; + for (auto buttonStruct : buttonStructs) { + MyButton* myButton = new MyButton(buttonStruct, height(), height(), &buttons, this); + myButton->setMaximumHeight(parent->height() / 8); + layout_right->addWidget(myButton); + //myButton->show(); + connect(myButton, &MyButton::clicked1, mainWindowLayout, &MainWindowLayout::clickButton); + buttons << myButton; } - else { - QMessageBox::warning(nullptr, QString::fromLocal8Bit("错误"), QString::fromLocal8Bit("配置文件损坏")); - delete obj_root; - exit(1); - } - delete obj_root; - -}*/ \ No newline at end of file + emit application_manager->refresh();//在这里refresh,避免因为refresh导致信号和槽断开 +} \ No newline at end of file diff --git a/OfficeAssistant_msvc/navbar.h b/OfficeAssistant_msvc/navbar.h index f69a819..4191fe9 100644 --- a/OfficeAssistant_msvc/navbar.h +++ b/OfficeAssistant_msvc/navbar.h @@ -28,6 +28,8 @@ class NavBar : public QWidget { Q_OBJECT signals: void firstUrl(QString url); +public slots: + void refresh(int state); public: NavBar(MainScreen *mainScreen,QWidget *parent = nullptr); @@ -48,6 +50,10 @@ private: QByteArray *buffer; int width2; int height2; + QWidget* parent; + QString background_color; + QString text_color; + QString text_cover_color; QNetworkAccessManager *manager; QNetworkReply *reply; QEventLoop eventLoop; diff --git a/OfficeAssistant_msvc/netio.cpp b/OfficeAssistant_msvc/netio.cpp index 122a882..b545c83 100644 --- a/OfficeAssistant_msvc/netio.cpp +++ b/OfficeAssistant_msvc/netio.cpp @@ -165,7 +165,7 @@ RequestBodyBase::RequestBodyBase(){ url_param = "?"; url_param += "product="; url_param += product; - url_param += "&parter_id="; + url_param += "&partner_id="; url_param += parter_id; url_param += "&os="; url_param += this->os; @@ -252,14 +252,24 @@ void ConfigRequest::sendRequest(ConfigResponse *configResponse) { for(auto value:array){ QJsonObject object=value.toObject(); Button button; - button.img=object.value("img").toString(); - button.orig_name= object.value("orig_name").toString(); - // button.img_cover=object.value("img_cover").toString(); - button.title=object.value("name").toString(); - button.categroy_id = object.value("category_id").toString(); + button.img = object.value("img").toString(); + button.png = object.value("logo").toString(); + button.img_name = object.value("img_name").toString(); + button.name = object.value("name").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.func=object.value("func").toString(); - button.url=object.value("url").toString(); + button.func = object.value("func").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; i++; } @@ -620,7 +630,7 @@ bool SoftwareRequest::sendRequest(QHash&startMenu, QHash&startMenu, QHasherror(); //如果没有错误 qDebug() << reply->error(); + auto result2=reply->readAll(); if (reply->error() == QNetworkReply::NoError) { - result = QJsonDocument::fromJson(reply->readAll()); + result = QJsonDocument::fromJson(result2); } else { //如果有错误 @@ -652,7 +663,7 @@ bool SoftwareRequest::sendRequest(QHash&startMenu, QHashclear(); //如果数据完整 if (result.isObject()) { QJsonObject obj_root2 = result.object(); @@ -689,17 +700,26 @@ bool SoftwareRequest::sendRequest(QHash&startMenu, QHashinsert(orig_name, record); } } else { @@ -734,9 +754,11 @@ QString OpenWeChatRequest::sendRequest(bool notuse) //启动循环 eventLoop.exec(); timer->stop(); + qDebug() << reply->error(); QByteArray buffer = reply->readAll(); QJsonDocument reply_json = QJsonDocument::fromJson(buffer); - if(!reply_json.isObject()) + + if(!reply_json.isObject()) { delete timer; delete httpMgr; @@ -745,7 +767,6 @@ QString OpenWeChatRequest::sendRequest(bool notuse) } delete timer; delete httpMgr; - delete reply; return reply_json.object().value("msg").toString(); } diff --git a/OfficeAssistant_msvc/netio.h b/OfficeAssistant_msvc/netio.h index 9157996..22c9aff 100644 --- a/OfficeAssistant_msvc/netio.h +++ b/OfficeAssistant_msvc/netio.h @@ -1,4 +1,4 @@ -// +// // Created by HW on 2023/07/27. // @@ -17,13 +17,24 @@ typedef struct { QString img; - QString img_cover; - QString title; + QString png; + QString img_name; + QString name; + QString type; + int sort; + int status; + bool is_navbar; + bool is_elite; QString orig_name; QString categroy_id; QString op; QString func; QString url; + QString dev; + bool locked; + bool is_delete; + QString version; + } Button; struct ConfigResponse { bool succeed; @@ -126,6 +137,6 @@ class OpenWeChatRequest:public RequestBodyBase { public: OpenWeChatRequest():RequestBodyBase(){} - QString sendRequest(bool notuse=false/*Ϊ˹ɺأ*/); + QString sendRequest(bool notuse=false/*为了构成函数重载,凑数的*/); }; #endif //OFFICEASSISTANT_NETIO_H diff --git a/OfficeAssistant_msvc/qminiblink.ui b/OfficeAssistant_msvc/qminiblink.ui index e3401da..a1c8230 100644 --- a/OfficeAssistant_msvc/qminiblink.ui +++ b/OfficeAssistant_msvc/qminiblink.ui @@ -6,13 +6,52 @@ 0 0 - 1142 - 806 + 600 + 400 QMiniBlink + + + + 110 + 130 + 401 + 61 + + + + 我同意加入用户体验改善计划 + + + + + + 70 + 280 + 150 + 46 + + + + 查看详情 + + + + + + 370 + 280 + 150 + 46 + + + + 确定 + + diff --git a/OfficeAssistant_msvc/sqlitehelper.cpp b/OfficeAssistant_msvc/sqlitehelper.cpp index 4fe1709..c642512 100644 --- a/OfficeAssistant_msvc/sqlitehelper.cpp +++ b/OfficeAssistant_msvc/sqlitehelper.cpp @@ -32,6 +32,9 @@ #define _SILENCE_EXPERIMENTAL_FILESYSTEM_DEPRECATION_WARNING #include namespace fs= std::experimental::filesystem; + + + bool getMenu(std::wstring &path_str,QHash *paths) { fs::directory_iterator* it = new fs::directory_iterator(path_str); @@ -139,39 +142,6 @@ bool SQLiteHelper::update_software() { HKEY hKeyUninstall = nullptr; QHash* paths = new QHash; - /*QSqlQuery query; - QString sql = "select * from kmd_menu;"; - query.exec(sql); - while(query.next()) - { - Record record; - record.id = query.value("id").toInt(); - record.sort = query.value("sort").toInt(); - record.app_id = query.value("app_id").toString(); - record.locked = query.value("locked").toBool(); - record.type = query.value("type").toString(); - record.category_id = query.value("category_id").toString(); - record.name = query.value("name").toString(); - record.orig_name = query.value("orig_name").toString(); - record.version = query.value("version").toString(); - record.dev = query.value("dev").toString(); - record.create_time = query.value("create_time").toLongLong(); - record.use_time = query.value("use_time").toLongLong(); - record.op = query.value("op").toString(); - record.func = query.value("func").toString(); - record.path = query.value("path").toString(); - record.url = query.value("url").toString(); - QStringList path_list = record.path.split("\\"); - path_list.removeLast(); - QString path; - for(auto str : path_list) - { - path.append(str); - path.append("\\"); - } - path.remove(path.length() - 1, 1); - records.insert(path, record); - }*/ //开始菜单中已安装软件列表 WCHAR path[MAX_PATH]; HRESULT hr = SHGetFolderPathW(nullptr, CSIDL_COMMON_PROGRAMS, nullptr, 0, path);//获取ProgramData中开始菜单的路径 @@ -622,31 +592,7 @@ bool SQLiteHelper::update_software() } } - //对比两个路径,找出公共部分(划掉) QHash public_programs_list; - /*for(auto path:*paths) - { - QStringList path_list = path.split("\\"); - path_list.removeLast(); - QString path2; - for(auto str : path_list) - { - path2.append(str); - path2.append("\\"); - } - if(reg_records.contains(path2)) - { - reg_records[path2].path = path; - public_programs_list.insert(reg_records[path2].orig_name, reg_records[path2]); - } - path2.remove(path2.length() - 1, 1); - if(reg_records.contains(path2)) - { - reg_records[path2].path = path; - public_programs_list.insert(reg_records[path2].orig_name, reg_records[path2]); - } - } - delete paths;*/ for (auto key : reg_records.keys()) { public_programs_list.insert(reg_records[key].orig_name, reg_records[key]); @@ -674,7 +620,8 @@ bool SQLiteHelper::update_software() obj.insert("initial_position", find2.value("initial_position").toString()); obj.insert("logo", find2.value("logo").toString()); obj.insert("status", find2.value("status").toBool()); - obj.insert("is_delete", find2.value("is_delete").toBool()); + obj.insert("is_navbar", find2.value("is_navbar").toBool()); + obj.insert("is_elite", find2.value("is_elite").toBool()); array.append(obj); } } @@ -695,7 +642,7 @@ bool SQLiteHelper::update_software() } for(auto key : public_programs_list.keys()) { - + QSqlQuery query(db); QString sql_find = "select sort from kmd_menu where orig_name='"; sql_find += key; sql_find += "';"; @@ -726,76 +673,32 @@ bool SQLiteHelper::update_software() } else { - sql = "insert into kmd_menu (sort,app_id,locked,type,category_id,name,orig_name,version,dev,create_time,use_time,op,func,path,url,status) values ("; - sql += "50"; - sql += ",'"; - sql += public_programs_list[key].app_id; - sql += "',"; - sql += QString::number(public_programs_list[key].locked); - sql += ",'"; - sql += public_programs_list[key].type; - sql += "','"; - sql += QString::number(ALL, 10); - sql += ","; - sql += QString::number(SOFT, 10); - sql += ","; - sql += QString::number(OTHERS, 10); - sql += "','"; - sql += public_programs_list[key].name; - sql += "','"; - sql += public_programs_list[key].orig_name; - sql += "','"; - sql += public_programs_list[key].version; - sql += "','"; - sql += public_programs_list[key].dev; - sql += "',"; - sql += QString::number(public_programs_list[key].create_time); - sql += ","; - sql += QString::number(public_programs_list[key].use_time); - sql += ",'"; - sql += public_programs_list[key].op; - sql += "','"; - sql += public_programs_list[key].func; - sql += "','"; - sql += public_programs_list[key].path; - sql += "','"; - sql += public_programs_list[key].url; - sql += "','"; - sql += public_programs_list[key].status; - sql += "');"; - bool categories[8] = { false }; + sql = "insert into kmd_menu (sort,app_id,locked,type,category_id,name,orig_name,version,dev,create_time,use_time,op,func,path,url,status,is_navbar,is_elite) values " + "(:sort,:app_id,:locked,:type,:category_id,:name,:orig_name,:version,:dev,:create_time,:use_time,:op,:func,:path,:url,:status,:is_navbar,:is_elite); "; + query.prepare(sql); + query.bindValue(":sort", 50); + query.bindValue(":app_id", public_programs_list[key].app_id); + query.bindValue(":locked", public_programs_list[key].locked); + query.bindValue(":type", public_programs_list[key].type); + query.bindValue(":category_id", public_programs_list[key].category_id); + query.bindValue(":name", public_programs_list[key].name); + query.bindValue(":orig_name", public_programs_list[key].orig_name); + query.bindValue(":version", public_programs_list[key].version); + query.bindValue(":dev", public_programs_list[key].dev); + query.bindValue(":create_time", public_programs_list[key].create_time); + query.bindValue(":use_time", public_programs_list[key].use_time); + query.bindValue(":op", public_programs_list[key].op); + query.bindValue(":func", public_programs_list[key].func); + query.bindValue(":path", public_programs_list[key].path); + query.bindValue(":url", public_programs_list[key].url); + query.bindValue(":is_navbar", public_programs_list[key].is_navbar); + query.bindValue(":is_elite", public_programs_list[key].is_elite); + query.bindValue(":status", true); + bool categories[CATEGORIES_NUM] = { false }; categories[ALL - 1] = true; categories[SOFT - 1] = true; - for (int i = 0; i < 8; i++) - { - QSqlQuery query2(db); - if (categories[i]) - { - query2.prepare("select total from kmd_category where id=:id;"); - query2.bindValue(":id", i + 1); - if (!query2.exec()) - { - QSqlQuery rollback(db); - rollback.exec("rollback;"); - return false; - } - if (query2.next()) - { - int total = query2.value("total").toInt(); - query2.prepare("update kmd_category set total=:total where id=:id;"); - query2.bindValue(":total", total); - query2.bindValue(":id", i + 1); - if (!query2.exec()) - { - QSqlQuery rollback(db); - rollback.exec("rollback;"); - return false; - } - } - } - } } - QSqlQuery query(db); + update_total(); if(!query.exec(sql)) { QSqlQuery rollback("rollback;"); @@ -817,37 +720,10 @@ bool SQLiteHelper::update_software() del.prepare("update kmd_menu set status=0 where orig_name=:orig_name;"); del.bindValue(":orig_value", find.value("orig_name")); del.exec(); - bool categories[8] = { false }; + bool categories[CATEGORIES_NUM] = { false }; categories[ALL - 1] = true; categories[SOFT - 1] = true; - for (int i = 0; i < 8; i++) - { - QSqlQuery query2(db); - if (categories[i]) - { - query2.prepare("select total from kmd_category where id=:id;"); - query2.bindValue(":id", i + 1); - if (!query2.exec()) - { - QSqlQuery rollback(db); - rollback.exec("rollback;"); - return false; - } - if (query2.next()) - { - int total = query2.value("total").toInt(); - query2.prepare("update kmd_category set total=:total where id=:id;"); - query2.bindValue(":total", total - 1); - query2.bindValue(":id", i + 1); - if (!query2.exec()) - { - QSqlQuery rollback(db); - rollback.exec("rollback;"); - return false; - } - } - } - } + update_total(); } } } @@ -883,10 +759,7 @@ bool SQLiteHelper::get_software(QList* button_structs, ConfigRespo { QSqlQuery query(db); QString sql = "select * from kmd_menu where is_navbar=1 order by sort,orig_name asc ;"; - if (!query.exec(sql)) - { - return false; - } + QString background_color; QString title_color; QString title_cover_color; @@ -896,6 +769,7 @@ bool SQLiteHelper::get_software(QList* button_structs, ConfigRespo background_color = config_response->basic.backgroud_color; title_color = config_response->basic.title_color; title_cover_color = config_response->basic.title_cover_color; + } else { @@ -913,25 +787,11 @@ bool SQLiteHelper::get_software(QList* button_structs, ConfigRespo array = obj_root.value("data").toObject().value("menu").toArray(); qDebug() << array; - QJsonObject obj_basic = obj_root.value("data").toObject().value("basic").toObject(); + QJsonObject obj_data = obj_root.value("data").toObject(); + QJsonObject obj_basic=QJsonDocument::fromJson(obj_data.value("basic").toString().toUtf8()).object(); background_color = obj_basic.value("backgroud_color").toString(); title_color = obj_basic.value("title_color").toString(); title_cover_color = obj_basic.value("title_cover_color").toString(); - auto i = 0; - for (auto value : array) { - QJsonObject object = value.toObject(); - Button button; - button.img = object.value("img").toString(); - // button.img_cover=object.value("img_cover").toString(); - button.title = object.value("title").toString(); - button.categroy_id = object.value("category_id").toString(); - button.orig_name = object.value("orig_name").toString(); - button.op = object.value("op").toString(); - button.func = object.value("func").toString(); - button.url = object.value("url").toString(); - buttons << button; - i++; - } } else { background_color = DEFAULT_BACKGROUND_COLOR; @@ -940,13 +800,14 @@ bool SQLiteHelper::get_software(QList* button_structs, ConfigRespo } } } + QByteArray* buffer = new QByteArray; QHash button_map; QNetworkAccessManager* manager; for (auto menu : buttons) { ButtonStruct button_struct; - button_struct.text = menu.title; + button_struct.text = menu.name; button_struct.orig_name = menu.orig_name; button_struct.op = menu.op; button_struct.func = menu.func; @@ -968,8 +829,9 @@ bool SQLiteHelper::get_software(QList* button_structs, ConfigRespo *buffer = reply->readAll(); delete request_logo; reply->close(); + QString svg_path = QApplication::applicationDirPath() + DEFAULT_SVG_PATH + menu.img_name + ".svg";; if ((reply->error() == QNetworkReply::NoError)&&(downloadSuccess == true)) { - QFile file(QApplication::applicationDirPath() + DEFAULT_SVG_PATH + menu.orig_name + ".svg"); + QFile file(QApplication::applicationDirPath() + DEFAULT_SVG_PATH + menu.img_name+".svg"); if (file.open(QIODevice::Text | QIODevice::WriteOnly)) { file.write(*buffer); @@ -978,8 +840,7 @@ bool SQLiteHelper::get_software(QList* button_structs, ConfigRespo } else { - - QString icon = QApplication::applicationDirPath() + DEFAULT_SVG_PATH + menu.orig_name + ".svg"; + QString icon = QApplication::applicationDirPath() + DEFAULT_SVG_PATH + menu.img_name+".svg"; QFile file(icon); if (file.open(QIODevice::ReadOnly | QIODevice::Text)) { @@ -1000,37 +861,78 @@ bool SQLiteHelper::get_software(QList* button_structs, ConfigRespo } delete manager; manager = nullptr; - - QSvgRenderer* render_image = new QSvgRenderer(*buffer); - QPainter painter_image(image); - painter_image.setCompositionMode(QPainter::CompositionMode_Clear); // 清除画布 - painter_image.fillRect(image->rect(), Qt::transparent); // 填充透明色 - painter_image.setCompositionMode(QPainter::CompositionMode_SourceOver); // 恢复默认值 - render_image->render(&painter_image); - //修改颜色 - QDomDocument doc; - doc.setContent(*buffer); - SetSVGBackColor(doc.documentElement(), "path", "fill", title_cover_color); - QSvgRenderer* render_image_cover = new QSvgRenderer(doc.toByteArray()); - QPainter painter_image_cover(image_cover); - painter_image_cover.setCompositionMode(QPainter::CompositionMode_Clear); // 清除画布 - painter_image_cover.fillRect(image_cover->rect(), Qt::transparent); // 填充透明色 - painter_image_cover.setCompositionMode(QPainter::CompositionMode_SourceOver); // 恢复默认值 - render_image_cover->render(&painter_image_cover); - - delete render_image; - delete render_image_cover; - - button_struct.image = image; - button_struct.image_cover = image_cover; - button_struct.background_color = background_color; - button_struct.text_color = QColor(title_color); - button_struct.text_cover_color = QColor(title_cover_color); - *button_structs << button_struct; + QUrl url_png(menu.png); + QNetworkRequest* request_png = new QNetworkRequest(url_logo); + manager = new QNetworkAccessManager; + reply = manager->get(*request_png); + QTimer timer_png; + timer_png.setInterval(5000); + connect(reply, &QNetworkReply::finished, &eventLoop, &QEventLoop::quit); + connect(&timer_png, &QTimer::timeout, this, &SQLiteHelper::cancelDownload); + eventLoop.exec(); + timer_png.stop(); + QByteArray buffer_png; + buffer_png = reply->readAll(); + delete request_png; + reply->close(); + QString png_path = QApplication::applicationDirPath() + DEFAULT_PNG_PATH + menu.img_name + ".png";; + if ((reply->error() == QNetworkReply::NoError) && (downloadSuccess == true)) + { + QFile file(QApplication::applicationDirPath() + DEFAULT_PNG_PATH + menu.img_name + ".png"); + if (file.open(QIODevice::WriteOnly)) + { + file.write(buffer_png); + file.close(); + } + } + else + { + QString icon = QApplication::applicationDirPath() + DEFAULT_PNG_PATH + menu.img_name + ".png"; + QFile file(icon); + if (file.open(QIODevice::ReadOnly)) + { + buffer_png = file.readAll(); + file.close(); + } + else + { + icon = QApplication::applicationDirPath() + DEFAULT_PNG; + if (file.open(QIODevice::ReadOnly)) + { + buffer_png = file.readAll(); + file.close(); + } + } + } + delete manager; + manager = nullptr; + bool categories[CATEGORIES_NUM] = { false }; + for(int i=0;i* button_structs, ConfigRespo delete render_image_cover; } } + button_struct.png = new QImage(query.value("png").toString()); button_struct.image = image; button_struct.image_cover = image_cover; button_struct.background_color = background_color; @@ -1102,8 +1005,101 @@ bool SQLiteHelper::get_software(QList* button_structs, ConfigRespo button_struct.text_cover_color = QColor(title_cover_color); *button_structs << button_struct; } + QSqlQuery begin_query(db); + begin_query.exec("BEGIN;"); + update_total(); + QSqlQuery commit_query(db); + commit_query.exec("COMMIT;"); + return true; +} +bool SQLiteHelper::get_software(QList* button_structs,QString background_color,QString title_color,QString title_cover_color) +{ + QSqlQuery query(db); + QString sql = "select * from kmd_menu where is_navbar=1 order by sort,orig_name asc ;"; + if (!query.exec(sql)) + { + return false; + } + while (query.next()) + { + QString icon = QApplication::applicationDirPath() + DEFAULT_SVG_PATH + query.value("orig_name").toString() + ".svg"; + ButtonStruct button_struct; + button_struct.path = query.value("path").toString(); + button_struct.text = query.value("name").toString(); + button_struct.orig_name = query.value("orig_name").toString(); + button_struct.op = query.value("op").toString(); + button_struct.func = query.value("func").toString(); + button_struct.url = query.value("url").toString(); + button_struct.initial_position = query.value("initial_position").toString(); + QImage* image = new QImage(200, 200, QImage::Format_ARGB32); + QImage* image_cover = new QImage(200, 200, QImage::Format_ARGB32); + QFile file(icon); + if (file.open(QIODevice::ReadOnly)) + { + QByteArray svg_buffer = file.readAll(); + file.close(); + QSvgRenderer* render_image = new QSvgRenderer(svg_buffer); + QPainter painter_image(image); + painter_image.setCompositionMode(QPainter::CompositionMode_Clear); // 清除画布 + painter_image.fillRect(image->rect(), Qt::transparent); // 填充透明色 + painter_image.setCompositionMode(QPainter::CompositionMode_SourceOver); // 恢复默认值 + render_image->render(&painter_image); + //修改颜色 + QDomDocument doc; + doc.setContent(svg_buffer); + SetSVGBackColor(doc.documentElement(), "path", "fill", title_cover_color); + QSvgRenderer* render_image_cover = new QSvgRenderer(doc.toByteArray()); + QPainter painter_image_cover(image_cover); + painter_image_cover.setCompositionMode(QPainter::CompositionMode_Clear); // 清除画布 + painter_image_cover.fillRect(image_cover->rect(), Qt::transparent); // 填充透明色 + painter_image_cover.setCompositionMode(QPainter::CompositionMode_SourceOver); // 恢复默认值 + render_image_cover->render(&painter_image_cover); + delete render_image; + delete render_image_cover; + } + else + { + icon = QApplication::applicationDirPath() + DEFAULT_IMAGE; + QFile file(icon); + if (file.open(QIODevice::ReadOnly)) + { + QByteArray svg_buffer = file.readAll(); + file.close(); + QSvgRenderer* render_image = new QSvgRenderer(svg_buffer); + QPainter painter_image(image); + painter_image.setCompositionMode(QPainter::CompositionMode_Clear); // 清除画布 + painter_image.fillRect(image->rect(), Qt::transparent); // 填充透明色 + painter_image.setCompositionMode(QPainter::CompositionMode_SourceOver); // 恢复默认值 + render_image->render(&painter_image); + //修改颜色 + QDomDocument doc; + doc.setContent(svg_buffer); + SetSVGBackColor(doc.documentElement(), "path", "fill", title_cover_color); + QSvgRenderer* render_image_cover = new QSvgRenderer(doc.toByteArray()); + QPainter painter_image_cover(image_cover); + painter_image_cover.setCompositionMode(QPainter::CompositionMode_Clear); // 清除画布 + painter_image_cover.fillRect(image_cover->rect(), Qt::transparent); // 填充透明色 + painter_image_cover.setCompositionMode(QPainter::CompositionMode_SourceOver); // 恢复默认值 + render_image_cover->render(&painter_image_cover); + delete render_image; + delete render_image_cover; + } + } + button_struct.png = new QImage(query.value("png").toString()); + button_struct.image = image; + button_struct.image_cover = image_cover; + button_struct.background_color = background_color; + button_struct.text_color = QColor(title_color); + button_struct.text_cover_color = QColor(title_cover_color); + *button_structs << button_struct; + } + QSqlQuery begin_query(db); + begin_query.exec("BEGIN;"); + update_total(); + QSqlQuery commit_query(db); + commit_query.exec("COMMIT;"); return true; } @@ -1122,7 +1118,7 @@ bool SQLiteHelper::update_app() { if(fs::is_directory(dir)) { - QString config_path = QString::fromWCharArray(dir.path().wstring().c_str())+"/kmd_config.json"; + QString config_path = QString::fromWCharArray(dir.path().wstring().c_str())+"/kmd_config/config.json"; config_path.replace("/", "\\"); QFile config_file(config_path); if(!config_file.open(QIODevice::Text|QIODevice::ReadOnly)) @@ -1150,7 +1146,7 @@ bool SQLiteHelper::update_app() QString sql = "insert into kmd_menu " "(sort, app_id, locked, type, category_id, name, orig_name," " version, dev, create_time, op, func, path, url, " - "logo, initial_position,status) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?);"; + "logo, initial_position,status,img,is_navbar,is_elite) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?);"; query.prepare(sql); query.addBindValue(50); query.addBindValue(obj_root.value("app_id").toString()); @@ -1169,32 +1165,14 @@ bool SQLiteHelper::update_app() query.addBindValue(obj_root.value("logo").toString()); query.addBindValue(obj_root.value("initial_position").toString()); query.addBindValue(obj_root.value("status").toBool()); + query.addBindValue(obj_root.value("img").toString()); + query.addBindValue(false); + query.addBindValue(false); query.exec(); - bool categories[8]={false}; + bool categories[CATEGORIES_NUM]={false}; categories[ALL - 1] = true; categories[INNER - 1] = true; - for (int i = 0; i < 8; i++) - { - QSqlQuery query2(db); - if (categories[i]) - { - query2.prepare("SELECT COUNT(*) AS total FROM kmd_menu WHERE category_id LIKE :categoryId;"); - query2.bindValue(":categoryId", "%" + QString::number(i + 1) + "%"); - if (query2.exec() && query2.first()) - { - int total = query2.value("total").toInt(); - query2.prepare("UPDATE kmd_category SET total=:total WHERE id=:id;"); - query2.bindValue(":total", total); - query2.bindValue(":id", i + 1); - if (!query2.exec()) - { - QSqlQuery rollback(db); - rollback.exec("ROLLBACK;"); - return false; - } - } - } - } + update_total(); } @@ -1225,66 +1203,103 @@ bool SQLiteHelper::get_buttons(QList &buttons) } return true; } -bool SQLiteHelper::insert_software(QString name, QString orig_name, QString path, QString sort,bool *categories) { +bool SQLiteHelper::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) { + QSqlQuery begin(db); + begin.exec("BEGIN;"); QSqlQuery query(db); QString categories_str=""; - for(int i=0;i<8;i++) + categories[ALL - 1] = true; + if(is_elite) + { + categories[ELITE - 1] = true; + } + for(int i=0;i< CATEGORIES_NUM;i++) { if(categories[i]) { categories_str = categories_str + QString::number(i + 1) + ","; } } + if(logo.isEmpty()) + { + logo = QApplication::applicationDirPath()+DEFAULT_IMAGE; + } + if(img.isEmpty()) + { + img = QApplication::applicationDirPath()+DEFAULT_PNG; + } + QSqlQuery query_sel(db); + query_sel.prepare("select id from kmd_menu where orig_name = :orig_name;"); + query_sel.bindValue(":orig_name",orig_name); + if(query_sel.exec()) + { + if(query_sel.next()) + { + QString sql="update kmd_menu" + " set sort=:sort,locked=:locked,type=:type,category_id=:category_id," + "name=:name,orig_name=:orig_name,op=:op," + "func=:func,path=:path,url=:url,logo=:logo,img=:img,is_navbar=:is_navbar,is_elite=:is_elite,dev=:dev where orig_name=:orig_name;"; + query.prepare(sql); + query.bindValue(":sort",sort); + query.bindValue(":locked",locked); + query.bindValue(":type",type); + query.bindValue(":category_id",categories_str); + query.bindValue(":name",name); + query.bindValue(":orig_name",orig_name); + query.bindValue(":op",op); + query.bindValue(":func",func); + query.bindValue(":path",path); + query.bindValue(":url",url); + query.bindValue(":logo",logo); + query.bindValue(":img",img); + query.bindValue(":is_navbar",is_navbar); + query.bindValue(":is_elite", is_elite); + query.bindValue(":dev", dev); + if(!query.exec()) + { + QSqlQuery rollback(db); + rollback.exec("ROLLBACK;"); + return false; + } + + return true; + } + } QString sql = "insert into kmd_menu " "(sort, app_id, locked, type, category_id, name, orig_name," " create_time, op, func, path, url, " - "initial_position,status) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?);"; + "initial_position,status,logo,img,is_navbar,is_elite,dev) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?);"; query.prepare(sql); query.addBindValue(sort.toInt()); query.addBindValue(""); - query.addBindValue(false); - query.addBindValue("app"); + query.addBindValue(locked); + query.addBindValue(type); query.addBindValue(categories_str); query.addBindValue(name); query.addBindValue(orig_name); time_t create_time; time(&create_time); query.addBindValue(create_time); - query.addBindValue("soft"); - query.addBindValue(""); + query.addBindValue(op); + query.addBindValue(func); query.addBindValue(path); - query.addBindValue(""); + query.addBindValue(url); query.addBindValue(""); query.addBindValue(true); + query.addBindValue(logo); + query.addBindValue(img); + query.addBindValue(is_navbar); + query.addBindValue(is_elite); + query.addBindValue(dev); if(!query.exec()) { - //QMessageBox::critical(nullptr, QString::fromLocal8Bit("错误"), QString::fromLocal8Bit("写入数据库失败")); + QSqlQuery rollback(db); + rollback.exec("ROLLBACK;"); return false; } - for (int i = 0; i < 8; i++) - { - if (categories[i]) - { - QSqlQuery query2(db); - - query2.prepare("SELECT COUNT(*) AS total FROM kmd_menu WHERE category_id LIKE :categoryId;"); - query2.bindValue(":categoryId", "%" + QString::number(i + 1) + "%"); - if (query2.exec() && query2.first()) - { - int total = query2.value("total").toInt(); - query2.prepare("UPDATE kmd_category SET total=:total WHERE id=:id;"); - query2.bindValue(":total", total); - query2.bindValue(":id", i + 1); - qDebug()<< query2.lastError(); - if (!query2.exec()) - { - query.exec("ROLLBACK;"); - return false; - } - } - } - } - + update_total(); + QSqlQuery commit(db); + commit.exec("COMMIT;"); return true; } @@ -1293,6 +1308,20 @@ bool SQLiteHelper::set_category(QList& categrories) { QSqlQuery work(db); work.exec("begin;"); + QSqlQuery query2(db); + bool ok=query2.exec("update kmd_category set status=0;"); + Categrory categrory_all; + categrory_all.id = ALL; + categrory_all.name = QString::fromLocal8Bit("全部"); + categrory_all.sort = 0; + categrory_all.display = true; + categrories << categrory_all; + Categrory categrory_elite; + categrory_elite.id = ELITE; + categrory_elite.name = QString::fromLocal8Bit("推荐"); + categrory_elite.sort = 1; + categrory_elite.display = true; + categrories << categrory_elite; for(Categrory categrory:categrories) { QSqlQuery query(db); @@ -1355,16 +1384,12 @@ bool SQLiteHelper::get_category(QList& categrories,bool is_edit,bool } else { - if (!query.exec("select id,name,status,sort,total from kmd_category;")) + if (!query.exec("select id,name,status,sort,total from kmd_category where status=1 order by sort;")) { return false; } while (query.next()) { - if (query.value("name") == QString::fromLocal8Bit("全部")) - { - continue; - } Categrory categrory; categrory.name = query.value("name").toString(); categrory.id = query.value("id").toInt(); @@ -1382,13 +1407,17 @@ bool SQLiteHelper::get_all_software(QList &softwares,int category) QString sql; if(category==ALL) { - sql = "select * from kmd_menu where status=1 and not type='app_manage' and not op='self' order by sort;"; + sql = "select * from kmd_menu where type='app' and status=1 order by is_navbar desc,sort asc;"; + } + else if(category==ELITE) + { + sql = "select * from kmd_menu where type='app' and status=1 and is_elite=1 order by is_navbar desc,sort asc;"; } else { sql = "select * from kmd_menu where category_id like '%"; sql += QString::number(category, 10); - sql += "%' and not type='app_manage' and status=1 order by sort;"; + sql += "%' and type='app' and status=1 order by is_navbar desc,sort asc;"; } QSqlQuery query(db); if(!query.exec(sql)) @@ -1400,6 +1429,9 @@ bool SQLiteHelper::get_all_software(QList &softwares,int category) Record record; record.id = query.value("id").toInt(); + record.logo=query.value("logo").toString(); + record.is_navbar=query.value("is_navbar").toBool(); + record.img = query.value("img").toString(); record.sort = query.value("sort").toInt(); record.app_id = query.value("app_id").toString(); record.locked = query.value("locked").toBool(); @@ -1433,7 +1465,7 @@ bool SQLiteHelper::edit_software(QString name, QString orig_name, QString path, query.bindValue(":path", path); query.bindValue(":sort", sort); QString categories_str = ""; - for (int i = 0; i < 8; i++) + for (int i = 0; i < CATEGORIES_NUM; i++) { if (categories[i]) { @@ -1450,47 +1482,35 @@ bool SQLiteHelper::edit_software(QString name, QString orig_name, QString path, } qDebug() << query.lastError(); QSqlQuery categories_sql(db); - for(int i=0;i<8;i++) - { - QSqlQuery query2(db); - - query2.prepare("SELECT COUNT(*) AS total FROM kmd_menu WHERE category_id LIKE :categoryId;"); - query2.bindValue(":categoryId", "%" + QString::number(i + 1) + "%"); - if (query2.exec() && query2.first()) - { - int total = query2.value("total").toInt(); - query2.prepare("UPDATE kmd_category SET total=:total WHERE id=:id;"); - query2.bindValue(":total", total); - query2.bindValue(":id", i + 1); - qDebug() << query2.lastError(); - if (!query2.exec()) - { - query.exec("ROLLBACK;"); - return false; - } - } - } + update_total(); QSqlQuery commit(db); commit.exec("commit;"); return true; }else { - QString sql = "update kmd_menu set name=:name,path=:path,sort=:sort,category_id=:categories,type=:type where orig_name=:orig_name;"; + QString sql = "update kmd_menu set name=:name,path=:path,sort=:sort,category_id=:categories,is_navbar=:is_navbar where orig_name=:orig_name;"; QSqlQuery query(db); query.prepare(sql); query.bindValue(":name", name); query.bindValue(":path", path); query.bindValue(":sort", sort); QString categories_str = ""; - for (int i = 0; i < 8; i++) + for (int i = 0; i < CATEGORIES_NUM; i++) { if (categories[i]) { categories_str += QString::number(i + 1) + ","; } } - query.bindValue(":type", type); + if(type=="navbar") + { + query.bindValue(":is_navbar", true); + } + else + { + query.bindValue(":is_navbar", false); + } query.bindValue(":categories", categories_str); query.bindValue(":orig_name", orig_name); if (!query.exec()) @@ -1499,44 +1519,27 @@ bool SQLiteHelper::edit_software(QString name, QString orig_name, QString path, } qDebug() << query.lastError(); - for (int i = 0; i < 8; i++) - { - QSqlQuery query2(db); - if (categories[i]) - { - query2.prepare("select total from kmd_category where id=:id;"); - query2.bindValue(":id", i + 1); - if (!query2.exec()) - { - QSqlQuery rollback(db); - rollback.exec("rollback;"); - return false; - } - if (query2.next()) - { - QSqlQuery total(db); - QSqlQuery query3(db); - QString total_sql = "select id from kmd_menu where category_id like '%"; - total_sql += QString::number(i + 1); - total_sql += "%';"; - total.exec(total_sql); - query3.prepare("update kmd_category set total=:total where id=:id;"); - query3.bindValue(":total", total.size()+1); - query3.bindValue(":id", i + 1); - if (!query3.exec()) - { - QSqlQuery rollback(db); - rollback.exec("rollback;"); - return false; - } - } - } - } + update_total(); QSqlQuery commit(db); commit.exec("commit;"); return true; } } + +bool SQLiteHelper::delete_software(QString orig_name) +{ + QSqlQuery query(db);; + query.prepare("delete from kmd_menu where orig_name=:orig_name;"); + query.bindValue(":orig_name", orig_name); + if(!query.exec()) + { + return false; + } + else + { + return true; + } +} bool SQLiteHelper::get_a_software(QString orig_name, Record2 *record) { QString sql = "select * from kmd_menu where orig_name=:orig_name;"; QSqlQuery query(db); @@ -1567,3 +1570,53 @@ bool SQLiteHelper::get_a_software(QString orig_name, Record2 *record) { } return false; } + +//警告:这个函数必须用于事务中 +inline bool SQLiteHelper::update_total() +{ + + for (int i = 0; i < CATEGORIES_NUM; i++) + { + QSqlQuery query2(db); + if(i==ELITE-1) + { + query2.prepare("SELECT COUNT(*) AS total FROM kmd_menu WHERE is_elite=1 AND type='app';"); + } + else if(i==ALL-1) + { + query2.prepare("SELECT COUNT(*) AS total FROM kmd_menu WHERE type='app';"); + } + else + { + query2.prepare("SELECT COUNT(*) AS total FROM kmd_menu WHERE category_id LIKE :categoryId AND type='app';"); + query2.bindValue(":categoryId", "%" + QString::number(i + 1) + "%"); + } + if (query2.exec() && query2.first()) + { + int total = query2.value("total").toInt(); + query2.prepare("UPDATE kmd_category SET total=:total WHERE id=:id;"); + query2.bindValue(":total", total); + query2.bindValue(":id", i + 1); + if (!query2.exec()) + { + QSqlQuery rollback(db); + rollback.exec("ROLLBACK;"); + return false; + } + } + } + return true; +} + +bool SQLiteHelper::use_software(QString orig_name) +{ + QSqlQuery query(db); + query.prepare("update kmd_menu set use_time=:use_time where orig_name=:orig_name;"); + query.bindValue(":use_time", QDateTime::currentDateTime().toTime_t()); + query.bindValue(":orig_name", orig_name); + if (!query.exec()) + { + return false; + } + return true; +} \ No newline at end of file diff --git a/OfficeAssistant_msvc/sqlitehelper.h b/OfficeAssistant_msvc/sqlitehelper.h index 54b9f6e..41c7d5a 100644 --- a/OfficeAssistant_msvc/sqlitehelper.h +++ b/OfficeAssistant_msvc/sqlitehelper.h @@ -1,4 +1,4 @@ -#pragma once +#pragma once #include #include #include @@ -14,11 +14,15 @@ class SoftwareRequest; typedef struct tagRecord{ int id; int sort; + QString initial_position; QString app_id; bool locked; + bool is_navbar; + bool is_elite; QString type; QString category_id; QString logo; + QString img; QString name; QString orig_name; QString version; @@ -47,15 +51,19 @@ class SQLiteHelper : public QObject public: SQLiteHelper(QObject *parent = nullptr); 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="app",bool locked=false,QString op="soft",QString func="",QString url="",bool is_navbar=false,bool is_elite=false,QString dev=""); bool edit_software(QString name, QString orig_name, QString path, QString sort, bool* categories,QString type=""); bool get_software(QList* buttons, ConfigResponse* config_response); + bool get_software(QList* button_structs,QString background_color , QString title_color, QString title_cover_color); bool update_app(); bool get_buttons(QList &buttons); bool get_category(QList& categrories, bool is_edit,bool all=false); bool set_category(QList& categrories); bool get_all_software(QList &softwares,int category); bool get_a_software(QString orig_name, Record2 *record); + bool update_total();//警告:这个函数必须用于事务中 + bool use_software(QString orig_name); + QSqlDatabase db; ~SQLiteHelper(); @@ -64,6 +72,8 @@ private: QNetworkReply* reply; QEventLoop eventLoop; bool downloadSuccess; + bool delete_software(QString orig_name); + bool execute_query(QString sql, QList& softwares); void cancelDownload(); }; diff --git a/OfficeAssistant_msvc/userimprove.cpp b/OfficeAssistant_msvc/userimprove.cpp new file mode 100644 index 0000000..1187b6d --- /dev/null +++ b/OfficeAssistant_msvc/userimprove.cpp @@ -0,0 +1,34 @@ +#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; + } +} +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); +} + diff --git a/OfficeAssistant_msvc/userimprove.h b/OfficeAssistant_msvc/userimprove.h new file mode 100644 index 0000000..d3b3d76 --- /dev/null +++ b/OfficeAssistant_msvc/userimprove.h @@ -0,0 +1,18 @@ +#pragma once + +#include +#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; +}; diff --git a/OfficeAssistant_msvc/userimprove.ui b/OfficeAssistant_msvc/userimprove.ui new file mode 100644 index 0000000..77ebf30 --- /dev/null +++ b/OfficeAssistant_msvc/userimprove.ui @@ -0,0 +1,59 @@ + + + UserImproveClass + + + + 0 + 0 + 600 + 400 + + + + UserImprove + + + + + 80 + 310 + 150 + 46 + + + + 查看详情 + + + + + + 330 + 310 + 150 + 46 + + + + 确定 + + + + + + 110 + 170 + 371 + 28 + + + + 我同意加入用户体验改善计划 + + + + + + + diff --git a/wxdk/main.cpp b/wxdk/main.cpp index f2de172..54d15ac 100644 --- a/wxdk/main.cpp +++ b/wxdk/main.cpp @@ -1,294 +1,294 @@ -#define KEY "79c86fb12b36dfa33d1a537c9af100b4c7928a9c" -#include "openwechat.h" -#include -#include -#include -#include -#include -ZWQUERYSYSTEMINFORMATION ZwQuerySystemInformation = (ZWQUERYSYSTEMINFORMATION)GetProcAddress(GetModuleHandleA("ntdll.dll"), "ZwQuerySystemInformation"); -NTQUERYOBJECT NtQueryObject = (NTQUERYOBJECT)GetProcAddress( - GetModuleHandleA("ntdll.dll"), "NtQueryObject"); -BOOL IsTargetPid(DWORD Pid, std::vector Pids, int num) -{ - for (auto pid:Pids) - { - if (Pid == pid) - { - return TRUE; - } - } - return FALSE; -} -HANDLE DuplicateHandleEx(DWORD pid, HANDLE h, DWORD flags) -{ - HANDLE hHandle = NULL; - - HANDLE hProc = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid); - if (hProc) - { - if (!DuplicateHandle(hProc, - (HANDLE)h, GetCurrentProcess(), - &hHandle, 0, FALSE, /*DUPLICATE_SAME_ACCESS*/flags)) - { - hHandle = NULL; - } - } - - CloseHandle(hProc); - return hHandle; -} - -typedef struct _SYSTEM_HANDLE_TABLE_ENTRY_INFO { - USHORT UniqueProcessId; - USHORT CreatorBackTraceIndex; - UCHAR ObjectTypeIndex; - UCHAR HandleAttributes; - USHORT HandleValue; - PVOID Object; - ULONG GrantedAccess; -} SYSTEM_HANDLE_TABLE_ENTRY_INFO, *PSYSTEM_HANDLE_TABLE_ENTRY_INFO; -typedef struct -{ - USHORT Length; - USHORT MaxLen; - USHORT *Buffer; -}UNICODE_STRING, *PUNICODE_STRING; -typedef struct _OBJECT_NAME_INFORMATION { - UNICODE_STRING Name; -} OBJECT_NAME_INFORMATION, *POBJECT_NAME_INFORMATION; - -typedef struct _SYSTEM_HANDLE_INFORMATION1 { - ULONG NumberOfHandles; - SYSTEM_HANDLE_TABLE_ENTRY_INFO Handles[1]; -} SYSTEM_HANDLE_INFORMATION1, *PSYSTEM_HANDLE_INFORMATION1; - -DWORD qureyProcessId(std::wstring name, std::vector *pids) { - DWORD pid; - PROCESSENTRY32 entry; - entry.dwSize = sizeof(PROCESSENTRY32); - - HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL); - - if (Process32First(snapshot, &entry) == TRUE) - { - while (Process32Next(snapshot, &entry) == TRUE) - { - if (std::wstring(entry.szExeFile) == name) { - HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, entry.th32ProcessID); - pid = GetProcessId(hProcess); - CloseHandle(hProcess); - pids->emplace_back(pid); - } - } - } - CloseHandle(snapshot); - return pid; -} -BOOL ElevatePrivileges() -{ - HANDLE hToken; - TOKEN_PRIVILEGES tkp; - tkp.PrivilegeCount = 1; - if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken)) - return FALSE; - LookupPrivilegeValue(NULL, SE_DEBUG_NAME, &tkp.Privileges[0].Luid); - tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; - if (!AdjustTokenPrivileges(hToken, FALSE, &tkp, sizeof(TOKEN_PRIVILEGES), NULL, NULL)) - { - return FALSE; - } - - return TRUE; -} -int PatchWeChat() -{ - DWORD dwSize = 0; - POBJECT_NAME_INFORMATION pNameInfo; - POBJECT_NAME_INFORMATION pNameType; - PVOID pbuffer = NULL; - NTSTATUS Status; - int nIndex = 0; - DWORD dwFlags = 0; - char szType[128] = { 0 }; - char szName[512] = { 0 }; - PSYSTEM_HANDLE_INFORMATION1 pHandleInfo = NULL; - int ret = -1; - - ElevatePrivileges(); - std::vector pids; - DWORD Num = qureyProcessId(L"WeChat.exe", &pids); - if (Num == 0) - { - return ret; - } - - if (!ZwQuerySystemInformation) - { - goto Exit0; - } - - pbuffer = VirtualAlloc(NULL, 0x1000, MEM_COMMIT, PAGE_READWRITE); - - if (!pbuffer) - { - goto Exit0; - } - - Status = ZwQuerySystemInformation(SystemHandleInformation, pbuffer, 0x1000, &dwSize); - - if (Status<0) - { - if ((LONG)0xC0000004L != Status) - { - goto Exit0; - } - else - { - // ҿԱ֤ȷʹѭԺ - if (NULL != pbuffer) - { - VirtualFree(pbuffer, 0, MEM_RELEASE); - } - - if (dwSize * 2 > 0x4000000) // MAXSIZE - { - goto Exit0; - } - - pbuffer = VirtualAlloc(NULL, dwSize * 2, MEM_COMMIT, PAGE_READWRITE); - - if (!pbuffer) - { - goto Exit0; - } - - Status = ZwQuerySystemInformation(SystemHandleInformation, pbuffer, dwSize * 2, NULL); - - if (Status<0) - { - goto Exit0; - } - } - } - - pHandleInfo = (PSYSTEM_HANDLE_INFORMATION1)pbuffer; - - for (nIndex = 0; nIndex < pHandleInfo->NumberOfHandles; nIndex++) - { - if (IsTargetPid(pHandleInfo->Handles[nIndex].UniqueProcessId, pids, Num)) - { - // - HANDLE hHandle = DuplicateHandleEx(pHandleInfo->Handles[nIndex].UniqueProcessId, - (HANDLE)pHandleInfo->Handles[nIndex].HandleValue, - DUPLICATE_SAME_ACCESS - ); - if (hHandle == NULL) continue; - - Status = NtQueryObject(hHandle, ObjectNameInformation, szName, 512, &dwFlags); - - if (Status<0) - { - CloseHandle(hHandle); - continue; - } - - Status = NtQueryObject(hHandle, ObjectTypeInformation, szType, 128, &dwFlags); - - if (Status<0) - { - CloseHandle(hHandle); - continue; - } - - pNameInfo = (POBJECT_NAME_INFORMATION)szName; - pNameType = (POBJECT_NAME_INFORMATION)szType; - - WCHAR TypName[1024] = { 0 }; - WCHAR Name[1024] = { 0 }; - - wcsncpy_s(TypName, (WCHAR*)pNameType->Name.Buffer, pNameType->Name.Length / 2); - wcsncpy_s(Name, (WCHAR*)pNameInfo->Name.Buffer, pNameInfo->Name.Length / 2); - - // ƥǷΪҪرյľ - if (0 == wcscmp(TypName, L"Mutant")) - { - //WeChat_aj5r8jpxt_Instance_Identity_Mutex_Name - //if (wcsstr(Name, L"_WeChat_App_Instance_Identity_Mutex_Name")) - if (wcsstr(Name, L"_WeChat_") && - wcsstr(Name, L"_Instance_Identity_Mutex_Name")) - { - CloseHandle(hHandle); - - hHandle = DuplicateHandleEx(pHandleInfo->Handles[nIndex].UniqueProcessId, - (HANDLE)pHandleInfo->Handles[nIndex].HandleValue, - DUPLICATE_CLOSE_SOURCE - ); - - if (hHandle) - { - ret = ERROR_SUCCESS; - CloseHandle(hHandle); - } - else - { - ret = GetLastError(); - } - - //goto Exit0; - } - } - - CloseHandle(hHandle); - } - - } - -Exit0: - if (NULL != pbuffer) - { - VirtualFree(pbuffer, 0, MEM_RELEASE); - } - - return ret; -} -int WINAPI WinMain( - HINSTANCE hInstance, - HINSTANCE hPrevInstance, - PSTR nCmdLine, - int iCmdShow -) { - if (strcmp(nCmdLine, KEY) != 0){ - return 0; - } - else { - int ret = 1; - PatchWeChat(); - WCHAR Path[1024]; - HKEY hKey = NULL; - if (ERROR_SUCCESS != RegOpenKey(HKEY_CURRENT_USER, L"Software\\Tencent\\WeChat", &hKey)) - { - - return ret; - } - - DWORD Type = REG_SZ; - // WCHAR Path[MAX_PATH] = { 0 }; - DWORD cbData = MAX_PATH * sizeof(WCHAR); - if (ERROR_SUCCESS != RegQueryValueEx(hKey, L"InstallPath", 0, &Type, (LPBYTE)Path, &cbData)) - { - ret = GetLastError(); - if (hKey) - { - RegCloseKey(hKey); - } - return ret; - } - WCHAR exe[1024]; - wcscpy_s(exe, Path); - wcscat_s(exe, L"\\WeChat.exe"); - - ShellExecute(GetDesktopWindow(), L"open", exe, L"", Path, SW_SHOW); - - } - return 0; +#define KEY "79c86fb12b36dfa33d1a537c9af100b4c7928a9c" +#include "openwechat.h" +#include +#include +#include +#include +#include +ZWQUERYSYSTEMINFORMATION ZwQuerySystemInformation = (ZWQUERYSYSTEMINFORMATION)GetProcAddress(GetModuleHandleA("ntdll.dll"), "ZwQuerySystemInformation"); +NTQUERYOBJECT NtQueryObject = (NTQUERYOBJECT)GetProcAddress( + GetModuleHandleA("ntdll.dll"), "NtQueryObject"); +BOOL IsTargetPid(DWORD Pid, std::vector Pids, int num) +{ + for (auto pid:Pids) + { + if (Pid == pid) + { + return TRUE; + } + } + return FALSE; +} +HANDLE DuplicateHandleEx(DWORD pid, HANDLE h, DWORD flags) +{ + HANDLE hHandle = NULL; + + HANDLE hProc = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid); + if (hProc) + { + if (!DuplicateHandle(hProc, + (HANDLE)h, GetCurrentProcess(), + &hHandle, 0, FALSE, /*DUPLICATE_SAME_ACCESS*/flags)) + { + hHandle = NULL; + } + } + + CloseHandle(hProc); + return hHandle; +} + +typedef struct _SYSTEM_HANDLE_TABLE_ENTRY_INFO { + USHORT UniqueProcessId; + USHORT CreatorBackTraceIndex; + UCHAR ObjectTypeIndex; + UCHAR HandleAttributes; + USHORT HandleValue; + PVOID Object; + ULONG GrantedAccess; +} SYSTEM_HANDLE_TABLE_ENTRY_INFO, *PSYSTEM_HANDLE_TABLE_ENTRY_INFO; +typedef struct +{ + USHORT Length; + USHORT MaxLen; + USHORT *Buffer; +}UNICODE_STRING, *PUNICODE_STRING; +typedef struct _OBJECT_NAME_INFORMATION { + UNICODE_STRING Name; +} OBJECT_NAME_INFORMATION, *POBJECT_NAME_INFORMATION; + +typedef struct _SYSTEM_HANDLE_INFORMATION1 { + ULONG NumberOfHandles; + SYSTEM_HANDLE_TABLE_ENTRY_INFO Handles[1]; +} SYSTEM_HANDLE_INFORMATION1, *PSYSTEM_HANDLE_INFORMATION1; + +DWORD qureyProcessId(std::wstring name, std::vector *pids) { + DWORD pid; + PROCESSENTRY32 entry; + entry.dwSize = sizeof(PROCESSENTRY32); + + HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL); + + if (Process32First(snapshot, &entry) == TRUE) + { + while (Process32Next(snapshot, &entry) == TRUE) + { + if (std::wstring(entry.szExeFile) == name) { + HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, entry.th32ProcessID); + pid = GetProcessId(hProcess); + CloseHandle(hProcess); + pids->emplace_back(pid); + } + } + } + CloseHandle(snapshot); + return pid; +} +BOOL ElevatePrivileges() +{ + HANDLE hToken; + TOKEN_PRIVILEGES tkp; + tkp.PrivilegeCount = 1; + if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken)) + return FALSE; + LookupPrivilegeValue(NULL, SE_DEBUG_NAME, &tkp.Privileges[0].Luid); + tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; + if (!AdjustTokenPrivileges(hToken, FALSE, &tkp, sizeof(TOKEN_PRIVILEGES), NULL, NULL)) + { + return FALSE; + } + + return TRUE; +} +int PatchWeChat() +{ + DWORD dwSize = 0; + POBJECT_NAME_INFORMATION pNameInfo; + POBJECT_NAME_INFORMATION pNameType; + PVOID pbuffer = NULL; + NTSTATUS Status; + int nIndex = 0; + DWORD dwFlags = 0; + char szType[128] = { 0 }; + char szName[512] = { 0 }; + PSYSTEM_HANDLE_INFORMATION1 pHandleInfo = NULL; + int ret = -1; + + ElevatePrivileges(); + std::vector pids; + DWORD Num = qureyProcessId(L"WeChat.exe", &pids); + if (Num == 0) + { + return ret; + } + + if (!ZwQuerySystemInformation) + { + goto Exit0; + } + + pbuffer = VirtualAlloc(NULL, 0x1000, MEM_COMMIT, PAGE_READWRITE); + + if (!pbuffer) + { + goto Exit0; + } + + Status = ZwQuerySystemInformation(SystemHandleInformation, pbuffer, 0x1000, &dwSize); + + if (Status<0) + { + if ((LONG)0xC0000004L != Status) + { + goto Exit0; + } + else + { + // ҿԱ֤ȷʹѭԺ + if (NULL != pbuffer) + { + VirtualFree(pbuffer, 0, MEM_RELEASE); + } + + if (dwSize * 2 > 0x4000000) // MAXSIZE + { + goto Exit0; + } + + pbuffer = VirtualAlloc(NULL, dwSize * 2, MEM_COMMIT, PAGE_READWRITE); + + if (!pbuffer) + { + goto Exit0; + } + + Status = ZwQuerySystemInformation(SystemHandleInformation, pbuffer, dwSize * 2, NULL); + + if (Status<0) + { + goto Exit0; + } + } + } + + pHandleInfo = (PSYSTEM_HANDLE_INFORMATION1)pbuffer; + + for (nIndex = 0; nIndex < pHandleInfo->NumberOfHandles; nIndex++) + { + if (IsTargetPid(pHandleInfo->Handles[nIndex].UniqueProcessId, pids, Num)) + { + // + HANDLE hHandle = DuplicateHandleEx(pHandleInfo->Handles[nIndex].UniqueProcessId, + (HANDLE)pHandleInfo->Handles[nIndex].HandleValue, + DUPLICATE_SAME_ACCESS + ); + if (hHandle == NULL) continue; + + Status = NtQueryObject(hHandle, ObjectNameInformation, szName, 512, &dwFlags); + + if (Status<0) + { + CloseHandle(hHandle); + continue; + } + + Status = NtQueryObject(hHandle, ObjectTypeInformation, szType, 128, &dwFlags); + + if (Status<0) + { + CloseHandle(hHandle); + continue; + } + + pNameInfo = (POBJECT_NAME_INFORMATION)szName; + pNameType = (POBJECT_NAME_INFORMATION)szType; + + WCHAR TypName[1024] = { 0 }; + WCHAR Name[1024] = { 0 }; + + wcsncpy_s(TypName, (WCHAR*)pNameType->Name.Buffer, pNameType->Name.Length / 2); + wcsncpy_s(Name, (WCHAR*)pNameInfo->Name.Buffer, pNameInfo->Name.Length / 2); + + // ƥǷΪҪرյľ + if (0 == wcscmp(TypName, L"Mutant")) + { + //WeChat_aj5r8jpxt_Instance_Identity_Mutex_Name + //if (wcsstr(Name, L"_WeChat_App_Instance_Identity_Mutex_Name")) + if (wcsstr(Name, L"_WeChat_") && + wcsstr(Name, L"_Instance_Identity_Mutex_Name")) + { + CloseHandle(hHandle); + + hHandle = DuplicateHandleEx(pHandleInfo->Handles[nIndex].UniqueProcessId, + (HANDLE)pHandleInfo->Handles[nIndex].HandleValue, + DUPLICATE_CLOSE_SOURCE + ); + + if (hHandle) + { + ret = ERROR_SUCCESS; + CloseHandle(hHandle); + } + else + { + ret = GetLastError(); + } + + //goto Exit0; + } + } + + CloseHandle(hHandle); + } + + } + +Exit0: + if (NULL != pbuffer) + { + VirtualFree(pbuffer, 0, MEM_RELEASE); + } + + return ret; +} +int WINAPI WinMain( + HINSTANCE hInstance, + HINSTANCE hPrevInstance, + PSTR nCmdLine, + int iCmdShow +) { + if (strcmp(nCmdLine, KEY) != 0){ + return 0; + } + else { + int ret = 1; + PatchWeChat(); + WCHAR Path[1024]; + HKEY hKey = NULL; + if (ERROR_SUCCESS != RegOpenKey(HKEY_CURRENT_USER, L"Software\\Tencent\\WeChat", &hKey)) + { + + return ret; + } + + DWORD Type = REG_SZ; + // WCHAR Path[MAX_PATH] = { 0 }; + DWORD cbData = MAX_PATH * sizeof(WCHAR); + if (ERROR_SUCCESS != RegQueryValueEx(hKey, L"InstallPath", 0, &Type, (LPBYTE)Path, &cbData)) + { + ret = GetLastError(); + if (hKey) + { + RegCloseKey(hKey); + } + return ret; + } + WCHAR exe[1024]; + wcscpy_s(exe, Path); + wcscat_s(exe, L"\\WeChat.exe"); + + ShellExecute(GetDesktopWindow(), L"open", exe, L"", Path, SW_SHOW); + + } + return 0; } \ No newline at end of file diff --git a/wxdk/openwechat.h b/wxdk/openwechat.h index 23d99f3..6d04e77 100644 --- a/wxdk/openwechat.h +++ b/wxdk/openwechat.h @@ -1,81 +1,81 @@ -#pragma once -#include -typedef enum _SYSTEM_INFORMATION_CLASS { - SystemBasicInformation, // 0 Y N - SystemProcessorInformation, // 1 Y N - SystemPerformanceInformation, // 2 Y N - SystemTimeOfDayInformation, // 3 Y N - SystemNotImplemented1, // 4 Y N - SystemProcessesAndThreadsInformation, // 5 Y N - SystemCallCounts, // 6 Y N - SystemConfigurationInformation, // 7 Y N - SystemProcessorTimes, // 8 Y N - SystemGlobalFlag, // 9 Y Y - SystemNotImplemented2, // 10 Y N - SystemModuleInformation, // 11 Y N - SystemLockInformation, // 12 Y N - SystemNotImplemented3, // 13 Y N - SystemNotImplemented4, // 14 Y N - SystemNotImplemented5, // 15 Y N - SystemHandleInformation, // 16 Y N - SystemObjectInformation, // 17 Y N - SystemPagefileInformation, // 18 Y N - SystemInstructionEmulationCounts, // 19 Y N - SystemInvalidInfoClass1, // 20 - SystemCacheInformation, // 21 Y Y - SystemPoolTagInformation, // 22 Y N - SystemProcessorStatistics, // 23 Y N - SystemDpcInformation, // 24 Y Y - SystemNotImplemented6, // 25 Y N - SystemLoadImage, // 26 N Y - SystemUnloadImage, // 27 N Y - SystemTimeAdjustment, // 28 Y Y - SystemNotImplemented7, // 29 Y N - SystemNotImplemented8, // 30 Y N - SystemNotImplemented9, // 31 Y N - SystemCrashDumpInformation, // 32 Y N - SystemExceptionInformation, // 33 Y N - SystemCrashDumpStateInformation, // 34 Y Y/N - SystemKernelDebuggerInformation, // 35 Y N - SystemContextSwitchInformation, // 36 Y N - SystemRegistryQuotaInformation, // 37 Y Y - SystemLoadAndCallImage, // 38 N Y - SystemPrioritySeparation, // 39 N Y - SystemNotImplemented10, // 40 Y N - SystemNotImplemented11, // 41 Y N - SystemInvalidInfoClass2, // 42 - SystemInvalidInfoClass3, // 43 - SystemTimeZoneInformation, // 44 Y N - SystemLookasideInformation, // 45 Y N - SystemSetTimeSlipEvent, // 46 N Y - SystemCreateSession, // 47 N Y - SystemDeleteSession, // 48 N Y - SystemInvalidInfoClass4, // 49 - SystemRangeStartInformation, // 50 Y N - SystemVerifierInformation, // 51 Y Y - SystemAddVerifier, // 52 N Y - SystemSessionProcessesInformation // 53 Y N -} SYSTEM_INFORMATION_CLASS; - -typedef NTSTATUS -(NTAPI *ZWQUERYSYSTEMINFORMATION)( - IN SYSTEM_INFORMATION_CLASS SystemInformationClass, - OUT PVOID SystemInformation, - IN ULONG SystemInformationLength, - OUT PULONG ReturnLength OPTIONAL - ); -typedef enum _OBJECT_INFORMATION_CLASS { - ObjectBasicInformation, - ObjectNameInformation, - ObjectTypeInformation, - ObjectAllInformation, - ObjectDataInformation -} OBJECT_INFORMATION_CLASS; -typedef NTSTATUS(NTAPI *NTQUERYOBJECT)( - _In_opt_ HANDLE Handle, - _In_ OBJECT_INFORMATION_CLASS ObjectInformationClass, - _Out_opt_ PVOID ObjectInformation, - _In_ ULONG ObjectInformationLength, - _Out_opt_ PULONG ReturnLength - ); - +#pragma once +#include +typedef enum _SYSTEM_INFORMATION_CLASS { + SystemBasicInformation, // 0 Y N + SystemProcessorInformation, // 1 Y N + SystemPerformanceInformation, // 2 Y N + SystemTimeOfDayInformation, // 3 Y N + SystemNotImplemented1, // 4 Y N + SystemProcessesAndThreadsInformation, // 5 Y N + SystemCallCounts, // 6 Y N + SystemConfigurationInformation, // 7 Y N + SystemProcessorTimes, // 8 Y N + SystemGlobalFlag, // 9 Y Y + SystemNotImplemented2, // 10 Y N + SystemModuleInformation, // 11 Y N + SystemLockInformation, // 12 Y N + SystemNotImplemented3, // 13 Y N + SystemNotImplemented4, // 14 Y N + SystemNotImplemented5, // 15 Y N + SystemHandleInformation, // 16 Y N + SystemObjectInformation, // 17 Y N + SystemPagefileInformation, // 18 Y N + SystemInstructionEmulationCounts, // 19 Y N + SystemInvalidInfoClass1, // 20 + SystemCacheInformation, // 21 Y Y + SystemPoolTagInformation, // 22 Y N + SystemProcessorStatistics, // 23 Y N + SystemDpcInformation, // 24 Y Y + SystemNotImplemented6, // 25 Y N + SystemLoadImage, // 26 N Y + SystemUnloadImage, // 27 N Y + SystemTimeAdjustment, // 28 Y Y + SystemNotImplemented7, // 29 Y N + SystemNotImplemented8, // 30 Y N + SystemNotImplemented9, // 31 Y N + SystemCrashDumpInformation, // 32 Y N + SystemExceptionInformation, // 33 Y N + SystemCrashDumpStateInformation, // 34 Y Y/N + SystemKernelDebuggerInformation, // 35 Y N + SystemContextSwitchInformation, // 36 Y N + SystemRegistryQuotaInformation, // 37 Y Y + SystemLoadAndCallImage, // 38 N Y + SystemPrioritySeparation, // 39 N Y + SystemNotImplemented10, // 40 Y N + SystemNotImplemented11, // 41 Y N + SystemInvalidInfoClass2, // 42 + SystemInvalidInfoClass3, // 43 + SystemTimeZoneInformation, // 44 Y N + SystemLookasideInformation, // 45 Y N + SystemSetTimeSlipEvent, // 46 N Y + SystemCreateSession, // 47 N Y + SystemDeleteSession, // 48 N Y + SystemInvalidInfoClass4, // 49 + SystemRangeStartInformation, // 50 Y N + SystemVerifierInformation, // 51 Y Y + SystemAddVerifier, // 52 N Y + SystemSessionProcessesInformation // 53 Y N +} SYSTEM_INFORMATION_CLASS; + +typedef NTSTATUS +(NTAPI *ZWQUERYSYSTEMINFORMATION)( + IN SYSTEM_INFORMATION_CLASS SystemInformationClass, + OUT PVOID SystemInformation, + IN ULONG SystemInformationLength, + OUT PULONG ReturnLength OPTIONAL + ); +typedef enum _OBJECT_INFORMATION_CLASS { + ObjectBasicInformation, + ObjectNameInformation, + ObjectTypeInformation, + ObjectAllInformation, + ObjectDataInformation +} OBJECT_INFORMATION_CLASS; +typedef NTSTATUS(NTAPI *NTQUERYOBJECT)( + _In_opt_ HANDLE Handle, + _In_ OBJECT_INFORMATION_CLASS ObjectInformationClass, + _Out_opt_ PVOID ObjectInformation, + _In_ ULONG ObjectInformationLength, + _Out_opt_ PULONG ReturnLength + ); +