mirror of
https://gitlab.com/square-game-liberation-front/F.E.I.S.git
synced 2024-11-12 02:00:53 +01:00
On linux, fallback to some standard paths for assets and settings when these folders aren't found next to the executable
This commit is contained in:
parent
28b15c3c0a
commit
1302543400
@ -1,3 +1,9 @@
|
||||
# v2.0.1
|
||||
|
||||
## 🚧 Changes 🚧
|
||||
- On Linux, if the `assets` and `settings` folders aren't found next to the executable,
|
||||
use fallbacks of `/usr/share/f.e.i.s/` and `~/.config/f.e.i.s/` respectively
|
||||
|
||||
# v2.0.0
|
||||
## 🥝🍇🍓🍊🍏 New Stuff 🍏🍊🍓🍇🥝
|
||||
- BPM Autodetect
|
||||
|
@ -36,6 +36,8 @@ fftw3_dep = dependency('fftw3')
|
||||
deps += [fftw3_dep]
|
||||
eigen_dep = dependency('eigen3')
|
||||
deps += [eigen_dep]
|
||||
platform_folders_dep = dependency('platform_folders', static: true)
|
||||
deps += [platform_folders_dep]
|
||||
|
||||
# I chose to put the .cpp files of the libs I vendor directly in include/
|
||||
# I store the files in a (lib name -> files) dict so that tests can
|
||||
|
@ -2,3 +2,4 @@
|
||||
|
||||
#define FEIS_NAME "@name@"
|
||||
#define FEIS_VERSION "@version@"
|
||||
#define FEIS_DATA_FOLDER_NAME "@data_folder_name@"
|
54
src/folders.cpp
Normal file
54
src/folders.cpp
Normal file
@ -0,0 +1,54 @@
|
||||
#include <folders.hpp>
|
||||
|
||||
#include <filesystem>
|
||||
#include <functional>
|
||||
#include <vector>
|
||||
|
||||
#include <sago/platform_folders.h>
|
||||
#include <stdexcept>
|
||||
#include <whereami++.hpp>
|
||||
|
||||
#include "compile_time_info.hpp"
|
||||
#include "utf8_strings.hpp"
|
||||
|
||||
const std::vector<std::function<std::filesystem::path(void)>> assets_folder_candidates = {
|
||||
[](){ return utf8_encoded_string_to_path(whereami::executable_dir()) / "assets"; },
|
||||
#ifdef __linux__
|
||||
[](){ return std::filesystem::path{"/usr/share"} / FEIS_DATA_FOLDER_NAME; },
|
||||
#endif
|
||||
};
|
||||
|
||||
std::filesystem::path choose_assets_folder() {
|
||||
for (const auto& folder_callback : assets_folder_candidates) {
|
||||
const auto& folder_candidate = folder_callback();
|
||||
if (std::filesystem::is_directory(folder_candidate)) {
|
||||
return folder_candidate;
|
||||
}
|
||||
}
|
||||
throw std::runtime_error("No suitable assets folder found");
|
||||
}
|
||||
|
||||
const std::vector<std::function<std::filesystem::path(void)>> settings_folder_candidates = {
|
||||
[](){ return utf8_encoded_string_to_path(whereami::executable_dir()) / "settings"; },
|
||||
#ifdef __linux__
|
||||
[](){ return utf8_encoded_string_to_path(sago::getConfigHome()) / FEIS_DATA_FOLDER_NAME; },
|
||||
#endif
|
||||
};
|
||||
|
||||
std::filesystem::path default_settings_folder() {
|
||||
#ifdef __linux__
|
||||
return utf8_encoded_string_to_path(sago::getConfigHome()) / FEIS_DATA_FOLDER_NAME;
|
||||
#else
|
||||
return utf8_encoded_string_to_path(whereami::executable_dir()) / "settings";
|
||||
#endif
|
||||
}
|
||||
|
||||
std::filesystem::path choose_settings_folder() {
|
||||
for (const auto& folder_callback : settings_folder_candidates) {
|
||||
const auto& folder_candidate = folder_callback();
|
||||
if (std::filesystem::is_directory(folder_candidate)) {
|
||||
return folder_candidate;
|
||||
}
|
||||
}
|
||||
return default_settings_folder();
|
||||
}
|
6
src/folders.hpp
Normal file
6
src/folders.hpp
Normal file
@ -0,0 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <filesystem>
|
||||
|
||||
std::filesystem::path choose_assets_folder();
|
||||
std::filesystem::path choose_settings_folder();
|
@ -30,6 +30,7 @@
|
||||
#include "editor_state.hpp"
|
||||
#include "error_messages.hpp"
|
||||
#include "file_dialogs.hpp"
|
||||
#include "folders.hpp"
|
||||
#include "history_item.hpp"
|
||||
#include "imgui_extras.hpp"
|
||||
#include "imgui_internal.h"
|
||||
@ -46,9 +47,8 @@ int main() {
|
||||
// extend SFML to be able to read mp3's
|
||||
sf::SoundFileFactory::registerReader<sf::priv::SoundFileReaderMp3>();
|
||||
|
||||
const auto executable_folder = utf8_encoded_string_to_path(whereami::executable_dir());
|
||||
const auto assets_folder = executable_folder / "assets";
|
||||
const auto settings_folder = executable_folder / "settings";
|
||||
const auto assets_folder = choose_assets_folder();
|
||||
const auto settings_folder = choose_settings_folder();
|
||||
const auto markers_folder = assets_folder / "textures" / "markers";
|
||||
|
||||
config::Config config{settings_folder};
|
||||
|
@ -16,6 +16,7 @@ sources += files(
|
||||
'editor_state.cpp',
|
||||
'error_messages.cpp',
|
||||
'file_dialogs.cpp',
|
||||
'folders.cpp',
|
||||
'guess_tempo.cpp',
|
||||
'history.cpp',
|
||||
'history_item.cpp',
|
||||
@ -46,6 +47,7 @@ conf_data = configuration_data()
|
||||
|
||||
conf_data.set('name', meson.project_name())
|
||||
conf_data.set('version', meson.project_version())
|
||||
conf_data.set('data_folder_name', meson.project_name().to_lower())
|
||||
|
||||
configure_file(
|
||||
input: 'compile_time_info.hpp.in',
|
||||
|
25
subprojects/packagefiles/platform_folders/meson.build
Normal file
25
subprojects/packagefiles/platform_folders/meson.build
Normal file
@ -0,0 +1,25 @@
|
||||
project(
|
||||
'platform_folders',
|
||||
'cpp',
|
||||
version: '4.2.0',
|
||||
license: 'MIT',
|
||||
default_options : ['cpp_std=c++11'],
|
||||
meson_version : '>=0.60.3',
|
||||
)
|
||||
|
||||
sources = files('sago/platform_folders.cpp')
|
||||
|
||||
includes = include_directories('.')
|
||||
|
||||
platform_folders_lib = library(
|
||||
'platform_folders',
|
||||
sources,
|
||||
include_directories: includes,
|
||||
)
|
||||
|
||||
platform_folders_dep = declare_dependency(
|
||||
include_directories: includes,
|
||||
link_with: platform_folders_lib,
|
||||
)
|
||||
|
||||
meson.override_dependency('platform_folders', platform_folders_dep)
|
6
subprojects/platform_folders.wrap
Normal file
6
subprojects/platform_folders.wrap
Normal file
@ -0,0 +1,6 @@
|
||||
[wrap-git]
|
||||
url = https://github.com/sago007/PlatformFolders
|
||||
revision = 4.2.0
|
||||
# Overlays subproject/packagefiles/platform_folders over the fresh git
|
||||
# clone of PlatformFolders
|
||||
patch_directory = platform_folders
|
Loading…
Reference in New Issue
Block a user