From 98f181fd6d0891beb84e97b2d60622331d50e1b2 Mon Sep 17 00:00:00 2001 From: Lukas Heiligenbrunner Date: Fri, 1 May 2020 16:56:37 +0200 Subject: [PATCH] store sampleconfig also in header for regenerating it if missing during runtime --- CMakeLists.txt | 24 ++++++++++++------------ src/Config.cpp | 17 ++--------------- 2 files changed, 14 insertions(+), 27 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 71cc012..e9bcd23 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -54,13 +54,18 @@ include_directories(${LIBCONFIG_INCLUDE_DIR}) message("") -#add version header -FILE(WRITE ${CMAKE_SOURCE_DIR}/inc/Version.h - "\#pragma once\n#include \nnamespace Version {\n const std::string VERSION = \"${PROJECT_VERSION}\";\n}" - ) - #read sample config FILE(READ ${CMAKE_SOURCE_DIR}/config/iprefresher.cfg SAMPLECONFIG) +#add version header +FILE(WRITE ${CMAKE_SOURCE_DIR}/inc/Version.h + "\#pragma once +#include +namespace Version { + const std::string VERSION = \"${PROJECT_VERSION}\"; + const std::string SAMPLECONFIG = R\"(${SAMPLECONFIG})\"; +}" + ) + # generate post script for checking if configuration already exists FILE(WRITE ${CMAKE_SOURCE_DIR}/postinstall.sh "#!/bin/bash @@ -72,18 +77,13 @@ fi" add_library(api ${LIB_METHOD} src/api/API.cpp - src/api/TelegramAPI.cpp - src/api/DynuAPI.cpp - - src/api/IPAPI.cpp - ) + src/api/IPAPI.cpp) add_library(logger ${LIB_METHOD} src/FileLogger.cpp - src/Logger.cpp - ) + src/Logger.cpp) SET(SOURCE diff --git a/src/Config.cpp b/src/Config.cpp index 9a07099..07bc961 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -9,6 +9,7 @@ #include #include #include +#include std::string Config::dynuapikey; std::string Config::domainid; //id of the dynu domain @@ -25,24 +26,10 @@ bool Config::readCredentials() { catch (const libconfig::FileIOException &fioex) { std::cout << "I/O error while reading config file." << std::endl << "creating new config file!" << std::endl; - std::string defaultconf = R"(# Dynu IP refresher config -# 2020 -# Lukas Heiligenbrunner - -## DYNU API Config -dynuapikey = "" -domainid = "" -domainname = "" - -## Telegram API Config (optional) -#telegramApiKey = "" -#chatId = "" -)"; - std::ofstream myfile; myfile.open("/etc/iprefresher.cfg"); if (myfile.is_open()) { - myfile << defaultconf; + myfile << Version::SAMPLECONFIG; myfile.close(); } else { std::cout << "error creating file" << std::endl;