This repository has been archived by the owner on Feb 19, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathgameinfo.cpp
69 lines (59 loc) · 1.75 KB
/
gameinfo.cpp
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
#include "gameinfo.h"
#include <QProcess>
#include <QFile>
#include <QFileInfo>
const QString ExecutablePath = "ExecutablePath";
static bool isFileExist(QString filePath)
{
return QFileInfo(filePath).isFile();
}
GameInfo::GameInfo()
{
}
QString GameInfo::getGamePath()
{
QStringList pathList;
QProcess process;
process.start("wmic process where name='LeagueClient.exe' GET ExecutablePath");
process.waitForFinished(-1);
QString result = QString::fromLocal8Bit(process.readAllStandardOutput());
if (result.left(ExecutablePath.length()) == ExecutablePath) {
pathList = result.split("\n");
for (int i = 0; i < pathList.size(); i++) {
QString string = pathList.at(i);
if (string.isEmpty() || string == "\r\r" || string == "")
pathList.removeAt(i);
}
pathList.removeFirst();
pathList.removeLast();
QString path = pathList.first();
path = path.trimmed();
path = path.simplified();
path.remove("LeagueClient.exe");
return path;
}
return "";
}
GameInfo::LockFile GameInfo::getLockFile(const QString &gamePath)
{
LockFile lockFile = { "", "" };
QString filePath = gamePath + "/lockfile";
if (!isFileExist(filePath))
return lockFile;
QFile loadFile(filePath);
if (!loadFile.open(QIODevice::ReadOnly))
return lockFile;
QString allData = loadFile.readAll();
loadFile.close();
QString pattern("(.*):(.*):(.*):(.*):(.*)");
QRegExp rx(pattern);
if (rx.exactMatch(allData)) {
//name = rx.cap(1);
//uid = rx.cap(2);
lockFile.port = rx.cap(3);
lockFile.token = rx.cap(4);
//protocol = rx.cap(5);
return lockFile;
}
return lockFile;
}