|
|
@@ -1,4 +1,6 @@
|
|
|
#include "processthread.h"
|
|
|
+#include <QProcess>
|
|
|
+#include <QTemporaryFile>
|
|
|
#include "api/configapi.h"
|
|
|
#include "appevent.h"
|
|
|
#include "processmodel.h"
|
|
|
@@ -64,6 +66,7 @@ void ProcessThread::sendExitTime(qint64 updataTime)
|
|
|
|
|
|
// 获取过滤名单
|
|
|
QSet<QString> filter;
|
|
|
+ QSet<QString> gameFilter;
|
|
|
for (const QJsonValue &item : serverArray) {
|
|
|
if (!item.isObject()) {
|
|
|
return;
|
|
|
@@ -75,6 +78,12 @@ void ProcessThread::sendExitTime(qint64 updataTime)
|
|
|
filter.insert(name);
|
|
|
}
|
|
|
}
|
|
|
+ if (object.contains("pid_type")) {
|
|
|
+ const QString type = object["pid_type"].toString();
|
|
|
+ if (type == "游戏" || type == "game") {
|
|
|
+ gameFilter.insert(name);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
ProcessModel processModel{storage};
|
|
|
@@ -124,9 +133,12 @@ void ProcessThread::sendExitTime(qint64 updataTime)
|
|
|
QJsonArray jsonArray = qry.toJson();
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ // 获取配置
|
|
|
QVariant messageBoxPointX = QVariant();
|
|
|
QVariant messageBoxPointY = QVariant();
|
|
|
QVariant messageText = QVariant("");
|
|
|
+ QVariant gameMessageText = QVariant("");
|
|
|
QVariant messageTitle = QVariant(Tr::tr("Tips"));
|
|
|
{
|
|
|
TC::ConfigApi configApi("messageBoxPointX");
|
|
|
@@ -156,7 +168,15 @@ void ProcessThread::sendExitTime(qint64 updataTime)
|
|
|
messageTitle = value.value();
|
|
|
}
|
|
|
}
|
|
|
+ {
|
|
|
+ TC::ConfigApi configApi("gameMessageText");
|
|
|
+ std::optional<QVariant> value = configApi.get();
|
|
|
+ if (value.has_value()) {
|
|
|
+ gameMessageText = value.value();
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
+ // 获取服务器 对应的时间信息
|
|
|
for (const QJsonValue &item : serverArray) {
|
|
|
if (!item.isObject()) {
|
|
|
return;
|
|
|
@@ -165,102 +185,134 @@ void ProcessThread::sendExitTime(qint64 updataTime)
|
|
|
|
|
|
const QString name = object["name"].toString();
|
|
|
const QString zhName = object["chinese_name"].toString();
|
|
|
- if (object.contains("is_prompt")) {
|
|
|
+ const QString type = object["pid_type"].toString();
|
|
|
+ // 2 提示 1 不提示 0 未知
|
|
|
+ if (object.contains("is_prompt")) { // 提示
|
|
|
if (object["is_prompt"].toInt() == 2) {
|
|
|
- const QString name = object["name"].toString();
|
|
|
- const QString zhName = object["chinese_name"].toString();
|
|
|
- const int time = object["prompt_time"].toInt();
|
|
|
- if (time > 0) {
|
|
|
- const QString whereTime = QString("(updataTime - lastAlertTime) > %1").arg(time);
|
|
|
- const QString whereProcessName = QString("processName = '%1'").arg(name);
|
|
|
- const QString whereUpdataTime = QString("updataTime = '%1'").arg(updataTime);
|
|
|
- CWF::SqlQueryManager qry(storage);
|
|
|
- qry.select("*", processModel.getTableName())
|
|
|
- .where(QString("%1 AND %2 AND %3")
|
|
|
- .arg(whereTime)
|
|
|
- .arg(whereProcessName)
|
|
|
- .arg(whereUpdataTime));
|
|
|
- qry.prepare();
|
|
|
- QJsonObject jsonObject = qry.exec();
|
|
|
- QJsonArray jsonArray = qry.toJson();
|
|
|
- qDebug() << jsonArray;
|
|
|
- for (const auto &value : jsonArray) {
|
|
|
- const QJsonObject object = value.toObject();
|
|
|
- const QString processName = object["processName"].toString();
|
|
|
- const qint64 runTime = object["exitTime"].toVariant().toLongLong()
|
|
|
- - object["creationTime"].toVariant().toLongLong();
|
|
|
-
|
|
|
- const QString text = QString(
|
|
|
- tr("Program %1 has been used for %2 minutes%3")
|
|
|
- .arg(zhName)
|
|
|
- .arg(convertSecondsToMinutesTimeFormat(runTime))
|
|
|
- .arg(messageText.toString()));
|
|
|
- emit messageBox(text, messageBoxPointX, messageBoxPointY, messageTitle);
|
|
|
-
|
|
|
- // 更新 lastAlertTime
|
|
|
- ProcessModel processModel{storage};
|
|
|
- processModel.buildFromJson(object);
|
|
|
- // 更新 消息时间
|
|
|
- processModel.setLastAlertTime(updataTime);
|
|
|
- processModel.save();
|
|
|
+ if (type == "游戏" || type == "game") {
|
|
|
+ } else {
|
|
|
+ // const QString name = object["name"].toString();
|
|
|
+ // const QString zhName = object["chinese_name"].toString();
|
|
|
+ const int time = object["prompt_time"].toInt();
|
|
|
+ if (time > 0) {
|
|
|
+ const QString whereTime = QString("(updataTime - lastAlertTime) > %1")
|
|
|
+ .arg(time);
|
|
|
+ const QString whereProcessName = QString("processName = '%1'").arg(name);
|
|
|
+ const QString whereUpdataTime = QString("updataTime = '%1'").arg(updataTime);
|
|
|
+ CWF::SqlQueryManager qry(storage);
|
|
|
+ qry.select("*", processModel.getTableName())
|
|
|
+ .where(QString("%1 AND %2 AND %3")
|
|
|
+ .arg(whereTime)
|
|
|
+ .arg(whereProcessName)
|
|
|
+ .arg(whereUpdataTime));
|
|
|
+ qry.prepare();
|
|
|
+ QJsonObject jsonObject = qry.exec();
|
|
|
+ QJsonArray jsonArray = qry.toJson();
|
|
|
+ qDebug() << jsonArray;
|
|
|
+ for (const auto &value : jsonArray) {
|
|
|
+ const QJsonObject object = value.toObject();
|
|
|
+ const QString processName = object["processName"].toString();
|
|
|
+ const qint64 runTime = object["exitTime"].toVariant().toLongLong()
|
|
|
+ - object["creationTime"].toVariant().toLongLong();
|
|
|
+
|
|
|
+ const QString text = QString(
|
|
|
+ tr("Program %1 has been used for %2 minutes%3")
|
|
|
+ .arg(zhName)
|
|
|
+ .arg(convertSecondsToMinutesTimeFormat(runTime))
|
|
|
+ .arg(messageText.toString()));
|
|
|
+ emit messageBox(text, messageBoxPointX, messageBoxPointY, messageTitle);
|
|
|
+
|
|
|
+ // 更新 lastAlertTime
|
|
|
+ ProcessModel processModel{storage};
|
|
|
+ processModel.buildFromJson(object);
|
|
|
+ // 更新 消息时间
|
|
|
+ processModel.setLastAlertTime(updataTime);
|
|
|
+ processModel.save();
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- // for (const QJsonValue &item : array) {
|
|
|
- // if (item.isObject()) {
|
|
|
- // const QJsonObject object = item.toObject();
|
|
|
-
|
|
|
- // const QString name = object["name"].toString();
|
|
|
- // const QString zhName = object["chinese_name"].toString();
|
|
|
- // if (object.contains("is_prompt")) {
|
|
|
- // if (object["is_prompt"].toInt() == 2) {
|
|
|
- // messageProcessName[name] = zhName;
|
|
|
- // };
|
|
|
- // }
|
|
|
- // }
|
|
|
- // }
|
|
|
- // qDebug() << messageProcessName;
|
|
|
- // // SELECT * FROM ProcessTime WHERE (updataTime - lastAlertTime) > 1565;
|
|
|
- // if (time > 0) {
|
|
|
- // const QString whereTime = QString("(updataTime - lastAlertTime) > %1").arg(time);
|
|
|
- // const QString whereProcessName = QString("processName = '%1'").arg("WeChat.exe");
|
|
|
- // CWF::SqlQueryManager qry(storage);
|
|
|
- // qry.select("*", processModel.getTableName()).where(whereTime);
|
|
|
- // qry.prepare();
|
|
|
- // QJsonObject jsonObject = qry.exec();
|
|
|
- // QJsonArray jsonArray = qry.toJson();
|
|
|
-
|
|
|
- // const QStringList keys = messageProcessName.keys();
|
|
|
-
|
|
|
- // for (const auto &value : jsonArray) {
|
|
|
- // // SLDWORKS.exe
|
|
|
-
|
|
|
- // const QJsonObject object = value.toObject();
|
|
|
- // const QString processName = object["processName"].toString();
|
|
|
- // const qint64 runTime = object["exitTime"].toVariant().toLongLong()
|
|
|
- // - object["creationTime"].toVariant().toLongLong();
|
|
|
-
|
|
|
- // for (const QString &key : keys) {
|
|
|
- // if (processName.compare(key, Qt::CaseSensitivity::CaseInsensitive) == 0) {
|
|
|
- // const QString text = QString(tr("Program %1 has been used for %2 minutes%3")
|
|
|
- // .arg(messageProcessName[key])
|
|
|
- // .arg(convertSecondsToMinutesTimeFormat(runTime))
|
|
|
- // .arg(messageText.toString()));
|
|
|
- // emit messageBox(text, messageBoxPointX, messageBoxPointY, messageTitle);
|
|
|
- // }
|
|
|
- // }
|
|
|
-
|
|
|
- // // 更新 lastAlertTime
|
|
|
- // ProcessModel processModel{storage};
|
|
|
- // processModel.buildFromJson(object);
|
|
|
- // // 更新 消息时间
|
|
|
- // processModel.setLastAlertTime(updataTime);
|
|
|
- // processModel.save();
|
|
|
- // }
|
|
|
- // }
|
|
|
+ if (object.contains("pid_type")) {
|
|
|
+ if (type == "游戏" || type == "game") {
|
|
|
+ const QString whereTime = QString("(updataTime - lastAlertTime) > %1").arg(1);
|
|
|
+ const QString whereProcessName = QString("processName = '%1'").arg(name);
|
|
|
+ const QString whereUpdataTime = QString("updataTime = '%1'").arg(updataTime);
|
|
|
+ CWF::SqlQueryManager qry(storage);
|
|
|
+ qry.select("*", processModel.getTableName())
|
|
|
+ .where(QString("%1 AND %2 AND %3")
|
|
|
+ .arg(whereTime)
|
|
|
+ .arg(whereProcessName)
|
|
|
+ .arg(whereUpdataTime));
|
|
|
+ qry.prepare();
|
|
|
+ QJsonObject jsonObject = qry.exec();
|
|
|
+ QJsonArray jsonArray = qry.toJson();
|
|
|
+
|
|
|
+ for (const auto &value : jsonArray) {
|
|
|
+ const QJsonObject object = value.toObject();
|
|
|
+ const QString processName = object["processName"].toString();
|
|
|
+ const qint64 runTime = object["exitTime"].toVariant().toLongLong()
|
|
|
+ - object["creationTime"].toVariant().toLongLong();
|
|
|
+
|
|
|
+ const QString text = QString(tr("Program %1 has been used for %2 minutes%3")
|
|
|
+ .arg(zhName)
|
|
|
+ .arg(convertSecondsToMinutesTimeFormat(runTime))
|
|
|
+ .arg(messageText.toString()));
|
|
|
+
|
|
|
+ qDebug() << "玩游戏?" << text;
|
|
|
+
|
|
|
+ QTemporaryFile tempFile("tempfile_XXXXXX.png");
|
|
|
+ tempFile.setAutoRemove(true);
|
|
|
+ tempFile.open();
|
|
|
+ AppEvent::captureDesktop(&tempFile, "PNG");
|
|
|
+
|
|
|
+ // qDebug() << "发送截图" << tempFile.fileName();
|
|
|
+ TC::ProcessImageApi processImageApi;
|
|
|
+ qDebug() << "发送截图" << processImageApi.post({tempFile.fileName()});
|
|
|
+ tempFile.close();
|
|
|
+ qDebug() << "发送截图" << tempFile.remove() << tempFile.errorString();
|
|
|
+ // if (object.contains("is_prompt")) { // 提示
|
|
|
+ // if (object["is_prompt"].toInt() == 2) {
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ const QString message = gameMessageText.toString().isEmpty()
|
|
|
+ ? text
|
|
|
+ : gameMessageText.toString();
|
|
|
+
|
|
|
+ emit messageBox(message, messageBoxPointX, messageBoxPointY, messageTitle);
|
|
|
+
|
|
|
+ QProcess p;
|
|
|
+ p.startDetached("taskkill", {"/im", name, "/f"});
|
|
|
+ p.waitForFinished(3000);
|
|
|
+ p.close();
|
|
|
+ // 更新 lastAlertTime
|
|
|
+ ProcessModel processModel{storage};
|
|
|
+ processModel.buildFromJson(object);
|
|
|
+ // 更新 消息时间
|
|
|
+ processModel.setLastAlertTime(updataTime);
|
|
|
+ processModel.save();
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取游戏 截图 并关闭进程
|
|
|
+ // QTemporaryFile tempFile("tempfile_XXXXXX.png");
|
|
|
+ // tempFile.setAutoRemove(true);
|
|
|
+ // tempFile.open();
|
|
|
+ // AppEvent::captureDesktop(&tempFile, "PNG");
|
|
|
+
|
|
|
+ // qDebug() << "发送截图" << tempFile.fileName();
|
|
|
+ // TC::ProcessImageApi processImageApi;
|
|
|
+ // qDebug() << "发送截图" << processImageApi.post({tempFile.fileName()});
|
|
|
+
|
|
|
+ // tempFile.close();
|
|
|
+ // qDebug() << "发送截图" << tempFile.remove() << tempFile.errorString();
|
|
|
+ // if (object.contains("is_prompt")) { // 提示
|
|
|
+ // if (object["is_prompt"].toInt() == 2) {
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
bool ProcessThread::upDataProcessSql()
|
|
|
@@ -309,71 +361,9 @@ bool ProcessThread::upDataProcessSql()
|
|
|
processModel.save();
|
|
|
}
|
|
|
}
|
|
|
- // qDebug().noquote().nospace() << jsonObject << qry.toJson();
|
|
|
-
|
|
|
- // jsonObject.insert("begin_time", object["creationTime"]);
|
|
|
- // jsonObject.insert("end_time", object["exitTime"]);
|
|
|
- // jsonObject.insert("last_check_time", object["updataTime"]);
|
|
|
- // jsonObject.insert("status", 1);
|
|
|
- // jsonObject.insert("notes", "");
|
|
|
- // FILETIME ft = timeProcess->creationTime;
|
|
|
- // FILETIME currentTime;
|
|
|
- // GetSystemTimeAsFileTime(¤tTime);
|
|
|
-
|
|
|
- // ULARGE_INTEGER creation, current;
|
|
|
- // creation.LowPart = ft.dwLowDateTime;
|
|
|
- // creation.HighPart = ft.dwHighDateTime;
|
|
|
- // current.LowPart = currentTime.dwLowDateTime;
|
|
|
- // current.HighPart = currentTime.dwHighDateTime;
|
|
|
-
|
|
|
- // ULONGLONG elapsedSeconds = (current.QuadPart - creation.QuadPart) / 10000000;
|
|
|
-
|
|
|
- // // 计算天、小时、分钟和秒
|
|
|
- // ULONGLONG days = elapsedSeconds / 86400; // 1天 = 86400秒
|
|
|
- // ULONGLONG hours = (elapsedSeconds % 86400) / 3600; // 1小时 = 3600秒
|
|
|
- // ULONGLONG minutes = (elapsedSeconds % 3600) / 60; // 1分钟 = 60秒
|
|
|
- // ULONGLONG seconds = elapsedSeconds % 60; // 剩余秒数
|
|
|
-
|
|
|
- // // 打印进程的运行时间
|
|
|
- // qDebug() << QString::fromStdString(timeProcess->processName) //
|
|
|
- // << days << hours << minutes << seconds << timestamp;
|
|
|
-
|
|
|
- /*
|
|
|
-INSERT OR REPLACE INTO ProcessTime (pid, processName, creationTime, exitTime)
|
|
|
-VALUES
|
|
|
- (123, 'process1', strftime('%s', 'now'), strftime('%s', 'now')),
|
|
|
- (124, 'process2', strftime('%s', 'now'), strftime('%s', 'now')),
|
|
|
- (125, 'process3', strftime('%s', 'now'), strftime('%s', 'now'));
|
|
|
-*/
|
|
|
- // sqlValues.append(QString("(%1,'%2',%3,%4,%5)")
|
|
|
- // .arg(timeProcess->pid) // pid
|
|
|
- // .arg(timeProcess->processName.c_str()) // 进程名
|
|
|
- // .arg(timestamp) // 开始时间戳
|
|
|
- // .arg(exitTimestamp) // 结束时间戳
|
|
|
- // .arg(updataTimestamp)); // 数据更新时间
|
|
|
}
|
|
|
-
|
|
|
- // const QString query = QString(
|
|
|
- // R"(INSERT OR REPLACE INTO ProcessTime
|
|
|
- // (pid, processName, creationTime, exitTime, updataTime)
|
|
|
- // VALUES
|
|
|
- // %1)")
|
|
|
- // .arg(sqlValues.join(","));
|
|
|
-
|
|
|
- // // 使用上述插入或者替换
|
|
|
- // // 首先查找
|
|
|
- // QString where;
|
|
|
- // CWF::SqlQueryManager qry(storage);
|
|
|
- // QJsonObject jsonObject = qry.exec(query);
|
|
|
-
|
|
|
// 发送更新后的数据
|
|
|
sendExitTime(updataTimestamp);
|
|
|
-
|
|
|
- // if (jsonObject.contains("success")) {
|
|
|
- // if (jsonObject["success"].toBool()) {
|
|
|
- // return true;
|
|
|
- // }
|
|
|
- // }
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
@@ -401,7 +391,7 @@ void ProcessThread::run()
|
|
|
|
|
|
while (true) {
|
|
|
// 校验网络
|
|
|
- if (timer.elapsed() >= 30 * 1000) { // 检查是否经过1分钟
|
|
|
+ if (timer.elapsed() >= 10 * 1000) { // 检查是否经过1分钟
|
|
|
timer.restart(); // 重新启动计时器
|
|
|
|
|
|
upDataProcessSql();
|