Skip to content

Commit

Permalink
Setup Qt for task tray icon
Browse files Browse the repository at this point in the history
  • Loading branch information
Latrolage committed Jun 16, 2022
1 parent 7efd6bd commit bd63fcb
Show file tree
Hide file tree
Showing 13 changed files with 1,669 additions and 143 deletions.
1,279 changes: 1,279 additions & 0 deletions Makefile

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions a.qrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<!DOCTYPE RCC><RCC version="1.0">
<qresource>
<file>systemTrayIcon.png</file>
</qresource>
</RCC>
179 changes: 84 additions & 95 deletions base64.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
//Taken from https://gist.github.com/tomykaira/f0fd86b6c73063283afe550bc5d77594
#ifndef _MACARON_BASE64_H_
#define _MACARON_BASE64_H_

/**
* The MIT License (MIT)
* Copyright (c) 2016 tomykaira
Expand All @@ -26,97 +23,89 @@
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

#include <string>

class Base64 {
public:

static std::string Encode(const std::string data) {
static constexpr char sEncodingTable[] = {
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X',
'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f',
'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
'w', 'x', 'y', 'z', '0', '1', '2', '3',
'4', '5', '6', '7', '8', '9', '+', '/'
};

size_t in_len = data.size();
size_t out_len = 4 * ((in_len + 2) / 3);
std::string ret(out_len, '\0');
size_t i;
char *p = const_cast<char*>(ret.c_str());

for (i = 0; i < in_len - 2; i += 3) {
*p++ = sEncodingTable[(data[i] >> 2) & 0x3F];
*p++ = sEncodingTable[((data[i] & 0x3) << 4) | ((int) (data[i + 1] & 0xF0) >> 4)];
*p++ = sEncodingTable[((data[i + 1] & 0xF) << 2) | ((int) (data[i + 2] & 0xC0) >> 6)];
*p++ = sEncodingTable[data[i + 2] & 0x3F];
}
if (i < in_len) {
*p++ = sEncodingTable[(data[i] >> 2) & 0x3F];
if (i == (in_len - 1)) {
*p++ = sEncodingTable[((data[i] & 0x3) << 4)];
*p++ = '=';
}
else {
*p++ = sEncodingTable[((data[i] & 0x3) << 4) | ((int) (data[i + 1] & 0xF0) >> 4)];
*p++ = sEncodingTable[((data[i + 1] & 0xF) << 2)];
}
*p++ = '=';
}

return ret;
#include "base64.h"

std::string Base64::Encode(const std::string data) {
static constexpr char sEncodingTable[] = {
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X',
'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f',
'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
'w', 'x', 'y', 'z', '0', '1', '2', '3',
'4', '5', '6', '7', '8', '9', '+', '/'
};

size_t in_len = data.size();
size_t out_len = 4 * ((in_len + 2) / 3);
std::string ret(out_len, '\0');
size_t i;
char *p = const_cast<char*>(ret.c_str());

for (i = 0; i < in_len - 2; i += 3) {
*p++ = sEncodingTable[(data[i] >> 2) & 0x3F];
*p++ = sEncodingTable[((data[i] & 0x3) << 4) | ((int) (data[i + 1] & 0xF0) >> 4)];
*p++ = sEncodingTable[((data[i + 1] & 0xF) << 2) | ((int) (data[i + 2] & 0xC0) >> 6)];
*p++ = sEncodingTable[data[i + 2] & 0x3F];
}
if (i < in_len) {
*p++ = sEncodingTable[(data[i] >> 2) & 0x3F];
if (i == (in_len - 1)) {
*p++ = sEncodingTable[((data[i] & 0x3) << 4)];
*p++ = '=';
}

static std::string Decode(const std::string& input, std::string& out) {
static constexpr unsigned char kDecodingTable[] = {
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 62, 64, 64, 64, 63,
52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 64, 64, 64, 64, 64, 64,
64, 0, 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, 64, 64, 64, 64, 64,
64, 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, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64
};

size_t in_len = input.size();
if (in_len % 4 != 0) return "Input data size is not a multiple of 4";

size_t out_len = in_len / 4 * 3;
if (input[in_len - 1] == '=') out_len--;
if (input[in_len - 2] == '=') out_len--;

out.resize(out_len);

for (size_t i = 0, j = 0; i < in_len;) {
uint32_t a = input[i] == '=' ? 0 & i++ : kDecodingTable[static_cast<int>(input[i++])];
uint32_t b = input[i] == '=' ? 0 & i++ : kDecodingTable[static_cast<int>(input[i++])];
uint32_t c = input[i] == '=' ? 0 & i++ : kDecodingTable[static_cast<int>(input[i++])];
uint32_t d = input[i] == '=' ? 0 & i++ : kDecodingTable[static_cast<int>(input[i++])];

uint32_t triple = (a << 3 * 6) + (b << 2 * 6) + (c << 1 * 6) + (d << 0 * 6);

if (j < out_len) out[j++] = (triple >> 2 * 8) & 0xFF;
if (j < out_len) out[j++] = (triple >> 1 * 8) & 0xFF;
if (j < out_len) out[j++] = (triple >> 0 * 8) & 0xFF;
}

return "";
else {
*p++ = sEncodingTable[((data[i] & 0x3) << 4) | ((int) (data[i + 1] & 0xF0) >> 4)];
*p++ = sEncodingTable[((data[i + 1] & 0xF) << 2)];
}

};


#endif /* _MACARON_BASE64_H_ */
*p++ = '=';
}

