2021-01-18 07:28:54 +00:00
|
|
|
/* Copyright 2013-2021 MultiMC Contributors
|
2014-01-23 20:31:41 +00:00
|
|
|
*
|
|
|
|
* 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 <QFile>
|
|
|
|
|
2015-02-09 00:51:14 +00:00
|
|
|
#include "BaseInstaller.h"
|
2017-07-24 08:01:37 +01:00
|
|
|
#include "minecraft/MinecraftInstance.h"
|
2014-01-23 20:31:41 +00:00
|
|
|
|
2023-08-14 17:16:53 +01:00
|
|
|
BaseInstaller::BaseInstaller() {}
|
2014-01-23 20:31:41 +00:00
|
|
|
|
2023-08-14 17:16:53 +01:00
|
|
|
bool BaseInstaller::isApplied(MinecraftInstance* on)
|
2014-01-23 20:31:41 +00:00
|
|
|
{
|
|
|
|
return QFile::exists(filename(on->instanceRoot()));
|
|
|
|
}
|
|
|
|
|
2023-08-14 17:16:53 +01:00
|
|
|
bool BaseInstaller::add(MinecraftInstance* to)
|
2014-01-23 20:31:41 +00:00
|
|
|
{
|
2023-08-14 17:16:53 +01:00
|
|
|
if (!patchesDir(to->instanceRoot()).exists()) {
|
2014-01-23 20:31:41 +00:00
|
|
|
QDir(to->instanceRoot()).mkdir("patches");
|
|
|
|
}
|
2018-07-15 13:51:05 +01:00
|
|
|
|
2023-08-14 17:16:53 +01:00
|
|
|
if (isApplied(to)) {
|
|
|
|
if (!remove(to)) {
|
2014-01-23 20:31:41 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2018-07-15 13:51:05 +01:00
|
|
|
|
2014-01-23 20:31:41 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2023-08-14 17:16:53 +01:00
|
|
|
bool BaseInstaller::remove(MinecraftInstance* from)
|
2014-01-23 20:31:41 +00:00
|
|
|
{
|
|
|
|
return QFile::remove(filename(from->instanceRoot()));
|
|
|
|
}
|
|
|
|
|
2023-08-14 17:16:53 +01:00
|
|
|
QString BaseInstaller::filename(const QString& root) const
|
2014-01-23 20:31:41 +00:00
|
|
|
{
|
|
|
|
return patchesDir(root).absoluteFilePath(id() + ".json");
|
|
|
|
}
|
2023-08-14 17:16:53 +01:00
|
|
|
QDir BaseInstaller::patchesDir(const QString& root) const
|
2014-01-23 20:31:41 +00:00
|
|
|
{
|
|
|
|
return QDir(root + "/patches/");
|
|
|
|
}
|