#include #include #include "LoadFilesCommand.h" #include "MuseumDeserializer.h" #include "Exception.h" #include "FileReaderFactory.h" #include "FileReader.h" #include "ToggleMuseumPauseCommand.h" #include "ParserFactory.h" using namespace std; LoadFilesCommand::LoadFilesCommand(Museum & m, int argc, char ** argv) : museum(m) { vector files = {}; for (size_t i = 0; i < argc; i++) { files.push_back(string(argv[i])); } this->files = files; } LoadFilesCommand::LoadFilesCommand(Museum & m, vector files) : museum(m) { this->files = files; } void LoadFilesCommand::load_files() { ToggleMuseumPauseCommand(this->museum, true).execute(); MuseumDeserializer deserializer { this->museum }; for (string url : files) { unique_ptr file = FileReaderFactory::open(url); try { ParserFactory::parse(*file, deserializer); } catch (Exception & e) { throw Exception("parser error: %s (%s)", e.what(), url.c_str()); } } } void LoadFilesCommand::execute() { try { this->load_files(); } catch (Exception & e) { throw Exception("LoadFilesCommand error: %s", e.what()); } }