2017-12-29 06:13:28 +01:00
|
|
|
#ifdef _MSC_VER
|
2021-02-20 23:22:10 +01:00
|
|
|
#ifndef _CRT_SECURE_NO_WARNINGS
|
|
|
|
#define _CRT_SECURE_NO_WARNINGS
|
|
|
|
#endif
|
2017-12-29 06:13:28 +01:00
|
|
|
#endif
|
2012-06-07 04:29:36 +02:00
|
|
|
#include "bind_eressea.h"
|
|
|
|
|
2014-03-15 06:30:07 +01:00
|
|
|
#include "json.h"
|
2017-10-07 19:44:23 +02:00
|
|
|
#include "orderfile.h"
|
2014-03-13 15:33:44 +01:00
|
|
|
|
2014-10-16 07:34:09 +02:00
|
|
|
#include <kernel/faction.h>
|
2014-12-31 00:20:19 +01:00
|
|
|
#include <kernel/item.h>
|
2012-06-07 04:29:36 +02:00
|
|
|
#include <kernel/config.h>
|
|
|
|
#include <kernel/save.h>
|
2013-12-31 10:06:28 +01:00
|
|
|
|
2017-02-11 17:38:39 +01:00
|
|
|
#include <util/language.h>
|
2018-09-28 20:50:24 +02:00
|
|
|
#include <util/log.h>
|
2017-02-11 17:38:39 +01:00
|
|
|
|
2014-03-13 15:33:44 +01:00
|
|
|
#include <stream.h>
|
2018-09-23 19:44:05 +02:00
|
|
|
#include <stdio.h>
|
2014-03-13 15:33:44 +01:00
|
|
|
#include <filestream.h>
|
|
|
|
|
2012-06-07 04:29:36 +02:00
|
|
|
|
|
|
|
void eressea_free_game(void) {
|
2015-01-30 20:37:14 +01:00
|
|
|
free_gamedata();
|
|
|
|
init_resources();
|
2018-10-06 20:47:23 +02:00
|
|
|
init_locales(init_locale);
|
2012-06-07 04:29:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int eressea_read_game(const char * filename) {
|
2021-03-15 20:00:58 +01:00
|
|
|
if (filename) {
|
|
|
|
return readgame(filename);
|
|
|
|
}
|
|
|
|
return -1;
|
2015-01-30 20:37:14 +01:00
|
|
|
}
|
2012-06-07 04:29:36 +02:00
|
|
|
|
|
|
|
int eressea_write_game(const char * filename) {
|
2021-03-15 20:00:58 +01:00
|
|
|
if (filename) {
|
|
|
|
remove_empty_factions();
|
|
|
|
return writegame(filename);
|
|
|
|
}
|
|
|
|
return -1;
|
2012-06-07 04:29:36 +02:00
|
|
|
}
|
2012-06-07 18:47:02 +02:00
|
|
|
|
|
|
|
int eressea_read_orders(const char * filename) {
|
2021-03-15 20:00:58 +01:00
|
|
|
if (filename) {
|
|
|
|
FILE *F = fopen(filename, "r");
|
|
|
|
int result;
|
2018-10-29 20:06:18 +01:00
|
|
|
|
2021-03-15 20:00:58 +01:00
|
|
|
if (!F) {
|
|
|
|
perror(filename);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
log_info("reading orders from %s", filename);
|
|
|
|
result = parseorders(F);
|
|
|
|
fclose(F);
|
|
|
|
return result;
|
2018-09-28 20:50:24 +02:00
|
|
|
}
|
2021-03-15 20:00:58 +01:00
|
|
|
return -1;
|
2012-06-07 18:47:02 +02:00
|
|
|
}
|
2014-03-13 15:33:44 +01:00
|
|
|
|
2014-06-21 16:34:36 +02:00
|
|
|
int eressea_export_json(const char * filename, int flags) {
|
2021-03-15 20:00:58 +01:00
|
|
|
if (filename) {
|
|
|
|
FILE *F = fopen(filename, "w");
|
|
|
|
if (F) {
|
|
|
|
stream out = { 0 };
|
|
|
|
int err;
|
|
|
|
fstream_init(&out, F);
|
|
|
|
err = json_export(&out, flags);
|
|
|
|
fstream_done(&out);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
perror(filename);
|
2014-03-13 15:33:44 +01:00
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
2014-03-16 09:51:08 +01:00
|
|
|
|
|
|
|
int eressea_import_json(const char * filename) {
|
2021-03-15 20:00:58 +01:00
|
|
|
if (filename) {
|
|
|
|
FILE *F = fopen(filename, "r");
|
|
|
|
if (F) {
|
|
|
|
stream out = { 0 };
|
|
|
|
int err;
|
|
|
|
fstream_init(&out, F);
|
|
|
|
err = json_import(&out);
|
|
|
|
fstream_done(&out);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
perror(filename);
|
2014-03-16 09:51:08 +01:00
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|