store the executable dir as a path
This commit is contained in:
parent
bc6b6fcf07
commit
3aa59be684
@ -66,14 +66,14 @@ namespace Data {
|
||||
}
|
||||
|
||||
// RAII style class which loads preferences from the dedicated file when constructed and saves them when destructed
|
||||
Preferences::Preferences(const std::filesystem::path& t_jujube_path) :
|
||||
Preferences::Preferences(const std::filesystem::path& jujube_path_) :
|
||||
screen(),
|
||||
layout(),
|
||||
options(),
|
||||
key_mapping(),
|
||||
jujube_path(t_jujube_path)
|
||||
jujube_path(jujube_path_)
|
||||
{
|
||||
auto path = jujube_path/"data"/"preferences.json";
|
||||
auto path = jujube_path / "data" / "preferences.json";
|
||||
if (std::filesystem::exists(path)) {
|
||||
std::ifstream prefs_file;
|
||||
prefs_file.open(path);
|
||||
|
@ -76,7 +76,7 @@ namespace Data {
|
||||
Input::KeyMapping key_mapping;
|
||||
std::filesystem::path jujube_path;
|
||||
|
||||
Preferences(const std::filesystem::path& t_jujube_path);
|
||||
Preferences(const std::filesystem::path& jujube_path);
|
||||
~Preferences();
|
||||
};
|
||||
|
||||
|
@ -30,7 +30,7 @@ namespace Data {
|
||||
}
|
||||
}
|
||||
|
||||
std::optional<fs::path> Song::full_cover_path() const {
|
||||
std::optional<std::filesystem::path> Song::full_cover_path() const {
|
||||
if (cover) {
|
||||
return folder/cover.value();
|
||||
} else {
|
||||
@ -38,7 +38,7 @@ namespace Data {
|
||||
}
|
||||
}
|
||||
|
||||
std::optional<fs::path> Song::full_audio_path() const {
|
||||
std::optional<std::filesystem::path> Song::full_audio_path() const {
|
||||
if (audio) {
|
||||
return folder/audio.value();
|
||||
} else {
|
||||
@ -46,13 +46,13 @@ namespace Data {
|
||||
}
|
||||
}
|
||||
|
||||
SongList::SongList(const fs::path& jujube_path) :
|
||||
SongList::SongList(const std::filesystem::path& jujube_path) :
|
||||
songs()
|
||||
{
|
||||
fs::path song_folder = jujube_path/"songs";
|
||||
std::filesystem::path song_folder = jujube_path/"songs";
|
||||
|
||||
if (fs::exists(song_folder) and fs::is_directory(song_folder)) {
|
||||
for (const auto& dir_item : fs::directory_iterator(song_folder)) {
|
||||
if (std::filesystem::exists(song_folder) and std::filesystem::is_directory(song_folder)) {
|
||||
for (const auto& dir_item : std::filesystem::directory_iterator(song_folder)) {
|
||||
if (dir_item.is_directory()) {
|
||||
songs.splice(songs.end(), recursiveSongSearch(dir_item.path()));
|
||||
}
|
||||
@ -61,16 +61,16 @@ namespace Data {
|
||||
std::cout << "Loaded Data::SongList, found " << songs.size() << " songs" << '\n';
|
||||
}
|
||||
|
||||
std::list<std::shared_ptr<Song>> recursiveSongSearch(fs::path song_or_pack) {
|
||||
std::list<std::shared_ptr<Song>> recursiveSongSearch(std::filesystem::path song_or_pack) {
|
||||
std::list<std::shared_ptr<Song>> res;
|
||||
|
||||
// First try : any .memo file in the folder ?
|
||||
fs::directory_iterator folder_memo{song_or_pack};
|
||||
std::filesystem::directory_iterator folder_memo{song_or_pack};
|
||||
if (
|
||||
std::any_of(
|
||||
fs::begin(folder_memo),
|
||||
fs::end(folder_memo),
|
||||
[](const fs::directory_entry& de) {return de.path().extension() == ".memo";}
|
||||
std::filesystem::begin(folder_memo),
|
||||
std::filesystem::end(folder_memo),
|
||||
[](const std::filesystem::directory_entry& de) {return de.path().extension() == ".memo";}
|
||||
)
|
||||
) {
|
||||
throw std::invalid_argument("jujube does not support .memo files for now ...");
|
||||
@ -78,13 +78,13 @@ namespace Data {
|
||||
|
||||
// Second try : any .memon file in the folder ?
|
||||
// if yes get the first one
|
||||
fs::directory_iterator folder_memon{song_or_pack};
|
||||
std::filesystem::directory_iterator folder_memon{song_or_pack};
|
||||
auto memon_path = std::find_if(
|
||||
fs::begin(folder_memon),
|
||||
fs::end(folder_memon),
|
||||
[](const fs::directory_entry& de) {return de.path().extension() == ".memon";}
|
||||
std::filesystem::begin(folder_memon),
|
||||
std::filesystem::end(folder_memon),
|
||||
[](const std::filesystem::directory_entry& de) {return de.path().extension() == ".memon";}
|
||||
);
|
||||
if (memon_path != fs::end(folder_memon)) {
|
||||
if (memon_path != std::filesystem::end(folder_memon)) {
|
||||
auto song = std::make_shared<MemonSong>(memon_path->path());
|
||||
if (not song->chart_levels.empty()) {
|
||||
res.push_back(song);
|
||||
@ -92,7 +92,7 @@ namespace Data {
|
||||
return res;
|
||||
}
|
||||
// Nothing found : recurse in subfolders
|
||||
for (auto& p : fs::directory_iterator(song_or_pack)) {
|
||||
for (auto& p : std::filesystem::directory_iterator(song_or_pack)) {
|
||||
if (p.is_directory()) {
|
||||
res.splice(res.end(), recursiveSongSearch(p));
|
||||
}
|
||||
@ -115,7 +115,7 @@ namespace Data {
|
||||
return time_bounds;
|
||||
}
|
||||
|
||||
MemonSong::MemonSong(const fs::path& t_memon_path) :
|
||||
MemonSong::MemonSong(const std::filesystem::path& t_memon_path) :
|
||||
memon_path(t_memon_path)
|
||||
{
|
||||
auto song_folder = t_memon_path.parent_path();
|
||||
|
@ -16,8 +16,6 @@
|
||||
#include "Chart.hpp"
|
||||
#include "TimeBounds.hpp"
|
||||
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
namespace Data {
|
||||
|
||||
/*
|
||||
@ -30,19 +28,19 @@ namespace Data {
|
||||
|
||||
// Basic metadata about a song
|
||||
struct Song {
|
||||
fs::path folder;
|
||||
std::filesystem::path folder;
|
||||
std::string title;
|
||||
std::string artist;
|
||||
// Path to the album cover
|
||||
std::optional<fs::path> cover;
|
||||
std::optional<std::filesystem::path> cover;
|
||||
// Path the the audio file
|
||||
std::optional<fs::path> audio;
|
||||
std::optional<std::filesystem::path> audio;
|
||||
std::optional<sf::Music::TimeSpan> preview;
|
||||
// Mapping from chart difficulty (BSC, ADV, EXT ...) to the numeric level,
|
||||
std::map<std::string, unsigned int, cmp_dif_name> chart_levels;
|
||||
|
||||
virtual std::optional<fs::path> full_cover_path() const;
|
||||
virtual std::optional<fs::path> full_audio_path() const;
|
||||
virtual std::optional<std::filesystem::path> full_cover_path() const;
|
||||
virtual std::optional<std::filesystem::path> full_audio_path() const;
|
||||
|
||||
virtual std::optional<Chart> get_chart(const std::string& difficulty) const = 0;
|
||||
|
||||
@ -74,10 +72,10 @@ namespace Data {
|
||||
};
|
||||
|
||||
struct MemonSong : public Song {
|
||||
explicit MemonSong(const fs::path& memon_path);
|
||||
explicit MemonSong(const std::filesystem::path& memon_path);
|
||||
std::optional<Chart> get_chart(const std::string& difficulty) const;
|
||||
private:
|
||||
fs::path memon_path;
|
||||
std::filesystem::path memon_path;
|
||||
};
|
||||
|
||||
/*
|
||||
@ -91,11 +89,11 @@ namespace Data {
|
||||
// Class holding all the necessary song data to run the Music Select screen
|
||||
class SongList {
|
||||
public:
|
||||
SongList(const fs::path& jujube_path);
|
||||
SongList(const std::filesystem::path& jujube_path);
|
||||
std::list<std::shared_ptr<Song>> songs;
|
||||
};
|
||||
|
||||
// Returns the folders conscidered to contain a valid song
|
||||
// classic memo files should have the .memo extension
|
||||
std::list<std::shared_ptr<Song>> recursiveSongSearch(fs::path song_or_pack);
|
||||
std::list<std::shared_ptr<Song>> recursiveSongSearch(std::filesystem::path song_or_pack);
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
#include <iostream>
|
||||
|
||||
#include <filesystem>
|
||||
|
||||
#include <imgui-sfml/imgui-SFML.h>
|
||||
#include <SFML/Graphics.hpp>
|
||||
#include <whereami/whereami++.hpp>
|
||||
@ -17,6 +19,9 @@
|
||||
#include "Screens/Gameplay/Resources.hpp"
|
||||
#include "Screens/Gameplay/Gameplay.hpp"
|
||||
#include "Screens/Results/Results.hpp"
|
||||
|
||||
#include "Toolkit/UTF8Strings.hpp"
|
||||
|
||||
#if defined(__unix__) && defined(__linux__)
|
||||
#include <X11/Xlib.h>
|
||||
#endif
|
||||
@ -28,7 +33,7 @@ int main() {
|
||||
#endif
|
||||
|
||||
// Load prefs, music, markers
|
||||
const std::string jujube_path = whereami::executable_dir();
|
||||
const std::filesystem::path jujube_path = utf8_encoded_string_to_path(whereami::executable_dir());
|
||||
Data::Preferences preferences{jujube_path};
|
||||
Data::SongList song_list{jujube_path};
|
||||
Resources::SharedResources shared_resources{preferences};
|
||||
|
Loading…
Reference in New Issue
Block a user