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 #pragma once
#include <string> #include <string>
#include <list>
#include "beatmap.h"
namespace Beatsaber { namespace Beatsaber {
const uint32_t STEAMGAMEID = 620980; const uint32_t STEAMGAMEID = 620980;
std::string findBeatsaberInstallation(); 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 "beatset.h"
#include "beatnoteimpl.h" #include "beatnoteimpl.h"
#include "beatmap.h" // for debug print
namespace Beatsaber { namespace Beatsaber {
@ -46,7 +47,11 @@ BeatLevelImpl::BeatLevelImpl(std::weak_ptr<BeatSet> p, std::shared_ptr<FileReade
} }
} }
} catch(...) { } 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 #include <iostream> //debug print
#if BEATSABERZIPSUPPORT == 1
#include <zipios/zipiosexceptions.hpp>
#endif
#include "beatsetimpl.h" #include "beatsetimpl.h"
#include "filereaderimpl.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) { std::shared_ptr<BeatMap> BeatMap::loadFromZip(const std::string& zipPath) {
#if BEATSABERZIPSUPPORT == 1 #if BEATSABERZIPSUPPORT == 1
auto map = std::make_shared<BeatMapImpl>(std::make_shared<ZipReader>(zipPath)); try {
if(!map->load()) return nullptr; auto map = std::make_shared<BeatMapImpl>(std::make_shared<ZipReader>(zipPath));
return map; if(!map->load()) return nullptr;
return map;
} catch(zipios::Exception& e) {
return nullptr;
}
#else #else
// Zip not supported // Zip not supported
std::cerr << "Zip not supported" << std::endl; std::cerr << "Zip not supported" << std::endl;

View File

@ -9,6 +9,7 @@
#include <fstream> #include <fstream>
#include <iostream> //debug print #include <iostream> //debug print
#include <list> #include <list>
#include <filesystem>
namespace Beatsaber { namespace Beatsaber {
@ -56,13 +57,14 @@ std::string findBeatsaberInstallation() {
//search in libs for beatsaber //search in libs for beatsaber
for(const std::string& it : paths) { for(const std::string& it : paths) {
//check if manifest exists
const std::string appmani = it + "appmanifest_" + std::to_string(STEAMGAMEID) + ".acf"; const std::string appmani = it + "appmanifest_" + std::to_string(STEAMGAMEID) + ".acf";
//std::cout << "Try to read file: " << appmani << std::endl; //std::cout << "Try to read file: " << appmani << std::endl;
std::ifstream appmanifest(appmani); std::ifstream appmanifest(appmani);
if(appmanifest.is_open()) { if(appmanifest.is_open()) {
//found it! //found it!
//do stuff with the manifest??? //do stuff with the manifest???
appmanifest.close(); appmanifest.close();
return it + "common/Beat Saber/"; return it + "common/Beat Saber/";
@ -72,4 +74,31 @@ std::string findBeatsaberInstallation() {
return ""; //not found 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"]; const json& arr = j["_difficultyBeatmaps"];
if(arr.is_array()) { if(arr.is_array()) {
level.reserve(arr.size()); 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) { for(const json& beat : arr) {
level.push_back(std::make_shared<BeatLevelImpl>(weak_from_this(), r, beat)); 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::string installdir = Beatsaber::findBeatsaberInstallation();
std::cout << "Beatsaber installation directory: " << installdir << std::endl; 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 //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; if(!bmap) std::cout << "Could not load File" << std::endl;
else bmap->printDebug(); else bmap->printDebug();
bmap = Beatsaber::BeatMap::loadFromZip("/home/yannis/Nextcloud/yannis/Beatsaber/BeatSaverLevel/18b92 (Empress of Light - ShadowLantern).zip"); 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; if(!bmap) std::cout << "Could not load File" << std::endl;
else bmap->printDebug(); else bmap->printDebug();
*/
return failcount > 0; return failcount > 0;
} }