| 113 | |
| 114 | |
| 115 | void File::Load(const fs::path &cfgfile) |
| 116 | { |
| 117 | std::string fname = cfgfile.empty() ? config_filename : cfgfile; |
| 118 | if (fname.empty()) |
| 119 | { |
| 120 | throw ConfigFileException("No configuration filename provided"); |
| 121 | } |
| 122 | |
| 123 | std::ifstream cfgs(fname); |
| 124 | if (cfgs.eof() || cfgs.fail()) |
| 125 | { |
| 126 | throw ConfigFileException(fname, "Could not open file"); |
| 127 | } |
| 128 | |
| 129 | // Read the configuration file |
| 130 | std::string line; |
| 131 | std::stringstream buf; |
| 132 | while (std::getline(cfgs, line)) |
| 133 | { |
| 134 | buf << line << std::endl; |
| 135 | } |
| 136 | |
| 137 | // Don't try to parse an empty file |
| 138 | if (0 == buf.tellp()) |
| 139 | { |
| 140 | return; |
| 141 | } |
| 142 | |
| 143 | // Parse the configuration file |
| 144 | Json::Value jcfg; |
| 145 | try |
| 146 | { |
| 147 | buf >> jcfg; |
| 148 | Parse(jcfg); |
| 149 | } |
| 150 | catch (const Json::Exception &excp) |
| 151 | { |
| 152 | throw ConfigFileException(fname, "Error parsing file:" + std::string(excp.what())); |
| 153 | } |
| 154 | } |
| 155 | |
| 156 | |
| 157 | std::vector<std::string> File::GetOptions(bool all_configured) |