Massive renaming in the backend folder, all around restructure in the same.

This commit is contained in:
Petr Mrázek 2013-07-29 00:59:35 +02:00
parent 8808a8b108
commit 2e0cbf393a
66 changed files with 491 additions and 962 deletions

View File

@ -13,7 +13,7 @@
* limitations under the License. * limitations under the License.
*/ */
#include "appsettings.h" #include "AppSettings.h"
#include <setting.h> #include <setting.h>

View File

@ -13,20 +13,17 @@
* limitations under the License. * limitations under the License.
*/ */
#ifndef APPSETTINGS_H #pragma once
#define APPSETTINGS_H
#include <QObject> #include <QObject>
#include <inisettingsobject.h> #include <inisettingsobject.h>
#include "libmmc_config.h" class AppSettings : public INISettingsObject
class LIBMULTIMC_EXPORT AppSettings : public INISettingsObject
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit AppSettings(QObject *parent = 0); explicit AppSettings(QObject *parent = 0);
}; };
#endif // APPSETTINGS_H

View File

@ -13,7 +13,7 @@
* limitations under the License. * limitations under the License.
*/ */
#include "version.h" #include "AppVersion.h"
#include "config.h" #include "config.h"

View File

@ -13,17 +13,14 @@
* limitations under the License. * limitations under the License.
*/ */
#ifndef VERSION_H #pragma once
#define VERSION_H
#include <QObject> #include <QObject>
#include "libmmc_config.h"
/*! /*!
* \brief The Version class represents a MultiMC version number. * \brief The Version class represents a MultiMC version number.
*/ */
class LIBMULTIMC_EXPORT Version : public QObject class Version : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
@ -66,4 +63,3 @@ public:
static Version current; static Version current;
}; };
#endif // VERSION_H

View File