return ret;
}

std::string Base64::Decode(const std::string& input, std::string& out) {
static constexpr unsigned char kDecodingTable[] = {
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 62, 64, 64, 64, 63,
52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 64, 64, 64, 64, 64, 64,
64, 0, 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, 64, 64, 64, 64, 64,
64, 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, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64
};

size_t in_len = input.size();
if (in_len % 4 != 0) return "Input data size is not a multiple of 4";

size_t out_len = in_len / 4 * 3;
if (input[in_len - 1] == '=') out_len--;
if (input[in_len - 2] == '=') out_len--;

out.resize(out_len);

for (size_t i = 0, j = 0; i < in_len;) {
uint32_t a = input[i] == '=' ? 0 & i++ : kDecodingTable[static_cast<int>(input[i++])];
uint32_t b = input[i] == '=' ? 0 & i++ : kDecodingTable[static_cast<int>(input[i++])];
uint32_t c = input[i] == '=' ? 0 & i++ : kDecodingTable[static_cast<int>(input[i++])];
uint32_t d = input[i] == '=' ? 0 & i++ : kDecodingTable[static_cast<int>(input[i++])];

uint32_t triple = (a << 3 * 6) + (b << 2 * 6) + (c << 1 * 6) + (d << 0 * 6);

if (j < out_len) out[j++] = (triple >> 2 * 8) & 0xFF;
if (j < out_len) out[j++] = (triple >> 1 * 8) & 0xFF;
if (j < out_len) out[j++] = (triple >> 0 * 8) & 0xFF;
}

return "";
}
11 changes: 11 additions & 0 deletions base64.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#ifndef BASE64_H
#define BASE64_H
#pragma once
#include <iostream>
class Base64 {
public:
static std::string Encode(const std::string data);
static std::string Decode(const std::string& input, std::string& out);
};

#endif // BASE64_H
67 changes: 67 additions & 0 deletions generalcurling.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#ifndef curling
#define curling

