MCPcopy Create free account
hub / github.com/FreesmTeam/FreesmLauncher / enable

Method enable

launcher/minecraft/mod/Resource.cpp:131–175  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

129}
130
131bool 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
177bool Resource::destroy(bool attemptTrash)
178{

Callers 3

openedImplMethod · 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