Gravar y cargar correctamente la configuración
Signed-off-by: somebody_master <somebody_master@somebodyserver.mooo.com>
This commit is contained in:
parent
2b7305360d
commit
e7466d01ee
@ -7,11 +7,11 @@ private:
|
|||||||
std::string *tiempo;
|
std::string *tiempo;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Config(int8_t nh, std::string t);
|
Config(int8_t numHilos, std::string tiempo);
|
||||||
~Config();
|
// ~Config();
|
||||||
int8_t getNumHilos();
|
int8_t getNumHilos();
|
||||||
std::string getTiempo();
|
std::string getTiempo();
|
||||||
void setNumHilos(int8_t nh);
|
void setNumHilos(int8_t numHilos);
|
||||||
void setTiempo(std::string t);
|
void setTiempo(std::string timepo);
|
||||||
};
|
};
|
||||||
#endif // __CONFIG_HPP_
|
#endif // __CONFIG_HPP_
|
||||||
|
@ -4,11 +4,11 @@
|
|||||||
#ifndef __CONFIG_FILE_HPP_
|
#ifndef __CONFIG_FILE_HPP_
|
||||||
#define __CONFIG_FILE_HPP_
|
#define __CONFIG_FILE_HPP_
|
||||||
namespace cf {
|
namespace cf {
|
||||||
const std::string g_cofigFile = "~/.config/stressUI.cfg";
|
const std::string g_configFile =
|
||||||
Config *openConfig();
|
std::string(getenv("HOME")) + "/.config/stressUI.cfg";
|
||||||
|
Config openConfig();
|
||||||
void closeConfig(Config *config);
|
void closeConfig(Config *config);
|
||||||
std::string getLine(std::ifstream *file);
|
std::string getLine(std::ifstream *file);
|
||||||
void saveConfig();
|
void saveConfig(Config *config);
|
||||||
void createConfig();
|
|
||||||
} // namespace cf
|
} // namespace cf
|
||||||
#endif // __CONFIG_FILE_HPP_
|
#endif // __CONFIG_FILE_HPP_
|
||||||
|
@ -1,19 +1,15 @@
|
|||||||
#include "config.hpp"
|
#include "config.hpp"
|
||||||
|
|
||||||
Config::Config(int8_t nh, std::string t) {
|
Config::Config(int8_t numHilos, std::string tiempo) {
|
||||||
Config::numHilos = &nh;
|
Config::numHilos = &numHilos;
|
||||||
Config::tiempo = &t;
|
Config::tiempo = &tiempo;
|
||||||
}
|
}
|
||||||
|
|
||||||
Config::~Config() {
|
// Config::~Config() {
|
||||||
delete Config::numHilos;
|
// delete numHilos;
|
||||||
delete Config::tiempo;
|
// delete tiempo;
|
||||||
}
|
// }
|
||||||
|
int8_t Config::getNumHilos() { return *numHilos; }
|
||||||
int8_t Config::getNumHilos() { return *Config::numHilos; }
|
std::string Config::getTiempo() { return *tiempo; }
|
||||||
|
void Config::setNumHilos(int8_t numHilos) { Config::numHilos = &numHilos; }
|
||||||
void Config::setNumHilos(int8_t nh) { Config::numHilos = &nh; }
|
void Config::setTiempo(std::string tiempo) { Config::tiempo = &tiempo; }
|
||||||
|
|
||||||
std::string Config::getTiempo() { return *Config::tiempo; }
|
|
||||||
|
|
||||||
void Config::setTiempo(std::string t) { Config::tiempo = &t; }
|
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
#include "configFile.hpp"
|
#include "configFile.hpp"
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
Config *cf::openConfig() {
|
Config cf::openConfig() {
|
||||||
std::ifstream file(g_cofigFile);
|
std::ifstream file;
|
||||||
|
file.open(cf::g_configFile);
|
||||||
if (file.is_open()) {
|
if (file.is_open()) {
|
||||||
std::string line;
|
std::string line;
|
||||||
line = cf::getLine(&file);
|
line = cf::getLine(&file);
|
||||||
@ -10,13 +11,10 @@ Config *cf::openConfig() {
|
|||||||
std::string t = cf::getLine(&file);
|
std::string t = cf::getLine(&file);
|
||||||
Config config = Config(nh, t);
|
Config config = Config(nh, t);
|
||||||
file.close();
|
file.close();
|
||||||
Config *ptr = &config;
|
// Config *ptr = &config;
|
||||||
return ptr;
|
return config;
|
||||||
} else {
|
} else {
|
||||||
// file.close();
|
return Config(0, "");
|
||||||
// cf::createConfig();
|
|
||||||
// return cf::openConfig();
|
|
||||||
return nullptr;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -34,6 +32,13 @@ std::string cf::getLine(std::ifstream *file) {
|
|||||||
return line;
|
return line;
|
||||||
}
|
}
|
||||||
|
|
||||||
void cf::createConfig() {}
|
void cf::saveConfig(Config *config) {
|
||||||
|
std::ofstream file(g_configFile);
|
||||||
|
|
||||||
void cf::saveConfig() {}
|
file << "Número de hilos\t\t= " << std::to_string(config->getNumHilos())
|
||||||
|
<< "\n";
|
||||||
|
file << "Tiempo de ejecución\t= " << config->getTiempo();
|
||||||
|
// std::string str = "shit";
|
||||||
|
// file << str;
|
||||||
|
file.close();
|
||||||
|
}
|
||||||
|
52
src/main.cpp
52
src/main.cpp
@ -35,11 +35,12 @@ const vector<string> TITULO_PRINCIPAL = {
|
|||||||
"_______________________________________________________________________",
|
"_______________________________________________________________________",
|
||||||
};
|
};
|
||||||
|
|
||||||
void userInterface(const int8_t *menu);
|
void userInterface(const int8_t *menu, Config *config);
|
||||||
void userInterface(const int8_t *menu, vector<string> *mensaje);
|
void userInterface(const int8_t *menu, vector<string> *mensaje, Config *config);
|
||||||
void showMenu(vector<string> *menu_elems, const int8_t *num_menu,
|
void showMenu(vector<string> *menu_elems, const int8_t *num_menu,
|
||||||
vector<string> *mensaje);
|
vector<string> *mensaje, Config *config);
|
||||||
void showMenu(vector<string> *menu_elems, const int8_t *num_menu);
|
void showMenu(vector<string> *menu_elems, const int8_t *num_menu,
|
||||||
|
Config *config);
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
locale::global(locale("es_ES.utf8"));
|
locale::global(locale("es_ES.utf8"));
|
||||||
@ -48,32 +49,34 @@ int main(int argc, char *argv[]) {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
Config *config = cf::openConfig();
|
Config config = cf::openConfig();
|
||||||
|
|
||||||
if (config == nullptr) {
|
if (config.getTiempo() == "") {
|
||||||
userInterface(&PRIMER_INICIO);
|
userInterface(&PRIMER_INICIO, &config);
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
userInterface(&MENU_PRINCIPAL);
|
userInterface(&MENU_PRINCIPAL, &config);
|
||||||
}
|
}
|
||||||
|
|
||||||
ui::closeUI();
|
ui::closeUI();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void userInterface(const int8_t *menu) {
|
void userInterface(const int8_t *menu, Config *config) {
|
||||||
/*int8_t menu_num = inputToInt(menu);*/
|
/*int8_t menu_num = inputToInt(menu);*/
|
||||||
vector<string> dummy = {""};
|
vector<string> dummy = {""};
|
||||||
userInterface(menu, &dummy);
|
userInterface(menu, &dummy, config);
|
||||||
}
|
}
|
||||||
|
|
||||||
void userInterface(const int8_t *num_menu, vector<string> *mensaje) {
|
void userInterface(const int8_t *num_menu, vector<string> *mensaje,
|
||||||
|
Config *config) {
|
||||||
switch (*num_menu) {
|
switch (*num_menu) {
|
||||||
|
|
||||||
case CONFIGURAR_MENU_PRINCIPAL:
|
case CONFIGURAR_MENU_PRINCIPAL:
|
||||||
case MENU_PRINCIPAL: {
|
case MENU_PRINCIPAL: {
|
||||||
vector<string> elem_menu = {"- Iniciar Stress Test", "- Configurar",
|
vector<string> elem_menu = {"- Iniciar Stress Test", "- Configurar",
|
||||||
"- Salir"};
|
"- Salir"};
|
||||||
showMenu(&elem_menu, &MENU_PRINCIPAL, mensaje);
|
showMenu(&elem_menu, &MENU_PRINCIPAL, mensaje, config);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -86,7 +89,7 @@ void userInterface(const int8_t *num_menu, vector<string> *mensaje) {
|
|||||||
vector<string> elem_menu = {"- Configurar todo", "- Número de hilos",
|
vector<string> elem_menu = {"- Configurar todo", "- Número de hilos",
|
||||||
"- Tiempo", "- Menú principal"};
|
"- Tiempo", "- Menú principal"};
|
||||||
|
|
||||||
showMenu(&elem_menu, num_menu, mensaje);
|
showMenu(&elem_menu, num_menu, mensaje, config);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -94,13 +97,15 @@ void userInterface(const int8_t *num_menu, vector<string> *mensaje) {
|
|||||||
case PRIMER_INICIO: {
|
case PRIMER_INICIO: {
|
||||||
|
|
||||||
vector<string> textos_init = {
|
vector<string> textos_init = {
|
||||||
"Toda la configuración se escribirá en " + cf::g_cofigFile, "", ""};
|
"Toda la configuración se escribirá en " + cf::g_configFile, "", ""};
|
||||||
vector<string> elemens = {"- Número de hilos\t> ", "- Tiempo\t\t> "};
|
vector<string> elemens = {"- Número de hilos\t> ", "- Tiempo\t\t> "};
|
||||||
ui::showTopTitle(&TITULO_PRINCIPAL);
|
ui::showTopTitle(&TITULO_PRINCIPAL);
|
||||||
ui::showCentralInputBox(&textos_init, &CONFIGURAR_TODO, &elemens,
|
vector<string> entrada = ui::showCentralInputBox(
|
||||||
TITULO_PRINCIPAL.size());
|
&textos_init, &CONFIGURAR_TODO, &elemens, TITULO_PRINCIPAL.size());
|
||||||
|
Config config2 = Config(atoi(entrada[0].c_str()), entrada[1]);
|
||||||
userInterface(&MENU_CONFIGURACION, mensaje);
|
config = &config2;
|
||||||
|
cf::saveConfig(config);
|
||||||
|
userInterface(&MENU_PRINCIPAL, mensaje, config);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -125,23 +130,24 @@ void userInterface(const int8_t *num_menu, vector<string> *mensaje) {
|
|||||||
*mensaje = {"¿Como has llegado aquí?",
|
*mensaje = {"¿Como has llegado aquí?",
|
||||||
"Por si acaso vamos al menú principal"};
|
"Por si acaso vamos al menú principal"};
|
||||||
|
|
||||||
userInterface(&MENU_PRINCIPAL, mensaje);
|
userInterface(&MENU_PRINCIPAL, mensaje, config);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void showMenu(vector<string> *menu_elems, const int8_t *num_menu,
|
void showMenu(vector<string> *menu_elems, const int8_t *num_menu,
|
||||||
vector<string> *mensaje) {
|
vector<string> *mensaje, Config *config) {
|
||||||
clear();
|
clear();
|
||||||
if (ui::g_mensaje) {
|
if (ui::g_mensaje) {
|
||||||
ui::showCenterMensaje(mensaje, &MENU_ERROR);
|
ui::showCenterMensaje(mensaje, &MENU_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
showMenu(menu_elems, num_menu);
|
showMenu(menu_elems, num_menu, config);
|
||||||
}
|
}
|
||||||
|
|
||||||
void showMenu(vector<string> *menu_elems, const int8_t *num_menu) {
|
void showMenu(vector<string> *menu_elems, const int8_t *num_menu,
|
||||||
|
Config *config) {
|
||||||
size_t height = menu_elems->size();
|
size_t height = menu_elems->size();
|
||||||
|
|
||||||
attron(COLOR_PAIR(MENU_PRINCIPAL));
|
attron(COLOR_PAIR(MENU_PRINCIPAL));
|
||||||
@ -252,5 +258,5 @@ void showMenu(vector<string> *menu_elems, const int8_t *num_menu) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
attroff(COLOR_PAIR(MENU_PRINCIPAL));
|
attroff(COLOR_PAIR(MENU_PRINCIPAL));
|
||||||
userInterface(&highlight);
|
userInterface(&highlight, config);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user