blob: 3d6a078caa0ec8afc3d792b31087aa11a018f027 (
plain)
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
|
#include "parse_file.h"
parse_file::parse_file()
{
}
QString parse_file::parse_user_data(QString option, QString split)
{
/*
* this function parses the userdata.dat file for info on the users steam account
*/
QFile file("userdata.dat");
if (file.open(QIODevice::ReadOnly))
{
QTextStream in(&file);
while (!in.atEnd())
{
QString line = in.readLine();
if (line.contains(option))
return line.split(split)[1].replace("\"", "").replace(",", "");
}
file.close();
}
return "null";
}
QString parse_file::parse_csgo_data(QString option)
{
/*
* this function parses csgodata.dat for stats
*/
QFile file("csgodata.dat");
if (file.open(QIODevice::ReadOnly))
{
QTextStream in(&file);
while (!in.atEnd())
{
QString line = in.readLine();
if (line.contains(option))
{
line = in.readLine();
return line.split(": ")[1];
}
}
file.close();
}
return "null";
}
void parse_file::parse_users()
{
/*
* This function populates our dropdown menu with users
*
* example users.dat file:
*
* daniel_j=76561198055087665
* ScruffyRules=76561198046533376
*
*/
usernames.clear();
userids.clear();
QFile inputFile("users.dat");
if (inputFile.open(QIODevice::ReadOnly))
{
QTextStream in(&inputFile);
while (!in.atEnd())
{
QString line = in.readLine();
if (line.contains("="))
{
usernames.append(line.split("=")[0]);
userids.append(line.split("=")[1]);
}
}
inputFile.close();
} else
{
qDebug() << "No users loaded.";
}
}
QStringList parse_file::get_usernames()
{
return usernames;
}
QStringList parse_file::get_ids()
{
return userids;
}
void parse_file::delete_user(QString user)
{
/* copy pasta, make pretty */
qDebug() << "deleting user" << user;
QFile f("users.dat");
if(f.open(QIODevice::ReadWrite | QIODevice::Text))
{
QString s;
QTextStream t(&f);
while(!t.atEnd())
{
QString line = t.readLine();
if(line != user)
s.append(line + "\n");
}
f.resize(0);
t << s;
f.close();
}
}
void parse_file::add_user(QString user)
{
qDebug() << "adding user" << user;
QFile file("users.dat");
if(!file.open(QIODevice::Append)) {
qDebug() << "Cannot open file to save";
} else
{
QTextStream stream(&file);
stream << user;
file.close();
}
}
|