load beatsaber safedata

This commit is contained in:
mrbesen 2021-06-12 18:04:14 +02:00
parent 4dcfcee3dd
commit 03cd4b3822
Signed by: MrBesen
GPG Key ID: 596B2350DCD67504
6 changed files with 66 additions and 7 deletions

View File

@ -1,11 +1,17 @@
#pragma once
#include <string>
#include <list>
#include "beatmap.h"
namespace Beatsaber {
const uint32_t STEAMGAMEID = 620980;
std::string findBeatsaberInstallation();
// when gamepath is empty, findBeatsaberInstallation is used to get a Path
// from the installation folder as many mas as possible are loaded
std::list<std::shared_ptr<BeatMap>> loadMapsfromInstallation(std::string gamePath = "");
}

View File

@ -5,6 +5,7 @@
#include "beatset.h"
#include "beatnoteimpl.h"
#include "beatmap.h" // for debug print
namespace Beatsaber {
@ -46,7 +47,11 @@ BeatLevelImpl::BeatLevelImpl(std::weak_ptr<BeatSet> p, std::shared_ptr<FileReade
}
}
} catch(...) {
std::cout << "Could not load difficulty: " << filename << std::endl;
std::string mapname = "<unknown>";
auto par = parent.lock();
if(par)
mapname = par->getBeatMap()->getSongName();
std::cout << "Could not load difficulty: " << filename << " from: " << mapname << std::endl; //is the direct access after p.lock() a problem? is the parent always loaded?
}
}
}

View File

@ -2,6 +2,10 @@
#include <iostream> //debug print
#if BEATSABERZIPSUPPORT == 1
#include <zipios/zipiosexceptions.hpp>
#endif
#include "beatsetimpl.h"
#include "filereaderimpl.h"
@ -156,9 +160,13 @@ std::shared_ptr<BeatMap> BeatMap::loadFromFolder(const std::string& folderPath)
std::shared_ptr<BeatMap> BeatMap::loadFromZip(const std::string& zipPath) {
#if BEATSABERZIPSUPPORT == 1
auto map = std::make_shared<BeatMapImpl>(std::make_shared<ZipReader>(zipPath));
if(!map->load()) return nullptr;
return map;
try {
auto map = std::make_shared<BeatMapImpl>(std::make_shared<ZipReader>(zipPath));
if(!map->load()) return nullptr;
return map;
} catch(zipios::Exception& e) {
return nullptr;
}
#else
// Zip not supported
std::cerr << "Zip not supported" << std::endl;

View File

@ -9,6 +9,7 @@
#include <fstream>
#include <iostream> //debug print
#include <list>
#include <filesystem>
namespace Beatsaber {
@ -56,13 +57,14 @@ std::string findBeatsaberInstallation() {
//search in libs for beatsaber
for(const std::string& it : paths) {
//check if manifest exists
const std::string appmani = it + "appmanifest_" + std::to_string(STEAMGAMEID) + ".acf";
//std::cout << "Try to read file: " << appmani << std::endl;
std::ifstream appmanifest(appmani);
if(appmanifest.is_open()) {
//found it!
//do stuff with the manifest???
appmanifest.close();
return it + "common/Beat Saber/";
@ -72,4 +74,31 @@ std::string findBeatsaberInstallation() {
return ""; //not found
}
std::list<std::shared_ptr<BeatMap>> loadMapsfromInstallation(std::string gamePath) {
if(gamePath.empty()) {
gamePath = findBeatsaberInstallation();
}
std::filesystem::path path(gamePath);
std::list<std::shared_ptr<BeatMap>> out;
for(const auto& i : std::filesystem::directory_iterator(path / "Beat Saber_Data/CustomLevels")) {
if(i.exists()) {
if(i.is_directory()) {
//try to load
auto map = BeatMap::loadFromFolder(i.path().string());
if(map)
out.push_back(map);
} else if(i.is_regular_file()) {
auto map = BeatMap::loadFromZip(i.path().string());
if(map)
out.push_back(map);
}
}
}
return out;
}
}

View File

@ -15,7 +15,7 @@ BeatSetImpl::BeatSetImpl(std::weak_ptr<BeatMap> p, std::shared_ptr<FileReader> r
const json& arr = j["_difficultyBeatmaps"];
if(arr.is_array()) {
level.reserve(arr.size());
std::cout << "Try to load: " << arr.size() << std::endl;
//std::cout << "Try to load: " << arr.size() << " BeatLevel" << std::endl;
for(const json& beat : arr) {
level.push_back(std::make_shared<BeatLevelImpl>(weak_from_this(), r, beat));
}

View File

@ -34,13 +34,24 @@ int main(int argc, char** argv) {
std::string installdir = Beatsaber::findBeatsaberInstallation();
std::cout << "Beatsaber installation directory: " << installdir << std::endl;
auto list = Beatsaber::loadMapsfromInstallation();
std::cout << "Loaded: " << list.size() << " Maps from Beatsaber Installation" << std::endl;
/*for(auto i : list) {
if(i) {
i->printDebug();
std::cin.get();
}
}*/
//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)");
/*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;
else bmap->printDebug();
bmap = Beatsaber::BeatMap::loadFromZip("/home/yannis/Nextcloud/yannis/Beatsaber/BeatSaverLevel/18b92 (Empress of Light - ShadowLantern).zip");
if(!bmap) std::cout << "Could not load File" << std::endl;
else bmap->printDebug();
*/
return failcount > 0;
}