@ -28,9 +28,6 @@ ENDIF()
################################ INCLUDE LIBRARIES ################################ ################################ INCLUDE LIBRARIES ################################
# First, include header overrides
include_directories(hacks)
######## 3rd Party Libs ######## ######## 3rd Party Libs ########
# Find the required Qt parts # Find the required Qt parts
@ -68,7 +65,7 @@ add_subdirectory(libsettings)
include_directories(${LIBSETTINGS_INCLUDE_DIR}) include_directories(${LIBSETTINGS_INCLUDE_DIR})
# Add the instance library. # Add the instance library.
add_subdirectory(libmultimc) add_subdirectory(backend)
include_directories(${LIBMULTIMC_INCLUDE_DIR}) include_directories(${LIBMULTIMC_INCLUDE_DIR})
# Add the group view library. # Add the group view library.
@ -161,6 +158,10 @@ ADD_DEFINITIONS(-DQUAZIP_STATIC)
######## Headers ######## ######## Headers ########
SET(MULTIMC_HEADERS SET(MULTIMC_HEADERS
multimc_pragma.h
AppVersion.h
AppSettings.h
gui/mainwindow.h gui/mainwindow.h
gui/modeditdialog.h gui/modeditdialog.h
gui/legacymodeditdialog.h gui/legacymodeditdialog.h
@ -178,8 +179,6 @@ gui/lwjglselectdialog.h
gui/iconcache.h gui/iconcache.h
gui/instancesettings.h gui/instancesettings.h
multimc_pragma.h
java/annotations.h java/annotations.h
java/classfile.h java/classfile.h
java/constants.h java/constants.h
@ -193,6 +192,8 @@ java/membuffer.h
######## Sources ######## ######## Sources ########
SET(MULTIMC_SOURCES SET(MULTIMC_SOURCES
main.cpp main.cpp
AppVersion.cpp
AppSettings.cpp
gui/mainwindow.cpp gui/mainwindow.cpp
gui/modeditdialog.cpp gui/modeditdialog.cpp
@ -270,9 +271,9 @@ ADD_EXECUTABLE(MultiMC MACOSX_BUNDLE WIN32
# Link # Link
QT5_USE_MODULES(MultiMC Widgets Network WebKitWidgets) QT5_USE_MODULES(MultiMC Widgets Network WebKitWidgets)
TARGET_LINK_LIBRARIES(MultiMC quazip patchlib TARGET_LINK_LIBRARIES(MultiMC quazip patchlib
libUtil libSettings libMultiMC libGroupView libUtil libSettings backend libGroupView
${MultiMC_LINK_ADDITIONAL_LIBS}) ${MultiMC_LINK_ADDITIONAL_LIBS})
ADD_DEPENDENCIES(MultiMC MultiMCLauncher libUtil libSettings libMultiMC libGroupView) ADD_DEPENDENCIES(MultiMC MultiMCLauncher libUtil libSettings backend libGroupView)
option(BUILD_KEYRING_TEST "Build the simple keyring test binary" OFF) option(BUILD_KEYRING_TEST "Build the simple keyring test binary" OFF)
@ -288,7 +289,7 @@ IF(BUILD_ASSET_TEST)
# test.cpp # test.cpp
ADD_EXECUTABLE(AssetTest asset_test.cpp) ADD_EXECUTABLE(AssetTest asset_test.cpp)
QT5_USE_MODULES(AssetTest Core Network) QT5_USE_MODULES(AssetTest Core Network)
TARGET_LINK_LIBRARIES(AssetTest libUtil libMultiMC libSettings) TARGET_LINK_LIBRARIES(AssetTest libUtil backend libSettings)
ENDIF() ENDIF()

View File

@ -13,7 +13,7 @@
* limitations under the License. * limitations under the License.
*/ */
#include "include/instance.h" #include "BaseInstance.h"
#include <QFileInfo> #include <QFileInfo>
@ -22,19 +22,18 @@
#include "overridesetting.h" #include "overridesetting.h"
#include "pathutils.h" #include "pathutils.h"
#include <minecraftversionlist.h> #include <lists/MinecraftVersionList.h>
Instance::Instance(const QString &rootDir, QObject *parent) : BaseInstance::BaseInstance(const QString &rootDir, QObject *parent) :
QObject(parent) QObject(parent)
{ {
m_rootDir = rootDir; m_rootDir = rootDir;
m_settings = new INISettingsObject(configFile(), this); m_settings = new INISettingsObject(PathCombine(rootDir, "instance.cfg"), this);
settings().registerSetting(new Setting("name", "Unnamed Instance")); settings().registerSetting(new Setting("name", "Unnamed Instance"));
settings().registerSetting(new Setting("iconKey", "default")); settings().registerSetting(new Setting("iconKey", "default"));
settings().registerSetting(new Setting("notes", "")); settings().registerSetting(new Setting("notes", ""));
settings().registerSetting(new Setting("NeedsRebuild", true)); settings().registerSetting(new Setting("NeedsRebuild", true));
settings().registerSetting(new Setting("IsForNewLauncher", false));
settings().registerSetting(new Setting("ShouldUpdate", false)); settings().registerSetting(new Setting("ShouldUpdate", false));
settings().registerSetting(new Setting("JarVersion", "Unknown")); settings().registerSetting(new Setting("JarVersion", "Unknown"));
settings().registerSetting(new Setting("LwjglVersion", "2.9.0")); settings().registerSetting(new Setting("LwjglVersion", "2.9.0"));
@ -77,17 +76,17 @@ Instance::Instance(const QString &rootDir, QObject *parent) :
settings().registerSetting(new Setting("OverrideCommands", false)); settings().registerSetting(new Setting("OverrideCommands", false));
} }
QString Instance::id() const QString BaseInstance::id() const
{ {
return QFileInfo(rootDir()).fileName(); return QFileInfo(rootDir()).fileName();
} }
QString Instance::rootDir() const QString BaseInstance::rootDir() const
{ {
return m_rootDir; return m_rootDir;
} }
InstanceList *Instance::instList() const InstanceList *BaseInstance::instList() const
{ {
if (parent()->inherits("InstanceList")) if (parent()->inherits("InstanceList"))
return (InstanceList *)parent(); return (InstanceList *)parent();
@ -95,7 +94,7 @@ InstanceList *Instance::instList() const
return NULL; return NULL;
} }
QString Instance::minecraftDir() const QString BaseInstance::minecraftDir() const
{ {
QFileInfo mcDir(PathCombine(rootDir(), "minecraft")); QFileInfo mcDir(PathCombine(rootDir(), "minecraft"));
QFileInfo dotMCDir(PathCombine(rootDir(), ".minecraft")); QFileInfo dotMCDir(PathCombine(rootDir(), ".minecraft"));
@ -106,78 +105,73 @@ QString Instance::minecraftDir() const
return mcDir.filePath(); return mcDir.filePath();
} }
QString Instance::instModsDir() const QString BaseInstance::instModsDir() const
{ {
return PathCombine(rootDir(), "instMods"); return PathCombine(rootDir(), "instMods");
} }
QString Instance::binDir() const QString BaseInstance::binDir() const
{ {
return PathCombine(minecraftDir(), "bin"); return PathCombine(minecraftDir(), "bin");
} }
QString Instance::savesDir() const QString BaseInstance::savesDir() const
{ {
return PathCombine(minecraftDir(), "saves"); return PathCombine(minecraftDir(), "saves");
} }
QString Instance::mlModsDir() const QString BaseInstance::mlModsDir() const
{ {
return PathCombine(minecraftDir(), "mods"); return PathCombine(minecraftDir(), "mods");
} }
QString Instance::coreModsDir() const QString BaseInstance::coreModsDir() const
{ {
return PathCombine(minecraftDir(), "coremods"); return PathCombine(minecraftDir(), "coremods");
} }
QString Instance::resourceDir() const QString BaseInstance::resourceDir() const
{ {
return PathCombine(minecraftDir(), "resources"); return PathCombine(minecraftDir(), "resources");
} }
QString Instance::screenshotsDir() const QString BaseInstance::screenshotsDir() const
{ {
return PathCombine(minecraftDir(), "screenshots"); return PathCombine(minecraftDir(), "screenshots");
} }
QString Instance::texturePacksDir() const QString BaseInstance::texturePacksDir() const
{ {
return PathCombine(minecraftDir(), "texturepacks"); return PathCombine(minecraftDir(), "texturepacks");
} }
QString Instance::mcJar() const QString BaseInstance::mcJar() const
{ {
return PathCombine(binDir(), "minecraft.jar"); return PathCombine(binDir(), "minecraft.jar");
} }
QString Instance::mcBackup() const QString BaseInstance::mcBackup() const
{ {
return PathCombine(binDir(), "mcbackup.jar"); return PathCombine(binDir(), "mcbackup.jar");
} }
QString Instance::configFile() const QString BaseInstance::modListFile() const
{
return PathCombine(rootDir(), "instance.cfg");
}
QString Instance::modListFile() const
{ {
return PathCombine(rootDir(), "modlist"); return PathCombine(rootDir(), "modlist");
} }
InstVersionList *Instance::versionList() const InstVersionList *BaseInstance::versionList() const
{ {
return &MinecraftVersionList::getMainList(); return &MinecraftVersionList::getMainList();
} }
bool Instance::shouldUpdateCurrentVersion() const bool BaseInstance::shouldUpdateCurrentVersion() const
{ {
QFileInfo jar(mcJar()); QFileInfo jar(mcJar());
return jar.lastModified().toUTC().toMSecsSinceEpoch() != lastCurrentVersionUpdate(); return jar.lastModified().toUTC().toMSecsSinceEpoch() != lastCurrentVersionUpdate();
} }
void Instance::updateCurrentVersion(bool keepCurrent) void BaseInstance::updateCurrentVersion(bool keepCurrent)
{ {
QFileInfo jar(mcJar()); QFileInfo jar(mcJar());
@ -199,7 +193,7 @@ void Instance::updateCurrentVersion(bool keepCurrent)
} }
} }
SettingsObject &Instance::settings() const SettingsObject &BaseInstance::settings() const
{ {
return *m_settings; return *m_settings;
} }

View File

@ -13,8 +13,7 @@
* limitations under the License. * limitations under the License.
*/ */
#ifndef INSTANCE_H #pragma once
#define INSTANCE_H
#include <QObject> #include <QObject>
#include <QDateTime> #include <QDateTime>
@ -22,7 +21,7 @@
#include <settingsobject.h> #include <settingsobject.h>
#include "inifile.h" #include "inifile.h"
#include "instversionlist.h" #include "lists/InstVersionList.h"
#include "libmmc_config.h" #include "libmmc_config.h"
@ -36,7 +35,7 @@ class InstanceList;
* To create a new instance type, create a new class inheriting from this class * To create a new instance type, create a new class inheriting from this class
* and implement the pure virtual functions. * and implement the pure virtual functions.
*/ */
class LIBMULTIMC_EXPORT Instance : public QObject class LIBMULTIMC_EXPORT BaseInstance : public QObject
{ {
Q_OBJECT Q_OBJECT
@ -67,6 +66,14 @@ class LIBMULTIMC_EXPORT Instance : public QObject
//! The instance's group. //! The instance's group.
Q_PROPERTY(QString group READ group WRITE setGroup) Q_PROPERTY(QString group READ group WRITE setGroup)
/*!
* Gets the time that the instance was last launched.
* Stored in milliseconds since epoch.
* This value is usually used for things like sorting instances by the time
* they were last launched.
*/
Q_PROPERTY(qint64 lastLaunch READ lastLaunch WRITE setLastLaunch)
/*! /*!
* Whether or not the instance's minecraft.jar needs to be rebuilt. * 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 * If this is true, when the instance launches, its jar mods will be
@ -100,14 +107,6 @@ class LIBMULTIMC_EXPORT Instance : public QObject
Q_PROPERTY(QString lwjglVersion READ lwjglVersion WRITE setLWJGLVersion) Q_PROPERTY(QString lwjglVersion READ lwjglVersion WRITE setLWJGLVersion)
/*!
* Gets the time that the instance was last launched.
* Stored in milliseconds since epoch.
* This value is usually used for things like sorting instances by the time
* they were last launched.
*/
Q_PROPERTY(qint64 lastLaunch READ lastLaunch WRITE setLastLaunch)
/*! /*!
* Gets the last time that the current version was checked. * 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 * This is checked against the last modified time on the jar file to see if
@ -115,11 +114,6 @@ class LIBMULTIMC_EXPORT Instance : public QObject
*/ */
Q_PROPERTY(qint64 lastCurrentVersionUpdate READ lastCurrentVersionUpdate WRITE setLastCurrentVersionUpdate) Q_PROPERTY(qint64 lastCurrentVersionUpdate READ lastCurrentVersionUpdate WRITE setLastCurrentVersionUpdate)
/*!
* Is the instance a new launcher instance? Get/Set
*/
Q_PROPERTY(bool isForNewLauncher READ isForNewLauncher WRITE setIsForNewLauncher)
// Dirs // Dirs
//! Path to the instance's .minecraft folder. //! Path to the instance's .minecraft folder.
Q_PROPERTY(QString minecraftDir READ minecraftDir STORED false) Q_PROPERTY(QString minecraftDir READ minecraftDir STORED false)
@ -156,22 +150,11 @@ class LIBMULTIMC_EXPORT Instance : public QObject
//! Path to the instance's mcbackup.jar //! Path to the instance's mcbackup.jar
Q_PROPERTY(QString mcBackup READ mcBackup STORED false) Q_PROPERTY(QString mcBackup READ mcBackup STORED false)
//! Path to the instance's config file.
Q_PROPERTY(QString configFile READ configFile STORED false)
//! Path to the instance's modlist file. //! Path to the instance's modlist file.
Q_PROPERTY(QString modListFile READ modListFile STORED false) Q_PROPERTY(QString modListFile READ modListFile STORED false)
public: public:
explicit Instance(const QString &rootDir, QObject *parent = 0); explicit BaseInstance(const QString &rootDir, QObject *parent = 0);
// Please, for the sake of my (and everyone else's) sanity, at least keep this shit
// *somewhat* organized. Also, documentation is semi-important here. Please don't
// leave undocumented stuff behind.
// As a side-note, doxygen processes comments for accessor functions and
// properties separately, so please document properties in the massive block of
// Q_PROPERTY declarations above rather than documenting their accessors.
//////// STUFF //////// //////// STUFF ////////
virtual QString id() const; virtual QString id() const;
@ -252,16 +235,6 @@ public:
virtual qint64 lastCurrentVersionUpdate() const { return settings().get("lastVersionUpdate").value<qint64>(); } virtual qint64 lastCurrentVersionUpdate() const { return settings().get("lastVersionUpdate").value<qint64>(); }
virtual void setLastCurrentVersionUpdate(qint64 val) { settings().set("lastVersionUpdate", val); } virtual void setLastCurrentVersionUpdate(qint64 val) { settings().set("lastVersionUpdate", val); }
virtual bool isForNewLauncher()
{
return settings().get("IsForNewLauncher").value<bool>();
}
virtual void setIsForNewLauncher(bool value = true)
{
settings().set("IsForNewLauncher", value);
}
////// Directories ////// ////// Directories //////
QString minecraftDir() const; QString minecraftDir() const;
QString instModsDir() const; QString instModsDir() const;
@ -277,7 +250,6 @@ public:
////// Files ////// ////// Files //////
QString mcJar() const; QString mcJar() const;
QString mcBackup() const; QString mcBackup() const;
QString configFile() const;
QString modListFile() const; QString modListFile() const;
@ -328,7 +300,7 @@ signals:
/*! /*!
* \brief Signal emitted when properties relevant to the instance view change * \brief Signal emitted when properties relevant to the instance view change
*/ */
void propertiesChanged(Instance * inst); void propertiesChanged(BaseInstance * inst);
private: private:
QString m_rootDir; QString m_rootDir;
@ -337,6 +309,5 @@ private:
}; };
// pointer for lazy people // pointer for lazy people
typedef QSharedPointer<Instance> InstancePtr; typedef QSharedPointer<BaseInstance> InstancePtr;
#endif // INSTANCE_H

91
backend/CMakeLists.txt Normal file
View File

@ -0,0 +1,91 @@
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
# Instance Stuff
BaseInstance.h
LegacyInstance.h
OneSixInstance.h
InstanceFactory.h
# Versions
InstanceVersion.h
MinecraftVersion.h
OneSixVersion.h
VersionFactory.h
# Lists
lists/InstanceList.h
lists/InstVersionList.h
lists/MinecraftVersionList.h
lists/LwjglVersionList.h
# Tasks
tasks/Task.h
tasks/LoginTask.h
tasks/LoginResponse.h
tasks/UserInfo.h
tasks/GameUpdateTask.h
MinecraftProcess.h
)
SET(LIBINST_SOURCES
# Instance Stuff
BaseInstance.cpp
LegacyInstance.cpp
OneSixInstance.cpp
InstanceFactory.cpp
# Versions
InstanceVersion.cpp
MinecraftVersion.cpp
OneSixVersion.cpp
VersionFactory.cpp
# Lists
lists/InstanceList.cpp
lists/InstVersionList.cpp
lists/MinecraftVersionList.cpp
lists/LwjglVersionList.cpp
# Tasks
tasks/Task.cpp
tasks/LoginTask.cpp
tasks/GameUpdateTask.cpp
tasks/UserInfo.cpp
tasks/LoginResponse.cpp
MinecraftProcess.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)

View File

@ -13,28 +13,28 @@
* limitations under the License. * limitations under the License.
*/ */
#include "include/instanceloader.h" #include "InstanceFactory.h"
#include <QDir> #include <QDir>
#include <QFileInfo> #include <QFileInfo>
#include "include/instance.h" #include "BaseInstance.h"
#include "inifile.h" #include "inifile.h"
#include "pathutils.h" #include "pathutils.h"
InstanceLoader InstanceLoader::loader; InstanceFactory InstanceFactory::loader;
InstanceLoader::InstanceLoader() : InstanceFactory::InstanceFactory() :
QObject(NULL) QObject(NULL)
{ {
} }
InstanceLoader::InstLoadError InstanceLoader::loadInstance(Instance *&inst, const QString &instDir) InstanceFactory::InstLoadError InstanceFactory::loadInstance(BaseInstance *&inst, const QString &instDir)
{ {
Instance *loadedInst = new Instance(instDir, this); BaseInstance *loadedInst = new BaseInstance(instDir, this);
// TODO: Sanity checks to verify that the instance is valid. // TODO: Sanity checks to verify that the instance is valid.
@ -44,18 +44,18 @@ InstanceLoader::InstLoadError InstanceLoader::loadInstance(Instance *&inst, cons
} }
InstanceLoader::InstCreateError InstanceLoader::createInstance(Instance *&inst, const QString &instDir) InstanceFactory::InstCreateError InstanceFactory::createInstance(BaseInstance *&inst, const QString &instDir)
{ {
QDir rootDir(instDir); QDir rootDir(instDir);
qDebug(instDir.toUtf8()); qDebug(instDir.toUtf8());
if (!rootDir.exists() && !rootDir.mkpath(".")) if (!rootDir.exists() && !rootDir.mkpath("."))
{ {
return InstanceLoader::CantCreateDir; return InstanceFactory::CantCreateDir;
} }
inst = new Instance(instDir, this); inst = new BaseInstance(instDir, this);
//FIXME: really, how do you even know? //FIXME: really, how do you even know?
return InstanceLoader::NoCreateError; return InstanceFactory::NoCreateError;
} }

View File

@ -13,8 +13,7 @@
* limitations under the License. * limitations under the License.
*/ */
#ifndef INSTANCELOADER_H #pragma once
#define INSTANCELOADER_H
#include <QObject> #include <QObject>
#include <QMap> #include <QMap>
@ -22,19 +21,19 @@
#include "libmmc_config.h" #include "libmmc_config.h"
class Instance; class BaseInstance;
/*! /*!
* The InstanceLoader is a singleton that manages loading and creating instances. * The \bInstanceFactory\b is a singleton that manages loading and creating instances.
*/ */
class LIBMULTIMC_EXPORT InstanceLoader : public QObject class LIBMULTIMC_EXPORT InstanceFactory : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
/*! /*!
* \brief Gets a reference to the instance loader. * \brief Gets a reference to the instance loader.
*/ */
static InstanceLoader &get() { return loader; } static InstanceFactory &get() { return loader; }
enum InstLoadError enum InstLoadError
{ {
@ -61,7 +60,7 @@ public:
* - InstExists if the given instance directory is already an instance. * - InstExists if the given instance directory is already an instance.
* - CantCreateDir if the given instance directory cannot be created. * - CantCreateDir if the given instance directory cannot be created.
*/ */
InstCreateError createInstance(Instance *&inst, const QString &instDir); InstCreateError createInstance(BaseInstance *&inst, const QString &instDir);
/*! /*!
* \brief Loads an instance from the given directory. * \brief Loads an instance from the given directory.
@ -71,12 +70,10 @@ public:
* \return An InstLoadError error code. * \return An InstLoadError error code.
* - NotAnInstance if the given instance directory isn't a valid instance. * - NotAnInstance if the given instance directory isn't a valid instance.
*/ */
InstLoadError loadInstance(Instance *&inst, const QString &instDir); InstLoadError loadInstance(BaseInstance *&inst, const QString &instDir);
private: private:
InstanceLoader(); InstanceFactory();
static InstanceLoader loader; static InstanceFactory loader;
}; };
#endif // INSTANCELOADER_H

View File

@ -13,8 +13,8 @@
* limitations under the License. * limitations under the License.
*/ */
#include "include/instversion.h" #include "InstanceVersion.h"
#include "include/instversionlist.h" #include "lists/InstVersionList.h"
InstVersion::InstVersion(const QString &descriptor, InstVersion::InstVersion(const QString &descriptor,
const QString &name, const QString &name,

View File

@ -13,8 +13,7 @@
* limitations under the License. * limitations under the License.
*/ */
#ifndef INSTVERSION_H #pragma once
#define INSTVERSION_H
#include <QObject> #include <QObject>
@ -120,5 +119,3 @@ protected:
QString m_name; QString m_name;
qint64 m_timestamp; qint64 m_timestamp;
}; };
#endif // INSTVERSION_H

View File

1
backend/LegacyInstance.h Normal file
View File

@ -0,0 +1 @@
#pragma once

View File

@ -15,7 +15,7 @@
* limitations under the License. * limitations under the License.
*/ */
#include "minecraftprocess.h" #include "MinecraftProcess.h"
#include <QDataStream> #include <QDataStream>
#include <QFile> #include <QFile>
@ -23,57 +23,17 @@
//#include <QImage> //#include <QImage>
#include <QProcessEnvironment> #include <QProcessEnvironment>
#include "instance.h" #include "BaseInstance.h"
#include "osutils.h" #include "osutils.h"
#include "pathutils.h" #include "pathutils.h"
#include "cmdutils.h"
#define LAUNCHER_FILE "MultiMCLauncher.jar" #define LAUNCHER_FILE "MultiMCLauncher.jar"
#define IBUS "@im=ibus" #define IBUS "@im=ibus"
// commandline splitter
QStringList MinecraftProcess::splitArgs(QString args)
{
QStringList argv;
QString current;
bool escape = false;
QChar inquotes;
for (int i=0; i<args.length(); i++)
{
QChar cchar = args.at(i);
// \ escaped
if (escape) {
current += cchar;
escape = false;
// in "quotes"
} else if (!inquotes.isNull()) {
if (cchar == 0x5C)
escape = true;
else if (cchar == inquotes)
inquotes = 0;
else
current += cchar;
// otherwise
} else {
if (cchar == 0x20) {
if (!current.isEmpty()) {
argv << current;
current.clear();
}
} else if (cchar == 0x22 || cchar == 0x27)
inquotes = cchar;
else
current += cchar;
}
}
if (!current.isEmpty())
argv << current;
return argv;
}
// prepare tools // prepare tools
inline void MinecraftProcess::extractIcon(Instance *inst, QString destination) inline void MinecraftProcess::extractIcon(BaseInstance *inst, QString destination)
{ {
// QImage(":/icons/instances/" + inst->iconKey()).save(destination); // QImage(":/icons/instances/" + inst->iconKey()).save(destination);
} }
@ -83,14 +43,14 @@ inline void MinecraftProcess::extractLauncher(QString destination)
QFile(":/launcher/launcher.jar").copy(destination); QFile(":/launcher/launcher.jar").copy(destination);
} }
void MinecraftProcess::prepare(Instance *inst) void MinecraftProcess::prepare(BaseInstance *inst)
{ {
extractLauncher(PathCombine(inst->minecraftDir(), LAUNCHER_FILE)); extractLauncher(PathCombine(inst->minecraftDir(), LAUNCHER_FILE));
extractIcon(inst, PathCombine(inst->minecraftDir(), "icon.png")); extractIcon(inst, PathCombine(inst->minecraftDir(), "icon.png"));
} }
// constructor // constructor
MinecraftProcess::MinecraftProcess(Instance *inst, QString user, QString session) : MinecraftProcess::MinecraftProcess(BaseInstance *inst, QString user, QString session) :
m_instance(inst), m_user(user), m_session(session) m_instance(inst), m_user(user), m_session(session)
{ {
connect(this, SIGNAL(finished(int, QProcess::ExitStatus)), SLOT(finish(int, QProcess::ExitStatus))); connect(this, SIGNAL(finished(int, QProcess::ExitStatus)), SLOT(finish(int, QProcess::ExitStatus)));
@ -245,7 +205,7 @@ void MinecraftProcess::genArgs()
windowTitle.append("MultiMC: ").append(m_instance->name()); windowTitle.append("MultiMC: ").append(m_instance->name());
// Java arguments // Java arguments
m_arguments.append(splitArgs(m_instance->settings().get("JvmArgs").toString())); m_arguments.append(Util::Commandline::splitArgs(m_instance->settings().get("JvmArgs").toString()));
#ifdef OSX #ifdef OSX
// OSX dock icon and name // OSX dock icon and name

View File

@ -14,12 +14,11 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
#ifndef MINECRAFTPROCESS_H #pragma once
#define MINECRAFTPROCESS_H
#include <QProcess> #include <QProcess>
#include "instance.h" #include "BaseInstance.h"
#include "libmmc_config.h" #include "libmmc_config.h"
@ -54,7 +53,7 @@ public:
* @param session the minecraft session id * @param session the minecraft session id
* @param console the instance console window * @param console the instance console window
*/ */
MinecraftProcess(Instance *inst, QString user, QString session); MinecraftProcess(BaseInstance *inst, QString user, QString session);
/** /**
* @brief launch minecraft * @brief launch minecraft
@ -66,7 +65,7 @@ public:
* @param inst the instance * @param inst the instance
* @param destination the destination path * @param destination the destination path
*/ */
static inline void extractIcon(Instance *inst, QString destination); static inline void extractIcon(BaseInstance *inst, QString destination);
/** /**
* @brief extract the MultiMC launcher.jar * @brief extract the MultiMC launcher.jar
@ -78,14 +77,7 @@ public:
* @brief prepare the launch by extracting icon and launcher * @brief prepare the launch by extracting icon and launcher
* @param inst the instance * @param inst the instance
*/ */
static void prepare(Instance *inst); static void prepare(BaseInstance *inst);
/**
* @brief split a string into argv items like a shell would do
* @param args the argument string
* @return a QStringList containing all arguments
*/
static QStringList splitArgs(QString args);
signals: signals:
/** /**
@ -101,7 +93,7 @@ signals:
void log(QString text, MessageLevel::Enum level=MessageLevel::MultiMC); void log(QString text, MessageLevel::Enum level=MessageLevel::MultiMC);
protected: protected:
Instance *m_instance; BaseInstance *m_instance;
QString m_user; QString m_user;
QString m_session; QString m_session;
QString m_err_leftover; QString m_err_leftover;
@ -117,5 +109,3 @@ protected slots:
void on_stdOut(); void on_stdOut();
}; };
#endif // MINECRAFTPROCESS_H

View File

@ -13,7 +13,7 @@
* limitations under the License. * limitations under the License.
*/ */
#include "minecraftversion.h" #include "MinecraftVersion.h"
MinecraftVersion::MinecraftVersion(QString descriptor, MinecraftVersion::MinecraftVersion(QString descriptor,
QString name, QString name,
@ -23,7 +23,6 @@ MinecraftVersion::MinecraftVersion(QString descriptor,
InstVersionList *parent) : InstVersionList *parent) :
InstVersion(descriptor, name, timestamp, parent), m_dlUrl(dlUrl), m_etag(etag) InstVersion(descriptor, name, timestamp, parent), m_dlUrl(dlUrl), m_etag(etag)
{ {
m_isNewLauncherVersion = false;
} }
QString MinecraftVersion::descriptor() const QString MinecraftVersion::descriptor() const
@ -85,14 +84,14 @@ QString MinecraftVersion::etag() const
return m_etag; return m_etag;
} }
MinecraftVersion::LauncherVersion MinecraftVersion::launcherVersion() const MinecraftVersion::VersionSource MinecraftVersion::versionSource() const
{ {
return m_launcherVersion; return m_versionSource;
}; };
void MinecraftVersion::setLauncherVersion(LauncherVersion launcherVersion) void MinecraftVersion::setVersionSource(VersionSource launcherVersion)
{ {
m_launcherVersion = launcherVersion; m_versionSource = launcherVersion;
} }
InstVersion *MinecraftVersion::copyVersion(InstVersionList *newParent) const InstVersion *MinecraftVersion::copyVersion(InstVersionList *newParent) const
@ -100,6 +99,6 @@ InstVersion *MinecraftVersion::copyVersion(InstVersionList *newParent) const
MinecraftVersion *version = new MinecraftVersion( MinecraftVersion *version = new MinecraftVersion(
descriptor(), name(), timestamp(), downloadURL(), etag(), newParent); descriptor(), name(), timestamp(), downloadURL(), etag(), newParent);
version->setVersionType(versionType()); version->setVersionType(versionType());
version->setLauncherVersion(launcherVersion()); version->setVersionSource(VersionSource());
return version; return version;
} }

