2#include <boost/filesystem.hpp>
5namespace cavoke::server::model {
7Game::Game(
const boost::filesystem::path &directory,
8 const GamesStorageConfig &game_storage_config)
9 : directory(directory),
10 logic_file(directory / LOGIC_FILE),
11 client_file(directory / CLIENT_FILE),
12 CLIENT_FILE(game_storage_config.zip_name),
13 LOGIC_FILE(game_storage_config.logic_name),
14 CONFIG_FILE(game_storage_config.config_name) {
15 json j = json::parse(std::ifstream(directory / CONFIG_FILE));
16 config = j.get<GameConfig>();
20bool check_is_directory(
const boost::filesystem::path &path) {
21 return exists(path) && is_directory(path);
24bool check_is_regular_file(
const boost::filesystem::path &path) {
25 return exists(path) && is_regular_file(path);
28bool check_valid_game_config(
const boost::filesystem::path &path) {
30 json j = json::parse(std::ifstream(path));
31 auto conf = j.get<GameConfig>();
39bool Game::is_game_directory(
const boost::filesystem::path &path,
40 const GamesStorageConfig &games_storage_config) {
41 return check_is_directory(path) &&
42 check_is_regular_file(path / games_storage_config.zip_name) &&
43 check_is_regular_file(path / games_storage_config.logic_name) &&
44 check_valid_game_config(path / games_storage_config.config_name);