xpack install #7

Open
Persson-dev wants to merge 12 commits from xpack into main
6 changed files with 30 additions and 19 deletions
Showing only changes of commit c9d5cc35ff - Show all commits

View File

@@ -1,2 +1,2 @@
#!/bin/sh
JMINOS_DATA="/app/share" /app/bin/graph
JMINOS_DATA="/app/share" JMINOS_CONFIG=$XDG_CONFIG_HOME /app/bin/graph

View File

@@ -21,7 +21,7 @@ Keybinds::Keybinds(int layoutNumber) :
}
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) {
this->keybinds.at(action).clear();
@@ -48,7 +48,7 @@ void Keybinds::loadKeybindsFromFile() {
void Keybinds::saveKeybindsToFile() const {
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;
for (Action action : ACTION_LIST_IN_ORDER) {

View File

@@ -50,7 +50,7 @@ void Settings::loadPieces(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;
// file format version
@@ -159,7 +159,7 @@ void Settings::saveSettingsToFile() const {
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;
// file format version

View File

@@ -59,19 +59,19 @@ int main() {
// 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;
everythingIsOK &= resetSettingsFile();
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;
everythingIsOK &= resetKeybindFile(i);
}
}
}
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;
settingsFile.get(byte);
@@ -101,11 +101,11 @@ int main() {
bool resetSettingsFile() {
if (!std::filesystem::exists(AssetManager::getResourcePath("data/config"))) {
std::filesystem::create_directories(AssetManager::getResourcePath("data/config"));
if (!std::filesystem::exists(AssetManager::getConfigPath("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);
if (!settingsFile.good()) {
std::cerr << "ERROR: Could not open file " << filePath << std::endl;
@@ -182,11 +182,11 @@ bool resetKeybindFile(int layout) {
return false;
}
if (!std::filesystem::exists(AssetManager::getResourcePath("data/config/keybinds"))) {
std::filesystem::create_directories(AssetManager::getResourcePath("data/config/keybinds"));
if (!std::filesystem::exists(AssetManager::getConfigPath("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);
if (!layoutFile.good()) {
std::cerr << "ERROR: Could not open file " << filePath << std::endl;

View File

@@ -2,11 +2,15 @@
namespace fs = std::filesystem;
std::string AssetManager::getResourcePrefix() {
char* env = std::getenv("JMINOS_DATA");
return env ? env : std::string{};
static std::string getEnv(const std::string& var) {
char* env = std::getenv(var.c_str());
return env ? env : "";
}
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;
}

View File

@@ -6,6 +6,13 @@
class AssetManager {
public:
static std::string getResourcePrefix();
/**
* @brief Used to load things (might be read-only)
*/
static std::filesystem::path getResourcePath(const std::string& resource);
/**
* @brief Used to save things
*/
static std::filesystem::path getConfigPath(const std::string& resource);
};