View File

@ -13,38 +13,16 @@
* limitations under the License. * limitations under the License.
*/ */
#ifndef MINECRAFTVERSION_H #pragma once
#define MINECRAFTVERSION_H
#include "libmmc_config.h" #include "libmmc_config.h"
#include "instversion.h" #include "InstanceVersion.h"
class LIBMULTIMC_EXPORT MinecraftVersion : public InstVersion class LIBMULTIMC_EXPORT MinecraftVersion : public InstVersion
{ {
Q_OBJECT Q_OBJECT
/*!
* This version's type. Used internally to identify what kind of version this is.
*/
Q_PROPERTY(VersionType versionType READ versionType WRITE setVersionType)
/*!
* This version's launcher. Used to identify the launcher version this is intended for.
*/
Q_PROPERTY(LauncherVersion versionType READ launcherVersion WRITE setLauncherVersion)
/*!
* The URL that this version will be downloaded from.
*/
Q_PROPERTY(QString downloadURL READ downloadURL)
/*!
* ETag/MD5 Used to verify the integrity of the downloaded minecraft.jar.
*/
Q_PROPERTY(QString etag READ etag)
public: public:
explicit MinecraftVersion(QString descriptor, explicit MinecraftVersion(QString descriptor,
QString name, QString name,
@ -64,7 +42,7 @@ public:
MCNostalgia MCNostalgia
}; };
enum LauncherVersion enum VersionSource
{ {
Unknown = -1, Unknown = -1,
Legacy = 0, // the legacy launcher that's been around since ... forever Legacy = 0, // the legacy launcher that's been around since ... forever
@ -79,8 +57,8 @@ public:
virtual VersionType versionType() const; virtual VersionType versionType() const;
virtual void setVersionType(VersionType typeName); virtual void setVersionType(VersionType typeName);
virtual LauncherVersion launcherVersion() const; virtual VersionSource versionSource() const;
virtual void setLauncherVersion(LauncherVersion launcherVersion); virtual void setVersionSource(VersionSource launcherVersion);
virtual QString downloadURL() const; virtual QString downloadURL() const;
virtual QString etag() const; virtual QString etag() const;
@ -88,12 +66,15 @@ public:
virtual InstVersion *copyVersion(InstVersionList *newParent) const; virtual InstVersion *copyVersion(InstVersionList *newParent) const;
private: private:
/// The URL that this version will be downloaded from. maybe.
QString m_dlUrl; QString m_dlUrl;
/// ETag/MD5 Used to verify the integrity of the downloaded minecraft.jar.
QString m_etag; QString m_etag;
/// This version's type. Used internally to identify what kind of version this is.
VersionType m_type; VersionType m_type;
LauncherVersion m_launcherVersion;
bool m_isNewLauncherVersion; /// Whete to get the full version info (or, where did we get this version from originally)
VersionSource m_versionSource;
}; };
#endif // MINECRAFTVERSION_H

View File

1
backend/OneSixInstance.h Normal file
View File

@ -0,0 +1 @@
#pragma once

View File

@ -1,19 +1,4 @@
/* Copyright 2013 MultiMC Contributors #include "OneSixVersion.h"
*
* 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/library.h"
RuleAction RuleAction_fromString(QString name) RuleAction RuleAction_fromString(QString name)
{ {
@ -78,4 +63,29 @@ void Library::finalize()
m_is_active = m_is_active && m_native_suffixes.contains ( currentSystem ); m_is_active = m_is_active && m_native_suffixes.contains ( currentSystem );
} }
} }
// default url for lib:
QList<QSharedPointer<Library> > FullVersion::getActiveNormalLibs()
{
QList<QSharedPointer<Library> > output;
for ( auto lib: libraries )
{
if (lib->getIsActive() && !lib->getIsNative())
{
output.append(lib);
}
}
return output;
}
QList<QSharedPointer<Library> > FullVersion::getActiveNativeLibs()
{
QList<QSharedPointer<Library> > output;
for ( auto lib: libraries )
{
if (lib->getIsActive() && lib->getIsNative())
{
output.append(lib);
}
}
return output;
}

View File

@ -1,20 +1,4 @@
/* 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 #pragma once
#include <QtCore> #include <QtCore>
class Library; class Library;
@ -206,3 +190,76 @@ public:
return m_is_native; return m_is_native;
} }
}; };
class FullVersion
{
public:
/// the ID - determines which jar to use! ACTUALLY IMPORTANT!
QString id;
/// Last updated time - as a string
QString time;
/// Release time - as a string
QString releaseTime;
/// Release type - "release" or "snapshot"
QString type;
/**
* DEPRECATED: Old versions of the new vanilla launcher used this
* ex: "username_session_version"
*/
QString processArguments;
/**
* arguments that should be used for launching minecraft
*
* ex: "--username ${auth_player_name} --session ${auth_session}
* --version ${version_name} --gameDir ${game_directory} --assetsDir ${game_assets}"
*/
QString minecraftArguments;
/**
* the minimum launcher version required by this version ... current is 4 (at point of writing)
*/
int minimumLauncherVersion;
/**
* The main class to load first
*/
QString mainClass;
/// the list of libs - both active and inactive, native and java
QList<QSharedPointer<Library> > libraries;
/**
* is this actually a legacy version? if so, none of the other stuff here will be ever used.
* added by FullVersionFactory
*/
bool isLegacy;
/*
FIXME: add support for those rules here? Looks like a pile of quick hacks to me though.
"rules": [
{
"action": "allow"
},
{
"action": "disallow",
"os": {
"name": "osx",
"version": "^10\\.5\\.\\d$"
}
}
],
"incompatibilityReason": "There is a bug in LWJGL which makes it incompatible with OSX 10.5.8. Please go to New Profile and use 1.5.2 for now. Sorry!"
}
*/
// QList<Rule> rules;
public:
FullVersion()
{
minimumLauncherVersion = 0xDEADBEEF;
isLegacy = false;
}
QList<QSharedPointer<Library> > getActiveNormalLibs();
QList<QSharedPointer<Library> > getActiveNativeLibs();
};

View File

@ -1,17 +1,5 @@
#include "fullversionfactory.h" #include "VersionFactory.h"
#include "fullversion.h" #include "OneSixVersion.h"
#include <library.h>
class LibraryFinalizer
{
public:
LibraryFinalizer(QSharedPointer<Library> library)
{
m_library = library;
}
QSharedPointer<Library> m_library;
};
// Library rules (if any) // Library rules (if any)
QList<QSharedPointer<Rule> > FullVersionFactory::parse4rules(QJsonObject & baseObj) QList<QSharedPointer<Rule> > FullVersionFactory::parse4rules(QJsonObject & baseObj)

View File

@ -13,8 +13,7 @@
* limitations under the License. * limitations under the License.
*/ */
//#ifndef LIBINSTANCE_CONFIG_H #pragma once
//#define LIBINSTANCE_CONFIG_H
#include <QtCore/QtGlobal> #include <QtCore/QtGlobal>
@ -23,5 +22,3 @@
#else #else
# define LIBMULTIMC_EXPORT Q_DECL_IMPORT # define LIBMULTIMC_EXPORT Q_DECL_IMPORT
#endif #endif
//#endif // LIBINSTANCE_CONFIG_H

View File

@ -13,8 +13,8 @@
* limitations under the License. * limitations under the License.
*/ */
#include "instversionlist.h" #include "InstVersionList.h"
#include "instversion.h" #include "InstanceVersion.h"
InstVersionList::InstVersionList(QObject *parent) : InstVersionList::InstVersionList(QObject *parent) :
QAbstractListModel(parent) QAbstractListModel(parent)

View File

@ -13,8 +13,7 @@
* limitations under the License. * limitations under the License.
*/ */
#ifndef INSTVERSIONLIST_H #pragma once
#define INSTVERSIONLIST_H
#include <QObject> #include <QObject>
#include <QVariant> #include <QVariant>
@ -120,5 +119,3 @@ protected slots:
*/ */
virtual void updateListData(QList<InstVersion *> versions) = 0; virtual void updateListData(QList<InstVersion *> versions) = 0;
}; };
#endif // INSTVERSIONLIST_H

