File: def_files.cpp

package info (click to toggle)
freespace2 24.2.0%2Brepack-1
  • links: PTS, VCS
  • area: non-free
  • in suites: forky, sid
  • size: 43,716 kB
  • sloc: cpp: 595,001; ansic: 21,741; python: 1,174; sh: 457; makefile: 248; xml: 181
file content (58 lines) | stat: -rw-r--r-- 1,229 bytes parent folder | download | duplicates (2)
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*
 * You may not sell or otherwise commercially exploit the source or things you
 * create based on the source.
 */

#include "globalincs/pstypes.h"
#include "def_files/def_files.h"

#include <iterator>

struct def_file
{
	const char* path_type;
	const char* filename;
	const void* contents;
	const size_t size;
};

#include "embedded_files.inc"

default_file defaults_get_file(const char *filename)
{
	default_file def{};

	auto endIter = std::end(Default_files);
	for (auto iter = std::begin(Default_files); iter != endIter; ++iter)
	{
		if (!stricmp(iter->filename, filename))
		{
			def.path_type = iter->path_type;
			def.filename = iter->filename;
			def.data = iter->contents;
			def.size = iter->size;

			return def;
		}
	}

	//WMC - This is really bad, because it means we have a default table missing.
	Error(LOCATION, "Default table '%s' missing from executable - contact a coder.", filename);
	return def;
}

SCP_vector<default_file> defaults_get_all() {
	SCP_vector<default_file> files;

	for (const auto& file : Default_files) {
		default_file def;
		def.path_type = file.path_type;
		def.filename = file.filename;
		def.data = file.contents;
		def.size = file.size;

		files.push_back(def);
	}

	return files;
}