提交测试,基本完成
This commit is contained in:
@ -34,7 +34,8 @@ namespace fs = std::filesystem;
|
||||
#include <experimental/filesystem>
|
||||
namespace fs = std::experimental::filesystem;
|
||||
#endif
|
||||
bool getMenu(std::wstring &path_str,QList<QString> *paths)
|
||||
|
||||
bool getMenu(std::wstring &path_str,QHash<QString,QString> *paths)
|
||||
{
|
||||
fs::directory_iterator* it = new fs::directory_iterator(path_str);
|
||||
for (auto file : *it)
|
||||
@ -65,7 +66,8 @@ bool getMenu(std::wstring &path_str,QList<QString> *paths)
|
||||
hr = pShellItem->GetPath(szTargetPath, sizeof(szTargetPath), &fd, 0); ;
|
||||
if (SUCCEEDED(hr))
|
||||
{
|
||||
*paths << QString::fromWCharArray(szTargetPath);
|
||||
QString filename = file.path().filename().string().c_str();
|
||||
*paths->insert(filename,QString::fromWCharArray(szTargetPath));
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -134,14 +136,12 @@ SQLiteHelper::SQLiteHelper(QObject *parent)
|
||||
|
||||
SQLiteHelper::~SQLiteHelper()
|
||||
{
|
||||
db.close();
|
||||
QSqlDatabase::removeDatabase("mydb");
|
||||
}
|
||||
|
||||
bool SQLiteHelper::update_software()
|
||||
{
|
||||
HKEY hKeyUninstall = nullptr;
|
||||
QList<QString>* paths = new QList<QString>;
|
||||
QHash<QString,QString>* paths = new QHash<QString, QString>;
|
||||
/*QSqlQuery query;
|
||||
QString sql = "select * from kmd_menu;";
|
||||
query.exec(sql);
|
||||
@ -176,7 +176,7 @@ bool SQLiteHelper::update_software()
|
||||
records.insert(path, record);
|
||||
}*/
|
||||
//<2F><>ʼ<EFBFBD>˵<EFBFBD><CBB5><EFBFBD><EFBFBD>Ѱ<EFBFBD>װ<EFBFBD><D7B0><EFBFBD><EFBFBD><EFBFBD>б<EFBFBD>
|
||||
/*WCHAR path[MAX_PATH];
|
||||
WCHAR path[MAX_PATH];
|
||||
HRESULT hr = SHGetFolderPathW(nullptr, CSIDL_COMMON_PROGRAMS, nullptr, 0, path);//<2F><>ȡProgramData<74>п<EFBFBD>ʼ<EFBFBD>˵<EFBFBD><CBB5><EFBFBD>·<EFBFBD><C2B7>
|
||||
std::wstring path_str(path);
|
||||
getMenu(path_str, paths);
|
||||
@ -188,7 +188,7 @@ bool SQLiteHelper::update_software()
|
||||
hr = SHGetFolderPathW(nullptr, CSIDL_PROGRAMS, nullptr, 0, path);//<2F><>ȡ<EFBFBD>û<EFBFBD><C3BB>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD>п<EFBFBD>ʼ<EFBFBD>˵<EFBFBD><CBB5><EFBFBD>·<EFBFBD><C2B7>
|
||||
path_str.clear();
|
||||
path_str = std::wstring(path);
|
||||
getMenu(path_str, paths); */
|
||||
getMenu(path_str, paths);
|
||||
// <20><><EFBFBD><EFBFBD>ע<EFBFBD><D7A2><EFBFBD><EFBFBD><EFBFBD>е<EFBFBD><D0B5>Ѱ<EFBFBD>װ<EFBFBD><D7B0><EFBFBD><EFBFBD><EFBFBD>б<EFBFBD>
|
||||
QHash<QString, Record> reg_records;
|
||||
HKEY hKey;
|
||||
@ -656,7 +656,13 @@ bool SQLiteHelper::update_software()
|
||||
}
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȫ<EFBFBD>ֶ<EFBFBD>
|
||||
SoftwareRequest software_request;
|
||||
software_request.sendRequest(&public_programs_list);
|
||||
bool ok=software_request.sendRequest(*paths,&public_programs_list);
|
||||
if(!ok)
|
||||
{
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
QSqlQuery begin(db);
|
||||
if (!begin.exec("begin;"))
|
||||
{
|
||||
@ -703,7 +709,7 @@ bool SQLiteHelper::update_software()
|
||||
sql += ",'";
|
||||
sql += public_programs_list[key].type;
|
||||
sql += "','";
|
||||
sql += public_programs_list[key].category_id;
|
||||
sql += QString::number(OTHERS, 10);
|
||||
sql += "','";
|
||||
sql += public_programs_list[key].name;
|
||||
sql += "','";
|
||||
@ -736,6 +742,29 @@ bool SQLiteHelper::update_software()
|
||||
return false;
|
||||
}
|
||||
}
|
||||
QSqlQuery find(db);
|
||||
|
||||
find.exec("select orig_name,op from kmd_menu;");
|
||||
while(find.next())
|
||||
{
|
||||
if(!public_programs_list.contains(find.value("orig_name").toString()))
|
||||
{
|
||||
if (find.value("op").toString() == "soft")
|
||||
{
|
||||
QSqlQuery del(db);
|
||||
del.prepare("update kmd_menu set status=0 where orig_name=:orig_name;");
|
||||
del.bindValue(":orig_value", find.value("orig_name"));
|
||||
del.exec();
|
||||
}
|
||||
}
|
||||
}
|
||||
find.clear();
|
||||
find.exec("select id from kmd_menu where status=0;");
|
||||
if(find.size()>=100)
|
||||
{
|
||||
QSqlQuery del(db);
|
||||
del.exec("delete from kmd_menu where status=0;");
|
||||
}
|
||||
QSqlQuery commit(db);
|
||||
commit.exec("commit;");
|
||||
return true;
|
||||
@ -765,11 +794,30 @@ bool SQLiteHelper::get_software(QList<ButtonStruct>* buttons, ConfigResponse* co
|
||||
{
|
||||
return false;
|
||||
}
|
||||
QString background_color;
|
||||
QString title_color;
|
||||
QString title_cover_color;
|
||||
if(config_response->succeed)
|
||||
{
|
||||
background_color = config_response->basic.backgroud_color;
|
||||
title_color = config_response->basic.title_color;
|
||||
title_cover_color = config_response->basic.title_cover_color;
|
||||
}
|
||||
else
|
||||
{
|
||||
background_color = DEFAULT_BACKGROUND_COLOR;
|
||||
title_color = DEFAULT_TEXT_COLOR;
|
||||
title_cover_color = DEFAULT_COVER_COLOR;
|
||||
}
|
||||
QByteArray* buffer = new QByteArray;
|
||||
QHash<QString, ButtonStruct> button_map;
|
||||
for(auto menu : config_response->buttons)
|
||||
{
|
||||
|
||||
}
|
||||
while (query.next())
|
||||
{
|
||||
QNetworkAccessManager manager;
|
||||
downloadSuccess = true;
|
||||
QString icon = QApplication::applicationDirPath() + "/images/software/" + query.value("orig_name").toString() + ".svg";
|
||||
ButtonStruct button_struct;
|
||||
button_struct.path = query.value("path").toString();
|
||||
button_struct.text = query.value("name").toString();
|
||||
@ -780,11 +828,6 @@ bool SQLiteHelper::get_software(QList<ButtonStruct>* buttons, ConfigResponse* co
|
||||
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);
|
||||
QString icon = QApplication::applicationDirPath() + query.value("logo").toString();
|
||||
if(icon.isEmpty())
|
||||
{
|
||||
icon = QApplication::applicationDirPath() + DEFAULT_IMAGE;
|
||||
}
|
||||
QFile file(icon);
|
||||
if (file.open(QIODevice::ReadOnly))
|
||||
{
|
||||
@ -799,7 +842,7 @@ bool SQLiteHelper::get_software(QList<ButtonStruct>* buttons, ConfigResponse* co
|
||||
//<2F><EFBFBD><DEB8><EFBFBD>ɫ
|
||||
QDomDocument doc;
|
||||
doc.setContent(svg_buffer);
|
||||
SetSVGBackColor(doc.documentElement(), "path", "fill", config_response->basic.title_cover_color);
|
||||
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); // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
@ -811,7 +854,7 @@ bool SQLiteHelper::get_software(QList<ButtonStruct>* buttons, ConfigResponse* co
|
||||
delete render_image_cover;
|
||||
}else
|
||||
{
|
||||
icon = QApplication::applicationDirPath() + "/images/icon/default.svg";
|
||||
icon = QApplication::applicationDirPath() + DEFAULT_IMAGE;
|
||||
QFile file(icon);
|
||||
if (file.open(QIODevice::ReadOnly))
|
||||
{
|
||||
@ -826,7 +869,7 @@ bool SQLiteHelper::get_software(QList<ButtonStruct>* buttons, ConfigResponse* co
|
||||
//<2F><EFBFBD><DEB8><EFBFBD>ɫ
|
||||
QDomDocument doc;
|
||||
doc.setContent(svg_buffer);
|
||||
SetSVGBackColor(doc.documentElement(), "path", "fill", config_response->basic.title_cover_color);
|
||||
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); // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
@ -840,11 +883,12 @@ bool SQLiteHelper::get_software(QList<ButtonStruct>* buttons, ConfigResponse* co
|
||||
}
|
||||
button_struct.image = image;
|
||||
button_struct.image_cover = image_cover;
|
||||
button_struct.background_color = config_response->basic.backgroud_color;
|
||||
button_struct.text_color = QColor(config_response->basic.title_color);
|
||||
button_struct.text_cover_color = QColor(config_response->basic.title_cover_color);
|
||||
button_struct.background_color = background_color;
|
||||
button_struct.text_color = QColor(title_color);
|
||||
button_struct.text_cover_color = QColor(title_cover_color);
|
||||
*buttons << button_struct;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -915,4 +959,207 @@ bool SQLiteHelper::update_app()
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
bool SQLiteHelper::get_buttons(QList<ButtonStruct> &buttons)
|
||||
{
|
||||
QSqlQuery query(db);
|
||||
if(!query.exec("select * from kmd_menu where type='app_manage'and status=1 order by sort asc"))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
while(query.next())
|
||||
{
|
||||
ButtonStruct button_struct;
|
||||
button_struct.text = query.value("name").toString();
|
||||
button_struct.op= query.value("op").toString();
|
||||
button_struct.func = query.value("func").toString();
|
||||
button_struct.path = query.value("path").toString();
|
||||
button_struct.url = query.value("url").toString();
|
||||
button_struct.text_color = DEFAULT_TEXT_COLOR;
|
||||
button_struct.background_color = DEFAULT_COVER_COLOR;
|
||||
buttons << button_struct;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
bool SQLiteHelper::insert_software(QString name, QString orig_name, QString path, QString sort,bool *categories) {
|
||||
QSqlQuery query(db);
|
||||
QString categories_str="";
|
||||
for(int i=0;i<8;i++)
|
||||
{
|
||||
if(categories[i])
|
||||
{
|
||||
categories_str = categories_str + QString::number(i + 1) + ",";
|
||||
}
|
||||
}
|
||||
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 (?,?,?,?,?,?,?,?,?,?,?,?,?,?);";
|
||||
query.prepare(sql);
|
||||
query.addBindValue(sort.toInt());
|
||||
query.addBindValue("");
|
||||
query.addBindValue(false);
|
||||
query.addBindValue("app");
|
||||
query.addBindValue(categories_str);
|
||||
query.addBindValue(name);
|
||||
query.addBindValue(name);
|
||||
time_t create_time;
|
||||
time(&create_time);
|
||||
query.addBindValue(create_time);
|
||||
query.addBindValue("soft");
|
||||
query.addBindValue("");
|
||||
query.addBindValue(path);
|
||||
query.addBindValue("");
|
||||
query.addBindValue("");
|
||||
query.addBindValue(true);
|
||||
if(!query.exec())
|
||||
{
|
||||
//QMessageBox::critical(nullptr, QString::fromLocal8Bit("<22><><EFBFBD><EFBFBD>"), QString::fromLocal8Bit("д<><D0B4><EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD>ʧ<EFBFBD><CAA7>"));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SQLiteHelper::set_category(QList<Categrory>& categrories)
|
||||
{
|
||||
QSqlQuery work(db);
|
||||
work.exec("begin;");
|
||||
for(Categrory categrory:categrories)
|
||||
{
|
||||
QSqlQuery query(db);
|
||||
query.prepare("update kmd_category set name=:name,sort=:sort,status=:status where id=:id;");
|
||||
query.bindValue(":name", categrory.name);
|
||||
query.bindValue(":status", categrory.display);
|
||||
query.bindValue(":sort", categrory.sort);
|
||||
query.bindValue(":id", categrory.id);
|
||||
if (!query.exec())
|
||||
{
|
||||
qDebug() << query.lastError();
|
||||
work.exec("rollback;");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
QSqlQuery work2(db);
|
||||
work2.exec("commit;");
|
||||
qDebug() << work.lastError();
|
||||
return true;
|
||||
}
|
||||
bool SQLiteHelper::get_category(QList<Categrory>& categrories)
|
||||
{
|
||||
QSqlQuery query(db);
|
||||
if(!query.exec("select id,name,status,sort from kmd_category"))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
while(query.next())
|
||||
{
|
||||
if(query.value("name")==QString::fromLocal8Bit("ȫ<EFBFBD><EFBFBD>"))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
Categrory categrory;
|
||||
categrory.name = query.value("name").toString();
|
||||
categrory.id = query.value("id").toInt();
|
||||
categrory.sort = query.value("sort").toInt();
|
||||
categrory.display = query.value("status").toBool();
|
||||
categrories << categrory;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SQLiteHelper::get_all_software(QList<Record> &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;";
|
||||
}
|
||||
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;";
|
||||
}
|
||||
QSqlQuery query(db);
|
||||
if(!query.exec(sql))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
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();
|
||||
softwares << record;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SQLiteHelper::edit_software(QString name, QString orig_name, QString path, QString sort, bool* categories, QString type)
|
||||
{
|
||||
if (type.isEmpty())
|
||||
{
|
||||
QString sql = "update kmd_menu set name=:name,path=:path,sort=:sort,category_id=:categories where orig_name=:orig_name;";
|
||||
QSqlQuery query(db);
|
||||
query.prepare(sql);
|
||||
query.bindValue(":name", name);
|
||||
query.bindValue(":path", path);
|
||||
query.bindValue(":sort", sort.toInt());
|
||||
QString categories_str = "";
|
||||
for (int i = 0; i < 8; i++)
|
||||
{
|
||||
if (categories[i])
|
||||
{
|
||||
categories_str += QString::number(i + 1) + ",";
|
||||
}
|
||||
}
|
||||
query.bindValue(":categories", categories_str);
|
||||
query.bindValue(":orig_name", orig_name);
|
||||
if (!query.exec())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
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;";
|
||||
QSqlQuery query(db);
|
||||
query.prepare(sql);
|
||||
query.bindValue(":name", name);
|
||||
query.bindValue(":path", path);
|
||||
query.bindValue(":sort", sort.toInt());
|
||||
QString categories_str = "";
|
||||
for (int i = 0; i < 8; i++)
|
||||
{
|
||||
if (categories[i])
|
||||
{
|
||||
categories_str += QString::number(i + 1) + ",";
|
||||
}
|
||||
}
|
||||
query.bindValue(":type", type);
|
||||
query.bindValue(":categories", categories_str);
|
||||
query.bindValue(":orig_name", orig_name);
|
||||
if (!query.exec())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user