View File

@ -13,8 +13,6 @@
* limitations under the License. * limitations under the License.
*/ */
#include "include/instancelist.h"
#include <QDir> #include <QDir>
#include <QFile> #include <QFile>
#include <QDirIterator> #include <QDirIterator>
@ -24,8 +22,9 @@
#include <QJsonObject> #include <QJsonObject>
#include <QJsonArray> #include <QJsonArray>
#include "include/instance.h" #include "lists/InstanceList.h"
#include "include/instanceloader.h" #include "BaseInstance.h"
#include "InstanceFactory.h"
#include "pathutils.h" #include "pathutils.h"
@ -139,20 +138,20 @@ InstanceList::InstListError InstanceList::loadList()
if (!QFileInfo(PathCombine(subDir, "instance.cfg")).exists()) if (!QFileInfo(PathCombine(subDir, "instance.cfg")).exists())
continue; continue;
Instance *instPtr = NULL; BaseInstance *instPtr = NULL;
auto &loader = InstanceLoader::get(); auto &loader = InstanceFactory::get();
auto error = loader.loadInstance(instPtr, subDir); auto error = loader.loadInstance(instPtr, subDir);
switch(error) switch(error)
{ {
case InstanceLoader::NoLoadError: case InstanceFactory::NoLoadError:
break; break;
case InstanceLoader::NotAnInstance: case InstanceFactory::NotAnInstance:
break; break;
} }
if (error != InstanceLoader::NoLoadError && if (error != InstanceFactory::NoLoadError &&
error != InstanceLoader::NotAnInstance) error != InstanceFactory::NotAnInstance)
{ {
QString errorMsg = QString("Failed to load instance %1: "). QString errorMsg = QString("Failed to load instance %1: ").
arg(QFileInfo(subDir).baseName()).toUtf8(); arg(QFileInfo(subDir).baseName()).toUtf8();
@ -173,7 +172,7 @@ InstanceList::InstListError InstanceList::loadList()
} }
else else
{ {
QSharedPointer<Instance> inst(instPtr); QSharedPointer<BaseInstance> inst(instPtr);
auto iter = groupMap.find(inst->id()); auto iter = groupMap.find(inst->id());
if(iter != groupMap.end()) if(iter != groupMap.end())
{ {
@ -182,7 +181,7 @@ InstanceList::InstListError InstanceList::loadList()
qDebug(QString("Loaded instance %1").arg(inst->name()).toUtf8()); qDebug(QString("Loaded instance %1").arg(inst->name()).toUtf8());
inst->setParent(this); inst->setParent(this);
m_instances.append(inst); m_instances.append(inst);
connect(instPtr, SIGNAL(propertiesChanged(Instance*)),this, SLOT(propertiesChanged(Instance*))); connect(instPtr, SIGNAL(propertiesChanged(BaseInstance*)),this, SLOT(propertiesChanged(BaseInstance*)));
} }
} }
emit invalidated(); emit invalidated();
@ -220,7 +219,7 @@ InstancePtr InstanceList::getInstanceById(QString instId)
return iter.peekPrevious(); return iter.peekPrevious();
} }
void InstanceList::propertiesChanged(Instance * inst) void InstanceList::propertiesChanged(BaseInstance * inst)
{ {
for(int i = 0; i < m_instances.count(); i++) for(int i = 0; i < m_instances.count(); i++)
{ {

View File

@ -13,16 +13,15 @@
* limitations under the License. * limitations under the License.
*/ */
#ifndef INSTANCELIST_H #pragma once
#define INSTANCELIST_H
#include <QObject> #include <QObject>
#include <QSharedPointer> #include <QSharedPointer>
#include "instance.h" #include "BaseInstance.h"
#include "libmmc_config.h" #include "libmmc_config.h"
class Instance; class BaseInstance;
class LIBMULTIMC_EXPORT InstanceList : public QObject class LIBMULTIMC_EXPORT InstanceList : public QObject
{ {
@ -85,11 +84,9 @@ signals:
void invalidated(); void invalidated();
private slots: private slots:
void propertiesChanged(Instance * inst); void propertiesChanged(BaseInstance * inst);
protected: protected:
QString m_instDir; QString m_instDir;
QList< InstancePtr > m_instances; QList< InstancePtr > m_instances;
}; };
#endif // INSTANCELIST_H

View File

@ -13,7 +13,7 @@
* limitations under the License. * limitations under the License.
*/ */
#include "include/lwjglversionlist.h" #include "LwjglVersionList.h"
#include <QtNetwork> #include <QtNetwork>

View File

@ -13,8 +13,7 @@
* limitations under the License. * limitations under the License.
*/ */
#ifndef LWJGLVERSIONLIST_H #pragma once
#define LWJGLVERSIONLIST_H
#include <QObject> #include <QObject>
#include <QAbstractListModel> #include <QAbstractListModel>
@ -131,4 +130,3 @@ private slots:
virtual void netRequestComplete(); virtual void netRequestComplete();
}; };
#endif // LWJGLVERSIONLIST_H

View File

@ -13,7 +13,7 @@
* limitations under the License. * limitations under the License.
*/ */
#include "include/minecraftversionlist.h" #include "MinecraftVersionList.h"
#include <QDebug> #include <QDebug>
@ -295,7 +295,7 @@ bool MCVListLoadTask::loadFromVList()
MinecraftVersion *mcVersion = new MinecraftVersion( MinecraftVersion *mcVersion = new MinecraftVersion(
versionID, versionID, versionTime.toMSecsSinceEpoch(), versionID, versionID, versionTime.toMSecsSinceEpoch(),
dlUrl, ""); dlUrl, "");
mcVersion->setLauncherVersion(MinecraftVersion::Launcher16); mcVersion->setVersionSource(MinecraftVersion::Launcher16);
mcVersion->setVersionType(versionType); mcVersion->setVersionType(versionType);
tempList.append(mcVersion); tempList.append(mcVersion);
} }

