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;
|
||||
|
||||
public:
|
||||
Config(int8_t nh, std::string t);
|
||||
~Config();
|
||||
Config(int8_t numHilos, std::string tiempo);
|
||||
// ~Config();
|
||||
int8_t getNumHilos();
|
||||
std::string getTiempo();
|
||||
void setNumHilos(int8_t nh);
|
||||
void setTiempo(std::string t);
|
||||
void setNumHilos(int8_t numHilos);
|
||||
void setTiempo(std::string timepo);
|
||||
};
|
||||
#endif // __CONFIG_HPP_
|
||||
|
@ -4,11 +4,11 @@
|
||||
#ifndef __CONFIG_FILE_HPP_
|
||||
#define __CONFIG_FILE_HPP_
|
||||
namespace cf {
|
||||
const std::string g_cofigFile = "~/.config/stressUI.cfg";
|
||||
Config *openConfig();
|
||||
const std::string g_configFile =
|
||||
std::string(getenv("HOME")) + "/.config/stressUI.cfg";
|
||||
Config openConfig();
|
||||
void closeConfig(Config *config);
|
||||
std::string getLine(std::ifstream *file);
|
||||
void saveConfig();
|
||||
void createConfig();
|
||||
void saveConfig(Config *config);
|
||||
} // namespace cf
|
||||
#endif // __CONFIG_FILE_HPP_
|
||||
|
@ -1,19 +1,15 @@
|
||||
#include "config.hpp"
|
||||
|
||||
Config::Config(int8_t nh, std::string t) {
|
||||
Config::numHilos = &nh;
|
||||
Config::tiempo = &t;
|
||||
Config::Config(int8_t numHilos, std::string tiempo) {
|
||||
Config::numHilos = &numHilos;
|
||||
Config::tiempo = &tiempo;
|
||||
}
|
||||
|
||||
Config::~Config() {
|
||||
delete Config::numHilos;
|
||||
delete Config::tiempo;
|
||||
}
|
||||
|
||||
int8_t Config::getNumHilos() { return *Config::numHilos; }
|
||||
|
||||
void Config::setNumHilos(int8_t nh) { Config::numHilos = &nh; }
|
||||
|
||||
std::string Config::getTiempo() { return *Config::tiempo; }
|
||||
|
||||
void Config::setTiempo(std::string t) { Config::tiempo = &t; }
|
||||
// Config::~Config() {
|
||||
// delete numHilos;
|
||||
// delete tiempo;
|
||||
// }
|
||||
int8_t Config::getNumHilos() { return *numHilos; }
|
||||
std::string Config::getTiempo() { return *tiempo; }
|
||||
void Config::setNumHilos(int8_t numHilos) { Config::numHilos = &numHilos; }
|
||||
void Config::setTiempo(std::string tiempo) { Config::tiempo = &tiempo; }
|
||||
|
@ -1,8 +1,9 @@
|
||||
#include "configFile.hpp"
|
||||
#include <sstream>
|
||||
|
||||
Config *cf::openConfig() {
|
||||
std::ifstream file(g_cofigFile);
|
||||
Config cf::openConfig() {
|
||||
std::ifstream file;
|
||||
file.open(cf::g_configFile);
|
||||
if (file.is_open()) {
|
||||
std::string line;
|
||||
line = cf::getLine(&file);
|
||||
@ -10,13 +11,10 @@ Config *cf::openConfig() {
|
||||
std::string t = cf::getLine(&file);
|
||||
Config config = Config(nh, t);
|
||||
file.close();
|
||||
Config *ptr = &config;
|
||||
return ptr;
|
||||
// Config *ptr = &config;
|
||||
return config;
|
||||
} else {
|
||||
// file.close();
|
||||
// cf::createConfig();
|
||||
// return cf::openConfig();
|
||||
return nullptr;
|
||||
return Config(0, "");
|
||||
}
|
||||
}
|
||||
|
||||
@ -34,6 +32,13 @@ std::string cf::getLine(std::ifstream *file) {
|
||||
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, vector<string> *mensaje);
|
||||
void userInterface(const int8_t *menu, Config *config);
|
||||
void userInterface(const int8_t *menu, vector<string> *mensaje, Config *config);
|
||||
void showMenu(vector<string> *menu_elems, const int8_t *num_menu,
|
||||
vector<string> *mensaje);
|
||||
void showMenu(vector<string> *menu_elems, const int8_t *num_menu);
|
||||
vector<string> *mensaje, Config *config);
|
||||
void showMenu(vector<string> *menu_elems, const int8_t *num_menu,
|
||||
Config *config);
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
locale::global(locale("es_ES.utf8"));
|
||||
@ -48,32 +49,34 @@ int main(int argc, char *argv[]) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
Config *config = cf::openConfig();
|
||||
Config config = cf::openConfig();
|
||||
|
||||
if (config == nullptr) {
|
||||
userInterface(&PRIMER_INICIO);
|
||||
if (config.getTiempo() == "") {
|
||||
userInterface(&PRIMER_INICIO, &config);
|
||||
} else {
|
||||
|
||||
userInterface(&MENU_PRINCIPAL);
|
||||
userInterface(&MENU_PRINCIPAL, &config);
|
||||
}
|
||||
|
||||
ui::closeUI();
|
||||
return 0;
|
||||
}
|
||||
|
||||
void userInterface(const int8_t *menu) {
|
||||
void userInterface(const int8_t *menu, Config *config) {
|
||||
/*int8_t menu_num = inputToInt(menu);*/
|
||||
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) {
|
||||
|
||||
case CONFIGURAR_MENU_PRINCIPAL:
|
||||
case MENU_PRINCIPAL: {
|
||||
vector<string> elem_menu = {"- Iniciar Stress Test", "- Configurar",
|
||||
"- Salir"};
|
||||
showMenu(&elem_menu, &MENU_PRINCIPAL, mensaje);
|
||||
showMenu(&elem_menu, &MENU_PRINCIPAL, mensaje, config);
|
||||
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",
|
||||
"- Tiempo", "- Menú principal"};
|
||||
|
||||
showMenu(&elem_menu, num_menu, mensaje);
|
||||
showMenu(&elem_menu, num_menu, mensaje, config);
|
||||
break;
|
||||
}
|
||||
|
||||
@ -94,13 +97,15 @@ void userInterface(const int8_t *num_menu, vector<string> *mensaje) {
|
||||
case PRIMER_INICIO: {
|
||||
|
||||
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> "};
|
||||
ui::showTopTitle(&TITULO_PRINCIPAL);
|
||||
ui::showCentralInputBox(&textos_init, &CONFIGURAR_TODO, &elemens,
|
||||
TITULO_PRINCIPAL.size());
|
||||
|
||||
userInterface(&MENU_CONFIGURACION, mensaje);
|
||||
vector<string> entrada = ui::showCentralInputBox(
|
||||
&textos_init, &CONFIGURAR_TODO, &elemens, TITULO_PRINCIPAL.size());
|
||||
Config config2 = Config(atoi(entrada[0].c_str()), entrada[1]);
|
||||
config = &config2;
|
||||
cf::saveConfig(config);
|
||||
userInterface(&MENU_PRINCIPAL, mensaje, config);
|
||||
break;
|
||||
}
|
||||
|
||||
@ -125,23 +130,24 @@ void userInterface(const int8_t *num_menu, vector<string> *mensaje) {
|
||||
*mensaje = {"¿Como has llegado aquí?",
|
||||
"Por si acaso vamos al menú principal"};
|
||||
|
||||
userInterface(&MENU_PRINCIPAL, mensaje);
|
||||
userInterface(&MENU_PRINCIPAL, mensaje, config);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void showMenu(vector<string> *menu_elems, const int8_t *num_menu,
|
||||
vector<string> *mensaje) {
|
||||
vector<string> *mensaje, Config *config) {
|
||||
clear();
|
||||
if (ui::g_mensaje) {
|
||||
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();
|
||||
|
||||
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));
|
||||
userInterface(&highlight);
|
||||
userInterface(&highlight, config);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user