-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpublic_func.cpp
More file actions
134 lines (112 loc) · 3.76 KB
/
public_func.cpp
File metadata and controls
134 lines (112 loc) · 3.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#include <public_func.h>
#include <QStandardPaths>
#include <QDir>
#include <QGuiApplication>
#include <QWindow>
#include <QRandomGenerator>
#include <QDebug>
namespace tool
{
bool isProcessRunning(const QString &processName)
{
QProcess process;
process.start("tasklist", QStringList() << "/FI" << QString("IMAGENAME eq %1").arg(processName));
process.waitForFinished();
QString output = process.readAllStandardOutput();
return output.contains(processName);
}
void startProgram(const QString &programPath)
{
QProcess::startDetached(programPath);
}
void activateRandomWindow()
{
QList<QWindow*> windows = QGuiApplication::allWindows();
if (windows.isEmpty()) return;
QList<QWindow*> visibleWindows;
for (QWindow* window : windows)
{
if (window->isVisible() && !(window->windowState() & Qt::WindowMinimized))
{
visibleWindows.append(window);
}
}
if (visibleWindows.isEmpty()) return;
QWindow* activeWindow = QGuiApplication::focusWindow();
if (activeWindow) {
visibleWindows.removeAll(activeWindow);
}
if (!visibleWindows.isEmpty())
{
int randomIndex = QRandomGenerator::global()->bounded(visibleWindows.size());
QWindow* randomWindow = visibleWindows.at(randomIndex);
randomWindow->show();
randomWindow->raise();
randomWindow->requestActivate();
}
}
std::string getAppCachePath()
{
try
{
// 获取应用数据目录(跨平台)
QString cacheDir = QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation);
if (cacheDir.isEmpty()) {
qWarning() << "Failed to get application data location";
return "";
}
QDir dir(cacheDir);
if (!dir.mkpath("2048Plan/FacingTheWholeWorld/Cache")) {
qWarning() << "Failed to create cache directory";
return "";
}
QString fullPath = dir.filePath("2048Plan/FacingTheWholeWorld/Cache");
// 转换为UTF-8编码的std::string
return fullPath.toStdString();
// 如果需要确保使用正斜杠(跨平台兼容)
// return QDir::toNativeSeparators(fullPath).toStdString();
}
catch (...)
{
qWarning() << "Exception occurred while getting cache path";
return "";
}
}
void xorEncryptDecrypt(char *data, size_t size)
{
if (ENCRYPTION_KEY.empty()) return;
const char* keyData = ENCRYPTION_KEY.data();
size_t keyLength = ENCRYPTION_KEY.size();
for (size_t i = 0; i < size; ++i)
{
data[i] ^= keyData[i % keyLength];
}
}
QString getAppCachePathQt()
{
QString cacheDir = QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation);
if (cacheDir.isEmpty())
{
return QString();
}
QDir dir(cacheDir);
if (!dir.mkpath("2048Plan/FacingTheWholeWorld/Cache"))
{
return QString();
}
return dir.filePath("2048Plan/FacingTheWholeWorld/Cache");
}
void xorEncryptDecrypt(QByteArray &data)
{
if (data.isEmpty()) return;
xorEncryptDecrypt(data.data(), static_cast<size_t>(data.size()));
}
void minimizeActiveWindow()
{
QWindow* activeWindow = QGuiApplication::focusWindow();
if (activeWindow)
{
activeWindow->showMinimized();
}
}
}// namespace tool