View File

@ -13,8 +13,7 @@
* limitations under the License. * limitations under the License.
*/ */
#ifndef MINECRAFTVERSIONLIST_H #pragma once
#define MINECRAFTVERSIONLIST_H
#include <QObject> #include <QObject>
@ -22,11 +21,11 @@
#include <QList> #include <QList>
#include "instversionlist.h" #include "InstVersionList.h"
#include "task.h" #include "tasks/Task.h"
#include "minecraftversion.h" #include "MinecraftVersion.h"
#include "libmmc_config.h" #include "libmmc_config.h"
@ -105,5 +104,3 @@ protected:
bool processedMCNReply; bool processedMCNReply;
}; };
#endif // MINECRAFTVERSIONLIST_H

View File

@ -13,7 +13,7 @@
* limitations under the License. * limitations under the License.
*/ */
#include "gameupdatetask.h" #include "GameUpdateTask.h"
#include <QtNetwork> #include <QtNetwork>
@ -24,14 +24,14 @@
#include <QDebug> #include <QDebug>
#include "minecraftversionlist.h" #include "lists/MinecraftVersionList.h"
#include "fullversionfactory.h" #include "VersionFactory.h"
#include <fullversion.h> #include "OneSixVersion.h"
#include "pathutils.h" #include "pathutils.h"
GameUpdateTask::GameUpdateTask(const LoginResponse &response, Instance *inst, QObject *parent) : GameUpdateTask::GameUpdateTask(const LoginResponse &response, BaseInstance *inst, QObject *parent) :
Task(parent), m_response(response) Task(parent), m_response(response)
{ {
m_inst = inst; m_inst = inst;
@ -60,7 +60,7 @@ void GameUpdateTask::executeTask()
setState(StateDetermineURLs); setState(StateDetermineURLs);
if (targetVersion->launcherVersion() == MinecraftVersion::Launcher16) if (targetVersion->versionSource() == MinecraftVersion::Launcher16)
{ {
determineNewVersion(); determineNewVersion();
} }
@ -141,7 +141,7 @@ void GameUpdateTask::jarlibFinished()
{ {
m_inst->setCurrentVersion(targetVersion->descriptor()); m_inst->setCurrentVersion(targetVersion->descriptor());
m_inst->setShouldUpdate(false); m_inst->setShouldUpdate(false);
m_inst->setIsForNewLauncher(true); // m_inst->setIsForNewLauncher(true);
exit(1); exit(1);
} }
@ -173,7 +173,7 @@ void GameUpdateTask::getLegacyJar()
// This will be either 'minecraft' or the version number, depending on where // This will be either 'minecraft' or the version number, depending on where
// we're downloading from. // we're downloading from.
QString jarFilename = "minecraft"; QString jarFilename = "minecraft";
if (targetVersion->launcherVersion() == MinecraftVersion::Launcher16) if (targetVersion->versionSource() == MinecraftVersion::Launcher16)
{ {
jarFilename = targetVersion->descriptor(); jarFilename = targetVersion->descriptor();
} }
@ -196,7 +196,7 @@ void GameUpdateTask::legacyJarFinished()
{ {
setState(StateFinished); setState(StateFinished);
emit gameUpdateComplete(m_response); emit gameUpdateComplete(m_response);
m_inst->setIsForNewLauncher(true); // m_inst->setIsForNewLauncher(true);
exit(1); exit(1);
} }

View File

@ -13,8 +13,7 @@
* limitations under the License. * limitations under the License.
*/ */
#ifndef GAMEUPDATETASK_H #pragma once
#define GAMEUPDATETASK_H
#include <QObject> #include <QObject>
@ -24,9 +23,9 @@
#include <QUrl> #include <QUrl>
#include "dlqueue.h" #include "dlqueue.h"
#include "task.h" #include "Task.h"
#include "loginresponse.h" #include "tasks/LoginResponse.h"
#include "instance.h" #include "BaseInstance.h"
#include "libmmc_config.h" #include "libmmc_config.h"
@ -51,7 +50,7 @@ class LIBMULTIMC_EXPORT GameUpdateTask : public Task
*/ */
Q_PROPERTY(QString subStatus READ subStatus WRITE setSubStatus) Q_PROPERTY(QString subStatus READ subStatus WRITE setSubStatus)
public: public:
explicit GameUpdateTask(const LoginResponse &response, Instance *inst, QObject *parent = 0); explicit GameUpdateTask(const LoginResponse &response, BaseInstance *inst, QObject *parent = 0);
///////////////////////// /////////////////////////
@ -119,7 +118,7 @@ private:
// STUFF // // STUFF //
/////////// ///////////
Instance *m_inst; BaseInstance *m_inst;
LoginResponse m_response; LoginResponse m_response;
//////////////////////////// ////////////////////////////
@ -156,4 +155,3 @@ private:
}; };
#endif // GAMEUPDATETASK_H

View File

@ -13,7 +13,7 @@
* limitations under the License. * limitations under the License.
*/ */
#include "loginresponse.h" #include "tasks/LoginResponse.h"
LoginResponse::LoginResponse(const QString& username, const QString& sessionID, LoginResponse::LoginResponse(const QString& username, const QString& sessionID,
qint64 latestVersion, QObject *parent) : qint64 latestVersion, QObject *parent) :

View File

@ -13,8 +13,7 @@
* limitations under the License. * limitations under the License.
*/ */
#ifndef LOGINRESPONSE_H #pragma once
#define LOGINRESPONSE_H
#include <QObject> #include <QObject>
@ -93,4 +92,3 @@ private:
Q_DECLARE_METATYPE(LoginResponse) Q_DECLARE_METATYPE(LoginResponse)
#endif // LOGINRESPONSE_H

View File

@ -13,7 +13,7 @@
* limitations under the License. * limitations under the License.
*/ */
#include "logintask.h" #include "LoginTask.h"
#include <QStringList> #include <QStringList>

View File

@ -16,10 +16,10 @@
#ifndef LOGINTASK_H #ifndef LOGINTASK_H
#define LOGINTASK_H #define LOGINTASK_H
#include "task.h" #include "Task.h"
#include "userinfo.h" #include "UserInfo.h"
#include "loginresponse.h" #include "tasks/LoginResponse.h"
#include "libmmc_config.h" #include "libmmc_config.h"

View File

@ -13,7 +13,7 @@
* limitations under the License. * limitations under the License.
*/ */
#include "task.h" #include "Task.h"
Task::Task(QObject *parent) : Task::Task(QObject *parent) :
QThread(parent) QThread(parent)

View File

@ -13,7 +13,7 @@
* limitations under the License. * limitations under the License.
*/ */
#include "userinfo.h" #include "UserInfo.h"
UserInfo::UserInfo(const QString &username, const QString &password, QObject *parent) : UserInfo::UserInfo(const QString &username, const QString &password, QObject *parent) :
QObject(parent) QObject(parent)

View File

@ -2,7 +2,7 @@
#define CONSOLEWINDOW_H #define CONSOLEWINDOW_H
#include <QDialog> #include <QDialog>
#include "minecraftprocess.h" #include "MinecraftProcess.h"
namespace Ui { namespace Ui {
class ConsoleWindow; class ConsoleWindow;

View File

@ -53,7 +53,7 @@ QVariant InstanceModel::data ( const QModelIndex& index, int role ) const
{ {
return QVariant(); return QVariant();
} }
Instance *pdata = static_cast<Instance*> ( index.internalPointer() ); BaseInstance *pdata = static_cast<BaseInstance*> ( index.internalPointer() );
switch ( role ) switch ( role )
{ {
case InstancePointerRole: case InstancePointerRole:
@ -114,8 +114,8 @@ InstanceProxyModel::InstanceProxyModel ( QObject *parent )
bool InstanceProxyModel::subSortLessThan ( bool InstanceProxyModel::subSortLessThan (
const QModelIndex& left, const QModelIndex& right ) const const QModelIndex& left, const QModelIndex& right ) const
{ {
Instance *pdataLeft = static_cast<Instance*> ( left.internalPointer() ); BaseInstance *pdataLeft = static_cast<BaseInstance*> ( left.internalPointer() );
Instance *pdataRight = static_cast<Instance*> ( right.internalPointer() ); BaseInstance *pdataRight = static_cast<BaseInstance*> ( right.internalPointer() );
//kDebug() << *pdataLeft << *pdataRight; //kDebug() << *pdataLeft << *pdataRight;
return QString::localeAwareCompare(pdataLeft->name(), pdataRight->name()) < 0; return QString::localeAwareCompare(pdataLeft->name(), pdataRight->name()) < 0;
//return pdataLeft->name() < pdataRight->name(); //return pdataLeft->name() < pdataRight->name();

View File

@ -2,7 +2,7 @@
#include <QAbstractListModel> #include <QAbstractListModel>
#include "kcategorizedsortfilterproxymodel.h" #include "kcategorizedsortfilterproxymodel.h"
#include "instancelist.h" #include "lists/InstanceList.h"
#include <QIcon> #include <QIcon>
class InstanceModel : public QAbstractListModel class InstanceModel : public QAbstractListModel

View File

@ -15,9 +15,9 @@
#include "legacymodeditdialog.h" #include "legacymodeditdialog.h"
#include "ui_legacymodeditdialog.h" #include "ui_legacymodeditdialog.h"
#include "instance.h" #include "BaseInstance.h"
LegacyModEditDialog::LegacyModEditDialog(QWidget *parent, Instance* m_inst) : LegacyModEditDialog::LegacyModEditDialog(QWidget *parent, BaseInstance* m_inst) :
QDialog(parent), QDialog(parent),
ui(new Ui::LegacyModEditDialog) ui(new Ui::LegacyModEditDialog)
{ {

View File

@ -18,7 +18,7 @@
#include <QDialog> #include <QDialog>
#include "instance.h" #include "BaseInstance.h"
namespace Ui { namespace Ui {
class LegacyModEditDialog; class LegacyModEditDialog;
@ -29,7 +29,7 @@ class LegacyModEditDialog : public QDialog
Q_OBJECT Q_OBJECT
public: public:
explicit LegacyModEditDialog(QWidget *parent = 0, Instance* m_inst = 0); explicit LegacyModEditDialog(QWidget *parent = 0, BaseInstance* m_inst = 0);
~LegacyModEditDialog(); ~LegacyModEditDialog();
private slots: private slots:

View File

@ -16,7 +16,7 @@
#include "lwjglselectdialog.h" #include "lwjglselectdialog.h"
#include "ui_lwjglselectdialog.h" #include "ui_lwjglselectdialog.h"
#include "lwjglversionlist.h" #include "lists/LwjglVersionList.h"
LWJGLSelectDialog::LWJGLSelectDialog(QWidget *parent) : LWJGLSelectDialog::LWJGLSelectDialog(QWidget *parent) :
QDialog(parent), QDialog(parent),

View File

@ -48,22 +48,22 @@
#include "kcategorizedview.h" #include "kcategorizedview.h"
#include "kcategorydrawer.h" #include "kcategorydrawer.h"
#include "instancelist.h" #include "lists/InstanceList.h"
#include "appsettings.h" #include "AppSettings.h"
#include "version.h" #include "AppVersion.h"
#include "logintask.h" #include "tasks/LoginTask.h"
#include "gameupdatetask.h" #include "tasks/GameUpdateTask.h"
#include "instance.h" #include "BaseInstance.h"
#include "instanceloader.h" #include "InstanceFactory.h"
#include "minecraftprocess.h" #include "MinecraftProcess.h"
#include "instancemodel.h" #include "instancemodel.h"
#include "instancedelegate.h" #include "instancedelegate.h"
#include "minecraftversionlist.h" #include "lists/MinecraftVersionList.h"
#include "lwjglversionlist.h" #include "lists/LwjglVersionList.h"
// Opens the given file in the default application. // Opens the given file in the default application.
// TODO: Move this somewhere. // TODO: Move this somewhere.
@ -89,16 +89,16 @@ MainWindow::MainWindow ( QWidget *parent ) :
view->setPalette(pal); view->setPalette(pal);
*/ */
// view->setStyleSheet( view->setStyleSheet(
// "QListView\ "QListView\
// {\ {\
// background-image: url(:/backgrounds/kitteh);\ background-image: url(:/backgrounds/kitteh);\
// background-attachment: fixed;\ background-attachment: fixed;\
// background-clip: padding;\ background-clip: padding;\
// background-position: top right;\ background-position: top right;\
// background-repeat: none;\ background-repeat: none;\
// background-color:palette(base);\ background-color:palette(base);\
// }"); }");
view->setSelectionMode ( QAbstractItemView::SingleSelection ); view->setSelectionMode ( QAbstractItemView::SingleSelection );
//view->setSpacing( KDialog::spacingHint() ); //view->setSpacing( KDialog::spacingHint() );
@ -168,7 +168,7 @@ void MainWindow::instanceActivated ( QModelIndex index )
{ {
if(!index.isValid()) if(!index.isValid())
return; return;
Instance * inst = (Instance *) index.data(InstanceModel::InstancePointerRole).value<void *>(); BaseInstance * inst = (BaseInstance *) index.data(InstanceModel::InstancePointerRole).value<void *>();
doLogin(); doLogin();
} }
@ -186,29 +186,29 @@ void MainWindow::on_actionAddInstance_triggered()
if (!newInstDlg->exec()) if (!newInstDlg->exec())
return; return;
Instance *newInstance = NULL; BaseInstance *newInstance = NULL;
QString instDirName = DirNameFromString(newInstDlg->instName()); QString instDirName = DirNameFromString(newInstDlg->instName());
QString instDir = PathCombine(globalSettings->get("InstanceDir").toString(), instDirName); QString instDir = PathCombine(globalSettings->get("InstanceDir").toString(), instDirName);
auto &loader = InstanceLoader::get(); auto &loader = InstanceFactory::get();
auto error = loader.createInstance(newInstance, instDir); auto error = loader.createInstance(newInstance, instDir);
QString errorMsg = QString("Failed to create instance %1: ").arg(instDirName); QString errorMsg = QString("Failed to create instance %1: ").arg(instDirName);
switch (error) switch (error)
{ {
case InstanceLoader::NoCreateError: case InstanceFactory::NoCreateError:
newInstance->setName(newInstDlg->instName()); newInstance->setName(newInstDlg->instName());
newInstance->setIntendedVersion(newInstDlg->selectedVersion()->descriptor()); newInstance->setIntendedVersion(newInstDlg->selectedVersion()->descriptor());
instList.add(InstancePtr(newInstance)); instList.add(InstancePtr(newInstance));
return; return;
case InstanceLoader::InstExists: case InstanceFactory::InstExists:
errorMsg += "An instance with the given directory name already exists."; errorMsg += "An instance with the given directory name already exists.";
QMessageBox::warning(this, "Error", errorMsg); QMessageBox::warning(this, "Error", errorMsg);
break; break;
case InstanceLoader::CantCreateDir: case InstanceFactory::CantCreateDir:
errorMsg += "Failed to create the instance directory."; errorMsg += "Failed to create the instance directory.";
QMessageBox::warning(this, "Error", errorMsg); QMessageBox::warning(this, "Error", errorMsg);
break; break;
@ -222,7 +222,7 @@ void MainWindow::on_actionAddInstance_triggered()
void MainWindow::on_actionChangeInstGroup_triggered() void MainWindow::on_actionChangeInstGroup_triggered()
{ {
Instance* inst = selectedInstance(); BaseInstance* inst = selectedInstance();
if(inst) if(inst)
{ {
bool ok = false; bool ok = false;
@ -291,7 +291,7 @@ void MainWindow::on_mainToolBar_visibilityChanged ( bool )
void MainWindow::on_actionDeleteInstance_triggered() void MainWindow::on_actionDeleteInstance_triggered()
{ {
Instance* inst = selectedInstance(); BaseInstance* inst = selectedInstance();
if (inst) if (inst)
{ {
int response = QMessageBox::question(this, "CAREFUL", int response = QMessageBox::question(this, "CAREFUL",
@ -306,7 +306,7 @@ void MainWindow::on_actionDeleteInstance_triggered()
void MainWindow::on_actionRenameInstance_triggered() void MainWindow::on_actionRenameInstance_triggered()
{ {
Instance* inst = selectedInstance(); BaseInstance* inst = selectedInstance();
if(inst) if(inst)
{ {
bool ok = false; bool ok = false;
@ -324,7 +324,7 @@ void MainWindow::on_actionRenameInstance_triggered()
void MainWindow::on_actionViewSelectedInstFolder_triggered() void MainWindow::on_actionViewSelectedInstFolder_triggered()
{ {
Instance* inst = selectedInstance(); BaseInstance* inst = selectedInstance();
if(inst) if(inst)
{ {
QString str = inst->rootDir(); QString str = inst->rootDir();
@ -335,7 +335,7 @@ void MainWindow::on_actionViewSelectedInstFolder_triggered()
void MainWindow::on_actionEditInstMods_triggered() void MainWindow::on_actionEditInstMods_triggered()
{ {
//TODO: Needs to do current ModEditDialog too //TODO: Needs to do current ModEditDialog too
Instance* inst = selectedInstance(); BaseInstance* inst = selectedInstance();
if (inst) if (inst)
{ {
LegacyModEditDialog dialog ( this, inst ); LegacyModEditDialog dialog ( this, inst );
@ -362,7 +362,7 @@ void MainWindow::on_instanceView_customContextMenuRequested ( const QPoint &pos
instContextMenu->exec ( view->mapToGlobal ( pos ) ); instContextMenu->exec ( view->mapToGlobal ( pos ) );
} }
Instance* MainWindow::selectedInstance() BaseInstance* MainWindow::selectedInstance()
{ {
QAbstractItemView * iv = view; QAbstractItemView * iv = view;
auto smodel = iv->selectionModel(); auto smodel = iv->selectionModel();
@ -375,7 +375,7 @@ Instance* MainWindow::selectedInstance()
if(mindex.isValid()) if(mindex.isValid())
{ {
return (Instance *) mindex.data(InstanceModel::InstancePointerRole).value<void *>(); return (BaseInstance *) mindex.data(InstanceModel::InstancePointerRole).value<void *>();
} }
else else
return nullptr; return nullptr;
@ -384,7 +384,7 @@ Instance* MainWindow::selectedInstance()
void MainWindow::on_actionLaunchInstance_triggered() void MainWindow::on_actionLaunchInstance_triggered()
{ {
Instance* inst = selectedInstance(); BaseInstance* inst = selectedInstance();
if(inst) if(inst)
{ {
doLogin(); doLogin();
@ -450,12 +450,12 @@ void MainWindow::launchInstance(LoginResponse response)
void MainWindow::launchInstance(QString instID, LoginResponse response) void MainWindow::launchInstance(QString instID, LoginResponse response)
{ {
Instance *instance = instList.getInstanceById(instID).data(); BaseInstance *instance = instList.getInstanceById(instID).data();
Q_ASSERT_X(instance != NULL, "launchInstance", "instance ID does not correspond to a valid instance"); Q_ASSERT_X(instance != NULL, "launchInstance", "instance ID does not correspond to a valid instance");
launchInstance(instance, response); launchInstance(instance, response);
} }
void MainWindow::launchInstance(Instance *instance, LoginResponse response) void MainWindow::launchInstance(BaseInstance *instance, LoginResponse response)
{ {
Q_ASSERT_X(instance != NULL, "launchInstance", "instance is NULL"); Q_ASSERT_X(instance != NULL, "launchInstance", "instance is NULL");
@ -531,7 +531,7 @@ void MainWindow::on_actionChangeInstMCVersion_triggered()
if (view->selectionModel()->selectedIndexes().count() < 1) if (view->selectionModel()->selectedIndexes().count() < 1)
return; return;
Instance *inst = selectedInstance(); BaseInstance *inst = selectedInstance();
VersionSelectDialog *vselect = new VersionSelectDialog(inst->versionList(), this); VersionSelectDialog *vselect = new VersionSelectDialog(inst->versionList(), this);
if (vselect->exec() && vselect->selectedVersion()) if (vselect->exec() && vselect->selectedVersion())
@ -542,7 +542,7 @@ void MainWindow::on_actionChangeInstMCVersion_triggered()
void MainWindow::on_actionChangeInstLWJGLVersion_triggered() void MainWindow::on_actionChangeInstLWJGLVersion_triggered()
{ {
Instance *inst = selectedInstance(); BaseInstance *inst = selectedInstance();
if (!inst) if (!inst)
return; return;
@ -559,7 +559,7 @@ void MainWindow::on_actionInstanceSettings_triggered()
if (view->selectionModel()->selectedIndexes().count() < 1) if (view->selectionModel()->selectedIndexes().count() < 1)
return; return;
Instance *inst = selectedInstance(); BaseInstance *inst = selectedInstance();
SettingsObject *s; SettingsObject *s;
s = &inst->settings(); s = &inst->settings();
InstanceSettings settings(s, this); InstanceSettings settings(s, this);

View File

@ -18,9 +18,9 @@
#include <QMainWindow> #include <QMainWindow>
#include "instancelist.h" #include "lists/InstanceList.h"
#include "loginresponse.h" #include "tasks/LoginResponse.h"
#include "instance.h" #include "BaseInstance.h"
class InstanceModel; class InstanceModel;
class InstanceProxyModel; class InstanceProxyModel;
@ -41,7 +41,7 @@ class MainWindow : public QMainWindow
/*! /*!
* The currently selected instance. * The currently selected instance.
*/ */
Q_PROPERTY(Instance* selectedInstance READ selectedInstance STORED false) Q_PROPERTY(BaseInstance* selectedInstance READ selectedInstance STORED false)
public: public:
explicit MainWindow(QWidget *parent = 0); explicit MainWindow(QWidget *parent = 0);
@ -53,7 +53,7 @@ public:
void openWebPage(QUrl url); void openWebPage(QUrl url);
Instance *selectedInstance(); BaseInstance *selectedInstance();
private slots: private slots:
void on_actionAbout_triggered(); void on_actionAbout_triggered();
@ -119,7 +119,7 @@ public slots:
void launchInstance(LoginResponse response); void launchInstance(LoginResponse response);
void launchInstance(QString instID, LoginResponse response); void launchInstance(QString instID, LoginResponse response);
void launchInstance(Instance *inst, LoginResponse response); void launchInstance(BaseInstance *inst, LoginResponse response);
private: private:
Ui::MainWindow *ui; Ui::MainWindow *ui;
@ -134,7 +134,7 @@ private:
// A pointer to the instance we are actively doing stuff with. // A pointer to the instance we are actively doing stuff with.
// This is set when the user launches an instance and is used to refer to that // This is set when the user launches an instance and is used to refer to that
// instance throughout the launching process. // instance throughout the launching process.
Instance *m_activeInst; BaseInstance *m_activeInst;
Task *m_versionLoadTask; Task *m_versionLoadTask;
}; };

View File

@ -15,9 +15,9 @@
#include "modeditdialog.h" #include "modeditdialog.h"
#include "ui_modeditdialog.h" #include "ui_modeditdialog.h"
#include "instance.h" #include "BaseInstance.h"
ModEditDialog::ModEditDialog(QWidget *parent, Instance* m_inst) : ModEditDialog::ModEditDialog(QWidget *parent, BaseInstance* m_inst) :
QDialog(parent), QDialog(parent),
ui(new Ui::ModEditDialog) ui(new Ui::ModEditDialog)
{ {

View File

@ -18,7 +18,7 @@
#include <QDialog> #include <QDialog>
#include "instance.h" #include "BaseInstance.h"
namespace Ui { namespace Ui {
class ModEditDialog; class ModEditDialog;
@ -29,7 +29,7 @@ class ModEditDialog : public QDialog
Q_OBJECT Q_OBJECT
public: public:
explicit ModEditDialog(QWidget *parent = 0, Instance* m_inst = 0); explicit ModEditDialog(QWidget *parent = 0, BaseInstance* m_inst = 0);
~ModEditDialog(); ~ModEditDialog();
private slots: private slots:

View File

@ -15,11 +15,11 @@
#include "modeditwindow.h" #include "modeditwindow.h"
#include "ui_modeditwindow.h" #include "ui_modeditwindow.h"
#include "instance.h" #include "BaseInstance.h"
#include <QDebug> #include <QDebug>
ModEditWindow::ModEditWindow(QWidget *parent, Instance* m_inst) : ModEditWindow::ModEditWindow(QWidget *parent, BaseInstance* m_inst) :
QDialog(parent), QDialog(parent),
ui(new Ui::ModEditWindow) ui(new Ui::ModEditWindow)
{ {

View File

@ -16,12 +16,12 @@
#include "newinstancedialog.h" #include "newinstancedialog.h"
#include "ui_newinstancedialog.h" #include "ui_newinstancedialog.h"
#include "instanceloader.h" #include "InstanceFactory.h"
#include "instversionlist.h" #include <lists/MinecraftVersionList.h>
#include "instversion.h" #include "InstanceVersion.h"
#include "task.h" #include "tasks/Task.h"
#include "versionselectdialog.h" #include "versionselectdialog.h"
#include "taskdialog.h" #include "taskdialog.h"
@ -29,7 +29,7 @@
#include <QLayout> #include <QLayout>
#include <QPushButton> #include <QPushButton>
#include <minecraftversionlist.h>
NewInstanceDialog::NewInstanceDialog(QWidget *parent) : NewInstanceDialog::NewInstanceDialog(QWidget *parent) :
QDialog(parent), QDialog(parent),

View File

@ -16,7 +16,7 @@
#include "settingsdialog.h" #include "settingsdialog.h"
#include "ui_settingsdialog.h" #include "ui_settingsdialog.h"
#include "appsettings.h" #include "AppSettings.h"
#include <QFileDialog> #include <QFileDialog>
#include <QMessageBox> #include <QMessageBox>

View File

@ -18,7 +18,7 @@
#include <QKeyEvent> #include <QKeyEvent>
#include "task.h" #include "tasks/Task.h"
TaskDialog::TaskDialog(QWidget *parent) : TaskDialog::TaskDialog(QWidget *parent) :
QDialog(parent), QDialog(parent),

View File

@ -22,9 +22,9 @@
#include <gui/taskdialog.h> #include <gui/taskdialog.h>
#include <instversionlist.h> #include <lists/InstVersionList.h>
#include <instversion.h> #include <InstanceVersion.h>
#include <task.h> #include <tasks/Task.h>
VersionSelectDialog::VersionSelectDialog(InstVersionList *vlist, QWidget *parent) : VersionSelectDialog::VersionSelectDialog(InstVersionList *vlist, QWidget *parent) :
QDialog(parent), QDialog(parent),

View File

@ -1,333 +0,0 @@
// ----------------------------------------------------------------------------
// Copyright (C) 2002-2006 Marcin Kalicinski
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// For more information, see www.boost.org
// ----------------------------------------------------------------------------
#ifndef BOOST_PROPERTY_TREE_DETAIL_JSON_PARSER_READ_HPP_INCLUDED
#define BOOST_PROPERTY_TREE_DETAIL_JSON_PARSER_READ_HPP_INCLUDED
//#define BOOST_SPIRIT_DEBUG
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/detail/ptree_utils.hpp>
#include <boost/property_tree/detail/json_parser_error.hpp>
#include <boost/spirit/include/classic.hpp>
#include <boost/limits.hpp>
#include <string>
#include <locale>
#include <istream>
#include <vector>
#include <algorithm>
namespace boost { namespace property_tree { namespace json_parser
{
///////////////////////////////////////////////////////////////////////
// Json parser context
template<class Ptree>
struct context
{
typedef typename Ptree::key_type::value_type Ch;
typedef std::basic_string<Ch> Str;
typedef typename std::vector<Ch>::iterator It;
Str string;
Str name;
Ptree root;
std::vector<Ptree *> stack;
struct a_object_s
{
context &c;
a_object_s(context &c): c(c) { }
void operator()(Ch) const
{
if (c.stack.empty())
c.stack.push_back(&c.root);
else
{
Ptree *parent = c.stack.back();
Ptree *child = &parent->push_back(std::make_pair(c.name, Ptree()))->second;
c.stack.push_back(child);
c.name.clear();
}
}
};
struct a_object_e
{
context &c;
a_object_e(context &c): c(c) { }
void operator()(Ch) const
{
BOOST_ASSERT(c.stack.size() >= 1);
c.stack.pop_back();
}
};
struct a_name
{
context &c;
a_name(context &c): c(c) { }
void operator()(It, It) const
{
c.name.swap(c.string);
c.string.clear();
}
};
struct a_string_val
{
context &c;
a_string_val(context &c): c(c) { }
void operator()(It, It) const
{
BOOST_ASSERT(c.stack.size() >= 1);
c.stack.back()->push_back(std::make_pair(c.name, Ptree(c.string)));
c.name.clear();
c.string.clear();
}
};
struct a_literal_val
{
context &c;
a_literal_val(context &c): c(c) { }
void operator()(It b, It e) const
{
BOOST_ASSERT(c.stack.size() >= 1);
c.stack.back()->push_back(std::make_pair(c.name,
Ptree(Str(b, e))));
c.name.clear();
c.string.clear();
}
};
struct a_char
{
context &c;
a_char(context &c): c(c) { }
void operator()(It b, It e) const
{
c.string += *b;
}
};
struct a_escape
{
context &c;
a_escape(context &c): c(c) { }
void operator()(Ch ch) const
{
switch (ch)
{
case Ch('\"'): c.string += Ch('\"'); break;
case Ch('\\'): c.string += Ch('\\'); break;
case Ch('/'): c.string += Ch('/'); break;
case Ch('b'): c.string += Ch('\b'); break;
case Ch('f'): c.string += Ch('\f'); break;
case Ch('n'): c.string += Ch('\n'); break;
case Ch('r'): c.string += Ch('\r'); break;
case Ch('t'): c.string += Ch('\t'); break;
default: BOOST_ASSERT(0);
}
}
};
struct a_unicode
{
context &c;
a_unicode(context &c): c(c) { }
void operator()(unsigned long u) const
{
//u = (std::min)(u, static_cast<unsigned long>((std::numeric_limits<Ch>::max)()));
c.string += Ch(u);
}
};
};
///////////////////////////////////////////////////////////////////////
// Json grammar
template<class Ptree>
struct json_grammar :
public boost::spirit::classic::grammar<json_grammar<Ptree> >
{
typedef context<Ptree> Context;
typedef typename Ptree::key_type::value_type Ch;
mutable Context c;
template<class Scanner>
struct definition
{
boost::spirit::classic::rule<Scanner>
root, object, member, array, item, value, string, number;
boost::spirit::classic::rule<
typename boost::spirit::classic::lexeme_scanner<Scanner>::type>
character, escape;
definition(const json_grammar &self)
{
using namespace boost::spirit::classic;
// There's a boost::assertion too, so another explicit using
// here:
using boost::spirit::classic::assertion;
// Assertions
assertion<std::string> expect_root("expected object or array");
assertion<std::string> expect_eoi("expected end of input");
assertion<std::string> expect_objclose("expected ',' or '}'");
assertion<std::string> expect_arrclose("expected ',' or ']'");
assertion<std::string> expect_name("expected object name");
assertion<std::string> expect_colon("expected ':'");
assertion<std::string> expect_value("expected value");
assertion<std::string> expect_escape("invalid escape sequence");
// JSON grammar rules
root
= expect_root(object | array)
>> expect_eoi(end_p)
;
object
= ch_p('{')[typename Context::a_object_s(self.c)]
>> (ch_p('}')[typename Context::a_object_e(self.c)]
| (list_p(member, ch_p(','))
>> expect_objclose(ch_p('}')[typename Context::a_object_e(self.c)])
)
)
;
member
= expect_name(string[typename Context::a_name(self.c)])
>> expect_colon(ch_p(':'))
>> expect_value(value)
;
array
= ch_p('[')[typename Context::a_object_s(self.c)]
>> (ch_p(']')[typename Context::a_object_e(self.c)]
| (list_p(item, ch_p(','))
>> expect_arrclose(ch_p(']')[typename Context::a_object_e(self.c)])
)
)
;
item
= expect_value(value)
;
value
= string[typename Context::a_string_val(self.c)]
| (number | str_p("true") | "false" | "null")[typename Context::a_literal_val(self.c)]
| object
| array
;
number
= !ch_p("-") >>
(ch_p("0") | (range_p(Ch('1'), Ch('9')) >> *digit_p)) >>
!(ch_p(".") >> +digit_p) >>
!(chset_p(detail::widen<Ch>("eE").c_str()) >>
!chset_p(detail::widen<Ch>("-+").c_str()) >>
+digit_p)
;
string
= +(lexeme_d[confix_p('\"', *character, '\"')])
;
character
= (anychar_p - "\\" - "\"")
[typename Context::a_char(self.c)]
| ch_p("\\") >> expect_escape(escape)
;
escape
= chset_p(detail::widen<Ch>("\"\\/bfnrt").c_str())
[typename Context::a_escape(self.c)]
| 'u' >> uint_parser<unsigned long, 16, 4, 4>()
[typename Context::a_unicode(self.c)]
;
// Debug
BOOST_SPIRIT_DEBUG_RULE(root);
BOOST_SPIRIT_DEBUG_RULE(object);
BOOST_SPIRIT_DEBUG_RULE(member);
BOOST_SPIRIT_DEBUG_RULE(array);
BOOST_SPIRIT_DEBUG_RULE(item);
BOOST_SPIRIT_DEBUG_RULE(value);
BOOST_SPIRIT_DEBUG_RULE(string);
BOOST_SPIRIT_DEBUG_RULE(number);
BOOST_SPIRIT_DEBUG_RULE(escape);
BOOST_SPIRIT_DEBUG_RULE(character);
}
const boost::spirit::classic::rule<Scanner> &start() const
{
return root;
}
};
};
template<class It, class Ch>
unsigned long count_lines(It begin, It end)
{
return static_cast<unsigned long>(std::count(begin, end, Ch('\n')) + 1);
}
template<class Ptree>
void read_json_internal(std::basic_istream<typename Ptree::key_type::value_type> &stream,
Ptree &pt,
const std::string &filename)
{
using namespace boost::spirit::classic;
typedef typename Ptree::key_type::value_type Ch;
typedef typename std::vector<Ch>::iterator It;
// Load data into vector
std::vector<Ch> v(std::istreambuf_iterator<Ch>(stream.rdbuf()),
std::istreambuf_iterator<Ch>());
if (!stream.good())
BOOST_PROPERTY_TREE_THROW(json_parser_error("read error", filename, 0));
// Prepare grammar
json_grammar<Ptree> g;
// Parse
try
{
parse_info<It> pi = parse(v.begin(), v.end(), g,
space_p | comment_p("//") | comment_p("/*", "*/"));
if (!pi.hit || !pi.full)
BOOST_PROPERTY_TREE_THROW((parser_error<std::string, It>(v.begin(), "syntax error")));
}
catch (parser_error<std::string, It> &e)
{
BOOST_PROPERTY_TREE_THROW(json_parser_error(e.descriptor, filename, count_lines<It, Ch>(v.begin(), e.where)));
}
// Swap grammar context root and pt
pt.swap(g.c.root);
}
} } }
#endif

View File

@ -1,102 +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
include/libmmc_config.h
# Instance Stuff
include/instance.h
include/instancelist.h
include/instanceloader.h
include/instversion.h
include/instversionlist.h
include/minecraftversion.h
include/minecraftversionlist.h
include/library.h
include/fullversion.h
include/fullversionfactory.h
# Tasks
include/task.h
include/logintask.h
include/gameupdatetask.h
# Login Data
include/userinfo.h
include/loginresponse.h
# Misc Data
include/version.h
include/appsettings.h
include/minecraftprocess.h
include/lwjglversionlist.h
)
SET(LIBINST_SOURCES
# Instance Stuff
src/instance.cpp
src/instancelist.cpp
src/instanceloader.cpp
src/instversion.cpp
src/instversionlist.cpp
src/minecraftversion.cpp
src/minecraftversionlist.cpp
src/library.cpp
src/fullversion.cpp
src/fullversionfactory.cpp
# Tasks
src/task.cpp
src/logintask.cpp
src/gameupdatetask.cpp
# Login Data
src/userinfo.cpp
src/loginresponse.cpp
# Misc Data
src/version.cpp
src/appsettings.cpp
src/minecraftprocess.cpp
src/lwjglversionlist.cpp
)
# Set the include dir path.
SET(LIBMULTIMC_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/include" PARENT_SCOPE)
# Include self.
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
include_directories(${CMAKE_BINARY_DIR}/include)
add_definitions(-DLIBMULTIMC_LIBRARY)
add_library(libMultiMC SHARED ${LIBINST_SOURCES} ${LIBINST_HEADERS})
qt5_use_modules(libMultiMC Core Network Xml)
target_link_libraries(libMultiMC libUtil libSettings)

View File

@ -1,76 +0,0 @@
#pragma once
#include <QString>
class Library;
class FullVersion
{
public:
/// the ID - determines which jar to use! ACTUALLY IMPORTANT!
QString id;
/// Last updated time - as a string
QString time;
/// Release time - as a string
QString releaseTime;
/// Release type - "release" or "snapshot"
QString type;
/**
* DEPRECATED: Old versions of the new vanilla launcher used this
* ex: "username_session_version"
*/
QString processArguments;
/**
* arguments that should be used for launching minecraft
*
* ex: "--username ${auth_player_name} --session ${auth_session}
* --version ${version_name} --gameDir ${game_directory} --assetsDir ${game_assets}"
*/
QString minecraftArguments;
/**
* the minimum launcher version required by this version ... current is 4 (at point of writing)
*/
int minimumLauncherVersion;
/**
* The main class to load first
*/
QString mainClass;
/// the list of libs - both active and inactive, native and java
QList<QSharedPointer<Library> > libraries;
/**
* is this actually a legacy version? if so, none of the other stuff here will be ever used.
* added by FullVersionFactory
*/
bool isLegacy;
/*
FIXME: add support for those rules here? Looks like a pile of quick hacks to me though.
"rules": [
{
"action": "allow"
},
{
"action": "disallow",
"os": {
"name": "osx",
"version": "^10\\.5\\.\\d$"
}
}
],
"incompatibilityReason": "There is a bug in LWJGL which makes it incompatible with OSX 10.5.8. Please go to New Profile and use 1.5.2 for now. Sorry!"
}
*/
// QList<Rule> rules;
public:
FullVersion()
{
minimumLauncherVersion = 0xDEADBEEF;
isLegacy = false;
}
QList<QSharedPointer<Library> > getActiveNormalLibs();
QList<QSharedPointer<Library> > getActiveNativeLibs();
};

View File

@ -1,29 +0,0 @@
#include <QtCore>
#include "fullversion.h"
#include <library.h>
QList<QSharedPointer<Library> > FullVersion::getActiveNormalLibs()
{
QList<QSharedPointer<Library> > output;
for ( auto lib: libraries )
{
if (lib->getIsActive() && !lib->getIsNative())
{
output.append(lib);
}
}
return output;
}
QList<QSharedPointer<Library> > FullVersion::getActiveNativeLibs()
{
QList<QSharedPointer<Library> > output;
for ( auto lib: libraries )
{
if (lib->getIsActive() && lib->getIsNative())
{
output.append(lib);
}
}
return output;
}

View File

@ -51,5 +51,5 @@ SET(LIBUTIL_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/include" PARENT_SCOPE)
add_definitions(-DLIBUTIL_LIBRARY) add_definitions(-DLIBUTIL_LIBRARY)
add_library(libUtil SHARED ${LIBUTIL_SOURCES} ${LIBUTIL_HEADERS}) add_library(libUtil SHARED ${LIBUTIL_SOURCES} ${LIBUTIL_HEADERS})
qt5_use_modules(libUtil Core) qt5_use_modules(libUtil Core Network)
target_link_libraries(libUtil) target_link_libraries(libUtil)

View File

@ -29,12 +29,19 @@
/** /**
* @file libutil/include/cmdutils.h * @file libutil/include/cmdutils.h
* @brief commandline parsing utilities * @brief commandline parsing and processing utilities
*/ */
namespace Util { namespace Util {
namespace Commandline { namespace Commandline {
/**
* @brief split a string into argv items like a shell would do
* @param args the argument string
* @return a QStringList containing all arguments
*/
LIBUTIL_EXPORT QStringList splitArgs(QString args);
/** /**
* @brief The FlagStyle enum * @brief The FlagStyle enum
* Specifies how flags are decorated * Specifies how flags are decorated

View File

@ -24,6 +24,56 @@
namespace Util { namespace Util {
namespace Commandline { namespace Commandline {
// commandline splitter
QStringList splitArgs(QString args)
{
QStringList argv;
QString current;
bool escape = false;
QChar inquotes;
for (int i=0; i<args.length(); i++)
{
QChar cchar = args.at(i);
// \ escaped
if (escape)
{
current += cchar;
escape = false;
// in "quotes"
}
else if (!inquotes.isNull())
{
if (cchar == 0x5C)
escape = true;
else if (cchar == inquotes)
inquotes = 0;
else
current += cchar;
// otherwise
}
else
{
if (cchar == 0x20)
{
if (!current.isEmpty())
{
argv << current;
current.clear();
}
}
else if (cchar == 0x22 || cchar == 0x27)
inquotes = cchar;
else
current += cchar;
}
}
if (!current.isEmpty())
argv << current;
return argv;
}
Parser::Parser(FlagStyle::Enum flagStyle, ArgumentStyle::Enum argStyle) Parser::Parser(FlagStyle::Enum flagStyle, ArgumentStyle::Enum argStyle)
{ {
m_flagStyle = flagStyle; m_flagStyle = flagStyle;

View File

@ -26,11 +26,11 @@
#include "gui/taskdialog.h" #include "gui/taskdialog.h"
#include "gui/consolewindow.h" #include "gui/consolewindow.h"
#include "appsettings.h" #include "AppSettings.h"
#include "instancelist.h" #include "lists/InstanceList.h"
#include "loginresponse.h" #include "tasks/LoginResponse.h"
#include "logintask.h" #include "tasks/LoginTask.h"
#include "minecraftprocess.h" #include "MinecraftProcess.h"
#include "pathutils.h" #include "pathutils.h"
#include "cmdutils.h" #include "cmdutils.h"