This commit is contained in:
@@ -1,2 +1,2 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
JMINOS_DATA="/app/share" /app/bin/graph
|
JMINOS_DATA="/app/share" JMINOS_CONFIG=$XDG_CONFIG_HOME /app/bin/graph
|
||||||
@@ -21,7 +21,7 @@ Keybinds::Keybinds(int layoutNumber) :
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Keybinds::loadKeybindsFromFile() {
|
void Keybinds::loadKeybindsFromFile() {
|
||||||
std::ifstream layoutFile(AssetManager::getResourcePath("data/config/keybinds/layout" + std::to_string(this->layoutNumber) + ".bin"), std::ios::binary);
|
std::ifstream layoutFile(AssetManager::getConfigPath("data/config/keybinds/layout" + std::to_string(this->layoutNumber) + ".bin"), std::ios::binary);
|
||||||
|
|
||||||
for (Action action : ACTION_LIST_IN_ORDER) {
|
for (Action action : ACTION_LIST_IN_ORDER) {
|
||||||
this->keybinds.at(action).clear();
|
this->keybinds.at(action).clear();
|
||||||
@@ -48,7 +48,7 @@ void Keybinds::loadKeybindsFromFile() {
|
|||||||
void Keybinds::saveKeybindsToFile() const {
|
void Keybinds::saveKeybindsToFile() const {
|
||||||
if (!this->modifiable) return;
|
if (!this->modifiable) return;
|
||||||
|
|
||||||
std::ofstream layoutFile(AssetManager::getResourcePath("data/config/keybinds/layout" + std::to_string(this->layoutNumber) + ".bin"), std::ios::trunc | std::ios::binary);
|
std::ofstream layoutFile(AssetManager::getConfigPath("data/config/keybinds/layout" + std::to_string(this->layoutNumber) + ".bin"), std::ios::trunc | std::ios::binary);
|
||||||
|
|
||||||
char byte;
|
char byte;
|
||||||
for (Action action : ACTION_LIST_IN_ORDER) {
|
for (Action action : ACTION_LIST_IN_ORDER) {
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ void Settings::loadPieces(int loadablePiecesSizeRequest) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Settings::loadSettingsFromFile(bool loadPieces, std::optional<int> loadablePiecesSizeRequest) {
|
void Settings::loadSettingsFromFile(bool loadPieces, std::optional<int> loadablePiecesSizeRequest) {
|
||||||
std::ifstream settingsFile(AssetManager::getResourcePath("data/config/settings.bin"), std::ios::binary);
|
std::ifstream settingsFile(AssetManager::getConfigPath("data/config/settings.bin"), std::ios::binary);
|
||||||
char byte;
|
char byte;
|
||||||
|
|
||||||
// file format version
|
// file format version
|
||||||
@@ -159,7 +159,7 @@ void Settings::saveSettingsToFile() const {
|
|||||||
|
|
||||||
this->keybinds.at(CUSTOMIZABLE_KEYBINDS).saveKeybindsToFile();
|
this->keybinds.at(CUSTOMIZABLE_KEYBINDS).saveKeybindsToFile();
|
||||||
|
|
||||||
std::ofstream settingsFile(AssetManager::getResourcePath("data/config/settings.bin"), std::ios::trunc | std::ios::binary);
|
std::ofstream settingsFile(AssetManager::getConfigPath("data/config/settings.bin"), std::ios::trunc | std::ios::binary);
|
||||||
char byte;
|
char byte;
|
||||||
|
|
||||||
// file format version
|
// file format version
|
||||||
|
|||||||
@@ -59,19 +59,19 @@ int main() {
|
|||||||
|
|
||||||
// CHECK CONFIG FILES
|
// CHECK CONFIG FILES
|
||||||
|
|
||||||
if (!std::filesystem::exists(AssetManager::getResourcePath("data/config/settings.bin"))) {
|
if (!std::filesystem::exists(AssetManager::getConfigPath("data/config/settings.bin"))) {
|
||||||
std::cout << "INFO: Settings file not found, generating..." << std::endl;
|
std::cout << "INFO: Settings file not found, generating..." << std::endl;
|
||||||
everythingIsOK &= resetSettingsFile();
|
everythingIsOK &= resetSettingsFile();
|
||||||
|
|
||||||
for (int i = 0; i < NUMBER_OF_KEYBINDS; i++) {
|
for (int i = 0; i < NUMBER_OF_KEYBINDS; i++) {
|
||||||
if (!std::filesystem::exists(AssetManager::getResourcePath("data/config/keybinds/layout" + std::to_string(i) + ".bin"))) {
|
if (!std::filesystem::exists(AssetManager::getConfigPath("data/config/keybinds/layout" + std::to_string(i) + ".bin"))) {
|
||||||
std::cout << "INFO: Keybind file number " << (i + 1) << "/" << NUMBER_OF_KEYBINDS << " not found, generating..." << std::endl;
|
std::cout << "INFO: Keybind file number " << (i + 1) << "/" << NUMBER_OF_KEYBINDS << " not found, generating..." << std::endl;
|
||||||
everythingIsOK &= resetKeybindFile(i);
|
everythingIsOK &= resetKeybindFile(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
std::ifstream settingsFile(AssetManager::getResourcePath("data/config/settings.bin"), std::ios::binary);
|
std::ifstream settingsFile(AssetManager::getConfigPath("data/config/settings.bin"), std::ios::binary);
|
||||||
char byte;
|
char byte;
|
||||||
|
|
||||||
settingsFile.get(byte);
|
settingsFile.get(byte);
|
||||||
@@ -101,11 +101,11 @@ int main() {
|
|||||||
|
|
||||||
|
|
||||||
bool resetSettingsFile() {
|
bool resetSettingsFile() {
|
||||||
if (!std::filesystem::exists(AssetManager::getResourcePath("data/config"))) {
|
if (!std::filesystem::exists(AssetManager::getConfigPath("data/config"))) {
|
||||||
std::filesystem::create_directories(AssetManager::getResourcePath("data/config"));
|
std::filesystem::create_directories(AssetManager::getConfigPath("data/config"));
|
||||||
}
|
}
|
||||||
|
|
||||||
auto filePath = AssetManager::getResourcePath("data/config/settings.bin");
|
auto filePath = AssetManager::getConfigPath("data/config/settings.bin");
|
||||||
std::ofstream settingsFile(filePath, std::ios::trunc | std::ios::binary);
|
std::ofstream settingsFile(filePath, std::ios::trunc | std::ios::binary);
|
||||||
if (!settingsFile.good()) {
|
if (!settingsFile.good()) {
|
||||||
std::cerr << "ERROR: Could not open file " << filePath << std::endl;
|
std::cerr << "ERROR: Could not open file " << filePath << std::endl;
|
||||||
@@ -182,11 +182,11 @@ bool resetKeybindFile(int layout) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!std::filesystem::exists(AssetManager::getResourcePath("data/config/keybinds"))) {
|
if (!std::filesystem::exists(AssetManager::getConfigPath("data/config/keybinds"))) {
|
||||||
std::filesystem::create_directories(AssetManager::getResourcePath("data/config/keybinds"));
|
std::filesystem::create_directories(AssetManager::getConfigPath("data/config/keybinds"));
|
||||||
}
|
}
|
||||||
|
|
||||||
auto filePath = AssetManager::getResourcePath("data/config/keybinds/layout" + std::to_string(layout) + ".bin");
|
auto filePath = AssetManager::getConfigPath("data/config/keybinds/layout" + std::to_string(layout) + ".bin");
|
||||||
std::ofstream layoutFile(filePath, std::ios::trunc | std::ios::binary);
|
std::ofstream layoutFile(filePath, std::ios::trunc | std::ios::binary);
|
||||||
if (!layoutFile.good()) {
|
if (!layoutFile.good()) {
|
||||||
std::cerr << "ERROR: Could not open file " << filePath << std::endl;
|
std::cerr << "ERROR: Could not open file " << filePath << std::endl;
|
||||||
|
|||||||
@@ -2,11 +2,15 @@
|
|||||||
|
|
||||||
namespace fs = std::filesystem;
|
namespace fs = std::filesystem;
|
||||||
|
|
||||||
std::string AssetManager::getResourcePrefix() {
|
static std::string getEnv(const std::string& var) {
|
||||||
char* env = std::getenv("JMINOS_DATA");
|
char* env = std::getenv(var.c_str());
|
||||||
return env ? env : std::string{};
|
return env ? env : "";
|
||||||
}
|
}
|
||||||
|
|
||||||
fs::path AssetManager::getResourcePath(const std::string& resource) {
|
fs::path AssetManager::getResourcePath(const std::string& resource) {
|
||||||
return fs::path{getResourcePrefix()} / resource;
|
return fs::path{getEnv("JMINOS_DATA")} / resource;
|
||||||
|
}
|
||||||
|
|
||||||
|
fs::path AssetManager::getConfigPath(const std::string& resource) {
|
||||||
|
return fs::path{getEnv("JMINOS_CONFIG")} / resource;
|
||||||
}
|
}
|
||||||
@@ -6,6 +6,13 @@
|
|||||||
|
|
||||||
class AssetManager {
|
class AssetManager {
|
||||||
public:
|
public:
|
||||||
static std::string getResourcePrefix();
|
/**
|
||||||
|
* @brief Used to load things (might be read-only)
|
||||||
|
*/
|
||||||
static std::filesystem::path getResourcePath(const std::string& resource);
|
static std::filesystem::path getResourcePath(const std::string& resource);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Used to save things
|
||||||
|
*/
|
||||||
|
static std::filesystem::path getConfigPath(const std::string& resource);
|
||||||
};
|
};
|
||||||
Reference in New Issue
Block a user