#include <curl/curl.h>
#include <iostream>
#include <sstream>
#include <regex>
#include "generalcurling.h"
std::string chatmedata="", methodtype;
size_t write_callback(char *ptr, size_t size, size_t nmemb, void *userdata) {
if (methodtype == "GET") chatmedata = "";
if (methodtype == "PUT") return 0;
for (size_t i(0); i != nmemb; ++i) {
if (methodtype == "GET")
chatmedata += ptr[i];
else {
std::cout << ptr[i];
}
}
return 0;
}
void curlstuff(const std::string& port, const std::string& pass,const std::string location, const std::string method, std::string* postdata) {
methodtype = method;
//CURLcode ret; //unused
CURL* curl;
struct curl_slist *slist1;
slist1 = NULL;
slist1 = curl_slist_append(slist1, (static_cast<std::string>("Authorization: Basic ") + pass).c_str());
curl = curl_easy_init();
std::stringstream urlstring;
curl_easy_setopt(curl, CURLOPT_BUFFERSIZE, 102400L);
urlstring << "https://127.0.0.1:" << port << location;
curl_easy_setopt(curl, CURLOPT_URL, urlstring.str().c_str());
curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 1L);
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, slist1);
curl_easy_setopt(curl, CURLOPT_HTTP_VERSION, (long)CURL_HTTP_VERSION_2TLS);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
if (method == "GET") {
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "GET");
} else if (method == "PUT") {
if (chatmedata.find("offline") != std::string::npos) {
std::cout << "Skip fakeoffline, (already offline)\n";
return;
}
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "PUT");
slist1 = curl_slist_append(slist1, "Content-Type: application/json");
chatmedata = std::regex_replace(chatmedata, std::regex("(.*)\"availability\":\".*?\"(.*)"), "$01\"availability\":\"offline\"$02");
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, chatmedata.c_str());
// curl_easy_setopt(curl, CURLOPT_POSTFIELDS, chatmedata.c_str());
// curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE_LARGE, (curl_off_t)933);
}
else {
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "POST");
}
curl_easy_setopt(curl, CURLOPT_FTP_SKIP_PASV_IP, 1L);
curl_easy_setopt(curl, CURLOPT_TCP_KEEPALIVE, 1L);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_callback);
curl_easy_perform(curl);
curl_easy_cleanup(curl);
curl=NULL;
curl_slist_free_all(slist1);
slist1=NULL;
std::cout << std::endl;
}

#endif
8 changes: 8 additions & 0 deletions generalcurling.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#ifndef GENERALCURLING_H
#define GENERALCURLING_H
#include <string>
#include <QtCore/QDebug>

size_t write_callback(char *ptr, size_t size, size_t nmemb, void *userdata);
void curlstuff(const std::string& port, const std::string& pass,const std::string location, const std::string method, std::string* postdata = nullptr);
#endif // GENERALCURLING_H
80 changes: 32 additions & 48 deletions leaguefiles.cpp
Original file line number Diff line number Diff line change
@@ -1,59 +1,54 @@
#ifndef leaguefiles
#define leaguefiles
#include "leaguefiles.h"
#include <sqlite3.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <thread>
#include <chrono>

