| 204 | } |
| 205 | |
| 206 | bool Resource::enable(EnableAction action) |
| 207 | { |
| 208 | if (m_type == ResourceType::UNKNOWN || m_type == ResourceType::FOLDER) |
| 209 | return false; |
| 210 | |
| 211 | QString path = m_file_info.absoluteFilePath(); |
| 212 | QFile file(path); |
| 213 | |
| 214 | bool enable = true; |
| 215 | switch (action) { |
| 216 | case EnableAction::ENABLE: |
| 217 | enable = true; |
| 218 | break; |
| 219 | case EnableAction::DISABLE: |
| 220 | enable = false; |
| 221 | break; |
| 222 | case EnableAction::TOGGLE: |
| 223 | default: |
| 224 | enable = !enabled(); |
| 225 | break; |
| 226 | } |
| 227 | |
| 228 | if (m_enabled == enable) |
| 229 | return false; |
| 230 | |
| 231 | if (enable) { |
| 232 | // m_enabled is false, but there's no '.disabled' suffix. |
| 233 | // TODO: Report error? |
| 234 | if (!path.endsWith(".disabled")) |
| 235 | return false; |
| 236 | path.chop(9); |
| 237 | } else { |
| 238 | path += ".disabled"; |
| 239 | if (QFile::exists(path)) { |
| 240 | path = FS::getUniqueResourceName(path); |
| 241 | } |
| 242 | } |
| 243 | if (!file.rename(path)) |
| 244 | return false; |
| 245 | |
| 246 | setFile(QFileInfo(path)); |
| 247 | |
| 248 | m_enabled = enable; |
| 249 | return true; |
| 250 | } |
| 251 | |
| 252 | auto Resource::destroy(const QDir& index_dir, bool preserve_metadata, bool attempt_trash) -> bool |
| 253 | { |