From bb7e8985f6d189de0acac6a1c3033cb16378c1fb Mon Sep 17 00:00:00 2001 From: Petr Mrázek Date: Mon, 4 Nov 2013 02:53:05 +0100 Subject: Reformat and (slightly) decruft all the things. --- logic/BaseInstance.cpp | 140 +++++++++++++++++---------------- logic/BaseInstance_p.h | 17 +++- logic/BaseUpdate.cpp | 17 +++- logic/BaseUpdate.h | 13 ++-- logic/BaseVersion.h | 9 ++- logic/CMakeLists.txt | 24 ------ logic/EnabledItemFilter.cpp | 27 +++++-- logic/EnabledItemFilter.h | 18 ++++- logic/ForgeInstaller.cpp | 15 ++++ logic/ForgeInstaller.h | 19 ++++- logic/InstanceFactory.cpp | 31 ++++---- logic/InstanceLauncher.cpp | 77 +++++++++++------- logic/InstanceLauncher.h | 26 +++++-- logic/JavaUtils.cpp | 72 ++++++++++------- logic/JavaUtils.h | 8 +- logic/LegacyForge.cpp | 37 +++++---- logic/LegacyForge.h | 32 ++++---- logic/LegacyInstance.cpp | 39 +++++++--- logic/LegacyInstance.h | 18 ++++- logic/LegacyInstance_p.h | 24 ++++-- logic/LegacyUpdate.cpp | 17 +++- logic/LegacyUpdate.h | 37 +++++---- logic/MinecraftProcess.h | 43 +++++++---- logic/MinecraftVersion.h | 30 +++---- logic/Mod.cpp | 38 ++++----- logic/Mod.h | 29 ++++--- logic/ModList.cpp | 31 ++++---- logic/ModList.h | 111 +++++++++++++++----------- logic/NagUtils.cpp | 27 +++---- logic/NostalgiaInstance.cpp | 26 +++++-- logic/NostalgiaInstance.h | 19 ++++- logic/OneSixAssets.cpp | 22 +++++- logic/OneSixAssets.h | 22 +++++- logic/OneSixInstance.cpp | 19 ++++- logic/OneSixInstance.h | 19 ++++- logic/OneSixInstance_p.h | 27 +++++-- logic/OneSixLibrary.cpp | 19 ++++- logic/OneSixLibrary.h | 36 ++++++--- logic/OneSixRule.cpp | 18 ++++- logic/OneSixRule.h | 59 ++++++++++---- logic/OneSixUpdate.cpp | 1 + logic/OneSixUpdate.h | 21 +++-- logic/OneSixVersion.cpp | 31 ++++++-- logic/OneSixVersion.h | 17 +++- logic/OpSys.cpp | 35 +++++++-- logic/OpSys.h | 27 +++++-- logic/lists/BaseVersionList.cpp | 36 ++++----- logic/lists/BaseVersionList.h | 46 +++++------ logic/lists/ForgeVersionList.cpp | 2 +- logic/lists/ForgeVersionList.h | 3 +- logic/lists/IconList.cpp | 146 +++++++++++++++++++---------------- logic/lists/IconList.h | 48 ++++++++---- logic/lists/InstanceList.cpp | 4 +- logic/lists/InstanceList.h | 2 +- logic/lists/JavaVersionList.cpp | 7 +- logic/lists/JavaVersionList.h | 6 +- logic/lists/LwjglVersionList.cpp | 2 +- logic/lists/LwjglVersionList.h | 113 +++++++++++++++++---------- logic/lists/MinecraftVersionList.cpp | 4 +- logic/lists/MinecraftVersionList.h | 31 ++++---- logic/net/ByteArrayDownload.cpp | 17 +++- logic/net/ByteArrayDownload.h | 15 ++++ logic/net/CacheDownload.cpp | 28 +++++-- logic/net/CacheDownload.h | 15 ++++ logic/net/FileDownload.cpp | 74 +++++++++++------- logic/net/FileDownload.h | 15 ++++ logic/net/ForgeXzDownload.cpp | 44 +++++++---- logic/net/ForgeXzDownload.h | 15 ++++ logic/net/HttpMetaCache.cpp | 129 ++++++++++++++++++------------- logic/net/HttpMetaCache.h | 15 ++++ logic/net/LoginTask.cpp | 29 +++---- logic/net/LoginTask.h | 6 +- logic/net/NetAction.h | 21 ++++- logic/net/NetJob.cpp | 21 ++++- logic/net/NetJob.h | 20 ++++- logic/net/S3ListBucket.cpp | 19 ++++- logic/net/S3ListBucket.h | 15 ++++ logic/tasks/ProgressProvider.h | 25 +++++- logic/tasks/Task.cpp | 12 +-- logic/tasks/Task.h | 22 +++--- 80 files changed, 1615 insertions(+), 836 deletions(-) delete mode 100644 logic/CMakeLists.txt (limited to 'logic') diff --git a/logic/BaseInstance.cpp b/logic/BaseInstance.cpp index 6a6b195b..c38f75ef 100644 --- a/logic/BaseInstance.cpp +++ b/logic/BaseInstance.cpp @@ -3,7 +3,7 @@ * 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 @@ -19,7 +19,7 @@ #include #include -#include +#include "MultiMC.h" #include "inisettingsobject.h" #include "setting.h" @@ -28,64 +28,74 @@ #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) +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)); - + /* - * custom base jar has no default. it is determined in code... see the accessor methods for it - * + * custom base jar has no default. it is determined in code... see the accessor methods for + *it + * * for instances that DO NOT have the CustomBaseJar setting (legacy instances), * [.]minecraft/bin/mcbackup.jar is the default base jar */ settings().registerSetting(new Setting("UseCustomBaseJar", true)); settings().registerSetting(new Setting("CustomBaseJar", "")); - + auto globalSettings = MMC->settings(); - + // Java Settings settings().registerSetting(new Setting("OverrideJava", false)); - settings().registerSetting(new OverrideSetting("JavaPath", globalSettings->getSetting("JavaPath"))); - settings().registerSetting(new OverrideSetting("JvmArgs", globalSettings->getSetting("JvmArgs"))); - + 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"))); - + 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"))); - + 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"))); - settings().registerSetting(new OverrideSetting("PermGen", globalSettings->getSetting("PermGen"))); - + settings().registerSetting( + new OverrideSetting("MinMemAlloc", globalSettings->getSetting("MinMemAlloc"))); + settings().registerSetting( + new OverrideSetting("MaxMemAlloc", globalSettings->getSetting("MaxMemAlloc"))); + settings().registerSetting( + new OverrideSetting("PermGen", globalSettings->getSetting("PermGen"))); + // Auto login settings().registerSetting(new Setting("OverrideLogin", false)); - settings().registerSetting(new OverrideSetting("AutoLogin", globalSettings->getSetting("AutoLogin"))); - + 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"))); + settings().registerSetting( + new OverrideSetting("ShowConsole", globalSettings->getSetting("ShowConsole"))); + settings().registerSetting(new OverrideSetting( + "AutoCloseConsole", globalSettings->getSetting("AutoCloseConsole"))); } void BaseInstance::nuke() @@ -94,7 +104,6 @@ void BaseInstance::nuke() emit nuked(this); } - QString BaseInstance::id() const { return QFileInfo(instanceRoot()).fileName(); @@ -106,7 +115,6 @@ QString BaseInstance::instanceType() const return d->m_settings->get("InstanceType").toString(); } - QString BaseInstance::instanceRoot() const { I_D(BaseInstance); @@ -117,9 +125,9 @@ QString BaseInstance::minecraftRoot() const { QFileInfo mcDir(PathCombine(instanceRoot(), "minecraft")); QFileInfo dotMCDir(PathCombine(instanceRoot(), ".minecraft")); - + if (dotMCDir.exists() && !mcDir.exists()) - return dotMCDir.filePath(); + return dotMCDir.filePath(); else return mcDir.filePath(); } @@ -147,7 +155,7 @@ QString BaseInstance::baseJar() const { I_D(BaseInstance); bool customJar = d->m_settings->get("UseCustomBaseJar").toBool(); - if(customJar) + if (customJar) { return customBaseJar(); } @@ -158,99 +166,97 @@ QString BaseInstance::baseJar() const QString BaseInstance::customBaseJar() const { I_D(BaseInstance); - QString value = d->m_settings->get ( "CustomBaseJar" ).toString(); - if(value.isNull() || value.isEmpty()) + QString value = d->m_settings->get("CustomBaseJar").toString(); + if (value.isNull() || value.isEmpty()) { return defaultCustomBaseJar(); } return value; } -void BaseInstance::setCustomBaseJar ( QString val ) +void BaseInstance::setCustomBaseJar(QString val) { I_D(BaseInstance); - if(val.isNull() || val.isEmpty() || val == defaultCustomBaseJar()) - d->m_settings->reset ( "CustomBaseJar" ); + if (val.isNull() || val.isEmpty() || val == defaultCustomBaseJar()) + d->m_settings->reset("CustomBaseJar"); else - d->m_settings->set ( "CustomBaseJar", val ); + d->m_settings->set("CustomBaseJar", val); } -void BaseInstance::setShouldUseCustomBaseJar ( bool val ) +void BaseInstance::setShouldUseCustomBaseJar(bool val) { I_D(BaseInstance); - d->m_settings->set ( "UseCustomBaseJar", val ); + d->m_settings->set("UseCustomBaseJar", val); } bool BaseInstance::shouldUseCustomBaseJar() const { I_D(BaseInstance); - return d->m_settings->get ( "UseCustomBaseJar" ).toBool(); + return d->m_settings->get("UseCustomBaseJar").toBool(); } - qint64 BaseInstance::lastLaunch() const { I_D(BaseInstance); - return d->m_settings->get ( "lastLaunchTime" ).value(); + return d->m_settings->get("lastLaunchTime").value(); } -void BaseInstance::setLastLaunch ( qint64 val ) +void BaseInstance::setLastLaunch(qint64 val) { I_D(BaseInstance); - d->m_settings->set ( "lastLaunchTime", val ); - emit propertiesChanged ( this ); + d->m_settings->set("lastLaunchTime", val); + emit propertiesChanged(this); } -void BaseInstance::setGroupInitial ( QString val ) +void BaseInstance::setGroupInitial(QString val) { I_D(BaseInstance); d->m_group = val; - emit propertiesChanged ( this ); + emit propertiesChanged(this); } -void BaseInstance::setGroupPost ( QString val ) +void BaseInstance::setGroupPost(QString val) { setGroupInitial(val); emit groupChanged(); } - QString BaseInstance::group() const { I_D(BaseInstance); return d->m_group; } -void BaseInstance::setNotes ( QString val ) +void BaseInstance::setNotes(QString val) { I_D(BaseInstance); - d->m_settings->set ( "notes", val ); + d->m_settings->set("notes", val); } QString BaseInstance::notes() const { I_D(BaseInstance); - return d->m_settings->get ( "notes" ).toString(); + return d->m_settings->get("notes").toString(); } -void BaseInstance::setIconKey ( QString val ) +void BaseInstance::setIconKey(QString val) { I_D(BaseInstance); - d->m_settings->set ( "iconKey", val ); - emit propertiesChanged ( this ); + d->m_settings->set("iconKey", val); + emit propertiesChanged(this); } QString BaseInstance::iconKey() const { I_D(BaseInstance); - return d->m_settings->get ( "iconKey" ).toString(); + return d->m_settings->get("iconKey").toString(); } -void BaseInstance::setName ( QString val ) +void BaseInstance::setName(QString val) { I_D(BaseInstance); - d->m_settings->set ( "name", val ); - emit propertiesChanged ( this ); + d->m_settings->set("name", val); + emit propertiesChanged(this); } QString BaseInstance::name() const { I_D(BaseInstance); - return d->m_settings->get ( "name" ).toString(); + return d->m_settings->get("name").toString(); } diff --git a/logic/BaseInstance_p.h b/logic/BaseInstance_p.h index 06c0c0ba..06581a34 100644 --- a/logic/BaseInstance_p.h +++ b/logic/BaseInstance_p.h @@ -1,10 +1,25 @@ +/* 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 class BaseInstance; -#define I_D(Class) Class##Private * const d = (Class##Private * const) inst_d.get() +#define I_D(Class) Class##Private *const d = (Class##Private * const)inst_d.get() struct BaseInstancePrivate { diff --git a/logic/BaseUpdate.cpp b/logic/BaseUpdate.cpp index 02b29d32..5aeb12ef 100644 --- a/logic/BaseUpdate.cpp +++ b/logic/BaseUpdate.cpp @@ -1,6 +1,21 @@ +/* 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 "BaseUpdate.h" -BaseUpdate::BaseUpdate ( BaseInstance* inst, QObject* parent ) : Task ( parent ) +BaseUpdate::BaseUpdate(BaseInstance *inst, QObject *parent) : Task(parent) { m_inst = inst; } diff --git a/logic/BaseUpdate.h b/logic/BaseUpdate.h index 9ada0770..ddeefa97 100644 --- a/logic/BaseUpdate.h +++ b/logic/BaseUpdate.h @@ -3,7 +3,7 @@ * 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 @@ -34,15 +34,14 @@ class 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); +protected +slots: + // virtual void error(const QString &msg); void updateDownloadProgress(qint64 current, qint64 total); - + protected: BaseInstance *m_inst; }; - - diff --git a/logic/BaseVersion.h b/logic/BaseVersion.h index 01745c46..1864c94c 100644 --- a/logic/BaseVersion.h +++ b/logic/BaseVersion.h @@ -3,7 +3,7 @@ * 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 @@ -14,6 +14,7 @@ */ #pragma once + #include /*! @@ -26,13 +27,13 @@ struct BaseVersion * This should be unique within the version list or shenanigans will occur. */ virtual QString descriptor() = 0; - + /*! * The name of this version as it is displayed to the user. * For example: "1.5.1" */ virtual QString name() = 0; - + /*! * This should return a string that describes * the kind of version this is (Stable, Beta, Snapshot, whatever) @@ -42,4 +43,4 @@ struct BaseVersion typedef std::shared_ptr BaseVersionPtr; -Q_DECLARE_METATYPE( BaseVersionPtr ) \ No newline at end of file +Q_DECLARE_METATYPE(BaseVersionPtr) \ No newline at end of file diff --git a/logic/CMakeLists.txt b/logic/CMakeLists.txt deleted file mode 100644 index b1eacced..00000000 --- a/logic/CMakeLists.txt +++ /dev/null @@ -1,24 +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 - -) - - diff --git a/logic/EnabledItemFilter.cpp b/logic/EnabledItemFilter.cpp index 6ecd0271..c252a0ad 100644 --- a/logic/EnabledItemFilter.cpp +++ b/logic/EnabledItemFilter.cpp @@ -1,9 +1,22 @@ +/* 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 "EnabledItemFilter.h" -EnabledItemFilter::EnabledItemFilter(QObject* parent) - :QSortFilterProxyModel(parent) +EnabledItemFilter::EnabledItemFilter(QObject *parent) : QSortFilterProxyModel(parent) { - } void EnabledItemFilter::setActive(bool active) @@ -14,17 +27,17 @@ void EnabledItemFilter::setActive(bool active) bool EnabledItemFilter::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const { - if(!m_active) + if (!m_active) return true; QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent); - if(sourceModel()->flags(index) & Qt::ItemIsEnabled) + if (sourceModel()->flags(index) & Qt::ItemIsEnabled) { return true; } return false; } -bool EnabledItemFilter::lessThan(const QModelIndex& left, const QModelIndex& right) const +bool EnabledItemFilter::lessThan(const QModelIndex &left, const QModelIndex &right) const { - return QSortFilterProxyModel::lessThan(left, right); + return QSortFilterProxyModel::lessThan(left, right); } diff --git a/logic/EnabledItemFilter.h b/logic/EnabledItemFilter.h index cb6d4041..bf5e1e85 100644 --- a/logic/EnabledItemFilter.h +++ b/logic/EnabledItemFilter.h @@ -1,3 +1,18 @@ +/* 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 @@ -7,10 +22,11 @@ class EnabledItemFilter : public QSortFilterProxyModel public: EnabledItemFilter(QObject *parent = 0); void setActive(bool active); - + protected: bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const; bool lessThan(const QModelIndex &left, const QModelIndex &right) const; + private: bool m_active = false; }; \ No newline at end of file diff --git a/logic/ForgeInstaller.cpp b/logic/ForgeInstaller.cpp index a946dd44..8d4c5b41 100644 --- a/logic/ForgeInstaller.cpp +++ b/logic/ForgeInstaller.cpp @@ -1,3 +1,18 @@ +/* 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 "ForgeInstaller.h" #include "OneSixVersion.h" #include "OneSixLibrary.h" diff --git a/logic/ForgeInstaller.h b/logic/ForgeInstaller.h index f6f22a2a..0b9f9c77 100644 --- a/logic/ForgeInstaller.h +++ b/logic/ForgeInstaller.h @@ -1,3 +1,18 @@ +/* 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 @@ -19,7 +34,3 @@ private: QString realVersionId; QString m_universal_url; }; - - - - diff --git a/logic/InstanceFactory.cpp b/logic/InstanceFactory.cpp index e64d22ca..e1f1f202 100644 --- a/logic/InstanceFactory.cpp +++ b/logic/InstanceFactory.cpp @@ -30,7 +30,7 @@ #include #include "pathutils.h" -#include +#include "logger/QsLog.h" InstanceFactory InstanceFactory::loader; @@ -129,19 +129,20 @@ InstanceFactory::InstCreateError InstanceFactory::copyInstance(BaseInstance *&ne return InstanceFactory::CantCreateDir; } auto error = loadInstance(newInstance, instDir); - switch(error) + switch (error) { - case NoLoadError: - return NoCreateError; - case UnknownLoadError: - { - rootDir.removeRecursively(); - return UnknownCreateError; - } - case NotAnInstance: - { - rootDir.removeRecursively(); - return CantCreateDir; - } - }; + case NoLoadError: + return NoCreateError; + case UnknownLoadError: + { + rootDir.removeRecursively(); + return UnknownCreateError; + } + case NotAnInstance: + { + rootDir.removeRecursively(); + return CantCreateDir; + } + } + ; } diff --git a/logic/InstanceLauncher.cpp b/logic/InstanceLauncher.cpp index 720052a3..9f78e55b 100644 --- a/logic/InstanceLauncher.cpp +++ b/logic/InstanceLauncher.cpp @@ -1,18 +1,34 @@ +/* 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 + #include "InstanceLauncher.h" #include "MultiMC.h" -#include -#include "gui/logindialog.h" -#include "gui/ProgressDialog.h" -#include "gui/consolewindow.h" +#include "gui/ConsoleWindow.h" +#include "gui/dialogs/LoginDialog.h" +#include "gui/dialogs/ProgressDialog.h" + #include "logic/net/LoginTask.h" #include "logic/MinecraftProcess.h" -#include "lists/InstanceList.h" - +#include "logic/lists/InstanceList.h" -InstanceLauncher::InstanceLauncher ( QString instId ) - :QObject(), instId ( instId ) -{} +InstanceLauncher::InstanceLauncher(QString instId) : QObject(), instId(instId) +{ +} void InstanceLauncher::onTerminated() { @@ -22,53 +38,56 @@ void InstanceLauncher::onTerminated() void InstanceLauncher::onLoginComplete() { - LoginTask * task = ( LoginTask * ) QObject::sender(); + LoginTask *task = (LoginTask *)QObject::sender(); auto result = task->getResult(); auto instance = MMC->instances()->getInstanceById(instId); - proc = instance->prepareForLaunch ( result ); - if ( !proc ) + proc = instance->prepareForLaunch(result); + if (!proc) { - //FIXME: report error + // FIXME: report error return; } console = new ConsoleWindow(proc); console->show(); - connect ( proc, SIGNAL ( ended() ), SLOT ( onTerminated() ) ); - connect ( proc, SIGNAL ( log ( QString,MessageLevel::Enum ) ), console, SLOT ( write ( QString,MessageLevel::Enum ) ) ); + connect(proc, SIGNAL(ended()), SLOT(onTerminated())); + connect(proc, SIGNAL(log(QString, MessageLevel::Enum)), console, + SLOT(write(QString, MessageLevel::Enum))); proc->launch(); } -void InstanceLauncher::doLogin ( const QString& errorMsg ) +void InstanceLauncher::doLogin(const QString &errorMsg) { - LoginDialog* loginDlg = new LoginDialog ( nullptr, errorMsg ); + LoginDialog *loginDlg = new LoginDialog(nullptr, errorMsg); loginDlg->exec(); - if ( loginDlg->result() == QDialog::Accepted ) + if (loginDlg->result() == QDialog::Accepted) { - UserInfo uInfo {loginDlg->getUsername(), loginDlg->getPassword() }; + UserInfo uInfo{loginDlg->getUsername(), loginDlg->getPassword()}; - ProgressDialog* tDialog = new ProgressDialog ( nullptr ); - LoginTask* loginTask = new LoginTask ( uInfo, tDialog ); - connect ( loginTask, SIGNAL ( succeeded() ),SLOT ( onLoginComplete() ), Qt::QueuedConnection ); - connect ( loginTask, SIGNAL ( failed ( QString ) ),SLOT ( doLogin ( QString ) ), Qt::QueuedConnection ); - tDialog->exec ( loginTask ); + ProgressDialog *tDialog = new ProgressDialog(nullptr); + LoginTask *loginTask = new LoginTask(uInfo, tDialog); + connect(loginTask, SIGNAL(succeeded()), SLOT(onLoginComplete()), Qt::QueuedConnection); + connect(loginTask, SIGNAL(failed(QString)), SLOT(doLogin(QString)), + Qt::QueuedConnection); + tDialog->exec(loginTask); } - //onLoginComplete(LoginResponse("Offline","Offline", 1)); + // onLoginComplete(LoginResponse("Offline","Offline", 1)); } int InstanceLauncher::launch() { - std::cout << "Launching Instance '" << qPrintable ( instId ) << "'" << std::endl; + std::cout << "Launching Instance '" << qPrintable(instId) << "'" << std::endl; auto instance = MMC->instances()->getInstanceById(instId); - if ( !instance ) + if (!instance) { - std::cout << "Could not find instance requested. note that you have to specify the ID, not the NAME" << std::endl; + std::cout << "Could not find instance requested. note that you have to specify the ID, " + "not the NAME" << std::endl; return 1; } std::cout << "Logging in..." << std::endl; - doLogin ( "" ); + doLogin(""); return MMC->exec(); } diff --git a/logic/InstanceLauncher.h b/logic/InstanceLauncher.h index de93e3d7..107c069f 100644 --- a/logic/InstanceLauncher.h +++ b/logic/InstanceLauncher.h @@ -1,3 +1,18 @@ +/* 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 @@ -9,20 +24,21 @@ class ConsoleWindow; class InstanceLauncher : public QObject { Q_OBJECT - + private: QString instId; MinecraftProcess *proc; ConsoleWindow *console; - + public: InstanceLauncher(QString instId); - -private slots: + +private +slots: void onTerminated(); void onLoginComplete(); void doLogin(const QString &errorMsg); - + public: int launch(); }; diff --git a/logic/JavaUtils.cpp b/logic/JavaUtils.cpp index 8e9c984f..61d0231a 100644 --- a/logic/JavaUtils.cpp +++ b/logic/JavaUtils.cpp @@ -13,21 +13,22 @@ * limitations under the License. */ -#include "JavaUtils.h" -#include "pathutils.h" -#include "MultiMC.h" - #include #include #include #include -#include -#include + #include +#include + +#include "MultiMC.h" + +#include "JavaUtils.h" +#include "logger/QsLog.h" +#include "gui/dialogs/VersionSelectDialog.h" JavaUtils::JavaUtils() { - } JavaVersionPtr JavaUtils::GetDefaultJava() @@ -48,20 +49,24 @@ QList JavaUtils::FindJavaFromRegistryKey(DWORD keyType, QString QList javas; QString archType = "unknown"; - if(keyType == KEY_WOW64_64KEY) archType = "64"; - else if(keyType == KEY_WOW64_32KEY) archType = "32"; + if (keyType == KEY_WOW64_64KEY) + archType = "64"; + else if (keyType == KEY_WOW64_32KEY) + archType = "32"; HKEY jreKey; - if (RegOpenKeyExA(HKEY_LOCAL_MACHINE, keyName.toStdString().c_str(), 0, KEY_READ | keyType | KEY_ENUMERATE_SUB_KEYS, &jreKey) == ERROR_SUCCESS) + if (RegOpenKeyExA(HKEY_LOCAL_MACHINE, keyName.toStdString().c_str(), 0, + KEY_READ | keyType | KEY_ENUMERATE_SUB_KEYS, &jreKey) == ERROR_SUCCESS) { // Read the current type version from the registry. // This will be used to find any key that contains the JavaHome value. char *value = new char[0]; DWORD valueSz = 0; - if (RegQueryValueExA(jreKey, "CurrentVersion", NULL, NULL, (BYTE*)value, &valueSz) == ERROR_MORE_DATA) + if (RegQueryValueExA(jreKey, "CurrentVersion", NULL, NULL, (BYTE *)value, &valueSz) == + ERROR_MORE_DATA) { value = new char[valueSz]; - RegQueryValueExA(jreKey, "CurrentVersion", NULL, NULL, (BYTE*)value, &valueSz); + RegQueryValueExA(jreKey, "CurrentVersion", NULL, NULL, (BYTE *)value, &valueSz); } QString recommended = value; @@ -70,37 +75,43 @@ QList JavaUtils::FindJavaFromRegistryKey(DWORD keyType, QString DWORD subKeyNameSize, numSubKeys, retCode; // Get the number of subkeys - RegQueryInfoKey(jreKey, NULL, NULL, NULL, &numSubKeys, NULL, NULL, NULL, NULL, NULL, NULL, NULL); + RegQueryInfoKey(jreKey, NULL, NULL, NULL, &numSubKeys, NULL, NULL, NULL, NULL, NULL, + NULL, NULL); // Iterate until RegEnumKeyEx fails - if(numSubKeys > 0) + if (numSubKeys > 0) { - for(int i = 0; i < numSubKeys; i++) + for (int i = 0; i < numSubKeys; i++) { subKeyNameSize = 255; - retCode = RegEnumKeyEx(jreKey, i, subKeyName, &subKeyNameSize, NULL, NULL, NULL, NULL); - if(retCode == ERROR_SUCCESS) + retCode = RegEnumKeyEx(jreKey, i, subKeyName, &subKeyNameSize, NULL, NULL, NULL, + NULL); + if (retCode == ERROR_SUCCESS) { // Now open the registry key for the version that we just got. QString newKeyName = keyName + "\\" + subKeyName; HKEY newKey; - if(RegOpenKeyEx(HKEY_LOCAL_MACHINE, newKeyName.toStdString().c_str(), 0, KEY_READ | KEY_WOW64_64KEY, &newKey) == ERROR_SUCCESS) + if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, newKeyName.toStdString().c_str(), 0, + KEY_READ | KEY_WOW64_64KEY, &newKey) == ERROR_SUCCESS) { // Read the JavaHome value to find where Java is installed. value = new char[0]; valueSz = 0; - if (RegQueryValueEx(newKey, "JavaHome", NULL, NULL, (BYTE*)value, &valueSz) == ERROR_MORE_DATA) + if (RegQueryValueEx(newKey, "JavaHome", NULL, NULL, (BYTE *)value, + &valueSz) == ERROR_MORE_DATA) { value = new char[valueSz]; - RegQueryValueEx(newKey, "JavaHome", NULL, NULL, (BYTE*)value, &valueSz); + RegQueryValueEx(newKey, "JavaHome", NULL, NULL, (BYTE *)value, + &valueSz); // Now, we construct the version object and add it to the list. JavaVersionPtr javaVersion(new JavaVersion()); javaVersion->id = subKeyName; javaVersion->arch = archType; - javaVersion->path = QDir(PathCombine(value, "bin")).absoluteFilePath("java.exe"); + javaVersion->path = + QDir(PathCombine(value, "bin")).absoluteFilePath("java.exe"); javaVersion->recommended = (recommended == subKeyName); javas.append(javaVersion); } @@ -121,17 +132,21 @@ QList JavaUtils::FindJavaPaths() { QList javas; - QList JRE64s = this->FindJavaFromRegistryKey(KEY_WOW64_64KEY, "SOFTWARE\\JavaSoft\\Java Runtime Environment"); - QList JDK64s = this->FindJavaFromRegistryKey(KEY_WOW64_64KEY, "SOFTWARE\\JavaSoft\\Java Development Kit"); - QList JRE32s = this->FindJavaFromRegistryKey(KEY_WOW64_32KEY, "SOFTWARE\\JavaSoft\\Java Runtime Environment"); - QList JDK32s = this->FindJavaFromRegistryKey(KEY_WOW64_32KEY, "SOFTWARE\\JavaSoft\\Java Development Kit"); + QList JRE64s = this->FindJavaFromRegistryKey( + KEY_WOW64_64KEY, "SOFTWARE\\JavaSoft\\Java Runtime Environment"); + QList JDK64s = this->FindJavaFromRegistryKey( + KEY_WOW64_64KEY, "SOFTWARE\\JavaSoft\\Java Development Kit"); + QList JRE32s = this->FindJavaFromRegistryKey( + KEY_WOW64_32KEY, "SOFTWARE\\JavaSoft\\Java Runtime Environment"); + QList JDK32s = this->FindJavaFromRegistryKey( + KEY_WOW64_32KEY, "SOFTWARE\\JavaSoft\\Java Development Kit"); javas.append(JRE64s); javas.append(JDK64s); javas.append(JRE32s); javas.append(JDK32s); - if(javas.size() <= 0) + if (javas.size() <= 0) { QLOG_WARN() << "Failed to find Java in the Windows registry - defaulting to \"java\""; javas.append(this->GetDefaultJava()); @@ -140,10 +155,11 @@ QList JavaUtils::FindJavaPaths() QLOG_INFO() << "Found the following Java installations (64 -> 32, JRE -> JDK): "; - for(auto &java : javas) + for (auto &java : javas) { QString sRec; - if(java->recommended) sRec = "(Recommended)"; + if (java->recommended) + sRec = "(Recommended)"; QLOG_INFO() << java->id << java->arch << " at " << java->path << sRec; } diff --git a/logic/JavaUtils.h b/logic/JavaUtils.h index e4f777d0..8d7550d0 100644 --- a/logic/JavaUtils.h +++ b/logic/JavaUtils.h @@ -17,11 +17,13 @@ #include #include -#include -#include "osutils.h" + +#include + +#include "logic/lists/JavaVersionList.h" #if WINDOWS - #include +#include #endif class JavaUtils diff --git a/logic/LegacyForge.cpp b/logic/LegacyForge.cpp index adcf487c..94212ae4 100644 --- a/logic/LegacyForge.cpp +++ b/logic/LegacyForge.cpp @@ -1,26 +1,25 @@ -// -// 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. -// +/* 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 "LegacyForge.h" -MinecraftForge::MinecraftForge ( const QString& file ) : Mod ( file ) +MinecraftForge::MinecraftForge(const QString &file) : Mod(file) { - } -bool MinecraftForge::FixVersionIfNeeded ( QString newVersion ) + +bool MinecraftForge::FixVersionIfNeeded(QString newVersion) {/* wxString reportedVersion = GetModVersion(); if(reportedVersion == "..." || reportedVersion.empty()) @@ -40,7 +39,7 @@ bool MinecraftForge::FixVersionIfNeeded ( QString newVersion ) // release last entry in.reset(); outzip.PutNextEntry("forgeversion.properties"); - + wxStringTokenizer tokenizer(newVersion,"."); wxString verFile; verFile << wxString("forge.major.number=") << tokenizer.GetNextToken() << "\n"; diff --git a/logic/LegacyForge.h b/logic/LegacyForge.h index 00a054b8..f4165ffa 100644 --- a/logic/LegacyForge.h +++ b/logic/LegacyForge.h @@ -1,25 +1,25 @@ -// -// 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. -// +/* 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 "Mod.h" class MinecraftForge : public Mod { public: - MinecraftForge ( const QString& file ); + MinecraftForge(const QString &file); bool FixVersionIfNeeded(QString newVersion); }; diff --git a/logic/LegacyInstance.cpp b/logic/LegacyInstance.cpp index 2fd18693..9a91b839 100644 --- a/logic/LegacyInstance.cpp +++ b/logic/LegacyInstance.cpp @@ -1,16 +1,35 @@ -#include "LegacyInstance.h" -#include "LegacyInstance_p.h" -#include "MinecraftProcess.h" -#include "LegacyUpdate.h" -#include "lists/IconList.h" -#include -#include -#include -#include "gui/LegacyModEditDialog.h" +/* 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 #include #include -#include +#include +#include +#include + +#include "MultiMC.h" + +#include "LegacyInstance.h" +#include "LegacyInstance_p.h" + +#include "logic/MinecraftProcess.h" +#include "logic/LegacyUpdate.h" +#include "logic/lists/IconList.h" + +#include "gui/dialogs/LegacyModEditDialog.h" #define LAUNCHER_FILE "MultiMCLauncher.jar" diff --git a/logic/LegacyInstance.h b/logic/LegacyInstance.h index 8bf334f6..8a8d4b91 100644 --- a/logic/LegacyInstance.h +++ b/logic/LegacyInstance.h @@ -1,3 +1,18 @@ +/* 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 "BaseInstance.h" @@ -58,7 +73,8 @@ public: virtual bool versionIsCustom() override { return false; - }; + } + ; virtual bool shouldUpdate() const; virtual void setShouldUpdate(bool val); diff --git a/logic/LegacyInstance_p.h b/logic/LegacyInstance_p.h index 0809b8d2..ed97ccd3 100644 --- a/logic/LegacyInstance_p.h +++ b/logic/LegacyInstance_p.h @@ -1,16 +1,30 @@ +/* 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 "BaseInstance_p.h" #include "ModList.h" -#include - -class ModList; -struct LegacyInstancePrivate: public BaseInstancePrivate +struct LegacyInstancePrivate : public BaseInstancePrivate { std::shared_ptr jar_mod_list; std::shared_ptr core_mod_list; std::shared_ptr loader_mod_list; std::shared_ptr texture_pack_list; -}; \ No newline at end of file +}; diff --git a/logic/LegacyUpdate.cpp b/logic/LegacyUpdate.cpp index 5120b241..9533f8ff 100644 --- a/logic/LegacyUpdate.cpp +++ b/logic/LegacyUpdate.cpp @@ -1,3 +1,18 @@ +/* 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 "LegacyUpdate.h" #include "lists/LwjglVersionList.h" #include "lists/MinecraftVersionList.h" @@ -9,7 +24,7 @@ #include #include #include -#include +#include "logger/QsLog.h" LegacyUpdate::LegacyUpdate(BaseInstance *inst, QObject *parent) : BaseUpdate(inst, parent) { diff --git a/logic/LegacyUpdate.h b/logic/LegacyUpdate.h index 69560f55..b30fa0b3 100644 --- a/logic/LegacyUpdate.h +++ b/logic/LegacyUpdate.h @@ -3,7 +3,7 @@ * 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 @@ -19,9 +19,9 @@ #include #include -#include "net/NetJob.h" -#include "tasks/Task.h" -#include "BaseUpdate.h" +#include "logic/net/NetJob.h" +#include "logic/tasks/Task.h" +#include "logic/BaseUpdate.h" class MinecraftVersion; class BaseInstance; @@ -34,39 +34,42 @@ class LegacyUpdate : public BaseUpdate public: explicit LegacyUpdate(BaseInstance *inst, QObject *parent = 0); virtual void executeTask(); - -private slots: + +private +slots: void lwjglStart(); - void lwjglFinished( QNetworkReply* ); + void lwjglFinished(QNetworkReply *); void lwjglFailed(); - + void jarStart(); void jarFinished(); void jarFailed(); - + void extractLwjgl(); - + void ModTheJar(); + private: enum MetainfAction { - KeepMetainf, // the META-INF folder will be added from the merged jar + KeepMetainf, // the META-INF folder will be added from the merged jar IgnoreMetainf // the META-INF from the merged jar will be ignored }; - bool MergeZipFiles(QuaZip *into, QFileInfo from, QSet& contained, MetainfAction metainf); + bool MergeZipFiles(QuaZip *into, QFileInfo from, QSet &contained, + MetainfAction metainf); + private: - + std::shared_ptr m_reply; - + // target version, determined during this task // MinecraftVersion *targetVersion; QString lwjglURL; QString lwjglVersion; - + QString lwjglTargetPath; QString lwjglNativesPath; + private: NetJobPtr legacyDownloadJob; }; - - diff --git a/logic/MinecraftProcess.h b/logic/MinecraftProcess.h index 812559d5..ad887c5b 100644 --- a/logic/MinecraftProcess.h +++ b/logic/MinecraftProcess.h @@ -14,6 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + #pragma once #include @@ -24,15 +25,17 @@ * @brief the MessageLevel Enum * defines what level a message is */ -namespace MessageLevel { -enum Enum { - MultiMC, /**< MultiMC Messages */ - Debug, /**< Debug Messages */ - Info, /**< Info Messages */ - Message, /**< Standard Messages */ - Warning, /**< Warnings */ - Error, /**< Errors */ - Fatal /**< Fatal Errors */ +namespace MessageLevel +{ +enum Enum +{ + MultiMC, /**< MultiMC Messages */ + Debug, /**< Debug Messages */ + Info, /**< Info Messages */ + Message, /**< Standard Messages */ + Warning, /**< Warnings */ + Error, /**< Errors */ + Fatal /**< Fatal Errors */ }; } @@ -56,25 +59,29 @@ public: void launch(); void setMinecraftWorkdir(QString path); - + void setMinecraftArguments(QStringList args); - + void killMinecraft(); - - inline void setLogin(QString user, QString sid) { username = user; sessionID = sid; } - + + inline void setLogin(QString user, QString sid) + { + username = user; + sessionID = sid; + } + signals: /** * @brief emitted when mc has finished and the PostLaunchCommand was run */ - void ended(BaseInstance*); + void ended(BaseInstance *); /** * @brief emitted when we want to log something * @param text the text to log * @param level the level to log at */ - void log(QString text, MessageLevel::Enum level=MessageLevel::MultiMC); + void log(QString text, MessageLevel::Enum level = MessageLevel::MultiMC); protected: BaseInstance *m_instance; @@ -83,10 +90,12 @@ protected: QString m_out_leftover; QProcess m_prepostlaunchprocess; -protected slots: +protected +slots: void finish(int, QProcess::ExitStatus status); void on_stdErr(); void on_stdOut(); + private: bool killed; MessageLevel::Enum getLevel(const QString &message, MessageLevel::Enum defaultLevel); diff --git a/logic/MinecraftVersion.h b/logic/MinecraftVersion.h index 53c2f5ef..504381a8 100644 --- a/logic/MinecraftVersion.h +++ b/logic/MinecraftVersion.h @@ -3,7 +3,7 @@ * 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 @@ -25,10 +25,10 @@ struct MinecraftVersion : public BaseVersion * This is primarily used for sorting versions in a list. */ qint64 timestamp; - + /// The URL that this version will be downloaded from. maybe. QString download_url; - + /// This version's type. Used internally to identify what kind of version this is. enum VersionType { @@ -36,31 +36,31 @@ struct MinecraftVersion : public BaseVersion Legacy, Nostalgia } type; - + /// is this the latest version? bool is_latest = false; - + /// is this a snapshot? bool is_snapshot = false; - + QString m_name; - + QString m_descriptor; - - virtual QString descriptor() + + virtual QString descriptor() { return m_descriptor; } - - virtual QString name() + + virtual QString name() { return m_name; } - + virtual QString typeString() const { QStringList pre_final; - if(is_latest == true) + if (is_latest == true) { pre_final.append("Latest"); } @@ -75,12 +75,12 @@ struct MinecraftVersion : public BaseVersion case Nostalgia: pre_final.append("Nostalgia"); break; - + default: pre_final.append(QString("Type(%1)").arg(type)); break; } - if(is_snapshot == true) + if (is_snapshot == true) { pre_final.append("Snapshot"); } diff --git a/logic/Mod.cpp b/logic/Mod.cpp index c45e3ad2..f9647eea 100644 --- a/logic/Mod.cpp +++ b/logic/Mod.cpp @@ -1,18 +1,17 @@ -// -// 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. -// +/* 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 #include @@ -26,7 +25,7 @@ #include "Mod.h" #include #include -#include +#include "logger/QsLog.h" Mod::Mod(const QFileInfo &file) { @@ -121,11 +120,12 @@ void Mod::ReadMCModInfo(QByteArray contents) m_homeurl = firstObj.value("url").toString(); m_description = firstObj.value("description").toString(); QJsonArray authors = firstObj.value("authors").toArray(); - if(authors.size() == 0) m_authors = ""; - else if(authors.size() >= 1) + if (authors.size() == 0) + m_authors = ""; + else if (authors.size() >= 1) { m_authors = authors.at(0).toString(); - for(int i = 1; i < authors.size(); i++) + for (int i = 1; i < authors.size(); i++) { m_authors += ", " + authors.at(i).toString(); } diff --git a/logic/Mod.h b/logic/Mod.h index f3aaf18b..ca362a9d 100644 --- a/logic/Mod.h +++ b/logic/Mod.h @@ -1,18 +1,17 @@ -// -// 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. -// +/* 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 diff --git a/logic/ModList.cpp b/logic/ModList.cpp index 236f0db6..8ec73955 100644 --- a/logic/ModList.cpp +++ b/logic/ModList.cpp @@ -1,18 +1,17 @@ -// -// 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. -// +/* 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 "ModList.h" #include "LegacyInstance.h" @@ -21,7 +20,7 @@ #include #include #include -#include +#include "logger/QsLog.h" ModList::ModList(const QString &dir, const QString &list_file) : QAbstractListModel(), m_dir(dir), m_list_file(list_file) diff --git a/logic/ModList.h b/logic/ModList.h index e99b6c82..803a5429 100644 --- a/logic/ModList.h +++ b/logic/ModList.h @@ -1,22 +1,29 @@ -// -// 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 -// +/* 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 -class LegacyInstance; -class BaseInstance; #include #include #include #include -#include "Mod.h" +#include "logic/Mod.h" + +class LegacyInstance; +class BaseInstance; class QFileSystemWatcher; /** @@ -27,91 +34,105 @@ class ModList : public QAbstractListModel { Q_OBJECT public: - ModList(const QString& dir, const QString& list_file = QString()); + ModList(const QString &dir, const QString &list_file = QString()); - virtual QVariant data ( const QModelIndex& index, int role = Qt::DisplayRole ) const; - virtual int rowCount ( const QModelIndex& parent = QModelIndex() ) const + virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; + virtual int rowCount(const QModelIndex &parent = QModelIndex()) const { return size(); - }; - virtual QVariant headerData ( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const; - virtual int columnCount ( const QModelIndex& parent ) const; - - size_t size() const { return mods.size(); }; - bool empty() const { return size() == 0; } - Mod& operator[](size_t index) { return mods[index]; }; - + } + ; + virtual QVariant headerData(int section, Qt::Orientation orientation, + int role = Qt::DisplayRole) const; + virtual int columnCount(const QModelIndex &parent) const; + + size_t size() const + { + return mods.size(); + } + ; + bool empty() const + { + return size() == 0; + } + Mod &operator[](size_t index) + { + return mods[index]; + } + ; + /// Reloads the mod list and returns true if the list changed. virtual bool update(); /** * Adds the given mod to the list at the given index - if the list supports custom ordering */ - virtual bool installMod(const QFileInfo& filename, int index = 0); + virtual bool installMod(const QFileInfo &filename, int index = 0); /// Deletes the mod at the given index. virtual bool deleteMod(int index); - + /// Deletes all the selected mods - virtual bool deleteMods( int first, int last ); - + virtual bool deleteMods(int first, int last); + /** * move the mod at index to the position N * 0 is the beginning of the list, length() is the end of the list. */ virtual bool moveModTo(int from, int to); - + /** * move the mod at index one position upwards */ virtual bool moveModUp(int from); - virtual bool moveModsUp( int first, int last ); - + virtual bool moveModsUp(int first, int last); + /** * move the mod at index one position downwards */ virtual bool moveModDown(int from); - virtual bool moveModsDown( int first, int last ); - + virtual bool moveModsDown(int first, int last); + /// flags, mostly to support drag&drop - virtual Qt::ItemFlags flags(const QModelIndex& index) const; + virtual Qt::ItemFlags flags(const QModelIndex &index) const; /// get data for drag action - virtual QMimeData* mimeData(const QModelIndexList& indexes) const; + virtual QMimeData *mimeData(const QModelIndexList &indexes) const; /// get the supported mime types virtual QStringList mimeTypes() const; /// process data from drop action - virtual bool dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column, const QModelIndex& parent); + virtual bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, + const QModelIndex &parent); /// what drag actions do we support? virtual Qt::DropActions supportedDragActions() const; - + /// what drop actions do we support? virtual Qt::DropActions supportedDropActions() const; - + void startWatching(); void stopWatching(); - + virtual bool isValid(); - + QDir dir() { return m_dir; } + private: QStringList readListFile(); bool saveListFile(); -private slots: +private +slots: void directoryChanged(QString path); - + signals: void changed(); + protected: - QFileSystemWatcher * m_watcher; + QFileSystemWatcher *m_watcher; bool is_watching; QDir m_dir; QString m_list_file; QString m_list_id; QList mods; }; - - - diff --git a/logic/NagUtils.cpp b/logic/NagUtils.cpp index ccabf71f..6f81b3c7 100644 --- a/logic/NagUtils.cpp +++ b/logic/NagUtils.cpp @@ -13,25 +13,26 @@ * limitations under the License. */ -#include "NagUtils.h" -#include "gui/CustomMessageBox.h" +#include "logic/NagUtils.h" +#include "gui/dialogs/CustomMessageBox.h" namespace NagUtils { void checkJVMArgs(QString jvmargs, QWidget *parent) { - if(jvmargs.contains("-XX:PermSize=") || jvmargs.contains(QRegExp("-Xm[sx]"))) + if (jvmargs.contains("-XX:PermSize=") || jvmargs.contains(QRegExp("-Xm[sx]"))) { - CustomMessageBox::selectable(parent, parent->tr("JVM arguments warning"), - parent->tr("You tried to manually set a JVM memory option (using " - " \"-XX:PermSize\", \"-Xmx\" or \"-Xms\") - there" - " are dedicated boxes for these in the settings (Java" - " tab, in the Memory group at the top).\n" - "Your manual settings will be overridden by the" - " dedicated options.\n" - "This message will be displayed until you remove them" - " from the JVM arguments."), - QMessageBox::Warning)->exec(); + CustomMessageBox::selectable( + parent, parent->tr("JVM arguments warning"), + parent->tr("You tried to manually set a JVM memory option (using " + " \"-XX:PermSize\", \"-Xmx\" or \"-Xms\") - there" + " are dedicated boxes for these in the settings (Java" + " tab, in the Memory group at the top).\n" + "Your manual settings will be overridden by the" + " dedicated options.\n" + "This message will be displayed until you remove them" + " from the JVM arguments."), + QMessageBox::Warning)->exec(); } } } diff --git a/logic/NostalgiaInstance.cpp b/logic/NostalgiaInstance.cpp index efd8f46b..2e23ee71 100644 --- a/logic/NostalgiaInstance.cpp +++ b/logic/NostalgiaInstance.cpp @@ -1,9 +1,24 @@ +/* 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 "NostalgiaInstance.h" -NostalgiaInstance::NostalgiaInstance ( const QString& rootDir, SettingsObject* settings, QObject* parent ) - : OneSixInstance ( rootDir