MCPcopy Create free account
hub / github.com/ElyPrismLauncher/Launcher / enable

Method enable

launcher/minecraft/mod/Resource.cpp:206–250  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

204}
205
206bool 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
252auto Resource::destroy(const QDir& index_dir, bool preserve_metadata, bool attempt_trash) -> bool
253{

Callers 3

checkCandidatesMethod · 0.45
setResourceEnabledMethod · 0.45
test_enable_disableFunction · 0.45

Calls 3

getUniqueResourceNameFunction · 0.85
QFileInfoClass · 0.85
renameMethod · 0.45

Tested by 1

test_enable_disableFunction · 0.36