From c39f2b0c1fa22b2f398159e7ae9d6cddaa7f1cfd Mon Sep 17 00:00:00 2001 From: Jacek Jagosz Date: Sun, 25 Jul 2021 20:39:45 +0200 Subject: [PATCH] If config files don't exist in user specified directory copy files from default, not override user choice --- sunshine/config.cpp | 6 ++++-- sunshine/confighttp.cpp | 6 ++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/sunshine/config.cpp b/sunshine/config.cpp index b5082f59..706da2b0 100644 --- a/sunshine/config.cpp +++ b/sunshine/config.cpp @@ -574,7 +574,8 @@ int apply_flags(const char *line) { void apply_config(std::unordered_map &&vars) { if(!fs::exists(stream.file_apps.c_str())) { - stream.file_apps = SUNSHINE_DEFAULT_DIR "/" APPS_JSON; + std::string sunshine_apps_default = SUNSHINE_DEFAULT_DIR "/" APPS_JSON; + fs::copy_file(sunshine_apps_default.c_str(), stream.file_apps.c_str()); } for(auto &[name, val] : vars) { @@ -759,7 +760,8 @@ int parse(int argc, char *argv[]) { } if(!fs::exists(sunshine.config_file.c_str())) { - sunshine.config_file = SUNSHINE_DEFAULT_DIR "/sunshine.conf"; + std::string sunshine_config_default = SUNSHINE_DEFAULT_DIR "/sunshine.conf"; + fs::copy_file(sunshine_config_default.c_str(), sunshine.config_file.c_str()); } auto vars = parse_config(read_file(sunshine.config_file.c_str())); diff --git a/sunshine/confighttp.cpp b/sunshine/confighttp.cpp index a1ef32f5..c1a643bb 100644 --- a/sunshine/confighttp.cpp +++ b/sunshine/confighttp.cpp @@ -250,8 +250,7 @@ void saveApp(resp_https_t response, req_https_t request) { fileTree.erase("apps"); fileTree.push_back(std::make_pair("apps", newApps)); } - std::string sunshine_apps_path = SUNSHINE_CONFIG_DIR "/" APPS_JSON; - pt::write_json(sunshine_apps_path, fileTree); + pt::write_json(config::stream.file_apps, fileTree); } catch(std::exception &e) { BOOST_LOG(warning) << "SaveApp: "sv << e.what(); @@ -361,8 +360,7 @@ void saveConfig(resp_https_t response, req_https_t request) { configStream << kv.first << " = " << value << std::endl; } - std::string sunshine_config_path = SUNSHINE_CONFIG_DIR "/sunshine.conf"; - write_file(sunshine_config_path.c_str(), configStream.str()); + write_file(config::sunshine.config_file.c_str(), configStream.str()); } catch(std::exception &e) { BOOST_LOG(warning) << "SaveConfig: "sv << e.what();