From 0b6f9e4af8f1ab695a193fabdb32b6219223c455 Mon Sep 17 00:00:00 2001 From: daniel-Jones Date: Fri, 22 Jul 2016 11:43:37 +0930 Subject: Added parsing functions for both steam and csgo data, added testing displays on the UI etc --- csgo_stats.pro | 6 ++++-- parse_file.cpp | 49 ++++++++++++++++++++++++++++++++++++++++++ parse_file.h | 15 +++++++++++++ stats_display_window.cpp | 55 ++++++++++++++++++++++++++++++++---------------- stats_display_window.h | 12 +++++------ stats_display_window.ui | 28 ++++++++++++++++++------ 6 files changed, 132 insertions(+), 33 deletions(-) create mode 100644 parse_file.cpp create mode 100644 parse_file.h diff --git a/csgo_stats.pro b/csgo_stats.pro index ef1f61c..647e441 100644 --- a/csgo_stats.pro +++ b/csgo_stats.pro @@ -15,11 +15,13 @@ TEMPLATE = app SOURCES += main.cpp\ user_select_dialog.cpp \ file_download.cpp \ - stats_display_window.cpp + stats_display_window.cpp \ + parse_file.cpp HEADERS += user_select_dialog.h \ file_download.h \ - stats_display_window.h + stats_display_window.h \ + parse_file.h FORMS += user_select_dialog.ui \ stats_display_window.ui diff --git a/parse_file.cpp b/parse_file.cpp new file mode 100644 index 0000000..b939a7d --- /dev/null +++ b/parse_file.cpp @@ -0,0 +1,49 @@ +#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"; +} diff --git a/parse_file.h b/parse_file.h new file mode 100644 index 0000000..3ee8b0d --- /dev/null +++ b/parse_file.h @@ -0,0 +1,15 @@ +#ifndef PARSE_FILE_H +#define PARSE_FILE_H +#include +#include +#include + +class parse_file +{ +public: + parse_file(); + QString parse_user_data(QString option, QString split); + QString parse_csgo_data(QString option); +}; + +#endif // PARSE_FILE_H diff --git a/stats_display_window.cpp b/stats_display_window.cpp index 1dee284..24bbbec 100644 --- a/stats_display_window.cpp +++ b/stats_display_window.cpp @@ -6,7 +6,7 @@ stats_display_window::stats_display_window(QWidget *parent) : ui(new Ui::stats_display_window) { ui->setupUi(this); - connect(this, SIGNAL(window_loaded()), this, SLOT(test()), Qt::ConnectionType(Qt::QueuedConnection | Qt::UniqueConnection)); + connect(this, SIGNAL(window_loaded()), this, SLOT(window_open()), Qt::ConnectionType(Qt::QueuedConnection | Qt::UniqueConnection)); } stats_display_window::~stats_display_window() @@ -19,25 +19,18 @@ void stats_display_window::showEvent(QShowEvent *ev) emit window_loaded(); } -void stats_display_window::test() +void stats_display_window::window_open() { - QFile file("userdata.dat"); - if (file.open(QIODevice::ReadOnly)) - { - QTextStream in(&file); - while (!in.atEnd()) - { - QString line = in.readLine(); - if (line.contains("\"personaname\":")) - user.username = line.split(": ")[1].replace("\"", "").replace(",", ""); - if (line.contains("\"realname\":")) - user.realname = line.split(": ")[1].replace("\"", "").replace(",", ""); - if (line.contains("\"avatarfull\":")) - user.avatar_url = line.split(": ")[1].replace("\"", "").replace(",", ""); - } - file.close(); - } + /* + * this slot is called when our stats window is opened + * we will parse our steam account file and edit the UI accordingly + */ + user.username = parse.parse_user_data("\"personaname\":", ": "); + user.realname = parse.parse_user_data("\"realname\":", ": "); + user.avatar_url = parse.parse_user_data("\"avatarfull\":", ": "); + user.status = parse.parse_user_data("\"personastate\":", ": "); download.download_file(user.avatar_url, "avatar.jpg"); + /* now we have to deal with our user account details */ ui->username_label->setText(user.username); if (user.realname == NULL) ui->realname_label->setText("Realname not set"); @@ -46,4 +39,30 @@ void stats_display_window::test() QPixmap image("avatar.jpg"); ui->avatar_label->setPixmap(image); + /* user online status */ + switch(user.status.toInt()) + { + case 0: + ui->status_label->setText("Offline"); + break; + case 1: + ui->status_label->setText("Online"); + break; + case 2: + ui->status_label->setText("Busy"); + break; + case 3: + ui->status_label->setText("Away"); + break; + case 4: + ui->status_label->setText("Snooze"); + break; + default: + ui->status_label->setText("Unknown status"); + break; + } + user.time_ingame = parse.parse_csgo_data("total_time_played"); + QString time_in_game = "Hours in CS:GO: " + QString::number(user.time_ingame.toInt() / 3600); + ui->time_in_label->setText(time_in_game); + qDebug() << user.time_ingame.toInt(); } diff --git a/stats_display_window.h b/stats_display_window.h index 887c550..d73f6ca 100644 --- a/stats_display_window.h +++ b/stats_display_window.h @@ -3,11 +3,8 @@ #include #include -#include -#include -#include -#include #include "file_download.h" +#include "parse_file.h" namespace Ui { class stats_display_window; @@ -28,18 +25,21 @@ public: private: Ui::stats_display_window *ui; - struct user_info { + struct user_info { /* contains our user data for both steam and csgo */ QString username; QString realname; QString avatar_url; + QString status; + QString time_ingame; } user; file_download download; + parse_file parse; signals: void window_loaded(); private slots: - void test(); + void window_open(); }; #endif // STATS_DISPLAY_WINDOW_H diff --git a/stats_display_window.ui b/stats_display_window.ui index bf6d27e..ca16129 100644 --- a/stats_display_window.ui +++ b/stats_display_window.ui @@ -9,15 +9,22 @@ 0 0 - 740 - 479 + 104 + 112 CS:GO Statistics - - + + + + + status + + + + @@ -32,6 +39,13 @@ + + + + avatar + + + @@ -39,10 +53,10 @@ - - + + - avatar + Time in CS:GO -- cgit v1.2.3