Skip to content

Commit

Permalink
Fix for case where client logged out and logged back in.
Browse files Browse the repository at this point in the history
  • Loading branch information
Latrolage committed Jun 2, 2022
1 parent abdcec3 commit 2078e93
Showing 1 changed file with 18 additions and 17 deletions.
35 changes: 18 additions & 17 deletions leaguefiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
#include <thread>
#include <chrono>

struct leagueDBfind {
std::string installlocation, XDG_DATA_HOME, databaselocation, lockfile="0";
sqlite3 *database;

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 : "";
Expand All @@ -27,37 +27,38 @@ struct leagueDBfind {
return sqlite3_open(databaselocation.c_str(), &database);
}
static int callback(void *currentDB, int a, char **res, char **azColName) { //gets called by getinstalllocation.
//std::cout << *res << std::endl;
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 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; }
};

std::ifstream getfile() { //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;
if (database.lockfile != "0") { //if the lockfile is already set to something, then it doesn't need to be found again not sure what's a better way of doing this
// std::cout << database.lockfile << '\n';
return std::ifstream(database.lockfile);
}
int code = database.open();
if (code) { //if the database wasn't opened properly
std::cerr << "couldn't open database to find league of legends install location";
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
lockfile.clear(std::ifstream::eofbit);
return std::ifstream(database.getlocklocation());
}
code = database.getinstalllocation();
std::ifstream lockfile(database.lockfile);
std::cout << "lockfile location: " << database.lockfile << std::endl;
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();
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;
lockfile.open(database.lockfile);
lockfile.clear(std::ifstream::eofbit);
lockfile.open(database.getlocklocation());
std::this_thread::sleep_for(std::chrono::seconds(2));
}
return lockfile;
Expand Down

0 comments on commit 2078e93

Please sign in to comment.