From 5bb5d87ad80adf1eb323a6d2efb8fb29b3269c77 Mon Sep 17 00:00:00 2001 From: lethosor Date: Thu, 18 Jun 2015 08:59:01 -0400 Subject: [PATCH] Install default dfhack-config files Files from the "dfhack-config" source directory are now installed to "dfhack-config/default" and copied to "dfhack-config" on startup if they don't already exist. Previously, config files weren't available at all unless they were manually installed (93c9a41). --- CMakeLists.txt | 2 ++ library/Core.cpp | 30 ++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 59f0eb1f3..19bd6684b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -174,6 +174,8 @@ IF(BUILD_LIBRARY) install(DIRECTORY images DESTINATION ${DFHACK_USERDOC_DESTINATION}) endif() +install(DIRECTORY dfhack-config/ DESTINATION dfhack-config/default) + #build the plugins IF(BUILD_PLUGINS) add_subdirectory (plugins) diff --git a/library/Core.cpp b/library/Core.cpp index f99c12039..2e59b7abe 100644 --- a/library/Core.cpp +++ b/library/Core.cpp @@ -1297,6 +1297,36 @@ bool Core::Init() virtual_identity::Init(this); init_screen_module(this); + // copy over default config files if necessary + std::vector config_files; + std::vector default_config_files; + if (Filesystem::listdir("dfhack-config", config_files) != 0) + con.printerr("Failed to list directory: dfhack-config"); + else if (Filesystem::listdir("dfhack-config/default", default_config_files) != 0) + con.printerr("Failed to list directory: dfhack-config/default"); + else + { + for (auto it = default_config_files.begin(); it != default_config_files.end(); ++it) + { + std::string filename = *it; + if (std::find(config_files.begin(), config_files.end(), filename) == config_files.end()) + { + std::string src_file = std::string("dfhack-config/default/") + filename; + std::string dest_file = std::string("dfhack-config/") + filename; + std::ifstream src(src_file, std::ios::binary); + std::ofstream dest(dest_file, std::ios::binary); + if (!src.good() || !dest.good()) + { + con.printerr("Copy failed: %s\n", filename.c_str()); + continue; + } + dest << src.rdbuf(); + src.close(); + dest.close(); + } + } + } + // initialize common lua context Lua::Core::Init(con);