aboutsummaryrefslogtreecommitdiff
path: root/LoadFilesCommand.cpp
blob: 9a0ca082837f9e4579c986ddfa3b37da6eb5e3b0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <vector>
#include <string>

#include "LoadFilesCommand.h"
#include "Deserializer.h"
#include "Exception.h"
#include "FileReader.h"
#include "FileStrategy.h"
#include "MuseumPauseCommand.h"
#include "Parser.h"

using namespace std;

void LoadFilesCommand::execute(int argc, char ** argv) {
	vector<string> files = {};
	for (size_t i = 0; i < argc; i++) {
		files.push_back(string(argv[i]));
	}
	return this->execute(files);
}

void LoadFilesCommand::execute(vector<string> files) {
	try {
		this->load_files(files);
	} catch (Exception & e) {
		throw Exception("LoadFilesCommand error: %s", e.what());
	}
}

void LoadFilesCommand::load_files(vector<string> files) {
	MuseumPauseCommand(this).set(true);

	Deserializer deserializer { this->get_museum() };
	for (string url : files) {
		unique_ptr<FileStrategy> file = FileReader::open(url);
		try {
			Parser::parse(*file, deserializer);
		} catch (Exception & e) {
			throw Exception("parser error: %s (%s)", e.what(), url.c_str());
		}
	}
}