refactor without raw pointers
This commit is contained in:
@@ -102,20 +102,12 @@ static bool save_prefs(fs::path fpath) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool load_prefs(fs::path fpath) {
|
static bool load_prefs(std::istream& in) {
|
||||||
prefsDirty = false;
|
prefsDirty = false;
|
||||||
std::map<std::string,boost::any> temp_prefs;
|
std::map<std::string,boost::any> temp_prefs;
|
||||||
std::istream* in;
|
|
||||||
if (replaying) {
|
|
||||||
Element* prefs_action = pop_next_action("load_prefs");
|
|
||||||
in = new std::istringstream(prefs_action->GetText());
|
|
||||||
} else {
|
|
||||||
in = new std::ifstream(fpath.c_str());
|
|
||||||
}
|
|
||||||
(fpath.string().c_str());
|
|
||||||
std::string line;
|
std::string line;
|
||||||
std::ostringstream prefs_recording;
|
std::ostringstream prefs_recording;
|
||||||
while(std::getline(*in, line)) {
|
while(std::getline(in, line)) {
|
||||||
if(!in) {
|
if(!in) {
|
||||||
perror("Error reading preferences");
|
perror("Error reading preferences");
|
||||||
return false;
|
return false;
|
||||||
@@ -156,7 +148,6 @@ static bool load_prefs(fs::path fpath) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
prefs.swap(temp_prefs);
|
prefs.swap(temp_prefs);
|
||||||
delete in;
|
|
||||||
|
|
||||||
if (recording) {
|
if (recording) {
|
||||||
record_action("load_prefs", prefs_recording.str());
|
record_action("load_prefs", prefs_recording.str());
|
||||||
@@ -165,6 +156,19 @@ static bool load_prefs(fs::path fpath) {
|
|||||||
return prefsLoaded = true;
|
return prefsLoaded = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool load_prefs(fs::path fpath) {
|
||||||
|
// When replaying a BoE session, disregard the system settings and use the ones
|
||||||
|
// that were recorded
|
||||||
|
if (replaying) {
|
||||||
|
Element* prefs_action = pop_next_action("load_prefs");
|
||||||
|
std::istringstream in(prefs_action->GetText());
|
||||||
|
return load_prefs(in);
|
||||||
|
} else {
|
||||||
|
std::ifstream in(fpath.c_str());
|
||||||
|
return load_prefs(in);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
extern fs::path tempDir;
|
extern fs::path tempDir;
|
||||||
bool sync_prefs() {
|
bool sync_prefs() {
|
||||||
fs::path prefsPath = tempDir.parent_path() / "bladesprefs.ini";
|
fs::path prefsPath = tempDir.parent_path() / "bladesprefs.ini";
|
||||||
|
@@ -74,5 +74,6 @@ Element* pop_next_action(std::string expected_action_type) {
|
|||||||
|
|
||||||
Element* clone = next_action->Clone()->ToElement();
|
Element* clone = next_action->Clone()->ToElement();
|
||||||
root->RemoveChild(next_action);
|
root->RemoveChild(next_action);
|
||||||
|
|
||||||
return clone;
|
return clone;
|
||||||
}
|
}
|
Reference in New Issue
Block a user