From 0c98589a7f9115075f2c51f5ad134dce3d244aba Mon Sep 17 00:00:00 2001 From: Petr Mrázek Date: Wed, 10 Mar 2021 03:52:35 +0100 Subject: GH-3602 Create .minecraft before running pre-launch commands --- api/logic/minecraft/launch/CreateGameFolders.cpp | 28 ++++++++++++++++ api/logic/minecraft/launch/CreateGameFolders.h | 37 ++++++++++++++++++++++ .../launch/CreateServerResourcePacksFolder.cpp | 19 ----------- .../launch/CreateServerResourcePacksFolder.h | 37 ---------------------- 4 files changed, 65 insertions(+), 56 deletions(-) create mode 100644 api/logic/minecraft/launch/CreateGameFolders.cpp create mode 100644 api/logic/minecraft/launch/CreateGameFolders.h delete mode 100644 api/logic/minecraft/launch/CreateServerResourcePacksFolder.cpp delete mode 100644 api/logic/minecraft/launch/CreateServerResourcePacksFolder.h (limited to 'api/logic/minecraft/launch') diff --git a/api/logic/minecraft/launch/CreateGameFolders.cpp b/api/logic/minecraft/launch/CreateGameFolders.cpp new file mode 100644 index 00000000..415b7e23 --- /dev/null +++ b/api/logic/minecraft/launch/CreateGameFolders.cpp @@ -0,0 +1,28 @@ +#include "CreateGameFolders.h" +#include "minecraft/MinecraftInstance.h" +#include "launch/LaunchTask.h" +#include "FileSystem.h" + +CreateGameFolders::CreateGameFolders(LaunchTask* parent): LaunchStep(parent) +{ +} + +void CreateGameFolders::executeTask() +{ + auto instance = m_parent->instance(); + std::shared_ptr minecraftInstance = std::dynamic_pointer_cast(instance); + + if(!FS::ensureFolderPathExists(minecraftInstance->gameRoot())) + { + emit logLine("Couldn't create the main game folder", MessageLevel::Error); + emitFailed("Couldn't create the main game folder"); + return; + } + + // HACK: this is a workaround for MCL-3732 - 'server-resource-packs' folder is created. + if(!FS::ensureFolderPathExists(FS::PathCombine(minecraftInstance->gameRoot(), "server-resource-packs"))) + { + emit logLine("Couldn't create the 'server-resource-packs' folder", MessageLevel::Error); + } + emitSucceeded(); +} diff --git a/api/logic/minecraft/launch/CreateGameFolders.h b/api/logic/minecraft/launch/CreateGameFolders.h new file mode 100644 index 00000000..9c7d3c94 --- /dev/null +++ b/api/logic/minecraft/launch/CreateGameFolders.h @@ -0,0 +1,37 @@ +/* Copyright 2013-2021 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 +#include +#include + +// Create the main .minecraft for the instance and any other necessary folders +class CreateGameFolders: public LaunchStep +{ + Q_OBJECT +public: + explicit CreateGameFolders(LaunchTask *parent); + virtual ~CreateGameFolders() {}; + + virtual void executeTask(); + virtual bool canAbort() const + { + return false; + } +}; + + diff --git a/api/logic/minecraft/launch/CreateServerResourcePacksFolder.cpp b/api/logic/minecraft/launch/CreateServerResourcePacksFolder.cpp deleted file mode 100644 index ae426e31..00000000 --- a/api/logic/minecraft/launch/CreateServerResourcePacksFolder.cpp +++ /dev/null @@ -1,19 +0,0 @@ -#include "CreateServerResourcePacksFolder.h" -#include "minecraft/MinecraftInstance.h" -#include "launch/LaunchTask.h" -#include "FileSystem.h" - -CreateServerResourcePacksFolder::CreateServerResourcePacksFolder(LaunchTask* parent): LaunchStep(parent) -{ -} - -void CreateServerResourcePacksFolder::executeTask() -{ - auto instance = m_parent->instance(); - std::shared_ptr minecraftInstance = std::dynamic_pointer_cast(instance); - if(!FS::ensureFolderPathExists(FS::PathCombine(minecraftInstance->gameRoot(), "server-resource-packs"))) - { - emit logLine(tr("Couldn't create the 'server-resource-packs' folder"), MessageLevel::Error); - } - emitSucceeded(); -} diff --git a/api/logic/minecraft/launch/CreateServerResourcePacksFolder.h b/api/logic/minecraft/launch/CreateServerResourcePacksFolder.h deleted file mode 100644 index d6b9e15a..00000000 --- a/api/logic/minecraft/launch/CreateServerResourcePacksFolder.h +++ /dev/null @@ -1,37 +0,0 @@ -/* Copyright 2013-2021 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 -#include -#include - -// HACK: this is a workaround for MCL-3732 - 'server-resource-packs' folder is created. -class CreateServerResourcePacksFolder: public LaunchStep -{ - Q_OBJECT -public: - explicit CreateServerResourcePacksFolder(LaunchTask *parent); - virtual ~CreateServerResourcePacksFolder() {}; - - virtual void executeTask(); - virtual bool canAbort() const - { - return false; - } -}; - - -- cgit