diff options
| author | Petr Mrázek <peterix@gmail.com> | 2013-08-17 13:40:51 +0200 |
|---|---|---|
| committer | Petr Mrázek <peterix@gmail.com> | 2013-08-17 13:40:51 +0200 |
| commit | 253067c782955380bbf66ac0475dc954375b1ff4 (patch) | |
| tree | ca97e231fd3a764256d95b5fc8d08fc25ff72161 /backend | |
| parent | 77e80665422c4e97e2286418ab55e20c4030023b (diff) | |
| download | PrismLauncher-253067c782955380bbf66ac0475dc954375b1ff4.tar.gz PrismLauncher-253067c782955380bbf66ac0475dc954375b1ff4.tar.bz2 PrismLauncher-253067c782955380bbf66ac0475dc954375b1ff4.zip | |
Move all the things (YES. Move them.)
Also, implemented some basic modlist logic, to be wired up.
Diffstat (limited to 'backend')
56 files changed, 0 insertions, 6272 deletions
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 <QFileInfo> - -#include "inisettingsobject.h" -#include "setting.h" -#include "overridesetting.h" - -#include "pathutils.h" -#include <lists/MinecraftVersionList.h> - - -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<qint64>(); -} -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 <QObject> -#include <QDateTime> - -#include <settingsobject.h> - -#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<BaseInstancePrivate> inst_d; -}; - -// pointer for lazy people -typedef QSharedPointer<BaseInstance> 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 <QString> -#include <settingsobject.h> - -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 <QObject> -#include <QList> -#include <QUrl> - -#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 <pathutils.h> -#include <QMap> -#include <QEventLoop> -#include <QDir> - -#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<QString, int> index; - QVector<entry> 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(); |
