GraphDef* GraphDef_Recv(World *inWorld, char *buffer, GraphDef *inList)
{

	try {
		inList = GraphDefLib_Read(inWorld, buffer, inList);
	} catch (std::exception& exc) {
		scprintf("exception in GraphDef_Recv: %s\n", exc.what());
	} catch (...) {
		scprintf("unknown exception in GraphDef_Recv\n");
	}

	return inList;
}
Exemple #2
0
GraphDef* GraphDef_Load(World *inWorld, const bfs::path& path, GraphDef *inList)
{
	try {
		std::string file_contents;
		bfs::load_string_file(path, file_contents);
		inList = GraphDefLib_Read(inWorld, &file_contents[0], inList);
	} catch (const std::exception& e) {
		scprintf("exception in GraphDef_Load: %s\n", e.what());
		const std::string path_utf8_str = SC_Codecvt::path_to_utf8_str(path);
		scprintf("while reading file: '%s'", path_utf8_str.c_str());
	} catch (...) {
		scprintf("unknown exception in GrafDef_Load\n");
		const std::string path_utf8_str = SC_Codecvt::path_to_utf8_str(path);
		scprintf("while reading file '%s'\n", path_utf8_str.c_str());
	}

	return inList;
}
GraphDef* GraphDef_Load(World *inWorld, const char *filename, GraphDef *inList)
{
	FILE *file = fopen(filename, "rb");

	if (!file) {
		scprintf("*** ERROR: can't fopen '%s'\n", filename);
		return inList;
	}

	fseek(file, 0, SEEK_END);
	int size = ftell(file);
	char *buffer = (char*)malloc(size);
	if (!buffer) {
		scprintf("*** ERROR: can't malloc buffer size %d\n", size);
		fclose(file);
		return inList;
	}
	fseek(file, 0, SEEK_SET);

	size_t readSize = fread(buffer, 1, size, file);
	fclose(file);

	if (readSize!= size) {
		scprintf("*** ERROR: invalid fread\n", size);
		free(buffer);
		return inList;
	}

	try {
		inList = GraphDefLib_Read(inWorld, buffer, inList);
	} catch (std::exception& exc) {
		scprintf("exception in GrafDef_Load: %s\n", exc.what());
		scprintf("while reading file '%s'\n", filename);
	} catch (...) {
		scprintf("unknown exception in GrafDef_Load\n");
		scprintf("while reading file '%s'\n", filename);
	}

	free(buffer);

	return inList;
}