Basic support for setting configuration file

This commit is contained in:
Patrick Nicolas
2024-06-14 10:22:33 +02:00
parent 64244980af
commit 8a96729983
3 changed files with 23 additions and 7 deletions
+8 -7
View File
@@ -33,10 +33,7 @@
#include "configuration.h" #include "configuration.h"
#include "utils/xdg_base_directory.h" #include "utils/xdg_base_directory.h"
static std::filesystem::path get_config_file() static std::filesystem::path config_file = xdg_config_home() / "wivrn" / "config.json";
{
return xdg_config_home() / "wivrn" / "config.json";
}
static std::filesystem::path get_cookie_file() static std::filesystem::path get_cookie_file()
{ {
@@ -56,13 +53,17 @@ NLOHMANN_JSON_SERIALIZE_ENUM(
}) })
} }
void configuration::set_config_file(const std::filesystem::path & path)
{
config_file = path;
}
configuration configuration::read_user_configuration() configuration configuration::read_user_configuration()
{ {
configuration result; configuration result;
auto config_file_path = get_config_file(); if (not std::filesystem::exists(config_file))
if (not std::filesystem::exists(config_file_path))
return result; return result;
std::ifstream file(config_file_path); std::ifstream file(config_file);
try try
{ {
auto json = nlohmann::json::parse(file); auto json = nlohmann::json::parse(file);
+2
View File
@@ -20,6 +20,7 @@
#pragma once #pragma once
#include <array> #include <array>
#include <filesystem>
#include <map> #include <map>
#include <optional> #include <optional>
#include <string> #include <string>
@@ -47,6 +48,7 @@ struct configuration
std::vector<std::string> application; std::vector<std::string> application;
bool tcp_only = false; bool tcp_only = false;
static void set_config_file(const std::filesystem::path &);
static configuration read_user_configuration(); static configuration read_user_configuration();
}; };
+13
View File
@@ -246,6 +246,12 @@ int inner_main(int argc, char * argv[])
// FIXME: synchronization fails on gfx pipeline // FIXME: synchronization fails on gfx pipeline
setenv("XRT_COMPOSITOR_COMPUTE", "1", true); setenv("XRT_COMPOSITOR_COMPUTE", "1", true);
// FIXME: use a proper library for cli options
if (argc == 2 and strcmp(argv[1], "-f") == 0)
{
configuration::set_config_file(argv[2]);
}
try try
{ {
return ipc_server_main(argc, argv); return ipc_server_main(argc, argv);
@@ -370,6 +376,13 @@ int inner_main(int argc, char * argv[])
int main(int argc, char * argv[]) int main(int argc, char * argv[])
{ {
if (argc > 1 and (strcmp(argv[1], "-f") != 0 or argc < 3))
{
std::cerr << "Usage: " << argv[0] << " [-f file]" << std::endl
<< "\t -f file: configuration file to use" << std::endl;
return EXIT_FAILURE;
}
try try
{ {
return inner_main(argc, argv); return inner_main(argc, argv);