73 lines
1.6 KiB
C++
73 lines
1.6 KiB
C++
#include "beatsaber.h"
|
|
|
|
#if __unix__
|
|
#include <unistd.h>
|
|
#include <sys/types.h>
|
|
#include <pwd.h>
|
|
#endif
|
|
|
|
#include <fstream>
|
|
#include <iostream> //debug print
|
|
#include <list>
|
|
|
|
namespace Beatsaber {
|
|
|
|
#if __unix__
|
|
static std::string getSteamDefault() {
|
|
//get the user process
|
|
uid_t user = getuid();
|
|
struct passwd pwd;
|
|
struct passwd* res;
|
|
char buf[4096];
|
|
getpwuid_r(user, &pwd, buf, sizeof(buf), &res);
|
|
|
|
char* userdirc = pwd.pw_dir;
|
|
std::string userdir(userdirc);
|
|
|
|
return userdir + "/.steam/steam";
|
|
}
|
|
#endif
|
|
|
|
std::string findBeatsaberInstallation() {
|
|
//get all steamfolders
|
|
const std::string defaultSteam = getSteamDefault() + "/steamapps/";
|
|
std::ifstream libinfo(defaultSteam + "libraryfolders.vdf");
|
|
std::string firstline;
|
|
libinfo >> firstline; //remove first line, should contain: "\"LibraryFolders\""
|
|
|
|
std::list<std::string> paths;
|
|
paths.push_back(defaultSteam);
|
|
|
|
std::string line;
|
|
while(std::getline(libinfo, line)) {
|
|
if(!line.empty() && line[0] == '\t') {
|
|
int num;
|
|
char pathbuffer[512];
|
|
int res = sscanf(line.c_str(), "\t\"%d\" \t\"%s\"", &num, pathbuffer);
|
|
if(res == 2) {
|
|
std::string path(pathbuffer);
|
|
paths.push_back(path + "/steamapps/");
|
|
}
|
|
}
|
|
}
|
|
libinfo.close();
|
|
|
|
std::cout << paths.size() << " steam libs found" << std::endl;
|
|
|
|
//search in libs for beatsaber
|
|
for(const std::string& it : paths) {
|
|
std::ifstream appmanifest(it + "appmanifest_" + std::to_string(STEAMGAMEID) + ".acf");
|
|
if(appmanifest.is_open()) {
|
|
//found it!
|
|
//do stuff with the manifest???
|
|
|
|
appmanifest.close();
|
|
|
|
return it + "common/Beat Saber/";
|
|
}
|
|
}
|
|
|
|
return ""; //not found
|
|
}
|
|
|
|
} |