| 65 | } |
| 66 | |
| 67 | bool ResourceFolderModel::installResource(QString original_path) |
| 68 | { |
| 69 | if (!m_can_interact) { |
| 70 | return false; |
| 71 | } |
| 72 | |
| 73 | // NOTE: fix for GH-1178: remove trailing slash to avoid issues with using the empty result of QFileInfo::fileName |
| 74 | original_path = FS::NormalizePath(original_path); |
| 75 | QFileInfo file_info(original_path); |
| 76 | |
| 77 | if (!file_info.exists() || !file_info.isReadable()) { |
| 78 | qWarning() << "Caught attempt to install non-existing file or file-like object:" << original_path; |
| 79 | return false; |
| 80 | } |
| 81 | qDebug() << "Installing: " << file_info.absoluteFilePath(); |
| 82 | |
| 83 | Resource resource(file_info); |
| 84 | if (!resource.valid()) { |
| 85 | qWarning() << original_path << "is not a valid resource. Ignoring it."; |
| 86 | return false; |
| 87 | } |
| 88 | |
| 89 | auto new_path = FS::NormalizePath(m_dir.filePath(file_info.fileName())); |
| 90 | if (original_path == new_path) { |
| 91 | qWarning() << "Overwriting the mod (" << original_path << ") with itself makes no sense..."; |
| 92 | return false; |
| 93 | } |
| 94 | |
| 95 | switch (resource.type()) { |
| 96 | case ResourceType::SINGLEFILE: |
| 97 | case ResourceType::ZIPFILE: |
| 98 | case ResourceType::LITEMOD: { |
| 99 | if (QFile::exists(new_path) || QFile::exists(new_path + QString(".disabled"))) { |
| 100 | if (!QFile::remove(new_path)) { |
| 101 | qCritical() << "Cleaning up new location (" << new_path << ") was unsuccessful!"; |
| 102 | return false; |
| 103 | } |
| 104 | qDebug() << new_path << "has been deleted."; |
| 105 | } |
| 106 | |
| 107 | if (!QFile::copy(original_path, new_path)) { |
| 108 | qCritical() << "Copy from" << original_path << "to" << new_path << "has failed."; |
| 109 | return false; |
| 110 | } |
| 111 | |
| 112 | FS::updateTimestamp(new_path); |
| 113 | |
| 114 | QFileInfo new_path_file_info(new_path); |
| 115 | resource.setFile(new_path_file_info); |
| 116 | |
| 117 | if (!m_is_watching) |
| 118 | return update(); |
| 119 | |
| 120 | return true; |
| 121 | } |
| 122 | case ResourceType::FOLDER: { |
| 123 | if (QFile::exists(new_path)) { |
| 124 | qDebug() << "Ignoring folder '" << original_path << "', it would merge with" << new_path; |