moved PlusROM id generation outside GUI code

This commit is contained in:
Thomas Jentzsch 2021-10-02 08:42:05 +02:00
parent ff4bb3cd77
commit 7c2721ef2e
2 changed files with 15 additions and 15 deletions

View File

@ -513,6 +513,21 @@ string OSystem::createConsole(const FilesystemNode& rom, const string& md5sum,
if(myConsole->cartridge().isPlusROM() &&
settings().getString("plusroms.id") == EmptyString)
{
// Make sure there always is an id
if(settings().getString("plusroms.id") == EmptyString)
{
const int ID_LEN = 32 - 2; // WE prefix added later
const char* HEX_DIGITS = "0123456789ABCDEF";
char id_chr[ID_LEN] = {0};
srand(time(NULL));
for(int i = 0; i < ID_LEN; i++)
id_chr[i] = HEX_DIGITS[(rand() % 16)];
std::string id_str(id_chr, ID_LEN);
settings().setValue("plusroms.id", id_str);
}
myEventHandler->changeStateByEvent(Event::PlusRomsSetupMode);
}
}

View File

@ -21,7 +21,6 @@
#include "PlusRomsSetupDialog.hxx"
static const int MAX_NICK_LEN = 16;
static const int ID_LEN = 32 - 2; // WE prefix added later
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
PlusRomsSetupDialog::PlusRomsSetupDialog(OSystem& osystem, DialogContainer& parent,
@ -40,20 +39,6 @@ PlusRomsSetupDialog::PlusRomsSetupDialog(OSystem& osystem, DialogContainer& pare
void PlusRomsSetupDialog::loadConfig()
{
setText(instance().settings().getString("plusroms.nick"));
// Make sure there always is an id
if(instance().settings().getString("plusroms.id") == EmptyString)
{
const char* HEX_DIGITS = "0123456789ABCDEF";
char id_chr[ID_LEN];
srand(time(nullptr));
for(int i = 0; i < ID_LEN; i++)
id_chr[i] = HEX_DIGITS[(rand() % 16)];
std::string id_str(id_chr, ID_LEN);
instance().settings().setValue("plusroms.id", id_str);
}
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -