| 62 | } |
| 63 | |
| 64 | bool cAvidaConfig::Load(const cString& filename, const cString& working_dir, cUserFeedback* feedback, |
| 65 | const Apto::Map<Apto::String, Apto::String>* mappings, bool warn_default) |
| 66 | { |
| 67 | Apto::Map<Apto::String, Apto::String> lmap; |
| 68 | |
| 69 | // Load the contents from the file. |
| 70 | cInitFile init_file(filename, (mappings) ? *mappings : lmap, working_dir); |
| 71 | |
| 72 | if (!init_file.WasOpened()) { |
| 73 | if (feedback) { |
| 74 | feedback->Append(init_file.GetFeedback()); |
| 75 | if (init_file.WasFound()) { |
| 76 | feedback->Error("unable to open configuration file '%s'", (const char*)filename); |
| 77 | } else { |
| 78 | feedback->Error("configuration file '%s' not found", (const char*)filename); |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | return false; |
| 83 | } |
| 84 | |
| 85 | cString version_id = init_file.ReadString("VERSION_ID", "Unknown", warn_default); |
| 86 | if (!Version::CheckCompatibility(version_id)) { |
| 87 | if (feedback) |
| 88 | feedback->Warning("config file version number mismatch -- Avida: '%s' File: '%s'", Version::String(), (const char*)version_id); |
| 89 | } |
| 90 | |
| 91 | |
| 92 | // Loop through all groups, then all entrys, and try to load each one. |
| 93 | tListIterator<cBaseConfigGroup> group_it(m_group_list); |
| 94 | cBaseConfigGroup* cur_group; |
| 95 | while ((cur_group = group_it.Next()) != NULL) { |
| 96 | // Loop through entries for this group... |
| 97 | tListIterator<cBaseConfigEntry> entry_it(cur_group->GetEntryList()); |
| 98 | cBaseConfigEntry* cur_entry; |
| 99 | while ((cur_entry = entry_it.Next()) != NULL) { |
| 100 | const Apto::Array<cString>& keywords = cur_entry->GetNames(); |
| 101 | const cString default_val = cur_entry->GetDefault(); |
| 102 | cur_entry->LoadStr( init_file.ReadString(keywords, default_val, warn_default) ); |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | |
| 107 | // Build dictionary of custom format entries |
| 108 | Apto::Map<Apto::String, cBaseConfigFormatEntry*> entry_dict; |
| 109 | |
| 110 | tListIterator<cBaseConfigCustomFormat> format_it(m_format_list); |
| 111 | cBaseConfigCustomFormat* cur_format; |
| 112 | while ((cur_format = format_it.Next())) { |
| 113 | tListIterator<cBaseConfigFormatEntry> entry_it(cur_format->GetEntryList()); |
| 114 | cBaseConfigFormatEntry* cur_entry; |
| 115 | while ((cur_entry = entry_it.Next())) { |
| 116 | Apto::String name = (const char*)cur_entry->GetName(); |
| 117 | entry_dict.Set(name, cur_entry); |
| 118 | } |
| 119 | } |
| 120 | |
| 121 |
nothing calls this directly
no test coverage detected