class leagueDBfind {
std::string installlocation, XDG_DATA_HOME, databaselocation, lockfile="0";
sqlite3 *database;
public:
leagueDBfind() { // constructor tries to find the location of the lutris database with the XDG_DATA_HOME environmental variable. If it doesn't, it gets set to ~/.local/share/lutris/pga.db
char* env = std::getenv("XDG_DATA_HOME");
XDG_DATA_HOME = env ? env : "";
leagueDBfind::leagueDBfind() : lockfile("0"),portnum("0"),password("0") { // constructor tries to find the location of the lutris database with the XDG_DATA_HOME environmental variable. If it doesn't, it gets set to ~/.local/share/lutris/pga.db
char* env = std::getenv("XDG_DATA_HOME");
XDG_DATA_HOME = env ? env : "";

databaselocation = XDG_DATA_HOME.empty() ? "" : XDG_DATA_HOME+"/lutris/pga.db";
if (XDG_DATA_HOME.empty()) {
std::cout << "Environmental var: XDG_DATA_HOME doesn't exist. defaulting to ~/.local/share\n";
XDG_DATA_HOME=static_cast<std::string>(std::getenv("HOME"))+"/.local/share";
databaselocation = XDG_DATA_HOME + "/lutris/pga.db";
}
//std::cout << "Using databaselocation: " << databaselocation << std::endl;;
}
int open() { //give sqlite3 object the location of the lutris database
return sqlite3_open(databaselocation.c_str(), &database);
}
static int callback(void *currentDB, int a, char **res, char **azColName) { //gets called by getinstalllocation.
static_cast<leagueDBfind *>(currentDB)->installlocation = *res;
static_cast<leagueDBfind *>(currentDB)->lockfile = static_cast<leagueDBfind *>(currentDB)->installlocation+"/drive_c/Riot Games/League of Legends/lockfile";
return 0;
if (XDG_DATA_HOME.empty()) {
std::cout << "Environmental var: XDG_DATA_HOME doesn't exist. defaulting to ~/.local/share\n";
XDG_DATA_HOME=static_cast<std::string>(std::getenv("HOME"))+"/.local/share";
}
int getinstalllocation() { // run sql command to find the location league of legends lockfile
return sqlite3_exec(database, "SELECT \"directory\" FROM \"main\".\"games\" WHERE \"slug\" LIKE 'league-of-legends'", callback, this, NULL);
}
const std::string& getlocklocation() { return lockfile; }
};
databaselocation = XDG_DATA_HOME+"/lutris/pga.db";
}
int leagueDBfind::open() { //give sqlite3 object the location of the lutris database
return sqlite3_open(databaselocation.c_str(), &database);
}
int leagueDBfind::callback(void *currentDB, int a, char **res, char **azColName) { //gets called by getinstalllocation.
static_cast<leagueDBfind *>(currentDB)->installlocation = *res;
static_cast<leagueDBfind *>(currentDB)->lockfile = static_cast<leagueDBfind *>(currentDB)->installlocation+"/drive_c/Riot Games/League of Legends/lockfile";
return 0;
}
int leagueDBfind::getinstalllocation() { // run sql command to find the location league of legends lockfile
return sqlite3_exec(database, "SELECT \"directory\" FROM \"main\".\"games\" WHERE \"slug\" LIKE 'league-of-legends'", callback, this, NULL); //callback function does not get called when using databaselocation.c_str()
}
const std::string& leagueDBfind::getlocklocation() { return lockfile; }
const std::string& leagueDBfind::getdatabaselocation() { return databaselocation; }
const std::string& leagueDBfind::thepassword() { return password; }
const std::string& leagueDBfind::theportnum() { return portnum; }
void leagueDBfind::setpassword(const std::string& pw) { password=pw; }
void leagueDBfind::setportnum(const std::string& port) { portnum=port; }


std::ifstream getfile() { //Get credentials from lockfile
std::ifstream getfile(leagueDBfind& database) { //Get credentials from lockfile
#ifdef _WIN32 // i haven't tried this program with windows at all. I wanted to but I don't know how to cross compile for windows
std::ifstream lockfile("C:\\Riot Games\\League of Legends\\lockfile");
#else
static leagueDBfind database;
std::ifstream lockfile;
if (database.getlocklocation() != "0" && lockfile.is_open()) { //if the lockfile is already set to something, then it doesn't need to be found again
//i think this whole getfile() function looks weird but i don't know how to make it better
if (database.getlocklocation() != "0") { //if the lockfile is already set to something, then it doesn't need to be found again
lockfile.clear(std::ifstream::eofbit);
return std::ifstream(database.getlocklocation());
}
int errcode = database.open();
//if the database wasn't opened properly
if (errcode) std::cerr << "couldn't open database to find league of legends install location";
database.getinstalllocation();
if (errcode) std::cerr << "couldn't open database to find league of legends install location\n"; //if the database wasn't opened properly
errcode = database.getinstalllocation();
if (errcode) std::cerr << "couldn't find install location errorcode: " << errcode << '\n';
lockfile.open(database.getlocklocation());
std::cout << "lockfile location: " << database.getlocklocation() << std::endl;
#endif
while (!lockfile.is_open()) { // if it didn't get anything, something went wrong. Retry until process is killed
std::cout << "League isn't open yet or something else went wrong. Retrying..." << std::endl;
Expand Down Expand Up @@ -86,14 +81,3 @@ std::vector<std::string> getdata(std::ifstream &lockfile) {
svec.push_back(std::string(pass));
return svec;
}

/*int main() {
leagueDBfind database;
int code = database.open();
if (code) {
std::cerr << "couldn't open database to find league of legends install location";
return 1;
}
code = database.getinstalllocation();
}*/
#endif
Loading

0 comments on commit bd63fcb

Please sign in to comment.