| 129 | } |
| 130 | |
| 131 | bool Resource::enable(EnableAction action) |
| 132 | { |
| 133 | if (m_type == ResourceType::UNKNOWN || m_type == ResourceType::FOLDER) |
| 134 | return false; |
| 135 | |
| 136 | QString path = m_file_info.absoluteFilePath(); |
| 137 | QFile file(path); |
| 138 | |
| 139 | bool enable = true; |
| 140 | switch (action) { |
| 141 | case EnableAction::ENABLE: |
| 142 | enable = true; |
| 143 | break; |
| 144 | case EnableAction::DISABLE: |
| 145 | enable = false; |
| 146 | break; |
| 147 | case EnableAction::TOGGLE: |
| 148 | default: |
| 149 | enable = !enabled(); |
| 150 | break; |
| 151 | } |
| 152 | |
| 153 | if (m_enabled == enable) |
| 154 | return false; |
| 155 | |
| 156 | if (enable) { |
| 157 | // m_enabled is false, but there's no '.disabled' suffix. |
| 158 | // TODO: Report error? |
| 159 | if (!path.endsWith(".disabled")) |
| 160 | return false; |
| 161 | path.chop(9); |
| 162 | } else { |
| 163 | path += ".disabled"; |
| 164 | if (QFile::exists(path)) { |
| 165 | path = FS::getUniqueResourceName(path); |
| 166 | } |
| 167 | } |
| 168 | if (!file.rename(path)) |
| 169 | return false; |
| 170 | |
| 171 | setFile(QFileInfo(path)); |
| 172 | |
| 173 | m_enabled = enable; |
| 174 | return true; |
| 175 | } |
| 176 | |
| 177 | bool Resource::destroy(bool attemptTrash) |
| 178 | { |