| 125 | } |
| 126 | |
| 127 | void V1::updateModIndex(QDir& index_dir, Mod& mod) |
| 128 | { |
| 129 | if (!mod.isValid()) { |
| 130 | qCritical() << QString("Tried to update metadata of an invalid mod!"); |
| 131 | return; |
| 132 | } |
| 133 | |
| 134 | // Ensure the corresponding mod's info exists, and create it if not |
| 135 | |
| 136 | auto normalized_fname = indexFileName(mod.slug); |
| 137 | auto real_fname = getRealIndexName(index_dir, normalized_fname); |
| 138 | |
| 139 | QFile index_file(index_dir.absoluteFilePath(real_fname)); |
| 140 | |
| 141 | if (real_fname != normalized_fname) |
| 142 | index_file.rename(normalized_fname); |
| 143 | |
| 144 | // There's already data on there! |
| 145 | // TODO: We should do more stuff here, as the user is likely trying to |
| 146 | // override a file. In this case, check versions and ask the user what |
| 147 | // they want to do! |
| 148 | if (index_file.exists()) { |
| 149 | index_file.remove(); |
| 150 | } |
| 151 | |
| 152 | if (!index_file.open(QIODevice::ReadWrite)) { |
| 153 | qCritical() << QString("Could not open file %1!").arg(indexFileName(mod.name)); |
| 154 | return; |
| 155 | } |
| 156 | |
| 157 | // Put TOML data into the file |
| 158 | QTextStream in_stream(&index_file); |
| 159 | auto addToStream = [&in_stream](QString&& key, QString value) { in_stream << QString("%1 = \"%2\"\n").arg(key, value); }; |
| 160 | |
| 161 | { |
| 162 | addToStream("name", mod.name); |
| 163 | addToStream("filename", mod.filename); |
| 164 | addToStream("side", mod.side); |
| 165 | |
| 166 | in_stream << QString("\n[download]\n"); |
| 167 | addToStream("mode", mod.mode); |
| 168 | addToStream("url", mod.url.toString()); |
| 169 | addToStream("hash-format", mod.hash_format); |
| 170 | addToStream("hash", mod.hash); |
| 171 | |
| 172 | in_stream << QString("\n[update]\n"); |
| 173 | in_stream << QString("[update.%1]\n").arg(ProviderCaps.name(mod.provider)); |
| 174 | switch (mod.provider) { |
| 175 | case (ModPlatform::Provider::FLAME): |
| 176 | in_stream << QString("file-id = %1\n").arg(mod.file_id.toString()); |
| 177 | in_stream << QString("project-id = %1\n").arg(mod.project_id.toString()); |
| 178 | break; |
| 179 | case (ModPlatform::Provider::MODRINTH): |
| 180 | addToStream("mod-id", mod.mod_id().toString()); |
| 181 | addToStream("version", mod.version().toString()); |
| 182 | break; |
| 183 | } |
| 184 | in_stream << QString("\n[update.do_updates]\n"); |
nothing calls this directly
no test coverage detected