basic steamDiscovery
This commit is contained in:
parent
483ed9a867
commit
bd2c91e39a
|
@ -0,0 +1,11 @@
|
|||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace Beatsaber {
|
||||
|
||||
const uint32_t STEAMGAMEID = 620980;
|
||||
std::string findBeatsaberInstallation();
|
||||
|
||||
|
||||
}
|
|
@ -94,6 +94,7 @@ void BeatLevelImpl::printDebug() const {
|
|||
<< "\n Filename: " << getFilename()
|
||||
<< "\n njs: " << getNoteJumpSpeed() << " nso: " << getNoteStartOffset()
|
||||
<< "\n noteCount: " << notes.size() << " wallCount: " << walls.size()
|
||||
<< "\n CustomData: " << getCustomData()
|
||||
<< std::endl;
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,73 @@
|
|||
#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
|
||||
}
|
||||
|
||||
}
|
|
@ -2,6 +2,7 @@
|
|||
#include "test.h"
|
||||
|
||||
#include "beatmap.h"
|
||||
#include "beatsaber.h"
|
||||
|
||||
//tests
|
||||
int difficulties_test();
|
||||
|
@ -29,6 +30,10 @@ int main(int argc, char** argv) {
|
|||
|
||||
printf("\033[1;93m%d\033[0;1m/%d failed\n", failcount, testcount);
|
||||
|
||||
//beatsaber installation dir discovery test
|
||||
std::string installdir = Beatsaber::findBeatsaberInstallation();
|
||||
std::cout << "Beatsaber installation directory: " << installdir << std::endl;
|
||||
|
||||
//simple read test
|
||||
std::shared_ptr<Beatsaber::BeatMap> bmap = Beatsaber::BeatMap::loadFromFolder("/home/yannis/Nextcloud/yannis/Beatsaber/BeatSaverLevel/1dd (Portal - Still Alive (Uppermost Remix) - kryptikos)");
|
||||
if(!bmap) std::cout << "Could not load File" << std::endl;
|
||||
|
|
Loading…
Reference in New Issue