Apparatus little overhaul
This commit is contained in:
parent
75e15bcc2b
commit
1c48512f62
2 changed files with 21 additions and 33 deletions
|
|
@ -4,16 +4,9 @@
|
|||
apparatus *apparatus::_instance = nullptr;
|
||||
const QString apparatus::filename = "data.bin";
|
||||
|
||||
void apparatus::open_reading_stream() {
|
||||
void apparatus::open_stream() {
|
||||
this->_bin_file = new QFile(apparatus::filename);
|
||||
this->_bin_file->open(QIODevice::ReadOnly);
|
||||
|
||||
stream.setDevice(_bin_file);
|
||||
}
|
||||
|
||||
void apparatus::open_writing_stream() {
|
||||
this->_bin_file = new QFile(apparatus::filename);
|
||||
this->_bin_file->open(QIODevice::WriteOnly);
|
||||
this->_bin_file->open(QIODevice::ReadWrite);
|
||||
|
||||
stream.setDevice(_bin_file);
|
||||
}
|
||||
|
|
@ -27,35 +20,27 @@ void apparatus::close_stream() {
|
|||
}
|
||||
|
||||
apparatus::apparatus() {
|
||||
this->open_reading_stream();
|
||||
this->loadGIDS();
|
||||
this->deserialize_data();
|
||||
this->close_stream();
|
||||
|
||||
}
|
||||
|
||||
apparatus::~apparatus() {
|
||||
if (this->_bin_file) {
|
||||
this->_bin_file->flush();
|
||||
this->_bin_file->close();
|
||||
delete this->_bin_file;
|
||||
this->_bin_file = nullptr;
|
||||
}
|
||||
this->shutdown();
|
||||
}
|
||||
|
||||
apparatus& apparatus::instance() {
|
||||
if (apparatus::_instance == nullptr) {
|
||||
apparatus::init();
|
||||
throw std::runtime_error("System non initialized!");
|
||||
}
|
||||
|
||||
return *apparatus::_instance;
|
||||
}
|
||||
|
||||
bool apparatus::isFirstRun() {
|
||||
return QFile(apparatus::filename).exists();
|
||||
return QFile().exists("first_run");
|
||||
}
|
||||
|
||||
void apparatus::generate_empty_data() {
|
||||
this->open_writing_stream();
|
||||
this->open_stream();
|
||||
this->writeGIDS();
|
||||
this->serialize_data();
|
||||
this->close_stream();
|
||||
|
|
@ -71,15 +56,18 @@ const object_system& apparatus::get_object_subsystem() {
|
|||
|
||||
void apparatus::init() {
|
||||
apparatus::_instance = new apparatus();
|
||||
|
||||
apparatus::instance().open_stream();
|
||||
apparatus::instance().loadGIDS();
|
||||
apparatus::instance().deserialize_data();
|
||||
apparatus::instance().close_stream();
|
||||
}
|
||||
|
||||
void apparatus::shutdown() {
|
||||
if (apparatus::_instance != nullptr) {
|
||||
apparatus::_instance->open_writing_stream();
|
||||
apparatus::_instance->writeGIDS();
|
||||
apparatus::_instance->serialize_data();
|
||||
apparatus::_instance->close_stream();
|
||||
}
|
||||
apparatus::instance().open_stream();
|
||||
apparatus::instance().writeGIDS();
|
||||
apparatus::instance().serialize_data();
|
||||
apparatus::instance().close_stream();
|
||||
}
|
||||
|
||||
void apparatus::writeGIDS() {
|
||||
|
|
@ -96,6 +84,7 @@ void apparatus::loadGIDS() {
|
|||
}
|
||||
|
||||
void apparatus::serialize_data() {
|
||||
QFile().remove("first_run");
|
||||
this->_auth_system.init(this->stream);
|
||||
this->_object_system.init(this->stream);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue