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

Method processURLs

launcher/ui/MainWindow.cpp:910–1073  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

908}
909
910void MainWindow::processURLs(QList<QUrl> urls)
911{
912 // NOTE: This loop only processes one dropped file!
913 for (auto& url : urls) {
914 qDebug() << "Processing" << url;
915
916 // The isLocalFile() check below doesn't work as intended without an explicit scheme.
917 if (url.scheme().isEmpty())
918 url.setScheme("file");
919
920 ModPlatform::IndexedVersion version;
921 QMap<QString, QString> extra_info;
922 QUrl local_url;
923 if (!url.isLocalFile()) { // download the remote resource and identify
924 QUrl dl_url;
925 if (url.scheme() == "curseforge") {
926 // need to find the download link for the modpack / resource
927 // format of url curseforge://install?addonId=IDHERE&fileId=IDHERE
928 QUrlQuery query(url);
929
930 if (query.allQueryItemValues("addonId").isEmpty() || query.allQueryItemValues("fileId").isEmpty()) {
931 qDebug() << "Invalid curseforge link:" << url;
932 continue;
933 }
934
935 auto addonId = query.allQueryItemValues("addonId")[0];
936 auto fileId = query.allQueryItemValues("fileId")[0];
937
938 extra_info.insert("pack_id", addonId);
939 extra_info.insert("pack_version_id", fileId);
940
941 auto array = std::make_shared<QByteArray>();
942
943 auto api = FlameAPI();
944 auto job = api.getFile(addonId, fileId, array);
945
946 connect(job.get(), &Task::failed, this,
947 [this](QString reason) { CustomMessageBox::selectable(this, tr("Error"), reason, QMessageBox::Critical)->show(); });
948 connect(job.get(), &Task::succeeded, this, [this, array, addonId, fileId, &dl_url, &version] {
949 qDebug() << "Returned CFURL Json:\n" << array->toStdString().c_str();
950 auto doc = Json::requireDocument(*array);
951 auto data = Json::ensureObject(Json::ensureObject(doc.object()), "data");
952 // No way to find out if it's a mod or a modpack before here
953 // And also we need to check if it ends with .zip, instead of any better way
954 version = FlameMod::loadIndexedPackVersion(data);
955 auto fileName = version.fileName;
956
957 // Have to use ensureString then use QUrl to get proper url encoding
958 dl_url = QUrl(version.downloadUrl);
959 if (!dl_url.isValid()) {
960 CustomMessageBox::selectable(
961 this, tr("Error"),
962 tr("The modpack, mod, or resource %1 is blocked for third-parties! Please download it manually.").arg(fileName),
963 QMessageBox::Critical)
964 ->show();
965 return;
966 }
967

Callers 3

eventMethod · 0.80
messageReceivedMethod · 0.80

Calls 15

FlameAPIClass · 0.85
selectableFunction · 0.85
requireDocumentFunction · 0.85
QUrlClass · 0.85
identifyFunction · 0.85
insertMethod · 0.80
getFileMethod · 0.80
showMethod · 0.80
objectMethod · 0.80
setSkipButtonMethod · 0.80
execWithTaskMethod · 0.80
resolveEntryMethod · 0.80

Tested by

no test coverage detected