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