From 2078e93bf3b26f56d8249cab5b280825f227783c Mon Sep 17 00:00:00 2001 From: Latrolage Date: Thu, 2 Jun 2022 21:05:28 +1000 Subject: [PATCH] Fix for case where client logged out and logged back in. --- leaguefiles.cpp | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/leaguefiles.cpp b/leaguefiles.cpp index ce96ee0..41f56cf 100644 --- a/leaguefiles.cpp +++ b/leaguefiles.cpp @@ -7,10 +7,10 @@ #include #include -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 : ""; @@ -27,7 +27,6 @@ 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(currentDB)->installlocation = *res; static_cast(currentDB)->lockfile = static_cast(currentDB)->installlocation+"/drive_c/Riot Games/League of Legends/lockfile"; return 0; @@ -35,7 +34,7 @@ struct leagueDBfind { 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 @@ -43,21 +42,23 @@ std::ifstream getfile() { //Get credentials from lockfile 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;