| 150 | } |
| 151 | |
| 152 | bool INIFile::loadFile(QString fileName) |
| 153 | { |
| 154 | QSettings _settings_obj{ fileName, QSettings::Format::IniFormat }; |
| 155 | _settings_obj.setFallbacksEnabled(false); |
| 156 | |
| 157 | if (auto status = _settings_obj.status(); status != QSettings::Status::NoError) { |
| 158 | if (status == QSettings::Status::AccessError) |
| 159 | qCritical() << "An access error occurred (e.g. trying to write to a read-only file)."; |
| 160 | if (status == QSettings::Status::FormatError) |
| 161 | qCritical() << "A format error occurred (e.g. loading a malformed INI file)."; |
| 162 | return false; |
| 163 | } |
| 164 | if (!_settings_obj.value("ConfigVersion").isValid()) { |
| 165 | QFile file(fileName); |
| 166 | if (!file.open(QIODevice::ReadOnly)) |
| 167 | return false; |
| 168 | QSettings::SettingsMap map; |
| 169 | parseOldFileFormat(file, map); |
| 170 | file.close(); |
| 171 | for (auto&& key : map.keys()) |
| 172 | insert(key, map.value(key)); |
| 173 | insert("ConfigVersion", "1.2"); |
| 174 | } else if (_settings_obj.value("ConfigVersion").toString() == "1.1") { |
| 175 | for (auto&& key : _settings_obj.allKeys()) { |
| 176 | if (auto valueStr = _settings_obj.value(key).toString(); |
| 177 | (valueStr.contains(QChar(';')) || valueStr.contains(QChar('=')) || valueStr.contains(QChar(','))) && |
| 178 | valueStr.endsWith("\"") && valueStr.startsWith("\"")) { |
| 179 | insert(key, unquote(valueStr)); |
| 180 | } else |
| 181 | insert(key, _settings_obj.value(key)); |
| 182 | } |
| 183 | insert("ConfigVersion", "1.2"); |
| 184 | } else |
| 185 | for (auto&& key : _settings_obj.allKeys()) |
| 186 | insert(key, _settings_obj.value(key)); |
| 187 | return true; |
| 188 | } |
| 189 | |
| 190 | bool INIFile::loadFile(QByteArray data) |
| 191 | { |