FIXME: this does not take disabled mod (with extra .disable extension) into account...
| 222 | |
| 223 | // FIXME: this does not take disabled mod (with extra .disable extension) into account... |
| 224 | bool ModFolderModel::installMod(const QString &filename) |
| 225 | { |
| 226 | if(interaction_disabled) { |
| 227 | return false; |
| 228 | } |
| 229 | |
| 230 | // NOTE: fix for GH-1178: remove trailing slash to avoid issues with using the empty result of QFileInfo::fileName |
| 231 | auto originalPath = FS::NormalizePath(filename); |
| 232 | QFileInfo fileinfo(originalPath); |
| 233 | |
| 234 | if (!fileinfo.exists() || !fileinfo.isReadable()) |
| 235 | { |
| 236 | qWarning() << "Caught attempt to install non-existing file or file-like object:" << originalPath; |
| 237 | return false; |
| 238 | } |
| 239 | qDebug() << "installing: " << fileinfo.absoluteFilePath(); |
| 240 | |
| 241 | Mod installedMod(fileinfo); |
| 242 | if (!installedMod.valid()) |
| 243 | { |
| 244 | qDebug() << originalPath << "is not a valid mod. Ignoring it."; |
| 245 | return false; |
| 246 | } |
| 247 | |
| 248 | auto type = installedMod.type(); |
| 249 | if (type == Mod::MOD_UNKNOWN) |
| 250 | { |
| 251 | qDebug() << "Cannot recognize mod type of" << originalPath << ", ignoring it."; |
| 252 | return false; |
| 253 | } |
| 254 | |
| 255 | auto newpath = FS::NormalizePath(FS::PathCombine(m_dir.path(), fileinfo.fileName())); |
| 256 | if(originalPath == newpath) |
| 257 | { |
| 258 | qDebug() << "Overwriting the mod (" << originalPath << ") with itself makes no sense..."; |
| 259 | return false; |
| 260 | } |
| 261 | |
| 262 | if (type == Mod::MOD_SINGLEFILE || type == Mod::MOD_ZIPFILE || type == Mod::MOD_LITEMOD) |
| 263 | { |
| 264 | if(QFile::exists(newpath) || QFile::exists(newpath + QString(".disabled"))) |
| 265 | { |
| 266 | if(!QFile::remove(newpath)) |
| 267 | { |
| 268 | // FIXME: report error in a user-visible way |
| 269 | qWarning() << "Copy from" << originalPath << "to" << newpath << "has failed."; |
| 270 | return false; |
| 271 | } |
| 272 | qDebug() << newpath << "has been deleted."; |
| 273 | } |
| 274 | if (!QFile::copy(fileinfo.filePath(), newpath)) |
| 275 | { |
| 276 | qWarning() << "Copy from" << originalPath << "to" << newpath << "has failed."; |
| 277 | // FIXME: report error in a user-visible way |
| 278 | return false; |
| 279 | } |
| 280 | FS::updateTimestamp(newpath); |
| 281 | installedMod.repath(newpath); |
no test coverage detected