-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsysteminformation.cpp
More file actions
100 lines (89 loc) · 3.43 KB
/
Copy pathsysteminformation.cpp
File metadata and controls
100 lines (89 loc) · 3.43 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
#include "systeminformation.h"
SystemInfoDialog::SystemInfoDialog(wxWindow* parent, const ClientInfo& info)
: wxDialog(parent, wxID_ANY, "System Information - " + info.clientName,
wxDefaultPosition, wxSize(430, 380),
wxDEFAULT_DIALOG_STYLE | wxMINIMIZE_BOX)
{
wxBoxSizer* mainSizer = new wxBoxSizer(wxVERTICAL);
wxFlexGridSizer* grid = new wxFlexGridSizer(2, 5, 12);
grid->AddGrowableCol(1);
auto AddField = [&](const wxString& label, const wxString& value)
{
grid->Add(new wxStaticText(this, wxID_ANY, label + ":"),
0, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL);
wxStaticText* val = new wxStaticText(this, wxID_ANY, value,
wxDefaultPosition, wxDefaultSize, wxST_ELLIPSIZE_END);
val->SetFont(wxFont(8, wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_BOLD));
val->SetForegroundColour(wxColour(0, 0, 160));
grid->Add(val, 0, wxALIGN_LEFT | wxEXPAND);
m_fields[label] = val;
};
AddField("Hostname", info.clientName);
AddField("IP Address", info.ipAddress);
AddField("Country", info.country);
AddField("Username", info.username);
AddField("Operating System", info.osVersion);
AddField("Antivirus", info.antiVirus);
AddField("CPU", "Loading...");
AddField("RAM", "Loading...");
AddField("Disk (C:)", "Loading...");
AddField("GPU", "Loading...");
AddField("MAC Address", "Loading...");
mainSizer->Add(grid, 1, wxEXPAND | wxALL, 15);
mainSizer->Add(new wxButton(this, wxID_OK, "Close"),
0, wxALIGN_CENTER | wxBOTTOM, 10);
SetSizer(mainSizer);
m_timer.SetOwner(this);
Bind(wxEVT_TIMER, &SystemInfoDialog::OnTimer, this);
m_timer.Start(500);
}
void SystemInfoDialog::SetHwid(const wxString& hwid) { m_hwid = hwid; }
void SystemInfoDialog::SetClientId(int id) { m_clientId = id; }
void SystemInfoDialog::OnTimer(wxTimerEvent&)
{
m_checks++;
if (!m_hwid.empty())
{
std::string resp = ServerManager::GetSysInfoResponse(m_hwid);
if (!resp.empty())
{
m_timer.Stop();
SetField("CPU", Extract(resp, "cpu"));
SetField("RAM", Extract(resp, "ram"));
SetField("Disk (C:)", Extract(resp, "disk"));
SetField("GPU", Extract(resp, "gpu"));
SetField("MAC Address", Extract(resp, "mac"));
return;
}
}
if (m_checks > 20)
{
m_timer.Stop();
for (auto& kv : m_fields)
if (kv.second->GetLabel() == "Loading...")
kv.second->SetLabel("No response");
}
}
void SystemInfoDialog::SetField(const wxString& label, const std::string& value)
{
auto it = m_fields.find(label);
if (it != m_fields.end())
it->second->SetLabel(value.empty() ? "N/A" : wxString::FromUTF8(value));
}
std::string SystemInfoDialog::Extract(const std::string& json, const std::string& key)
{
std::string s = "\"" + key + "\":\"";
size_t p = json.find(s);
if (p == std::string::npos) return "";
p += s.length();
size_t e = json.find("\"", p);
if (e == std::string::npos) return "";
std::string v = json.substr(p, e - p);
std::string r;
for (size_t i = 0; i < v.size(); i++)
{
if (v[i] == '\\' && i + 1 < v.size()) { i++; r += v[i]; }
else r += v[i];
}
return r;
}