context: Add program directory's path
This commit is contained in:
@@ -33,6 +33,7 @@ typedef struct ctx {
|
|||||||
std::shared_ptr<Selection> selection = nullptr;
|
std::shared_ptr<Selection> selection = nullptr;
|
||||||
std::shared_ptr<PaternsMenu> paterns_menu = nullptr;
|
std::shared_ptr<PaternsMenu> paterns_menu = nullptr;
|
||||||
nlohmann::json config_json;
|
nlohmann::json config_json;
|
||||||
|
std::filesystem::path program_dir;
|
||||||
} ctx;
|
} ctx;
|
||||||
|
|
||||||
} // namespace gol
|
} // namespace gol
|
||||||
|
|||||||
@@ -82,6 +82,15 @@ int main(int ac, char **av) {
|
|||||||
context->config_json["fps"] = 800;
|
context->config_json["fps"] = 800;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get program directory
|
||||||
|
char path_buf[1024];
|
||||||
|
ssize_t len = readlink("/proc/self/exe", path_buf, sizeof(path_buf)-1);
|
||||||
|
if (len == -1) {
|
||||||
|
std::cerr << "Failed to determine program directory" << std::endl;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
context->program_dir = std::filesystem::path(path_buf).parent_path();
|
||||||
|
|
||||||
InitWindow(context->config_json["screen_width"], context->config_json["screen_height"],
|
InitWindow(context->config_json["screen_width"], context->config_json["screen_height"],
|
||||||
&av[0][2]);
|
&av[0][2]);
|
||||||
|
|
||||||
|
|||||||
@@ -62,11 +62,8 @@ void SelectionMenu::display() {
|
|||||||
rlImGuiImageSize(&selectionTexture_.texture, 200, 200);
|
rlImGuiImageSize(&selectionTexture_.texture, 200, 200);
|
||||||
ImGui::InputText("patern_name", patern_name_, 255);
|
ImGui::InputText("patern_name", patern_name_, 255);
|
||||||
if (ImGui::Button("Save")) {
|
if (ImGui::Button("Save")) {
|
||||||
char path_buf[1024];
|
|
||||||
ssize_t len = readlink("/proc/self/exe", path_buf, sizeof(path_buf)-1);
|
|
||||||
if (len != -1) {
|
|
||||||
// Create paterns dir if not present
|
// Create paterns dir if not present
|
||||||
std::filesystem::path paterns_dir = std::filesystem::path(path_buf).parent_path() / "paterns";
|
std::filesystem::path paterns_dir = context_->program_dir / "paterns";
|
||||||
if (!std::filesystem::exists(paterns_dir) && !std::filesystem::create_directory(paterns_dir)) {
|
if (!std::filesystem::exists(paterns_dir) && !std::filesystem::create_directory(paterns_dir)) {
|
||||||
std::cerr << "Failed to create paterns directory" << std::endl;
|
std::cerr << "Failed to create paterns directory" << std::endl;
|
||||||
} else { // Could be optimized by early returning in a function
|
} else { // Could be optimized by early returning in a function
|
||||||
@@ -97,7 +94,6 @@ void SelectionMenu::display() {
|
|||||||
}
|
}
|
||||||
sel_ctrl_ = false;
|
sel_ctrl_ = false;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
if (ImGui::Button("Discard")) {
|
if (ImGui::Button("Discard")) {
|
||||||
sel_ctrl_ = false;
|
sel_ctrl_ = false;
|
||||||
|
|||||||
Reference in New Issue
Block a user