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).
develop
lethosor 2015-06-18 08:59:01 -04:00
parent 81cba0b0fc
commit 5bb5d87ad8
2 changed files with 32 additions and 0 deletions

@ -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)

@ -1297,6 +1297,36 @@ bool Core::Init()
virtual_identity::Init(this);
init_screen_module(this);
// copy over default config files if necessary
std::vector<std::string> config_files;
std::vector<std::string> 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);