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

Method installResource

launcher/minecraft/mod/ResourceFolderModel.cpp:85–159  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers 4

processURLsMethod · 0.80
addItemMethod · 0.80
test_removeResourceFunction · 0.80
test_enable_disableFunction · 0.80

Calls 10

NormalizePathFunction · 0.85
QStringClass · 0.85
deletePathFunction · 0.85
copyClass · 0.85
updateTimestampFunction · 0.85
existsMethod · 0.80
filePathMethod · 0.80
setFileMethod · 0.80
validMethod · 0.45
typeMethod · 0.45

Tested by 2

test_removeResourceFunction · 0.64
test_enable_disableFunction · 0.64