From 39d144639f837ee4a49c25158c2385f007d01417 Mon Sep 17 00:00:00 2001 From: psychocrypt Date: Thu, 28 Sep 2017 23:12:53 +0200 Subject: [PATCH] config as template - create config on startup - remove copy `config.txt` on `make install` --- CMakeLists.txt | 9 -------- cli/cli-miner.cpp | 44 +++++++++++++++++++++++++++++++++++----- config.txt => config.tpl | 10 ++++++--- 3 files changed, 46 insertions(+), 17 deletions(-) rename config.txt => config.tpl (98%) diff --git a/CMakeLists.txt b/CMakeLists.txt index ade87b2..f818209 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -398,12 +398,3 @@ if( NOT "${CMAKE_INSTALL_PREFIX}" STREQUAL "${PROJECT_BINARY_DIR}" ) else() set(WIN_OUTPUT_RELEASE "/Release") endif() - -# avoid overwrite of user defined settings -# install `config.txt`if file not exists in `${CMAKE_INSTALL_PREFIX}/bin` -install(CODE " \ - if(NOT EXISTS ${CMAKE_INSTALL_PREFIX}/bin${WIN_OUTPUT_RELEASE}/config.txt)\n \ - file(INSTALL ${CMAKE_CURRENT_SOURCE_DIR}/config.txt \ - DESTINATION ${CMAKE_INSTALL_PREFIX}/bin${WIN_OUTPUT_RELEASE})\n \ - endif()" -) diff --git a/cli/cli-miner.cpp b/cli/cli-miner.cpp index df9432e..f2c5c1d 100644 --- a/cli/cli-miner.cpp +++ b/cli/cli-miner.cpp @@ -29,6 +29,7 @@ #include "../console.h" #include "../donate-level.h" #include "../Params.hpp" +#include "../ConfigEditor.hpp" #include "../version.h" @@ -39,6 +40,7 @@ #include #include #include +#include #include @@ -91,17 +93,14 @@ int main(int argc, char *argv[]) else if(opName.compare("--noCPU") == 0) { Params::inst().useCPU = false; - return 0; } else if(opName.compare("--noAMD") == 0) { Params::inst().useAMD = false; - return 0; } else if(opName.compare("--noAMD") == 0) { Params::inst().useNVIDIA = false; - return 0; } else if(opName.compare("--cpu") == 0) { @@ -172,7 +171,42 @@ int main(int argc, char *argv[]) else Params::inst().configFile = argv[i]; } - + + // check if we need a guided start + if(!ConfigEditor::file_exist(Params::inst().configFile)) + { + // load the template of the backend config into a char variable + const char *tpl = + #include "../config.tpl" + ; + ConfigEditor configTpl{}; + configTpl.set(std::string(tpl)); + auto& pool = Params::inst().poolURL; + if(pool.empty()) + { + std::cout<<"Please enter:\n- pool address: e.g. pool.usxmrpool.com:3333"<> pool; + } + auto& userName = Params::inst().poolUsername; + if(userName.empty()) + { + std::cout<<"- user name (wallet address or pool login):"<> userName; + } + auto& passwd = Params::inst().poolPasswd; + if(passwd.empty()) + { + // clear everything from stdin to allow an empty password + std::cin.clear(); std::cin.ignore(INT_MAX,'\n'); + std::cout<<"- password (mostly empty or x):"<parse_config(Params::inst().configFile.c_str())) { @@ -180,7 +214,7 @@ int main(int argc, char *argv[]) return 0; } - if (!xmrstak::BackendConnector::self_test()) + if (!BackendConnector::self_test()) { win_exit(); return 0; diff --git a/config.txt b/config.tpl similarity index 98% rename from config.txt rename to config.tpl index 888b655..60d85cd 100644 --- a/config.txt +++ b/config.tpl @@ -1,3 +1,4 @@ +R"===( /* * pool_address - Pool address should be in the form "pool.supportxmr.com:3333". Only stratum pools are supported. * wallet_address - Your wallet, or pool login. @@ -5,9 +6,9 @@ * * We feature pools up to 1MH/s. For a more complete list see M5M400's pool list at www.moneropools.com */ -"pool_address" : "pool.usxmrpool.com:3333", -"wallet_address" : "", -"pool_password" : "", +"pool_address" : "POOLURL", +"wallet_address" : "POOLUSER", +"pool_password" : "POOLPASSWD", /* * Network timeouts. @@ -155,3 +156,6 @@ * This setting will only be needed in 2020's. No need to worry about it now. */ "prefer_ipv4" : true, + +)===" + \ No newline at end of file