diff options
Diffstat (limited to 'api/logic/meta/tasks')
-rw-r--r-- | api/logic/meta/tasks/LocalLoadTask.cpp | 57 | ||||
-rw-r--r-- | api/logic/meta/tasks/LocalLoadTask.h | 39 | ||||
-rw-r--r-- | api/logic/meta/tasks/RemoteLoadTask.cpp | 103 | ||||
-rw-r--r-- | api/logic/meta/tasks/RemoteLoadTask.h | 46 |
4 files changed, 0 insertions, 245 deletions
diff --git a/api/logic/meta/tasks/LocalLoadTask.cpp b/api/logic/meta/tasks/LocalLoadTask.cpp deleted file mode 100644 index b64fc5d3..00000000 --- a/api/logic/meta/tasks/LocalLoadTask.cpp +++ /dev/null @@ -1,57 +0,0 @@ -/* Copyright 2015-2017 MultiMC Contributors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "LocalLoadTask.h" - -#include <QFile> - -#include "meta/format/Format.h" -#include "meta/Util.h" -#include "meta/Index.h" -#include "meta/Version.h" -#include "meta/VersionList.h" -#include "Env.h" -#include "Json.h" - -namespace Meta -{ -LocalLoadTask::LocalLoadTask(BaseEntity *entity, QObject *parent) - : Task(parent), m_entity(entity) -{ -} - -void LocalLoadTask::executeTask() -{ - const QString fname = Meta::localDir().absoluteFilePath(m_entity->localFilename()); - if (!QFile::exists(fname)) - { - emitFailed(tr("File doesn't exist")); - return; - } - setStatus(tr("Reading %1...").arg(fname)); - setProgress(0, 0); - - try - { - m_entity->parse(Json::requireObject(Json::requireDocument(fname, fname), fname)); - m_entity->notifyLocalLoadComplete(); - emitSucceeded(); - } - catch (Exception &e) - { - emitFailed(tr("Unable to parse file %1: %2").arg(fname, e.cause())); - } -} -} diff --git a/api/logic/meta/tasks/LocalLoadTask.h b/api/logic/meta/tasks/LocalLoadTask.h deleted file mode 100644 index 905660ed..00000000 --- a/api/logic/meta/tasks/LocalLoadTask.h +++ /dev/null @@ -1,39 +0,0 @@ -/* Copyright 2015-2017 MultiMC Contributors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include "tasks/Task.h" -#include <memory> - -namespace Meta -{ -class BaseEntity; -class Index; -class VersionList; -class Version; - -// FIXME: this is now just an odd function, get rid of it -class LocalLoadTask : public Task -{ - Q_OBJECT -public: - explicit LocalLoadTask(BaseEntity *entity, QObject *parent = nullptr); - -private: - void executeTask() override; - BaseEntity *m_entity; -}; -} diff --git a/api/logic/meta/tasks/RemoteLoadTask.cpp b/api/logic/meta/tasks/RemoteLoadTask.cpp deleted file mode 100644 index b73af021..00000000 --- a/api/logic/meta/tasks/RemoteLoadTask.cpp +++ /dev/null @@ -1,103 +0,0 @@ -/* Copyright 2015-2017 MultiMC Contributors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "RemoteLoadTask.h" - -#include "net/Download.h" -#include "net/HttpMetaCache.h" -#include "net/NetJob.h" -#include "meta/format/Format.h" -#include "meta/Util.h" -#include "meta/Index.h" -#include "meta/Version.h" -#include "meta/VersionList.h" -#include "Env.h" -#include "Json.h" - -namespace Meta -{ - -RemoteLoadTask::RemoteLoadTask(BaseEntity *entity, QObject *parent) - : Task(parent), m_entity(entity) -{ -} - -class ParsingValidator : public Net::Validator -{ -public: /* con/des */ - ParsingValidator(BaseEntity *entity) : m_entity(entity) - { - }; - virtual ~ParsingValidator() - { - }; - -public: /* methods */ - bool init(QNetworkRequest &) override - { - return true; - } - bool write(QByteArray & data) override - { - this->data.append(data); - return true; - } - bool abort() override - { - return true; - } - bool validate(QNetworkReply &) override - { - auto fname = m_entity->localFilename(); - try - { - m_entity->parse(Json::requireObject(Json::requireDocument(data, fname), fname)); - m_entity->notifyRemoteLoadComplete(); - return true; - } - catch (Exception &e) - { - qWarning() << "Unable to parse response:" << e.cause(); - return false; - } - } - -private: /* data */ - QByteArray data; - BaseEntity *m_entity; -}; - -void RemoteLoadTask::executeTask() -{ - // FIXME: leak here!!! - NetJob *job = new NetJob(tr("Download of meta file %1").arg(m_entity->localFilename())); - - auto url = m_entity->url(); - auto entry = ENV.metacache()->resolveEntry("meta", m_entity->localFilename()); - entry->setStale(true); - m_dl = Net::Download::makeCached(url, entry); - /* - * The validator parses the file and loads it into the object. - * If that fails, the file is not written to storage. - */ - m_dl->addValidator(new ParsingValidator(m_entity)); - job->addNetAction(m_dl); - connect(job, &NetJob::failed, this, &RemoteLoadTask::emitFailed); - connect(job, &NetJob::succeeded, this, &RemoteLoadTask::succeeded); - connect(job, &NetJob::status, this, &RemoteLoadTask::setStatus); - connect(job, &NetJob::progress, this, &RemoteLoadTask::setProgress); - job->start(); -} -} diff --git a/api/logic/meta/tasks/RemoteLoadTask.h b/api/logic/meta/tasks/RemoteLoadTask.h deleted file mode 100644 index 6d81d8ea..00000000 --- a/api/logic/meta/tasks/RemoteLoadTask.h +++ /dev/null @@ -1,46 +0,0 @@ -/* Copyright 2015-2017 MultiMC Contributors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include "tasks/Task.h" -#include <memory> - -namespace Net -{ -class Download; -} - -namespace Meta -{ -class BaseEntity; -class Index; -class VersionList; -class Version; - -// FIXME: this is now just an oddly constructed NetJob, get rid of it. -class RemoteLoadTask : public Task -{ - Q_OBJECT -public: - explicit RemoteLoadTask(BaseEntity *entity, QObject *parent = nullptr); - -private: - void executeTask() override; - - BaseEntity *m_entity; - std::shared_ptr<Net::Download> m_dl; -}; -} |