-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathCoverConfig.cpp
58 lines (53 loc) · 1.93 KB
/
CoverConfig.cpp
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
#include "CoverConfig.h"
#include "utils.h"
CoverConfigMap builtInCoverConfigs() {
CoverConfigMap map;
const char** p = builtInCoverConfigArray;
while (*p != nullptr) {
const char* name = *(p++);
const char* script = *(p++);
map[name] = CoverConfig{script, true};
}
PFC_ASSERT(map.count(defaultCoverConfig) == 1);
PFC_ASSERT(map.count(coverConfigTemplate) == 1);
return map;
}
cfg_coverConfigs::cfg_coverConfigs(const GUID& p_guid)
: cfg_var(p_guid), CoverConfigMap(builtInCoverConfigs()) {}
void cfg_coverConfigs::get_data_raw(stream_writer* p_stream, abort_callback& p_abort) {
p_stream->write_lendian_t(version, p_abort);
int customCount = std::count_if(
begin(), end(), [](CoverConfigMap::value_type& x) { return !x.second.buildIn; });
p_stream->write_lendian_t(customCount, p_abort);
for (auto& [name, config] : *this) {
if (config.buildIn)
continue;
p_stream->write_string(name.c_str(), p_abort);
p_stream->write_string(config.script.c_str(), p_abort);
}
}
void cfg_coverConfigs::set_data_raw(stream_reader* p_stream, t_size /*p_sizehint*/,
abort_callback& p_abort) {
int c, v;
p_stream->read_lendian_t(v, p_abort);
if (v != 1) {
MessageBox(
nullptr,
L"Couldn't load cover configs (incompatible version)\r\nIf you have not done it "
L"yet, kill foobar with the taskmanager and make a backup of your coverflow "
L"configs with the version of foo_chronflow you created them with.",
L"foo_chronflow - loading Error", MB_ICONERROR);
return;
}
p_stream->read_lendian_t(c, p_abort);
clear();
for (int i = 0; i < c; i++) {
pfc::string8 name;
pfc::string8 script;
p_stream->read_string(name, p_abort);
p_stream->read_string(script, p_abort);
insert({name.c_str(), CoverConfig{script.c_str(), false}});
}
auto builtIn = builtInCoverConfigs();
insert(builtIn.begin(), builtIn.end());
}