From 253067c782955380bbf66ac0475dc954375b1ff4 Mon Sep 17 00:00:00 2001 From: Petr Mrázek Date: Sat, 17 Aug 2013 13:40:51 +0200 Subject: Move all the things (YES. Move them.) Also, implemented some basic modlist logic, to be wired up. --- backend/BaseInstance.cpp | 181 -------------- backend/BaseInstance.h | 143 ----------- backend/BaseInstance_p.h | 14 -- backend/BaseUpdate.cpp | 13 - backend/BaseUpdate.h | 50 ---- backend/CMakeLists.txt | 120 ---------- backend/IconListModel.cpp | 163 ------------- backend/IconListModel.h | 33 --- backend/InstanceFactory.cpp | 113 --------- backend/InstanceFactory.h | 81 ------- backend/InstanceVersion.h | 69 ------ backend/LegacyForge.cpp | 57 ----- backend/LegacyForge.h | 25 -- backend/LegacyInstance.cpp | 229 ------------------ backend/LegacyInstance.h | 85 ------- backend/LegacyInstance_p.h | 10 - backend/LegacyUpdate.cpp | 381 ------------------------------ backend/LegacyUpdate.h | 68 ------ backend/MinecraftProcess.cpp | 169 ------------- backend/MinecraftProcess.h | 88 ------- backend/MinecraftVersion.h | 78 ------ backend/Mod.cpp | 264 --------------------- backend/Mod.h | 69 ------ backend/ModList.cpp | 418 --------------------------------- backend/ModList.h | 75 ------ backend/NostalgiaInstance.cpp | 12 - backend/NostalgiaInstance.h | 10 - backend/OneSixAssets.cpp | 162 ------------- backend/OneSixAssets.h | 22 -- backend/OneSixInstance.cpp | 211 ----------------- backend/OneSixInstance.h | 32 --- backend/OneSixInstance_p.h | 9 - backend/OneSixUpdate.cpp | 169 ------------- backend/OneSixUpdate.h | 55 ----- backend/OneSixVersion.cpp | 132 ----------- backend/OneSixVersion.h | 212 ----------------- backend/VersionFactory.cpp | 195 --------------- backend/VersionFactory.h | 24 -- backend/libmmc_config.h | 24 -- backend/lists/InstVersionList.cpp | 129 ---------- backend/lists/InstVersionList.h | 122 ---------- backend/lists/InstanceList.cpp | 232 ------------------ backend/lists/InstanceList.h | 92 -------- backend/lists/LwjglVersionList.cpp | 206 ---------------- backend/lists/LwjglVersionList.h | 119 ---------- backend/lists/MinecraftVersionList.cpp | 300 ----------------------- backend/lists/MinecraftVersionList.h | 84 ------- backend/net/DownloadJob.cpp | 138 ----------- backend/net/DownloadJob.h | 51 ---- backend/net/JobQueue.h | 180 -------------- backend/net/NetWorker.cpp | 12 - backend/net/NetWorker.h | 20 -- backend/tasks/LoginTask.cpp | 111 --------- backend/tasks/LoginTask.h | 59 ----- backend/tasks/Task.cpp | 85 ------- backend/tasks/Task.h | 67 ------ 56 files changed, 6272 deletions(-) delete mode 100644 backend/BaseInstance.cpp delete mode 100644 backend/BaseInstance.h delete mode 100644 backend/BaseInstance_p.h delete mode 100644 backend/BaseUpdate.cpp delete mode 100644 backend/BaseUpdate.h delete mode 100644 backend/CMakeLists.txt delete mode 100644 backend/IconListModel.cpp delete mode 100644 backend/IconListModel.h delete mode 100644 backend/InstanceFactory.cpp delete mode 100644 backend/InstanceFactory.h delete mode 100644 backend/InstanceVersion.h delete mode 100644 backend/LegacyForge.cpp delete mode 100644 backend/LegacyForge.h delete mode 100644 backend/LegacyInstance.cpp delete mode 100644 backend/LegacyInstance.h delete mode 100644 backend/LegacyInstance_p.h delete mode 100644 backend/LegacyUpdate.cpp delete mode 100644 backend/LegacyUpdate.h delete mode 100644 backend/MinecraftProcess.cpp delete mode 100644 backend/MinecraftProcess.h delete mode 100644 backend/MinecraftVersion.h delete mode 100644 backend/Mod.cpp delete mode 100644 backend/Mod.h delete mode 100644 backend/ModList.cpp delete mode 100644 backend/ModList.h delete mode 100644 backend/NostalgiaInstance.cpp delete mode 100644 backend/NostalgiaInstance.h delete mode 100644 backend/OneSixAssets.cpp delete mode 100644 backend/OneSixAssets.h delete mode 100644 backend/OneSixInstance.cpp delete mode 100644 backend/OneSixInstance.h delete mode 100644 backend/OneSixInstance_p.h delete mode 100644 backend/OneSixUpdate.cpp delete mode 100644 backend/OneSixUpdate.h delete mode 100644 backend/OneSixVersion.cpp delete mode 100644 backend/OneSixVersion.h delete mode 100644 backend/VersionFactory.cpp delete mode 100644 backend/VersionFactory.h delete mode 100644 backend/libmmc_config.h delete mode 100644 backend/lists/InstVersionList.cpp delete mode 100644 backend/lists/InstVersionList.h delete mode 100644 backend/lists/InstanceList.cpp delete mode 100644 backend/lists/InstanceList.h delete mode 100644 backend/lists/LwjglVersionList.cpp delete mode 100644 backend/lists/LwjglVersionList.h delete mode 100644 backend/lists/MinecraftVersionList.cpp delete mode 100644 backend/lists/MinecraftVersionList.h delete mode 100644 backend/net/DownloadJob.cpp delete mode 100644 backend/net/DownloadJob.h delete mode 100644 backend/net/JobQueue.h delete mode 100644 backend/net/NetWorker.cpp delete mode 100644 backend/net/NetWorker.h delete mode 100644 backend/tasks/LoginTask.cpp delete mode 100644 backend/tasks/LoginTask.h delete mode 100644 backend/tasks/Task.cpp delete mode 100644 backend/tasks/Task.h (limited to 'backend') diff --git a/backend/BaseInstance.cpp b/backend/BaseInstance.cpp deleted file mode 100644 index 951b403a..00000000 --- a/backend/BaseInstance.cpp +++ /dev/null @@ -1,181 +0,0 @@ -/* Copyright 2013 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 "BaseInstance.h" -#include "BaseInstance_p.h" - -#include - -#include "inisettingsobject.h" -#include "setting.h" -#include "overridesetting.h" - -#include "pathutils.h" -#include - - -BaseInstance::BaseInstance( BaseInstancePrivate* d_in, - const QString& rootDir, - SettingsObject* settings_obj, - QObject* parent - ) -:inst_d(d_in), QObject(parent) -{ - I_D(BaseInstance); - d->m_settings = settings_obj; - d->m_rootDir = rootDir; - - settings().registerSetting(new Setting("name", "Unnamed Instance")); - settings().registerSetting(new Setting("iconKey", "default")); - settings().registerSetting(new Setting("notes", "")); - settings().registerSetting(new Setting("lastLaunchTime", 0)); - - // Java Settings - settings().registerSetting(new Setting("OverrideJava", false)); - settings().registerSetting(new OverrideSetting("JavaPath", globalSettings->getSetting("JavaPath"))); - settings().registerSetting(new OverrideSetting("JvmArgs", globalSettings->getSetting("JvmArgs"))); - - // Custom Commands - settings().registerSetting(new Setting("OverrideCommands", false)); - settings().registerSetting(new OverrideSetting("PreLaunchCommand", globalSettings->getSetting("PreLaunchCommand"))); - settings().registerSetting(new OverrideSetting("PostExitCommand", globalSettings->getSetting("PostExitCommand"))); - - // Window Size - settings().registerSetting(new Setting("OverrideWindow", false)); - settings().registerSetting(new OverrideSetting("LaunchMaximized", globalSettings->getSetting("LaunchMaximized"))); - settings().registerSetting(new OverrideSetting("MinecraftWinWidth", globalSettings->getSetting("MinecraftWinWidth"))); - settings().registerSetting(new OverrideSetting("MinecraftWinHeight", globalSettings->getSetting("MinecraftWinHeight"))); - - // Memory - settings().registerSetting(new Setting("OverrideMemory", false)); - settings().registerSetting(new OverrideSetting("MinMemAlloc", globalSettings->getSetting("MinMemAlloc"))); - settings().registerSetting(new OverrideSetting("MaxMemAlloc", globalSettings->getSetting("MaxMemAlloc"))); - - // Auto login - settings().registerSetting(new Setting("OverrideLogin", false)); - settings().registerSetting(new OverrideSetting("AutoLogin", globalSettings->getSetting("AutoLogin"))); - - // Console - settings().registerSetting(new Setting("OverrideConsole", false)); - settings().registerSetting(new OverrideSetting("ShowConsole", globalSettings->getSetting("ShowConsole"))); - settings().registerSetting(new OverrideSetting("AutoCloseConsole", globalSettings->getSetting("AutoCloseConsole"))); -} - -QString BaseInstance::id() const -{ - return QFileInfo(instanceRoot()).fileName(); -} - -QString BaseInstance::instanceType() const -{ - I_D(BaseInstance); - return d->m_settings->get("InstanceType").toString(); -} - - -QString BaseInstance::instanceRoot() const -{ - I_D(BaseInstance); - return d->m_rootDir; -} - -QString BaseInstance::minecraftRoot() const -{ - QFileInfo mcDir(PathCombine(instanceRoot(), "minecraft")); - QFileInfo dotMCDir(PathCombine(instanceRoot(), ".minecraft")); - - if (dotMCDir.exists() && !mcDir.exists()) - return dotMCDir.filePath(); - else - return mcDir.filePath(); -} - -InstanceList *BaseInstance::instList() const -{ - if (parent()->inherits("InstanceList")) - return (InstanceList *)parent(); - else - return NULL; -} - -InstVersionList *BaseInstance::versionList() const -{ - return &MinecraftVersionList::getMainList(); -} - -SettingsObject &BaseInstance::settings() const -{ - I_D(BaseInstance); - return *d->m_settings; -} - -qint64 BaseInstance::lastLaunch() const -{ - I_D(BaseInstance); - return d->m_settings->get ( "lastLaunchTime" ).value(); -} -void BaseInstance::setLastLaunch ( qint64 val ) -{ - I_D(BaseInstance); - d->m_settings->set ( "lastLaunchTime", val ); - emit propertiesChanged ( this ); -} - -void BaseInstance::setGroup ( QString val ) -{ - I_D(BaseInstance); - d->m_group = val; - emit propertiesChanged ( this ); -} -QString BaseInstance::group() const -{ - I_D(BaseInstance); - return d->m_group; -} - -void BaseInstance::setNotes ( QString val ) -{ - I_D(BaseInstance); - d->m_settings->set ( "notes", val ); -} -QString BaseInstance::notes() const -{ - I_D(BaseInstance); - return d->m_settings->get ( "notes" ).toString(); -} - -void BaseInstance::setIconKey ( QString val ) -{ - I_D(BaseInstance); - d->m_settings->set ( "iconKey", val ); - emit propertiesChanged ( this ); -} -QString BaseInstance::iconKey() const -{ - I_D(BaseInstance); - return d->m_settings->get ( "iconKey" ).toString(); -} - -void BaseInstance::setName ( QString val ) -{ - I_D(BaseInstance); - d->m_settings->set ( "name", val ); - emit propertiesChanged ( this ); -} -QString BaseInstance::name() const -{ - I_D(BaseInstance); - return d->m_settings->get ( "name" ).toString(); -} diff --git a/backend/BaseInstance.h b/backend/BaseInstance.h deleted file mode 100644 index 05f3ce00..00000000 --- a/backend/BaseInstance.h +++ /dev/null @@ -1,143 +0,0 @@ -/* Copyright 2013 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 - -#include "inifile.h" -#include "lists/InstVersionList.h" - -#include "libmmc_config.h" - -class BaseUpdate; -class MinecraftProcess; -class OneSixUpdate; -class InstanceList; -class BaseInstancePrivate; - -/*! - * \brief Base class for instances. - * This class implements many functions that are common between instances and - * provides a standard interface for all instances. - * - * To create a new instance type, create a new class inheriting from this class - * and implement the pure virtual functions. - */ -class LIBMULTIMC_EXPORT BaseInstance : public QObject -{ - Q_OBJECT -protected: - /// no-touchy! - BaseInstance(BaseInstancePrivate * d, const QString &rootDir, SettingsObject * settings, QObject *parent = 0); -public: - /// virtual destructor to make sure the destruction is COMPLETE - virtual ~BaseInstance() {}; - - /// The instance's ID. The ID SHALL be determined by MMC internally. The ID IS guaranteed to be unique. - QString id() const; - - /// get the type of this instance - QString instanceType() const; - - /// Path to the instance's root directory. - QString instanceRoot() const; - - /// Path to the instance's minecraft directory. - QString minecraftRoot() const; - - QString name() const; - void setName(QString val); - - QString iconKey() const; - void setIconKey(QString val); - - QString notes() const; - void setNotes(QString val); - - QString group() const; - void setGroup(QString val); - - virtual QString intendedVersionId() const = 0; - virtual bool setIntendedVersionId(QString version) = 0; - - /*! - * The instance's current version. - * This value represents the instance's current version. If this value is - * different from the intendedVersion, the instance should be updated. - * \warning Don't change this value unless you know what you're doing. - */ - virtual QString currentVersionId() const = 0; - //virtual void setCurrentVersionId(QString val) = 0; - - /*! - * Whether or not Minecraft should be downloaded when the instance is launched. - */ - virtual bool shouldUpdate() const = 0; - virtual void setShouldUpdate(bool val) = 0; - - /** - * Gets the time that the instance was last launched. - * Stored in milliseconds since epoch. - */ - qint64 lastLaunch() const; - /// Sets the last launched time to 'val' milliseconds since epoch - void setLastLaunch(qint64 val = QDateTime::currentMSecsSinceEpoch()); - - /*! - * \brief Gets the instance list that this instance is a part of. - * Returns NULL if this instance is not in a list - * (the parent is not an InstanceList). - * \return A pointer to the InstanceList containing this instance. - */ - InstanceList *instList() const; - - /*! - * \brief Gets a pointer to this instance's version list. - * \return A pointer to the available version list for this instance. - */ - virtual InstVersionList *versionList() const; - - /*! - * \brief Gets this instance's settings object. - * This settings object stores instance-specific settings. - * \return A pointer to this instance's settings object. - */ - virtual SettingsObject &settings() const; - - /// returns a valid update task if update is needed, NULL otherwise - virtual BaseUpdate* doUpdate() = 0; - - /// returns a valid minecraft process, ready for launch - virtual MinecraftProcess* prepareForLaunch(QString user, QString session) = 0; - - /// do any necessary cleanups after the instance finishes. also runs before 'prepareForLaunch' - virtual void cleanupAfterRun() = 0; -signals: - /*! - * \brief Signal emitted when properties relevant to the instance view change - */ - void propertiesChanged(BaseInstance * inst); - -protected: - QSharedPointer inst_d; -}; - -// pointer for lazy people -typedef QSharedPointer InstancePtr; - diff --git a/backend/BaseInstance_p.h b/backend/BaseInstance_p.h deleted file mode 100644 index a30916a4..00000000 --- a/backend/BaseInstance_p.h +++ /dev/null @@ -1,14 +0,0 @@ -#pragma once -#include -#include - -class BaseInstance; - -#define I_D(Class) Class##Private * const d = (Class##Private * const) inst_d.data() - -struct BaseInstancePrivate -{ - QString m_rootDir; - QString m_group; - SettingsObject *m_settings; -}; \ No newline at end of file diff --git a/backend/BaseUpdate.cpp b/backend/BaseUpdate.cpp deleted file mode 100644 index b086ab14..00000000 --- a/backend/BaseUpdate.cpp +++ /dev/null @@ -1,13 +0,0 @@ -#include "BaseUpdate.h" - -BaseUpdate::BaseUpdate ( BaseInstance* inst, QObject* parent ) : Task ( parent ) -{ - m_inst = inst; -} - -void BaseUpdate::updateDownloadProgress(qint64 current, qint64 total) -{ - // The progress on the current file is current / total - float currentDLProgress = (float) current / (float) total; - setProgress((int)(currentDLProgress * 100)); // convert to percentage -} \ No newline at end of file diff --git a/backend/BaseUpdate.h b/backend/BaseUpdate.h deleted file mode 100644 index b7d2017e..00000000 --- a/backend/BaseUpdate.h +++ /dev/null @@ -1,50 +0,0 @@ -/* Copyright 2013 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 - -#include "net/DownloadJob.h" - -#include "tasks/Task.h" -#include "libmmc_config.h" - -class MinecraftVersion; -class BaseInstance; - -/*! - * The game update task is the task that handles downloading instances' files. - */ -class LIBMULTIMC_EXPORT BaseUpdate : public Task -{ - Q_OBJECT -public: - explicit BaseUpdate(BaseInstance *inst, QObject *parent = 0); - - virtual void executeTask() = 0; - -protected slots: - //virtual void error(const QString &msg); - void updateDownloadProgress(qint64 current, qint64 total); - -protected: - JobListQueue download_queue; - BaseInstance *m_inst; -}; - - diff --git a/backend/CMakeLists.txt b/backend/CMakeLists.txt deleted file mode 100644 index 7a92d5cf..00000000 --- a/backend/CMakeLists.txt +++ /dev/null @@ -1,120 +0,0 @@ -project(libMultiMC) - -set(CMAKE_AUTOMOC ON) - -# Find Qt -find_package(Qt5Core REQUIRED) -find_package(Qt5Network REQUIRED) -find_package(Qt5Xml REQUIRED) - -# Include Qt headers. -include_directories(${Qt5Base_INCLUDE_DIRS}) -include_directories(${Qt5Network_INCLUDE_DIRS}) - -# Include utility library. -include_directories(${CMAKE_SOURCE_DIR}/libutil/include) - -# Include settings library. -include_directories(${CMAKE_SOURCE_DIR}/libsettings/include) - -SET(LIBINST_HEADERS -libmmc_config.h - -# Base classes and infrastructure -InstanceVersion.h -MinecraftVersion.h -InstanceFactory.h -BaseUpdate.h -BaseInstance.h -BaseInstance_p.h -MinecraftProcess.h -Mod.h -ModList.h - -# network stuffs -net/DownloadJob.h -net/JobQueue.h -net/NetWorker.h - -# legacy instances -LegacyInstance.h -LegacyInstance_p.h -LegacyUpdate.h -LegacyForge.h - -# 1.6 instances -OneSixAssets.h -OneSixInstance.h -OneSixInstance_p.h -OneSixUpdate.h -OneSixVersion.h -VersionFactory.h - -# Nostalgia -NostalgiaInstance.h - -# Lists -lists/InstanceList.h -lists/InstVersionList.h -lists/MinecraftVersionList.h -lists/LwjglVersionList.h -IconListModel.h - -# Tasks -tasks/Task.h -tasks/LoginTask.h -) - -SET(LIBINST_SOURCES -# Base classes and infrastructure -InstanceFactory.cpp -BaseUpdate.cpp -BaseInstance.cpp -MinecraftProcess.cpp -Mod.cpp -ModList.cpp - -# network stuffs -net/NetWorker.cpp -net/DownloadJob.cpp - -# legacy instances -LegacyInstance.cpp -LegacyUpdate.cpp -LegacyForge.cpp - -# 1.6 instances -OneSixAssets.cpp -OneSixInstance.cpp -OneSixVersion.cpp -OneSixUpdate.cpp -VersionFactory.cpp - -# Nostalgia -NostalgiaInstance.cpp - -# Lists -lists/InstanceList.cpp -lists/InstVersionList.cpp -lists/MinecraftVersionList.cpp -lists/LwjglVersionList.cpp -IconListModel.cpp - -# Tasks -tasks/Task.cpp -tasks/LoginTask.cpp -) - -# Set the include dir path. -SET(LIBMULTIMC_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}" PARENT_SCOPE) - -# Include self. -include_directories(${CMAKE_CURRENT_SOURCE_DIR}) -include_directories(${CMAKE_BINARY_DIR}/include) - -add_definitions(-DLIBMULTIMC_LIBRARY) - -add_library(backend SHARED ${LIBINST_SOURCES} ${LIBINST_HEADERS}) -qt5_use_modules(backend Core Network Xml) -target_link_libraries(backend libUtil libSettings quazip) - diff --git a/backend/IconListModel.cpp b/backend/IconListModel.cpp deleted file mode 100644 index 2d2fb6cf..00000000 --- a/backend/IconListModel.cpp +++ /dev/null @@ -1,163 +0,0 @@ -#include "IconListModel.h" -#include -#include -#include -#include - -#define MAX_SIZE 1024 -IconList* IconList::m_Instance = 0; -QMutex IconList::mutex; - -struct entry -{ - QString key; - QString name; - QIcon icon; - bool is_builtin; -}; - -class Private : public QObject -{ - Q_OBJECT -public: - QMap index; - QVector icons; - Private() - { - } -}; - - -IconList::IconList() : QAbstractListModel(), d(new Private()) -{ - QDir instance_icons(":/icons/instances/"); - auto file_info_list = instance_icons.entryInfoList(QDir::Files, QDir::Name); - for(auto file_info: file_info_list) - { - QString key = file_info.baseName(); - addIcon(key, key, file_info.absoluteFilePath(), true); - } - - // FIXME: get from settings - ensurePathExists("icons/"); - QDir user_icons("icons/"); - file_info_list = user_icons.entryInfoList(QDir::Files, QDir::Name); - for(auto file_info: file_info_list) - { - QString filename = file_info.absoluteFilePath(); - QString key = file_info.baseName(); - addIcon(key, key, filename); - } -} - -IconList::~IconList() -{ - delete d; - d = nullptr; -} - -QVariant IconList::data ( const QModelIndex& index, int role ) const -{ - if(!index.isValid()) - return QVariant(); - - int row = index.row(); - - if(row < 0 || row >= d->icons.size()) - return QVariant(); - - switch(role) - { - case Qt::DecorationRole: - return d->icons[row].icon; - case Qt::DisplayRole: - return d->icons[row].name; - case Qt::UserRole: - return d->icons[row].key; - default: - return QVariant(); - } -} - -int IconList::rowCount ( const QModelIndex& parent ) const -{ - return d->icons.size(); -} - -bool IconList::addIcon ( QString key, QString name, QString path, bool is_builtin ) -{ - auto iter = d->index.find(key); - if(iter != d->index.end()) - { - if(d->icons[*iter].is_builtin) return false; - - QIcon icon(path); - if(icon.isNull()) return false; - - // replace the icon - d->icons[*iter] = {key, name, icon, is_builtin}; - return true; - } - else - { - QIcon icon(path); - if(icon.isNull()) return false; - - // add a new icon - d->icons.push_back({key, name, icon, is_builtin}); - d->index[key] = d->icons.size() - 1; - return true; - } -} - - -QIcon IconList::getIcon ( QString key ) -{ - int icon_index = getIconIndex(key); - - if(icon_index != -1) - return d->icons[icon_index].icon; - - // Fallback for icons that don't exist. - icon_index = getIconIndex("infinity"); - - if(icon_index != -1) - return d->icons[icon_index].icon; - return QIcon(); -} - -int IconList::getIconIndex ( QString key ) -{ - if(key == "default") - key = "infinity"; - - auto iter = d->index.find(key); - if(iter != d->index.end()) - return *iter; - - - return -1; -} - - -void IconList::drop() -{ - mutex.lock(); - delete m_Instance; - m_Instance = 0; - mutex.unlock(); -} - -IconList* IconList::instance() -{ - if ( !m_Instance ) - { - mutex.lock(); - if ( !m_Instance ) - m_Instance = new IconList; - mutex.unlock(); - } - return m_Instance; -} - -#include "IconListModel.moc" \ No newline at end of file diff --git a/backend/IconListModel.h b/backend/IconListModel.h deleted file mode 100644 index 31b05e64..00000000 --- a/backend/IconListModel.h +++ /dev/null @@ -1,33 +0,0 @@ -#pragma once - -#include -#include -#include - -class Private; - -class IconList : public QAbstractListModel -{ -public: - static IconList* instance(); - static void drop(); - QIcon getIcon ( QString key ); - int getIconIndex ( QString key ); - - virtual QVariant data ( const QModelIndex& index, int role = Qt::DisplayRole ) const; - virtual int rowCount ( const QModelIndex& parent = QModelIndex() ) const; - - bool addIcon(QString key, QString name, QString path, bool is_builtin = false); - - -private: - virtual ~IconList(); - IconList(); - // hide copy constructor - IconList ( const IconList & ) = delete; - // hide assign op - IconList& operator= ( const IconList & ) = delete; - static IconList* m_Instance; - static QMutex mutex; - Private* d; -}; diff --git a/backend/InstanceFactory.cpp b/backend/InstanceFactory.cpp deleted file mode 100644 index f3511157..00000000 --- a/backend/InstanceFactory.cpp +++ /dev/null @@ -1,113 +0,0 @@ -/* Copyright 2013 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 "InstanceFactory.h" - -#include -#include - -#include "BaseInstance.h" -#include "LegacyInstance.h" -#include "OneSixInstance.h" -#include "NostalgiaInstance.h" -#include "InstanceVersion.h" -#include "MinecraftVersion.h" - -#include "inifile.h" -#include -#include - -#include "pathutils.h" - -InstanceFactory InstanceFactory::loader; - -InstanceFactory::InstanceFactory() : - QObject(NULL) -{ - -} - -InstanceFactory::InstLoadError InstanceFactory::loadInstance(BaseInstance *&inst, const QString &instDir) -{ - auto m_settings = new INISettingsObject(PathCombine(instDir, "instance.cfg")); - - m_settings->registerSetting(new Setting("InstanceType", "Legacy")); - - QString inst_type = m_settings->get("InstanceType").toString(); - - //FIXME: replace with a map lookup, where instance classes register their types - if(inst_type == "Legacy") - { - inst = new LegacyInstance(instDir, m_settings, this); - } - else if(inst_type == "OneSix") - { - inst = new OneSixInstance(instDir, m_settings, this); - } - else if(inst_type == "Nostalgia") - { - inst = new NostalgiaInstance(instDir, m_settings, this); - } - else - { - return InstanceFactory::UnknownLoadError; - } - return NoLoadError; -} - - -InstanceFactory::InstCreateError InstanceFactory::createInstance( BaseInstance*& inst, InstVersionPtr version, const QString& instDir ) -{ - QDir rootDir(instDir); - - qDebug(instDir.toUtf8()); - if (!rootDir.exists() && !rootDir.mkpath(".")) - { - return InstanceFactory::CantCreateDir; - } - auto mcVer = version.dynamicCast(); - if(!mcVer) - return InstanceFactory::NoSuchVersion; - - auto m_settings = new INISettingsObject(PathCombine(instDir, "instance.cfg")); - m_settings->registerSetting(new Setting("InstanceType", "Legacy")); - - switch(mcVer->type) - { - case MinecraftVersion::Legacy: - m_settings->set("InstanceType", "Legacy"); - inst = new LegacyInstance(instDir, m_settings, this); - inst->setIntendedVersionId(version->descriptor); - break; - case MinecraftVersion::OneSix: - m_settings->set("InstanceType", "OneSix"); - inst = new OneSixInstance(instDir, m_settings, this); - inst->setIntendedVersionId(version->descriptor); - break; - case MinecraftVersion::Nostalgia: - m_settings->set("InstanceType", "Nostalgia"); - inst = new NostalgiaInstance(instDir, m_settings, this); - inst->setIntendedVersionId(version->descriptor); - break; - default: - { - delete m_settings; - return InstanceFactory::NoSuchVersion; - } - } - - //FIXME: really, how do you even know? - return InstanceFactory::NoCreateError; -} diff --git a/backend/InstanceFactory.h b/backend/InstanceFactory.h deleted file mode 100644 index e1100504..00000000 --- a/backend/InstanceFactory.h +++ /dev/null @@ -1,81 +0,0 @@ -/* Copyright 2013 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 - -#include "libmmc_config.h" -#include "InstanceVersion.h" - -class InstVersion; -class BaseInstance; - -/*! - * The \bInstanceFactory\b is a singleton that manages loading and creating instances. - */ -class LIBMULTIMC_EXPORT InstanceFactory : public QObject -{ - Q_OBJECT -public: - /*! - * \brief Gets a reference to the instance loader. - */ - static InstanceFactory &get() { return loader; } - - enum InstLoadError - { - NoLoadError = 0, - UnknownLoadError, - NotAnInstance - }; - - enum InstCreateError - { - NoCreateError = 0, - NoSuchVersion, - UnknownCreateError, - InstExists, - CantCreateDir - }; - - /*! - * \brief Creates a stub instance - * - * \param inst Pointer to store the created instance in. - * \param instDir The instance's directory. - * \return An InstCreateError error code. - * - InstExists if the given instance directory is already an instance. - * - CantCreateDir if the given instance directory cannot be created. - */ - InstCreateError createInstance(BaseInstance *&inst, InstVersionPtr version, const QString &instDir); - - /*! - * \brief Loads an instance from the given directory. - * Checks the instance's INI file to figure out what the instance's type is first. - * \param inst Pointer to store the loaded instance in. - * \param instDir The instance's directory. - * \return An InstLoadError error code. - * - NotAnInstance if the given instance directory isn't a valid instance. - */ - InstLoadError loadInstance(BaseInstance *&inst, const QString &instDir); - -private: - InstanceFactory(); - - static InstanceFactory loader; -}; diff --git a/backend/InstanceVersion.h b/backend/InstanceVersion.h deleted file mode 100644 index aeff9842..00000000 --- a/backend/InstanceVersion.h +++ /dev/null @@ -1,69 +0,0 @@ -/* Copyright 2013 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 "libmmc_config.h" -#include - -/*! - * An abstract base class for versions. - */ -struct LIBMULTIMC_EXPORT InstVersion -{ - /*! - * Checks if this version is less (older) than the given version. - * \param other The version to compare this one to. - * \return True if this version is older than the given version. - */ - virtual bool operator<(const InstVersion &rhs) const - { - return timestamp < rhs.timestamp; - } - - /*! - * Checks if this version is greater (newer) than the given version. - * \param other The version to compare this one to. - * \return True if this version is newer than the given version. - */ - virtual bool operator>( const InstVersion& rhs ) const - { - return timestamp > rhs.timestamp; - } - - /*! - * A string used to identify this version in config files. - * This should be unique within the version list or shenanigans will occur. - */ - QString descriptor; - /*! - * The name of this version as it is displayed to the user. - * For example: "1.5.1" - */ - QString name; - /*! - * Gets the version's timestamp. - * This is primarily used for sorting versions in a list. - */ - qint64 timestamp; - - virtual QString typeString() const - { - return "InstVersion"; - } -}; - -typedef QSharedPointer InstVersionPtr; - -Q_DECLARE_METATYPE( InstVersionPtr ) \ No newline at end of file diff --git a/backend/LegacyForge.cpp b/backend/LegacyForge.cpp deleted file mode 100644 index adcf487c..00000000 --- a/backend/LegacyForge.cpp +++ /dev/null @@ -1,57 +0,0 @@ -// -// Copyright 2012 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 "LegacyForge.h" - -MinecraftForge::MinecraftForge ( const QString& file ) : Mod ( file ) -{ - -} -bool MinecraftForge::FixVersionIfNeeded ( QString newVersion ) -{/* - wxString reportedVersion = GetModVersion(); - if(reportedVersion == "..." || reportedVersion.empty()) - { - std::auto_ptr in(new wxFFileInputStream("forge.zip")); - wxTempFileOutputStream out("forge.zip"); - wxTextOutputStream textout(out); - wxZipInputStream inzip(*in); - wxZipOutputStream outzip(out); - std::auto_ptr entry; - // preserve metadata - outzip.CopyArchiveMetaData(inzip); - // copy all entries - while (entry.reset(inzip.GetNextEntry()), entry.get() != NULL) - if (!outzip.CopyEntry(entry.release(), inzip)) - return false; - // release last entry - in.reset(); - outzip.PutNextEntry("forgeversion.properties"); - - wxStringTokenizer tokenizer(newVersion,"."); - wxString verFile; - verFile << wxString("forge.major.number=") << tokenizer.GetNextToken() << "\n"; - verFile << wxString("forge.minor.number=") << tokenizer.GetNextToken() << "\n"; - verFile << wxString("forge.revision.number=") << tokenizer.GetNextToken() << "\n"; - verFile << wxString("forge.build.number=") << tokenizer.GetNextToken() << "\n"; - auto buf = verFile.ToUTF8(); - outzip.Write(buf.data(), buf.length()); - // check if we succeeded - return inzip.Eof() && outzip.Close() && out.Commit(); - } - */ - return true; -} diff --git a/backend/LegacyForge.h b/backend/LegacyForge.h deleted file mode 100644 index 00a054b8..00000000 --- a/backend/LegacyForge.h +++ /dev/null @@ -1,25 +0,0 @@ -// -// Copyright 2012 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 "Mod.h" - -class MinecraftForge : public Mod -{ -public: - MinecraftForge ( const QString& file ); - bool FixVersionIfNeeded(QString newVersion); -}; diff --git a/backend/LegacyInstance.cpp b/backend/LegacyInstance.cpp deleted file mode 100644 index 9102c9c7..00000000 --- a/backend/LegacyInstance.cpp +++ /dev/null @@ -1,229 +0,0 @@ -#include "LegacyInstance.h" -#include "LegacyInstance_p.h" -#include "MinecraftProcess.h" -#include "LegacyUpdate.h" -#include -#include -#include -#include -#include -#include - -#define LAUNCHER_FILE "MultiMCLauncher.jar" - -LegacyInstance::LegacyInstance(const QString& rootDir, SettingsObject* settings, QObject* parent) - :BaseInstance( new LegacyInstancePrivate(),rootDir, settings, parent) -{ - settings->registerSetting(new Setting("NeedsRebuild", true)); - settings->registerSetting(new Setting("ShouldUpdate", false)); - settings->registerSetting(new Setting("JarVersion", "Unknown")); - settings->registerSetting(new Setting("LwjglVersion", "2.9.0")); - settings->registerSetting(new Setting("IntendedJarVersion", "")); -} - -BaseUpdate* LegacyInstance::doUpdate() -{ - return new LegacyUpdate(this, this); -} - -MinecraftProcess* LegacyInstance::prepareForLaunch(QString user, QString session) -{ - MinecraftProcess * proc = new MinecraftProcess(this); - - // FIXME: extract the icon - // QImage(":/icons/instances/" + iconKey()).save(PathCombine(minecraftRoot(), "icon.png")); - - // extract the legacy launcher - QFile(":/launcher/launcher.jar").copy(PathCombine(minecraftRoot(), LAUNCHER_FILE)); - - // set the process arguments - { - QStringList args; - - // window size - QString windowSize; - if (settings().get("LaunchMaximized").toBool()) - windowSize = "max"; - else - windowSize = QString("%1x%2"). - arg(settings().get("MinecraftWinWidth").toInt()). - arg(settings().get("MinecraftWinHeight").toInt()); - - // window title - QString windowTitle; - windowTitle.append("MultiMC: ").append(name()); - - // Java arguments - args.append(Util::Commandline::splitArgs(settings().get("JvmArgs").toString())); - -#ifdef OSX - // OSX dock icon and name - args << "-Xdock:icon=icon.png"; - args << QString("-Xdock:name=\"%1\"").arg(windowTitle); -#endif - - QString lwjgl = QDir(globalSettings->get("LWJGLDir").toString() + "/" + lwjglVersion()).absolutePath(); - - // launcher arguments - args << QString("-Xms%1m").arg(settings().get("MinMemAlloc").toInt()); - args << QString("-Xmx%1m").arg(settings().get("MaxMemAlloc").toInt()); - args << "-jar" << LAUNCHER_FILE; - args << user; - args << session; - args << windowTitle; - args << windowSize; - args << lwjgl; - proc->setMinecraftArguments(args); - } - - // set the process work path - proc->setMinecraftWorkdir(minecraftRoot()); - - return proc; -} - -void LegacyInstance::cleanupAfterRun() -{ - //FIXME: delete the launcher and icons and whatnot. -} - - -QString LegacyInstance::instModsDir() const -{ - return PathCombine(instanceRoot(), "instMods"); -} - -QString LegacyInstance::binDir() const -{ - return PathCombine(minecraftRoot(), "bin"); -} - -QString LegacyInstance::savesDir() const -{ - return PathCombine(minecraftRoot(), "saves"); -} - -QString LegacyInstance::mlModsDir() const -{ - return PathCombine(minecraftRoot(), "mods"); -} - -QString LegacyInstance::coreModsDir() const -{ - return PathCombine(minecraftRoot(), "coremods"); -} - -QString LegacyInstance::resourceDir() const -{ - return PathCombine(minecraftRoot(), "resources"); -} - -QString LegacyInstance::mcJar() const -{ - return PathCombine(binDir(), "minecraft.jar"); -} - -QString LegacyInstance::mcBackup() const -{ - return PathCombine(binDir(), "mcbackup.jar"); -} - -QString LegacyInstance::modListFile() const -{ - return PathCombine(instanceRoot(), "modlist"); -} - -bool LegacyInstance::shouldUpdateCurrentVersion() const -{ - QFileInfo jar(mcJar()); - return jar.lastModified().toUTC().toMSecsSinceEpoch() != lastCurrentVersionUpdate(); -} - -void LegacyInstance::updateCurrentVersion(bool keepCurrent) -{ - QFileInfo jar(mcJar()); - - if(!jar.exists()) - { - setLastCurrentVersionUpdate(0); - setCurrentVersionId("Unknown"); - return; - } - - qint64 time = jar.lastModified().toUTC().toMSecsSinceEpoch(); - - setLastCurrentVersionUpdate(time); - if (!keepCurrent) - { - // TODO: Implement GetMinecraftJarVersion function. - QString newVersion = "Unknown";//javautils::GetMinecraftJarVersion(jar.absoluteFilePath()); - setCurrentVersionId(newVersion); - } -} -qint64 LegacyInstance::lastCurrentVersionUpdate() const -{ - I_D(LegacyInstance); - return d->m_settings->get ( "lastVersionUpdate" ).value(); -} -void LegacyInstance::setLastCurrentVersionUpdate ( qint64 val ) -{ - I_D(LegacyInstance); - d->m_settings->set ( "lastVersionUpdate", val ); -} -bool LegacyInstance::shouldRebuild() const -{ - I_D(LegacyInstance); - return d->m_settings->get ( "NeedsRebuild" ).toBool(); -} -void LegacyInstance::setShouldRebuild ( bool val ) -{ - I_D(LegacyInstance); - d->m_settings->set ( "NeedsRebuild", val ); -} -QString LegacyInstance::currentVersionId() const -{ - I_D(LegacyInstance); - return d->m_settings->get ( "JarVersion" ).toString(); -} - -void LegacyInstance::setCurrentVersionId ( QString val ) -{ - I_D(LegacyInstance); - d->m_settings->set ( "JarVersion", val ); -} - -QString LegacyInstance::lwjglVersion() const -{ - I_D(LegacyInstance); - return d->m_settings->get ( "LwjglVersion" ).toString(); -} -void LegacyInstance::setLWJGLVersion ( QString val ) -{ - I_D(LegacyInstance); - d->m_settings->set ( "LwjglVersion", val ); -} -QString LegacyInstance::intendedVersionId() const -{ - I_D(LegacyInstance); - return d->m_settings->get ( "IntendedJarVersion" ).toString(); -} -bool LegacyInstance::setIntendedVersionId ( QString version ) -{ - settings().set("IntendedJarVersion", version); - setShouldUpdate(true); - return true; -} -bool LegacyInstance::shouldUpdate() const -{ - I_D(LegacyInstance); - QVariant var = settings().get ( "ShouldUpdate" ); - if ( !var.isValid() || var.toBool() == false ) - { - return intendedVersionId() != currentVersionId(); - } - return true; -} -void LegacyInstance::setShouldUpdate ( bool val ) -{ - settings().set ( "ShouldUpdate", val ); -} diff --git a/backend/LegacyInstance.h b/backend/LegacyInstance.h deleted file mode 100644 index 6c9a295f..00000000 --- a/backend/LegacyInstance.h +++ /dev/null @@ -1,85 +0,0 @@ -#pragma once - -#include "BaseInstance.h" - -class BaseUpdate; - -class LIBMULTIMC_EXPORT LegacyInstance : public BaseInstance -{ - Q_OBJECT -public: - - explicit LegacyInstance(const QString &rootDir, SettingsObject * settings, QObject *parent = 0); - - /// Path to the instance's minecraft.jar - QString mcJar() const; - - //! Path to the instance's mcbackup.jar - QString mcBackup() const; - - //! Path to the instance's modlist file. - QString modListFile() const; - - ////// Directories ////// - QString savesDir() const; - QString instModsDir() const; - QString binDir() const; - QString mlModsDir() const; - QString coreModsDir() const; - QString resourceDir() const; - - /*! - * \brief Checks whether or not the currentVersion of the instance needs to be updated. - * If this returns true, updateCurrentVersion is called. In the - * standard instance, this is determined by checking a timestamp - * stored in the instance config file against the last modified time of Minecraft.jar. - * \return True if updateCurrentVersion() should be called. - */ - bool shouldUpdateCurrentVersion() const; - - /*! - * \brief Updates the current version. - * This function should first set the current version timestamp - * (setCurrentVersionTimestamp()) to the current time. Next, if - * keepCurrent is false, this function should check what the - * instance's current version is and call setCurrentVersion() to - * update it. This function will automatically be called when the - * instance is loaded if shouldUpdateCurrentVersion returns true. - * \param keepCurrent If true, only the version timestamp will be updated. - */ - void updateCurrentVersion(bool keepCurrent = false); - - /*! - * Gets the last time that the current version was checked. - * This is checked against the last modified time on the jar file to see if - * the current version needs to be checked again. - */ - qint64 lastCurrentVersionUpdate() const; - void setLastCurrentVersionUpdate(qint64 val); - - /*! - * Whether or not the instance's minecraft.jar needs to be rebuilt. - * If this is true, when the instance launches, its jar mods will be - * re-added to a fresh minecraft.jar file. - */ - bool shouldRebuild() const; - void setShouldRebuild(bool val); - - virtual QString currentVersionId() const; - virtual void setCurrentVersionId(QString val); - - //! The version of LWJGL that this instance uses. - QString lwjglVersion() const; - /// st the version of LWJGL libs this instance will use - void setLWJGLVersion(QString val); - - virtual QString intendedVersionId() const; - virtual bool setIntendedVersionId ( QString version ); - - virtual bool shouldUpdate() const; - virtual void setShouldUpdate(bool val); - virtual BaseUpdate* doUpdate(); - - virtual MinecraftProcess* prepareForLaunch( QString user, QString session ); - virtual void cleanupAfterRun(); -}; \ No newline at end of file diff --git a/backend/LegacyInstance_p.h b/backend/LegacyInstance_p.h deleted file mode 100644 index ac367e20..00000000 --- a/backend/LegacyInstance_p.h +++ /dev/null @@ -1,10 +0,0 @@ -#pragma once -#include -#include -#include "BaseInstance_p.h" - -class BaseInstance; - -struct LegacyInstancePrivate: public BaseInstancePrivate -{ -}; \ No newline at end of file diff --git a/backend/LegacyUpdate.cpp b/backend/LegacyUpdate.cpp deleted file mode 100644 index a748bad3..00000000 --- a/backend/LegacyUpdate.cpp +++ /dev/null @@ -1,381 +0,0 @@ -#include "LegacyUpdate.h" -#include "lists/LwjglVersionList.h" -#include "lists/MinecraftVersionList.h" -#include "BaseInstance.h" -#include "LegacyInstance.h" -#include "net/NetWorker.h" -#include -#include -#include - - -LegacyUpdate::LegacyUpdate ( BaseInstance* inst, QObject* parent ) : BaseUpdate ( inst, parent ) {} - -void LegacyUpdate::executeTask() -{ - lwjglStart(); -} - -void LegacyUpdate::lwjglStart() -{ - LegacyInstance * inst = (LegacyInstance *) m_inst; - - lwjglVersion = inst->lwjglVersion(); - lwjglTargetPath = PathCombine("lwjgl", lwjglVersion ); - lwjglNativesPath = PathCombine( lwjglTargetPath, "natives/"); - - // if the 'done' file exists, we don't have to download this again - QFileInfo doneFile(PathCombine(lwjglTargetPath, "done")); - if(doneFile.exists()) - { - jarStart(); - return; - } - - auto &list = LWJGLVersionList::get(); - if(!list.isLoaded()) - { - emitFailed("Too soon! Let the LWJGL list load :)"); - return; - } - - setStatus("Downloading new LWJGL."); - auto version = list.getVersion(lwjglVersion); - if(!version) - { - emitFailed("Game update failed: the selected LWJGL version is invalid."); - return; - } - - QString url = version->url(); - QUrl realUrl(url); - QString hostname = realUrl.host(); - auto &worker = NetWorker::spawn(); - QNetworkRequest req(realUrl); - req.setRawHeader("Host", hostname.toLatin1()); - req.setHeader(QNetworkRequest::UserAgentHeader, "Wget/1.14 (linux-gnu)"); - QNetworkReply * rep = worker.get ( req ); - - m_reply = QSharedPointer (rep, &QObject::deleteLater); - connect(rep, SIGNAL(downloadProgress(qint64,qint64)), SLOT(updateDownloadProgress(qint64,qint64))); - connect(&worker, SIGNAL(finished(QNetworkReply*)), SLOT(lwjglFinished(QNetworkReply*))); - //connect(rep, SIGNAL(error(QNetworkReply::NetworkError)), SLOT(downloadError(QNetworkReply::NetworkError))); -} - -void LegacyUpdate::lwjglFinished(QNetworkReply* reply) -{ - if(m_reply != reply) - { - return; - } - if(reply->error() != QNetworkReply::NoError) - { - emitFailed( "Failed to download: "+ - reply->errorString()+ - "\nSometimes you have to wait a bit if you download many LWJGL versions in a row. YMMV"); - return; - } - auto &worker = NetWorker::spawn(); - //Here i check if there is a cookie for me in the reply and extract it - QList cookies = qvariant_cast>(reply->header(QNetworkRequest::SetCookieHeader)); - if(cookies.count() != 0) - { - //you must tell which cookie goes with which url - worker.cookieJar()->setCookiesFromUrl(cookies, QUrl("sourceforge.net")); - } - - //here you can check for the 302 or whatever other header i need - QVariant newLoc = reply->header(QNetworkRequest::LocationHeader); - if(newLoc.isValid()) - { - auto &worker = NetWorker::spawn(); - QString redirectedTo = reply->header(QNetworkRequest::LocationHeader).toString(); - QUrl realUrl(redirectedTo); - QString hostname = realUrl.host(); - QNetworkRequest req(redirectedTo); - req.setRawHeader("Host", hostname.toLatin1()); - req.setHeader(QNetworkRequest::UserAgentHeader, "Wget/1.14 (linux-gnu)"); - QNetworkReply * rep = worker.get(req); - connect(rep, SIGNAL(downloadProgress(qint64,qint64)), SLOT(updateDownloadProgress(qint64,qint64))); - m_reply = QSharedPointer (rep, &QObject::deleteLater); - return; - } - QFile saveMe("lwjgl.zip"); - saveMe.open(QIODevice::WriteOnly); - saveMe.write(m_reply->readAll()); - saveMe.close(); - setStatus("Installing new LWJGL..."); - extractLwjgl(); - jarStart(); -} -void LegacyUpdate::extractLwjgl() -{ - // make sure the directories are there - - bool success = ensurePathExists(lwjglNativesPath); - - if(!success) - { - emitFailed("Failed to extract the lwjgl libs - error when creating required folders."); - return; - } - - QuaZip zip("lwjgl.zip"); - if(!zip.open(QuaZip::mdUnzip)) - { - emitFailed("Failed to extract the lwjgl libs - not a valid archive."); - return; - } - - // and now we are going to access files inside it - QuaZipFile file(&zip); - const QString jarNames[] = { "jinput.jar", "lwjgl_util.jar", "lwjgl.jar" }; - for(bool more=zip.goToFirstFile(); more; more=zip.goToNextFile()) - { - if(!file.open(QIODevice::ReadOnly)) - { - zip.close(); - emitFailed("Failed to extract the lwjgl libs - error while reading archive."); - return; - } - QuaZipFileInfo info; - QString name = file.getActualFileName(); - if(name.endsWith('/')) - { - file.close(); - continue; - } - QString destFileName; - // Look for the jars - for (int i = 0; i < 3; i++) - { - if (name.endsWith(jarNames[i])) - { - destFileName = PathCombine(lwjglTargetPath, jarNames[i]); - } - } - // Not found? look for the natives - if(destFileName.isEmpty()) - { -#ifdef Q_OS_WIN32 - QString nativesDir = "windows"; -#elif Q_OS_MAC - QString nativesDir = "macosx"; -#else - QString nativesDir = "linux"; -#endif - if (name.contains(nativesDir)) - { - int lastSlash = name.lastIndexOf('/'); - int lastBackSlash = name.lastIndexOf('/'); - if(lastSlash != -1) - name = name.mid(lastSlash+1); - else if(lastBackSlash != -1) - name = name.mid(lastBackSlash+1); - destFileName = PathCombine(lwjglNativesPath, name); - } - } - // Now if destFileName is still empty, go to the next file. - if (!destFileName.isEmpty()) - { - setStatus("Installing new LWJGL - Extracting " + name); - QFile output(destFileName); - output.open(QIODevice::WriteOnly); - output.write(file.readAll()); // FIXME: wste of memory!? - output.close(); - } - file.close(); // do not forget to close! - } - zip.close(); - m_reply.clear(); - QFile doneFile(PathCombine(lwjglTargetPath, "done")); - doneFile.open(QIODevice::WriteOnly); - doneFile.write("done."); - doneFile.close(); -} - -void LegacyUpdate::lwjglFailed() -{ - emitFailed("Bad stuff happened while trying to get the lwjgl libs..."); -} - -void LegacyUpdate::jarStart() -{ - setStatus("Checking ..."); - LegacyInstance * inst = (LegacyInstance *) m_inst; - QString current_version_id = inst->currentVersionId(); - QString intended_version_id = inst->intendedVersionId(); - bool shouldUpdate = inst->shouldUpdate(); - if(!shouldUpdate) - { - emitSucceeded(); - return; - } - - // nuke the backup file, we are replacing the base jar anyway - QFile mc_backup(inst->mcBackup()); - if (mc_backup.exists()) - { - mc_backup.remove(); - } - - // Get a pointer to the version object that corresponds to the instance's version. - auto targetVersion = MinecraftVersionList::getMainList().findVersion(intended_version_id); - - if(!targetVersion) - { - emitFailed("Not a valid version:" + intended_version_id); - return; - } - - // Make directories - QDir binDir(inst->binDir()); - if (!binDir.exists() && !binDir.mkpath(".")) - { - emitFailed("Failed to create bin folder."); - return; - } - - // Build a list of URLs that will need to be downloaded. - setStatus("Downloading new minecraft.jar"); - - // This will be either 'minecraft' or the version number, depending on where - // we're downloading from. - QString jarFilename = "minecraft"; - QString download_path = PathCombine(inst->minecraftRoot(), "bin/minecraft.jar"); - - QString urlstr("http://s3.amazonaws.com/Minecraft.Download/versions/"); - urlstr += targetVersion->descriptor + "/" + targetVersion->descriptor + ".jar"; - auto dljob = DownloadJob::create(QUrl(urlstr), download_path); - - legacyDownloadJob.reset(new JobList()); - legacyDownloadJob->add(dljob); - connect(legacyDownloadJob.data(), SIGNAL(finished()), SLOT(jarFinished())); - connect(legacyDownloadJob.data(), SIGNAL(failed()), SLOT(jarFailed())); - connect(legacyDownloadJob.data(), SIGNAL(progress(qint64,qint64)), SLOT(updateDownloadProgress(qint64,qint64))); - download_queue.enqueue(legacyDownloadJob); -} - -void LegacyUpdate::jarFinished() -{ - // process the jar - emitSucceeded(); -} - -void LegacyUpdate::jarFailed() -{ - // bad, bad - emitFailed("Failed to download the minecraft jar. Try again later."); -} - -void LegacyUpdate::ModTheJar() -{ - /* - LegacyInstance * inst = (LegacyInstance *) m_inst; - // Get the mod list - auto modList = inst->getJarModList(); - - QFileInfo mcBin(inst->binDir()); - QFileInfo mcJar(inst->mcJar()); - QFileInfo mcBackup(inst->mcBackup()); - - // Nothing to do if there are no jar mods to install, no backup and just the mc jar - if(mcJar.isFile() && !mcBackup.exists() && modList->empty()) - { - inst->setShouldRebuild(false); - emitSucceeded(); - return; - } - - setStatus("Installing mods - backing up minecraft.jar..."); - if (!mcBackup.exists() && !QFile::copy(mcJar.absoluteFilePath(), mcBackup.absoluteFilePath()) ) - { - emitFailed("Failed to back up minecraft.jar"); - return; - } - - if (mcJar.isFile() && !QFile::remove(mcJar.absoluteFilePath())) - { - emitFailed("Failed to delete old minecraft.jar"); - return; - } - - setStatus("Installing mods - Opening minecraft.jar"); - - wxFFileOutputStream jarStream(mcJar.absoluteFilePath()); - wxZipOutputStream zipOut(jarStream); - - // Files already added to the jar. - // These files will be skipped. - QSet addedFiles; - - // Modify the jar - setStatus("Installing mods - Adding mod files..."); - for (ModList::const_reverse_iterator iter = modList->rbegin(); iter != modList->rend(); iter++) - { - wxFileName modFileName = iter->GetFileName(); - setStatus("Installing mods - Adding " + modFileName.GetFullName()); - if (iter->GetModType() == Mod::ModType::MOD_ZIPFILE) - { - wxFFileInputStream modStream(modFileName.GetFullPath()); - wxZipInputStream zipStream(modStream); - std::unique_ptr entry; - while (entry.reset(zipStream.GetNextEntry()), entry.get() != NULL) - { - if (entry->IsDir()) - continue; - - wxString name = entry->GetName(); - if (addedFiles.count(name) == 0) - { - if (!zipOut.CopyEntry(entry.release(), zipStream)) - break; - addedFiles.insert(name); - } - } - } - else - { - wxFileName destFileName = modFileName; - destFileName.MakeRelativeTo(m_inst->GetInstModsDir().GetFullPath()); - wxString destFile = destFileName.GetFullPath(); - - if (addedFiles.count(destFile) == 0) - { - wxFFileInputStream input(modFileName.GetFullPath()); - zipOut.PutNextEntry(destFile); - zipOut.Write(input); - - addedFiles.insert(destFile); - } - } - } - - { - wxFFileInputStream inStream(mcBackup.GetFullPath()); - wxZipInputStream zipIn(inStream); - - std::auto_ptr entry; - while (entry.reset(zipIn.GetNextEntry()), entry.get() != NULL) - { - wxString name = entry->GetName(); - - if (!name.Matches("META-INF*") && - addedFiles.count(name) == 0) - { - if (!zipOut.CopyEntry(entry.release(), zipIn)) - break; - addedFiles.insert(name); - } - } - } - - // Recompress the jar - TaskStep(); // STEP 3 - SetStatus(_("Installing mods - Recompressing jar...")); - - inst->SetNeedsRebuild(false); - inst->UpdateVersion(true); - return (ExitCode)1; - */ -} \ No newline at end of file diff --git a/backend/LegacyUpdate.h b/backend/LegacyUpdate.h deleted file mode 100644 index a48189a6..00000000 --- a/backend/LegacyUpdate.h +++ /dev/null @@ -1,68 +0,0 @@ -/* Copyright 2013 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 - -#include "net/DownloadJob.h" -#include "tasks/Task.h" -#include "libmmc_config.h" -#include "BaseUpdate.h" - -class MinecraftVersion; -class BaseInstance; - -class LIBMULTIMC_EXPORT LegacyUpdate : public BaseUpdate -{ - Q_OBJECT -public: - explicit LegacyUpdate(BaseInstance *inst, QObject *parent = 0); - virtual void executeTask(); - -private slots: - void lwjglStart(); - void lwjglFinished( QNetworkReply* ); - void lwjglFailed(); - - void jarStart(); - void jarFinished(); - void jarFailed(); - - void extractLwjgl(); - - void ModTheJar(); -private: - - QSharedPointer m_reply; - - // target version, determined during this task - // MinecraftVersion *targetVersion; - QString lwjglURL; - QString lwjglVersion; - - QString lwjglTargetPath; - QString lwjglNativesPath; -private: - JobListPtr legacyDownloadJob; - JobListQueue download_queue; - - // target version, determined during this task - QSharedPointer targetVersion; -}; - - diff --git a/backend/MinecraftProcess.cpp b/backend/MinecraftProcess.cpp deleted file mode 100644 index d34be835..00000000 --- a/backend/MinecraftProcess.cpp +++ /dev/null @@ -1,169 +0,0 @@ -/* Copyright 2013 MultiMC Contributors - * - * Authors: Orochimarufan - * - * 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 "MinecraftProcess.h" - -#include -#include -#include -//#include -#include - -#include "BaseInstance.h" - -#include "osutils.h" -#include "pathutils.h" -#include "cmdutils.h" - -#define IBUS "@im=ibus" - -// constructor -MinecraftProcess::MinecraftProcess( BaseInstance* inst ) : - m_instance(inst) -{ - connect(this, SIGNAL(finished(int, QProcess::ExitStatus)), SLOT(finish(int, QProcess::ExitStatus))); - - // prepare the process environment - QProcessEnvironment env = QProcessEnvironment::systemEnvironment(); - -#ifdef LINUX - // Strip IBus - if (env.value("XMODIFIERS").contains(IBUS)) - env.insert("XMODIFIERS", env.value("XMODIFIERS").replace(IBUS, "")); -#endif - - // export some infos - env.insert("INST_NAME", inst->name()); - env.insert("INST_ID", inst->id()); - env.insert("INST_DIR", QDir(inst->instanceRoot()).absolutePath()); - - this->setProcessEnvironment(env); - m_prepostlaunchprocess.setProcessEnvironment(env); - - // std channels - connect(this, SIGNAL(readyReadStandardError()), SLOT(on_stdErr())); - connect(this, SIGNAL(readyReadStandardOutput()), SLOT(on_stdOut())); -} - -void MinecraftProcess::setMinecraftArguments ( QStringList args ) -{ - m_args = args; -} - -void MinecraftProcess::setMinecraftWorkdir ( QString path ) -{ - QDir mcDir(path); - this->setWorkingDirectory(mcDir.absolutePath()); - m_prepostlaunchprocess.setWorkingDirectory(mcDir.absolutePath()); -} - - -// console window -void MinecraftProcess::on_stdErr() -{ - QByteArray data = readAllStandardError(); - QString str = m_err_leftover + QString::fromLocal8Bit(data); - m_err_leftover.clear(); - QStringList lines = str.split("\n"); - bool complete = str.endsWith("\n"); - - for(int i = 0; i < lines.size() - 1; i++) - { - QString & line = lines[i]; - MessageLevel::Enum level = MessageLevel::Error; - if(line.contains("[INFO]") || line.contains("[CONFIG]") || line.contains("[FINE]") || line.contains("[FINER]") || line.contains("[FINEST]") ) - level = MessageLevel::Message; - if(line.contains("[SEVERE]") || line.contains("[WARNING]") || line.contains("[STDERR]")) - level = MessageLevel::Error; - emit log(lines[i].toLocal8Bit(), level); - } - if(!complete) - m_err_leftover = lines.last(); -} - -void MinecraftProcess::on_stdOut() -{ - QByteArray data = readAllStandardOutput(); - QString str = m_out_leftover + QString::fromLocal8Bit(data); - m_out_leftover.clear(); - QStringList lines = str.split("\n"); - bool complete = str.endsWith("\n"); - - for(int i = 0; i < lines.size() - 1; i++) - { - QString & line = lines[i]; - emit log(lines[i].toLocal8Bit(), MessageLevel::Message); - } - if(!complete) - m_out_leftover = lines.last(); -} - -// exit handler -void MinecraftProcess::finish(int code, ExitStatus status) -{ - if (status != NormalExit) - { - //TODO: error handling - } - - emit log("Minecraft exited."); - - m_prepostlaunchprocess.processEnvironment().insert("INST_EXITCODE", QString(code)); - - // run post-exit - if (!m_instance->settings().get("PostExitCommand").toString().isEmpty()) - { - m_prepostlaunchprocess.start(m_instance->settings().get("PostExitCommand").toString()); - m_prepostlaunchprocess.waitForFinished(); - if (m_prepostlaunchprocess.exitStatus() != NormalExit) - { - //TODO: error handling - } - } - m_instance->cleanupAfterRun(); - emit ended(); -} - -void MinecraftProcess::launch() -{ - if (!m_instance->settings().get("PreLaunchCommand").toString().isEmpty()) - { - m_prepostlaunchprocess.start(m_instance->settings().get("PreLaunchCommand").toString()); - m_prepostlaunchprocess.waitForFinished(); - if (m_prepostlaunchprocess.exitStatus() != NormalExit) - { - //TODO: error handling - return; - } - } - - m_instance->setLastLaunch(); - - emit log(QString("Minecraft folder is: '%1'").arg(workingDirectory())); - QString JavaPath = m_instance->settings().get("JavaPath").toString(); - emit log(QString("Java path: '%1'").arg(JavaPath)); - emit log(QString("Arguments: '%1'").arg(m_args.join("' '"))); - start(JavaPath, m_args); - if (!waitForStarted()) - { - emit log("Could not launch minecraft!"); - return; - //TODO: error handling - } -} - - diff --git a/backend/MinecraftProcess.h b/backend/MinecraftProcess.h deleted file mode 100644 index 756d2de5..00000000 --- a/backend/MinecraftProcess.h +++ /dev/null @@ -1,88 +0,0 @@ -/* Copyright 2013 MultiMC Contributors - * - * Authors: O