Basic support for setting configuration file
This commit is contained in:
@@ -33,10 +33,7 @@
|
||||
#include "configuration.h"
|
||||
#include "utils/xdg_base_directory.h"
|
||||
|
||||
static std::filesystem::path get_config_file()
|
||||
{
|
||||
return xdg_config_home() / "wivrn" / "config.json";
|
||||
}
|
||||
static std::filesystem::path config_file = xdg_config_home() / "wivrn" / "config.json";
|
||||
|
||||
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 result;
|
||||
auto config_file_path = get_config_file();
|
||||
if (not std::filesystem::exists(config_file_path))
|
||||
if (not std::filesystem::exists(config_file))
|
||||
return result;
|
||||
std::ifstream file(config_file_path);
|
||||
std::ifstream file(config_file);
|
||||
try
|
||||
{
|
||||
auto json = nlohmann::json::parse(file);
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <array>
|
||||
#include <filesystem>
|
||||
#include <map>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
@@ -47,6 +48,7 @@ struct configuration
|
||||
std::vector<std::string> application;
|
||||
bool tcp_only = false;
|
||||
|
||||
static void set_config_file(const std::filesystem::path &);
|
||||
static configuration read_user_configuration();
|
||||
};
|
||||
|
||||
|
||||
@@ -246,6 +246,12 @@ int inner_main(int argc, char * argv[])
|
||||
// FIXME: synchronization fails on gfx pipeline
|
||||
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
|
||||
{
|
||||
return ipc_server_main(argc, argv);
|
||||
@@ -370,6 +376,13 @@ int inner_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
|
||||
{
|
||||
return inner_main(argc, argv);
|
||||
|
||||
Reference in New Issue
Block a user