Reformat and (slightly) decruft all the things.

This commit is contained in:
Petr Mrázek
2013-11-04 02:53:05 +01:00
parent d6e4fb2971
commit bb7e8985f6
208 changed files with 4492 additions and 3767 deletions

View File

@ -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 <QFileInfo>
#include <QDir>
#include <MultiMC.h>
#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<qint64>();
return d->m_settings->get("lastLaunchTime").value<qint64>();
}
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();
}

View File

@ -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 <QString>
#include <settingsobject.h>
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
{

View File

@ -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;
}

View File

@ -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;
};

View File

@ -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 <memory>
/*!
@ -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<BaseVersion> BaseVersionPtr;
Q_DECLARE_METATYPE( BaseVersionPtr )
Q_DECLARE_METATYPE(BaseVersionPtr)

View File

@ -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
)

View File

@ -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);
}

View File

@ -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 <QSortFilterProxyModel>
@ -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;
};

View File

@ -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"

View File

@ -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 <QString>
#include <memory>
@ -19,7 +34,3 @@ private:
QString realVersionId;
QString m_universal_url;
};

View File

@ -30,7 +30,7 @@
#include <setting.h>
#include "pathutils.h"
#include <logger/QsLog.h>
#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;
}
}
;
}

View File

@ -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 <iostream>
#include "InstanceLauncher.h"
#include "MultiMC.h"
#include <iostream>
#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();
}

View File

@ -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 <QObject>
@ -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();
};

View File

@ -13,21 +13,22 @@
* limitations under the License.
*/
#include "JavaUtils.h"
#include "pathutils.h"
#include "MultiMC.h"
#include <QStringList>
#include <QString>
#include <QDir>
#include <QMessageBox>
#include <logger/QsLog.h>
#include <gui/versionselectdialog.h>
#include <setting.h>
#include <pathutils.h>
#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<JavaVersionPtr> JavaUtils::FindJavaFromRegistryKey(DWORD keyType, QString
QList<JavaVersionPtr> 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<JavaVersionPtr> 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<JavaVersionPtr> JavaUtils::FindJavaPaths()
{
QList<JavaVersionPtr> javas;
QList<JavaVersionPtr> JRE64s = this->FindJavaFromRegistryKey(KEY_WOW64_64KEY, "SOFTWARE\\JavaSoft\\Java Runtime Environment");
QList<JavaVersionPtr> JDK64s = this->FindJavaFromRegistryKey(KEY_WOW64_64KEY, "SOFTWARE\\JavaSoft\\Java Development Kit");
QList<JavaVersionPtr> JRE32s = this->FindJavaFromRegistryKey(KEY_WOW64_32KEY, "SOFTWARE\\JavaSoft\\Java Runtime Environment");
QList<JavaVersionPtr> JDK32s = this->FindJavaFromRegistryKey(KEY_WOW64_32KEY, "SOFTWARE\\JavaSoft\\Java Development Kit");
QList<JavaVersionPtr> JRE64s = this->FindJavaFromRegistryKey(
KEY_WOW64_64KEY, "SOFTWARE\\JavaSoft\\Java Runtime Environment");
QList<JavaVersionPtr> JDK64s = this->FindJavaFromRegistryKey(
KEY_WOW64_64KEY, "SOFTWARE\\JavaSoft\\Java Development Kit");
QList<JavaVersionPtr> JRE32s = this->FindJavaFromRegistryKey(
KEY_WOW64_32KEY, "SOFTWARE\\JavaSoft\\Java Runtime Environment");
QList<JavaVersionPtr> 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<JavaVersionPtr> 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;
}

View File

@ -17,11 +17,13 @@
#include <QStringList>
#include <QWidget>
#include <logic/lists/JavaVersionList.h>
#include "osutils.h"
#include <osutils.h>
#include "logic/lists/JavaVersionList.h"
#if WINDOWS
#include <windows.h>
#include <windows.h>
#endif
class JavaUtils

View File

@ -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";

View File

@ -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);
};

View File

@ -1,16 +1,35 @@
#include "LegacyInstance.h"
#include "LegacyInstance_p.h"
#include "MinecraftProcess.h"
#include "LegacyUpdate.h"
#include "lists/IconList.h"
#include <setting.h>
#include <pathutils.h>
#include <cmdutils.h>
#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 <QFileInfo>
#include <QDir>
#include <QImage>
#include <MultiMC.h>
#include <setting.h>
#include <pathutils.h>
#include <cmdutils.h>
#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"

View File

@ -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);

View File

@ -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 <QString>
#include <settingsobject.h>
#include <memory>
#include "BaseInstance_p.h"
#include "ModList.h"
#include <QSharedPointer>
class ModList;
struct LegacyInstancePrivate: public BaseInstancePrivate
struct LegacyInstancePrivate : public BaseInstancePrivate
{
std::shared_ptr<ModList> jar_mod_list;
std::shared_ptr<ModList> core_mod_list;
std::shared_ptr<ModList> loader_mod_list;
std::shared_ptr<ModList> texture_pack_list;
};
};

View File

@ -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 <quazip.h>
#include <quazipfile.h>
#include <JlCompress.h>
#include <logger/QsLog.h>
#include "logger/QsLog.h"
LegacyUpdate::LegacyUpdate(BaseInstance *inst, QObject *parent) : BaseUpdate(inst, parent)
{

View File

@ -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 <QList>
#include <QUrl>
#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<QString>& contained, MetainfAction metainf);
bool MergeZipFiles(QuaZip *into, QFileInfo from, QSet<QString> &contained,
MetainfAction metainf);
private:
std::shared_ptr<QNetworkReply> m_reply;
// target version, determined during this task
// MinecraftVersion *targetVersion;
QString lwjglURL;
QString lwjglVersion;
QString lwjglTargetPath;
QString lwjglNativesPath;
private:
NetJobPtr legacyDownloadJob;
};

View File

@ -14,6 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once
#include <QProcess>
@ -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);

View File

@ -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");
}

View File

@ -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 <QDir>
#include <QString>
@ -26,7 +25,7 @@
#include "Mod.h"
#include <pathutils.h>
#include <inifile.h>
#include <logger/QsLog.h>
#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();
}

View File

@ -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 <QFileInfo>

View File

@ -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 <QUrl>
#include <QUuid>
#include <QFileSystemWatcher>
#include <logger/QsLog.h>
#include "logger/QsLog.h"
ModList::ModList(const QString &dir, const QString &list_file)
: QAbstractListModel(), m_dir(dir), m_list_file(list_file)

View File

@ -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 <QList>
#include <QString>
#include <QDir>
#include <QAbstractListModel>
#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<Mod> mods;
};

View File

@ -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();
}
}
}

View File

@ -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, settings, parent )
NostalgiaInstance::NostalgiaInstance(const QString &rootDir, SettingsObject *settings,
QObject *parent)
: OneSixInstance(rootDir, settings, parent)
{
}
QString NostalgiaInstance::getStatusbarDescription()
@ -15,8 +30,3 @@ bool NostalgiaInstance::menuActionEnabled(QString action_name) const
{
return false;
}
/*
ADD MORE
IF REQUIRED
*/

View File

@ -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 "OneSixInstance.h"
@ -6,8 +21,8 @@ class NostalgiaInstance : public OneSixInstance
{
Q_OBJECT
public:
explicit NostalgiaInstance(const QString &rootDir, SettingsObject * settings, QObject *parent = 0);
explicit NostalgiaInstance(const QString &rootDir, SettingsObject *settings,
QObject *parent = 0);
virtual QString getStatusbarDescription();
virtual bool menuActionEnabled(QString action_name) const;
};

View File

@ -1,5 +1,20 @@
/* 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 <QString>
#include <logger/QsLog.h>
#include "logger/QsLog.h"
#include <QtXml/QtXml>
#include "OneSixAssets.h"
#include "net/NetJob.h"
@ -70,7 +85,7 @@ void OneSixAssets::S3BucketFinished()
auto metacache = MMC->metacache();
for (auto object: objectList)
for (auto object : objectList)
{
// Filter folder keys (zero size)
if (object.size == 0)
@ -99,8 +114,7 @@ void OneSixAssets::S3BucketFinished()
void OneSixAssets::start()
{
auto job = new NetJob("Assets index");
job->addNetAction(
S3ListBucket::make(QUrl("http://s3.amazonaws.com/Minecraft.Resources/")));
job->addNetAction(S3ListBucket::make(QUrl("http://s3.amazonaws.com/Minecraft.Resources/")));
connect(job, SIGNAL(succeeded()), SLOT(S3BucketFinished()));
connect(job, SIGNAL(failed()), SIGNAL(failed()));
emit indexStarted();

View File

@ -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 "net/NetJob.h"
@ -14,13 +29,16 @@ signals:
void filesStarted();
void filesProgress(int, int, int);
public slots:
public
slots:
void S3BucketFinished();
void downloadFinished();
public:
void start();
private:
ThreadedDeleter * deleter;
ThreadedDeleter *deleter;
QStringList nuke_whitelist;
NetJobPtr index_job;
NetJobPtr files_job;

View File

@ -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 "OneSixInstance.h"
#include "OneSixInstance_p.h"
#include "OneSixUpdate.h"
@ -8,8 +23,8 @@
#include <pathutils.h>
#include <cmdutils.h>
#include <JlCompress.h>
#include <gui/OneSixModEditDialog.h>
#include <logger/QsLog.h>
#include "gui/dialogs/OneSixModEditDialog.h"
#include "logger/QsLog.h"
OneSixInstance::OneSixInstance(const QString &rootDir, SettingsObject *setting_obj,
QObject *parent)

View File

@ -1,7 +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.
*/
#pragma once
#include "BaseInstance.h"
#include <QStringList>
#include "BaseInstance.h"
class OneSixVersion;
class BaseUpdate;
class ModList;

View File

@ -1,11 +1,28 @@
/* 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_p.h"
#include "OneSixVersion.h"
#include "OneSixLibrary.h"
#include "ModList.h"
#include <memory>
struct OneSixInstancePrivate: public BaseInstancePrivate
#include "logic/BaseInstance_p.h"
#include "logic/OneSixVersion.h"
#include "logic/OneSixLibrary.h"
#include "logic/ModList.h"
struct OneSixInstancePrivate : public BaseInstancePrivate
{
std::shared_ptr<OneSixVersion> version;
std::shared_ptr<ModList> loader_mod_list;

View File

@ -1,7 +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 <QJsonArray>
#include "OneSixLibrary.h"
#include "OneSixRule.h"
#include "OpSys.h"
#include <QJsonArray>
void OneSixLibrary::finalize()
{
QStringList parts = m_name.split(':');

View File

@ -1,9 +1,26 @@
/* 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 <QString>
#include <QStringList>
#include <QMap>
#include <memory>
#include <QJsonObject>
#include <memory>
#include "OpSys.h"
class Rule;
@ -14,7 +31,7 @@ private:
// basic values used internally (so far)
QString m_name;
QString m_base_url = "http://s3.amazonaws.com/Minecraft.Download/libraries/";
QList<std::shared_ptr<Rule> > m_rules;
QList<std::shared_ptr<Rule>> m_rules;
// custom values
/// absolute URL. takes precedence over m_download_path, if defined
@ -39,25 +56,26 @@ private:
bool m_is_native = false;
/// native suffixes per OS
QMap<OpSys, QString> m_native_suffixes;
public:
QStringList extract_excludes;
public:
/// Constructor
OneSixLibrary(QString name)
{
m_name = name;
}
QJsonObject toJson();
/**
* finalize the library, processing the input values into derived values and state
*
*
* This SHALL be called after all the values are parsed or after any further change.
*/
void finalize();
/// Set the library composite name
void setName(QString name);
/// get a decent-looking name
@ -77,13 +95,13 @@ public:
}
/// Set the url base for downloads
void setBaseUrl(QString base_url);
/// Call this to mark the library as 'native' (it's a zip archive with DLLs)
void setIsNative();
/// Attach a name suffix to the specified OS native
void addNative(OpSys os, QString suffix);
/// Set the load rules
void setRules(QList<std::shared_ptr<Rule> > rules);
void setRules(QList<std::shared_ptr<Rule>> rules);
/// Returns true if the library should be loaded (or extracted, in case of natives)
bool isActive();

View File

@ -1,7 +1,23 @@
#include "OneSixRule.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 <QJsonObject>
#include <QJsonArray>
#include "OneSixRule.h"
QList<std::shared_ptr<Rule>> rulesFromJsonV4(QJsonObject &objectWithRules)
{
QList<std::shared_ptr<Rule>> rules;

View File

@ -1,7 +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.
*/
#pragma once
#include <QString>
#include <QSharedPointer>
#include "OneSixLibrary.h"
#include "logic/OneSixLibrary.h"
enum RuleAction
{
@ -17,19 +34,22 @@ class Rule
{
protected:
RuleAction m_result;
virtual bool applies(OneSixLibrary * parent) = 0;
virtual bool applies(OneSixLibrary *parent) = 0;
public:
Rule(RuleAction result)
:m_result(result) {}
virtual ~Rule(){};
virtual QJsonObject toJson() = 0;
RuleAction apply(OneSixLibrary * parent)
Rule(RuleAction result) : m_result(result)
{
if(applies(parent))
}
virtual ~Rule() {};
virtual QJsonObject toJson() = 0;
RuleAction apply(OneSixLibrary *parent)
{
if (applies(parent))
return m_result;
else
return Defer;
};
}
;
};
class OsRule : public Rule
@ -39,34 +59,41 @@ private:
OpSys m_system;
// the OS version regexp
QString m_version_regexp;
protected:
virtual bool applies ( OneSixLibrary* )
virtual bool applies(OneSixLibrary *)
{
return (m_system == currentSystem);
}
OsRule(RuleAction result, OpSys system, QString version_regexp)
: Rule(result), m_system(system), m_version_regexp(version_regexp) {}
: Rule(result), m_system(system), m_version_regexp(version_regexp)
{
}
public:
virtual QJsonObject toJson();
static std::shared_ptr<OsRule> create(RuleAction result, OpSys system, QString version_regexp)
static std::shared_ptr<OsRule> create(RuleAction result, OpSys system,
QString version_regexp)
{
return std::shared_ptr<OsRule> (new OsRule(result, system, version_regexp));
return std::shared_ptr<OsRule>(new OsRule(result, system, version_regexp));
}
};
class ImplicitRule : public Rule
{
protected:
virtual bool applies ( OneSixLibrary* )
virtual bool applies(OneSixLibrary *)
{
return true;
}
ImplicitRule(RuleAction result)
: Rule(result) {}
ImplicitRule(RuleAction result) : Rule(result)
{
}
public:
virtual QJsonObject toJson();
static std::shared_ptr<ImplicitRule> create(RuleAction result)
{
return std::shared_ptr<ImplicitRule> (new ImplicitRule(result));
return std::shared_ptr<ImplicitRule>(new ImplicitRule(result));
}
};

View File

@ -12,6 +12,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "MultiMC.h"
#include "OneSixUpdate.h"

View File

@ -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
@ -18,10 +18,10 @@
#include <QObject>
#include <QList>
#include <QUrl>
#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;
@ -32,22 +32,21 @@ class OneSixUpdate : public BaseUpdate
public:
explicit OneSixUpdate(BaseInstance *inst, QObject *parent = 0);
virtual void executeTask();
private slots:
private
slots:
void versionFileStart();
void versionFileFinished();
void versionFileFailed();
void jarlibStart();
void jarlibFinished();
void jarlibFailed();
private:
NetJobPtr specificVersionDownloadJob;
NetJobPtr jarlibDownloadJob;
// target version, determined during this task
std::shared_ptr<MinecraftVersion> targetVersion;
};

View File

@ -1,9 +1,24 @@
#include "OneSixVersion.h"
#include "OneSixLibrary.h"
#include "OneSixRule.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 "logic/OneSixVersion.h"
#include "logic/OneSixLibrary.h"
#include "logic/OneSixRule.h"
std::shared_ptr<OneSixVersion> fromJsonV4(QJsonObject root,
std::shared_ptr<OneSixVersion> fullVersion)
std::shared_ptr<OneSixVersion> fullVersion)
{
fullVersion->id = root.value("id").toString();
@ -82,7 +97,7 @@ std::shared_ptr<OneSixVersion> fromJsonV4(QJsonObject root,
{
library->setAbsoluteUrl(urlAbsVal.toString());
}
else if(urlAbsuVal.isString())
else if (urlAbsuVal.isString())
{
library->setAbsoluteUrl(urlAbsuVal.toString());
}
@ -167,7 +182,7 @@ std::shared_ptr<OneSixVersion> OneSixVersion::fromFile(QString filepath)
}
QJsonObject root = jsonDoc.object();
auto version = fromJson(root);
if(version)
if (version)
version->original_file = filepath;
return version;
}
@ -192,11 +207,11 @@ bool OneSixVersion::toOriginalFile()
// screw processArguments
root.insert("releaseTime", releaseTime);
QJsonArray libarray;
for(const auto & lib: libraries)
for (const auto &lib : libraries)
{
libarray.append(lib->toJson());
}
if(libarray.count())
if (libarray.count())
root.insert("libraries", libarray);
QJsonDocument doc(root);
file.write(doc.toJson());

View File

@ -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 <QtCore>
#include <memory>
@ -86,6 +101,4 @@ public:
}
*/
// QList<Rule> rules;
};

View File

@ -1,23 +1,42 @@
/* 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 "OpSys.h"
OpSys OpSys_fromString(QString name)
{
if(name == "linux")
if (name == "linux")
return Os_Linux;
if(name == "windows")
if (name == "windows")
return Os_Windows;
if(name == "osx")
if (name == "osx")
return Os_OSX;
return Os_Other;
}
QString OpSys_toString(OpSys name)
{
switch(name)
switch (name)
{
case Os_Linux: return "linux";
case Os_OSX: return "osx";
case Os_Windows: return "windows";
default: return "other";
case Os_Linux:
return "linux";
case Os_OSX:
return "osx";
case Os_Windows:
return "windows";
default:
return "other";
}
}

View File

@ -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 <QString>
enum OpSys
@ -12,11 +27,11 @@ OpSys OpSys_fromString(QString);
QString OpSys_toString(OpSys);
#ifdef Q_OS_WIN32
#define currentSystem Os_Windows
#define currentSystem Os_Windows
#else
#ifdef Q_OS_MAC
#define currentSystem Os_OSX
#else
#define currentSystem Os_Linux
#endif
#ifdef Q_OS_MAC
#define currentSystem Os_OSX
#else
#define currentSystem Os_Linux
#endif
#endif

View File

@ -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
@ -16,12 +16,11 @@
#include "logic/lists/BaseVersionList.h"
#include "logic/BaseVersion.h"
BaseVersionList::BaseVersionList(QObject *parent) :
QAbstractListModel(parent)
BaseVersionList::BaseVersionList(QObject *parent) : QAbstractListModel(parent)
{
}
BaseVersionPtr BaseVersionList::findVersion( const QString& descriptor )
BaseVersionPtr BaseVersionList::findVersion(const QString &descriptor)
{
for (int i = 0; i < count(); i++)
{
@ -43,13 +42,12 @@ QVariant BaseVersionList::data(const QModelIndex &index, int role) const
{
if (!index.isValid())
return QVariant();
if (index.row() > count())
return QVariant();
BaseVersionPtr version = at(index.row());
switch (role)
{
case Qt::DisplayRole:
@ -57,20 +55,20 @@ QVariant BaseVersionList::data(const QModelIndex &index, int role) const
{
case NameColumn:
return version->name();
case TypeColumn:
return version->typeString();
default:
return QVariant();
}
case Qt::ToolTipRole:
return version->descriptor();
case VersionPointerRole:
return qVariantFromValue(version);
default:
return QVariant();
}
@ -85,27 +83,27 @@ QVariant BaseVersionList::headerData(int section, Qt::Orientation orientation, i
{
case NameColumn:
return "Name";
case TypeColumn:
return "Type";
default:
return QVariant();
}
case Qt::ToolTipRole:
switch (section)
{
case NameColumn:
return "The name of the version.";
case TypeColumn:
return "The version's type.";
default:
return QVariant();
}
default:
return QVariant();
}

View File

@ -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,12 +25,12 @@
class Task;
/*!
* \brief Class that each instance type's version list derives from.
* Version lists are the lists that keep track of the available game versions
* for that instance. This list will not be loaded on startup. It will be loaded
* \brief Class that each instance type's version list derives from.
* Version lists are the lists that keep track of the available game versions
* for that instance. This list will not be loaded on startup. It will be loaded
* when the list's load function is called. Before using the version list, you
* should check to see if it has been loaded yet and if not, load the list.
*
*
* Note that this class also inherits from QAbstractListModel. Methods from that
* class determine how this version list shows up in a list view. Said methods
* all have a default implementation, but they can be overridden by plugins to
@ -44,21 +44,21 @@ public:
{
VersionPointerRole = 0x34B1CB48
};
enum VListColumns
{
// First column - Name
NameColumn = 0,
// Second column - Type
TypeColumn,
// Third column - Timestamp
TimeColumn
};
explicit BaseVersionList(QObject *parent = 0);
/*!
* \brief Gets a task that will reload the version list.
* Simply execute the task to load the list.
@ -66,24 +66,23 @@ public:
* \return A pointer to a task that reloads the version list.
*/
virtual Task *getLoadTask() = 0;
//! Checks whether or not the list is loaded. If this returns false, the list should be loaded.
//! Checks whether or not the list is loaded. If this returns false, the list should be
//loaded.
virtual bool isLoaded() = 0;
//! Gets the version at the given index.
virtual const BaseVersionPtr at(int i) const = 0;
//! Returns the number of versions in the list.
virtual int count() const = 0;
//////// List Model Functions ////////
virtual QVariant data(const QModelIndex &index, int role) const;
virtual QVariant headerData(int section, Qt::Orientation orientation, int role) const;
virtual int rowCount(const QModelIndex &parent) const;
virtual int columnCount(const QModelIndex &parent) const;
/*!
* \brief Finds a version by its descriptor.
* \param The descriptor of the version to find.
@ -91,20 +90,21 @@ public:
* one doesn't exist.
*/
virtual BaseVersionPtr findVersion(const QString &descriptor);
/*!
* \brief Gets the latest stable version of this instance type.
* This is the version that will be selected by default.
* By default, this is simply the first version in the list.
*/
virtual BaseVersionPtr getLatestStable() const;
/*!
* Sorts the version list.
*/
virtual void sort() = 0;
protected slots:
protected
slots:
/*!
* Updates this list with the given list of versions.
* This is done by copying each version in the given list and inserting it
@ -117,5 +117,5 @@ protected slots:
* then copies the versions and sets their parents correctly.
* \param versions List of versions whose parents should be set.
*/
virtual void updateListData(QList<BaseVersionPtr > versions) = 0;
virtual void updateListData(QList<BaseVersionPtr> versions) = 0;
};

View File

@ -21,7 +21,7 @@
#include <QtXml>
#include <QRegExp>
#include <logger/QsLog.h>
#include "logger/QsLog.h"
#define JSON_URL "http://files.minecraftforge.net/minecraftforge/json"

View File

@ -75,8 +75,7 @@ public:
virtual BaseVersionPtr getLatestStable() const;
virtual QVariant data(const QModelIndex &index, int role) const;
virtual QVariant headerData(int section, Qt::Orientation orientation,
int role) const;
virtual QVariant headerData(int section, Qt::Orientation orientation, int role) const;
virtual int columnCount(const QModelIndex &parent) const;
protected:

View File

@ -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 "IconList.h"
#include <pathutils.h>
#include <QMap>
@ -27,22 +42,21 @@ public:
}
};
IconList::IconList() : QAbstractListModel(), d(new Private())
{
QDir instance_icons(":/icons/instances/");
auto file_info_list = instance_icons.entryInfoList(QDir::Files, QDir::Name);
for(auto file_info: file_info_list)
for (auto file_info : file_info_list)
{
QString key = file_info.baseName();
addIcon(key, key, file_info.absoluteFilePath(), true);
}
// FIXME: get from settings
ensureFolderPathExists("icons");
QDir user_icons("icons");
file_info_list = user_icons.entryInfoList(QDir::Files, QDir::Name);
for(auto file_info: file_info_list)
for (auto file_info : file_info_list)
{
QString filename = file_info.absoluteFilePath();
QString key = file_info.baseName();
@ -67,16 +81,17 @@ Qt::DropActions IconList::supportedDropActions() const
return Qt::CopyAction;
}
bool IconList::dropMimeData ( const QMimeData* data, Qt::DropAction action, int row, int column, const QModelIndex& parent )
bool IconList::dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column,
const QModelIndex &parent)
{
if (action == Qt::IgnoreAction)
return true;
return true;
// check if the action is supported
if (!data || !(action & supportedDropActions()))
return false;
// files dropped from outside?
if(data->hasUrls())
if (data->hasUrls())
{
/*
bool was_watching = is_watching;
@ -85,10 +100,10 @@ bool IconList::dropMimeData ( const QMimeData* data, Qt::DropAction action, int
*/
auto urls = data->urls();
QStringList iconFiles;
for(auto url: urls)
for (auto url : urls)
{
// only local files may be dropped...
if(!url.isLocalFile())
if (!url.isLocalFile())
continue;
iconFiles += url.toLocalFile();
}
@ -102,73 +117,73 @@ bool IconList::dropMimeData ( const QMimeData* data, Qt::DropAction action, int
return false;
}
Qt::ItemFlags IconList::flags ( const QModelIndex& index ) const
Qt::ItemFlags IconList::flags(const QModelIndex &index) const
{
Qt::ItemFlags defaultFlags = QAbstractListModel::flags ( index );
Qt::ItemFlags defaultFlags = QAbstractListModel::flags(index);
if (index.isValid())
return Qt::ItemIsDropEnabled | defaultFlags;
else
return Qt::ItemIsDropEnabled | defaultFlags;
}
QVariant IconList::data ( const QModelIndex& index, int role ) const
QVariant IconList::data(const QModelIndex &index, int role) const
{
if(!index.isValid())
if (!index.isValid())
return QVariant();
int row = index.row();
if(row < 0 || row >= d->icons.size())
if (row < 0 || row >= d->icons.size())
return QVariant();
switch(role)
switch (role)
{
case Qt::DecorationRole:
return d->icons[row].icon;
case Qt::DisplayRole:
return d->icons[row].name;
case Qt::UserRole:
return d->icons[row].key;
default:
return QVariant();
case Qt::DecorationRole:
return d->icons[row].icon;
case Qt::DisplayRole:
return d->icons[row].name;
case Qt::UserRole:
return d->icons[row].key;
default:
return QVariant();
}
}
int IconList::rowCount ( const QModelIndex& parent ) const
int IconList::rowCount(const QModelIndex &parent) const
{
return d->icons.size();
}
void IconList::installIcons ( QStringList iconFiles )
void IconList::installIcons(QStringList iconFiles)
{
for(QString file: iconFiles)
for (QString file : iconFiles)
{
QFileInfo fileinfo(file);
if(!fileinfo.isReadable() || !fileinfo.isFile())
if (!fileinfo.isReadable() || !fileinfo.isFile())
continue;
QString target = PathCombine("icons", fileinfo.fileName());
QString suffix = fileinfo.suffix();
if(suffix != "jpeg" && suffix != "png" && suffix != "jpg")
if (suffix != "jpeg" && suffix != "png" && suffix != "jpg")
continue;
if(!QFile::copy(file, target))
if (!QFile::copy(file, target))
continue;
QString key = fileinfo.baseName();
addIcon(key, key, target);
}
}
bool IconList::deleteIcon ( QString key )
bool IconList::deleteIcon(QString key)
{
int iconIdx = getIconIndex(key);
if(iconIdx == -1)
if (iconIdx == -1)
return false;
auto & iconEntry = d->icons[iconIdx];
if(iconEntry.is_builtin)
auto &iconEntry = d->icons[iconIdx];
if (iconEntry.is_builtin)
return false;
if(QFile::remove(iconEntry.filename))
if (QFile::remove(iconEntry.filename))
{
beginRemoveRows(QModelIndex(), iconIdx, iconIdx);
d->icons.remove(iconIdx);
@ -178,35 +193,36 @@ bool IconList::deleteIcon ( QString key )
return true;
}
bool IconList::addIcon ( QString key, QString name, QString path, bool is_builtin )
bool IconList::addIcon(QString key, QString name, QString path, bool is_builtin)
{
auto iter = d->index.find(key);
if(iter != d->index.end())
if (iter != d->index.end())
{
if(d->icons[*iter].is_builtin)
if (d->icons[*iter].is_builtin)
return false;
QIcon icon(path);
if(icon.isNull())
if (icon.isNull())
return false;
auto & oldOne = d->icons[*iter];
if(!QFile::remove(oldOne.filename))
auto &oldOne = d->icons[*iter];
if (!QFile::remove(oldOne.filename))
return false;
// replace the icon
oldOne = {key, name, icon, is_builtin, path};
dataChanged(index(*iter),index(*iter));
dataChanged(index(*iter), index(*iter));
return true;
}
else
{
QIcon icon(path);
if(icon.isNull()) return false;
if (icon.isNull())
return false;
// add a new icon
beginInsertRows(QModelIndex(), d->icons.size(),d->icons.size());
beginInsertRows(QModelIndex(), d->icons.size(), d->icons.size());
d->icons.push_back({key, name, icon, is_builtin, path});
d->index[key] = d->icons.size() - 1;
endInsertRows();
@ -218,39 +234,37 @@ void IconList::reindex()
{
d->index.clear();
int i = 0;
for(auto& iter: d->icons)
for (auto &iter : d->icons)
{
d->index[iter.key] = i;
i++;
}
}
QIcon IconList::getIcon ( QString key )
QIcon IconList::getIcon(QString key)
{
int icon_index = getIconIndex(key);
if(icon_index != -1)
if (icon_index != -1)
return d->icons[icon_index].icon;
// Fallback for icons that don't exist.
icon_index = getIconIndex("infinity");
if(icon_index != -1)
if (icon_index != -1)
return d->icons[icon_index].icon;
return QIcon();
}
int IconList::getIconIndex ( QString key )
int IconList::getIconIndex(QString key)
{
if(key == "default")
if (key == "default")
key = "infinity";
auto iter = d->index.find(key);
if(iter != d->index.end())
if (iter != d->index.end())
return *iter;
return -1;
}

View File

@ -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 <QMutex>
@ -11,28 +26,29 @@ class IconList : public QAbstractListModel
public:
IconList();
virtual ~IconList();
QIcon getIcon ( QString key );
int getIconIndex ( QString key );
virtual QVariant data ( const QModelIndex& index, int role = Qt::DisplayRole ) const;
virtual int rowCount ( const QModelIndex& parent = QModelIndex() ) const;
QIcon getIcon(QString key);
int getIconIndex(QString key);
virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
virtual int rowCount(const QModelIndex &parent = QModelIndex()) const;
bool addIcon(QString key, QString name, QString path, bool is_builtin = false);
bool deleteIcon(QString key);
virtual QStringList mimeTypes() const;
virtual Qt::DropActions supportedDropActions() const;
virtual bool dropMimeData ( const QMimeData* data, Qt::DropAction action, int row, int column, const QModelIndex& parent );
virtual Qt::ItemFlags flags ( const QModelIndex& index ) const;
void installIcons ( QStringList iconFiles );
virtual bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column,
const QModelIndex &parent);
virtual Qt::ItemFlags flags(const QModelIndex &index) const;
void installIcons(QStringList iconFiles);
private:
// hide copy constructor
IconList ( const IconList & ) = delete;
IconList(const IconList &) = delete;
// hide assign op
IconList& operator= ( const IconList & ) = delete;
IconList &operator=(const IconList &) = delete;
void reindex();
Private* d;
Private *d;
};

View File

@ -29,7 +29,7 @@
#include "logic/lists/IconList.h"
#include "logic/BaseInstance.h"
#include "logic/InstanceFactory.h"
#include <logger/QsLog.h>
#include "logger/QsLog.h"
const static int GROUP_FILE_FORMAT_VERSION = 1;
@ -423,7 +423,7 @@ bool InstanceProxyModel::subSortLessThan(const QModelIndex &left,
BaseInstance *pdataLeft = static_cast<BaseInstance *>(left.internalPointer());
BaseInstance *pdataRight = static_cast<BaseInstance *>(right.internalPointer());
QString sortMode = MMC->settings()->get("InstSortMode").toString();
if(sortMode == "LastLaunch")
if (sortMode == "LastLaunch")
{
return pdataLeft->lastLaunch() > pdataRight->lastLaunch();
}

View File

@ -98,7 +98,7 @@ signals:
public
slots:
void on_InstFolderChanged(const Setting & setting, QVariant value);
void on_InstFolderChanged(const Setting &setting, QVariant value);
private
slots:

View File

@ -20,7 +20,7 @@
#include <QtXml>
#include <QRegExp>
#include <logger/QsLog.h>
#include "logger/QsLog.h"
#include <logic/JavaUtils.h>
JavaVersionList::JavaVersionList(QObject *parent) : BaseVersionList(parent)
@ -32,7 +32,6 @@ Task *JavaVersionList::getLoadTask()
return new JavaListLoadTask(this);
}
const BaseVersionPtr JavaVersionList::at(int i) const
{
return m_vlist.at(i);
@ -187,11 +186,11 @@ void JavaListLoadTask::executeTask()
QList<JavaVersionPtr> javas = ju.FindJavaPaths();
QList<BaseVersionPtr> javas_bvp;
for(int i = 0; i < javas.length(); i++)
for (int i = 0; i < javas.length(); i++)
{
BaseVersionPtr java = std::dynamic_pointer_cast<BaseVersion>(javas.at(i));
if(java)
if (java)
{
javas_bvp.append(java);
}

View File

@ -64,11 +64,11 @@ public:
virtual BaseVersionPtr getTopRecommended() const;
virtual QVariant data(const QModelIndex &index, int role) const;
virtual QVariant headerData(int section, Qt::Orientation orientation,
int role) const;
virtual QVariant headerData(int section, Qt::Orientation orientation, int role) const;
virtual int columnCount(const QModelIndex &parent) const;
public slots:
public
slots:
virtual void updateListData(QList<BaseVersionPtr> versions);
protected:

View File

@ -20,7 +20,7 @@
#include <QtXml>
#include <QRegExp>
#include <logger/QsLog.h>
#include "logger/QsLog.h"
#define RSS_URL "http://sourceforge.net/api/file/index/project-id/58488/mtime/desc/rss"

View File

@ -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
@ -28,20 +28,30 @@ typedef std::shared_ptr<LWJGLVersion> PtrLWJGLVersion;
class LWJGLVersion : public QObject
{
Q_OBJECT
LWJGLVersion(const QString &name, const QString &url, QObject *parent = 0) :
QObject(parent), m_name(name), m_url(url) { }
LWJGLVersion(const QString &name, const QString &url, QObject *parent = 0)
: QObject(parent), m_name(name), m_url(url)
{
}
public:
static PtrLWJGLVersion Create(const QString &name, const QString &url, QObject *parent = 0)
{
return PtrLWJGLVersion(new LWJGLVersion(name, url, parent));
};
QString name() const { return m_name; }
QString url() const { return m_url; }
}
;
QString name() const
{
return m_name;
}
QString url() const
{
return m_url;
}
protected:
QString m_name;
QString m_url;
@ -52,64 +62,87 @@ class LWJGLVersionList : public QAbstractListModel
Q_OBJECT
public:
explicit LWJGLVersionList(QObject *parent = 0);
bool isLoaded() { return m_vlist.length() > 0; }
bool isLoaded()
{
return m_vlist.length() > 0;
}
const PtrLWJGLVersion getVersion(const QString &versionName);
PtrLWJGLVersion at(int index) { return m_vlist[index]; }
const PtrLWJGLVersion at(int index) const { return m_vlist[index]; }
int count() const { return m_vlist.length(); }
PtrLWJGLVersion at(int index)
{
return m_vlist[index];
}
const PtrLWJGLVersion at(int index) const
{
return m_vlist[index];
}
int count() const
{
return m_vlist.length();
}
virtual QVariant data(const QModelIndex &index, int role) const;
virtual QVariant headerData(int section, Qt::Orientation orientation, int role) const;
virtual int rowCount(const QModelIndex &parent) const { return count(); }
virtual int rowCount(const QModelIndex &parent) const
{
return count();
}
virtual int columnCount(const QModelIndex &parent) const;
virtual bool isLoading() const;
virtual bool errored() const { return m_errored; }
virtual QString lastErrorMsg() const { return m_lastErrorMsg; }
public slots:
virtual bool errored() const
{
return m_errored;
}
virtual QString lastErrorMsg() const
{
return m_lastErrorMsg;
}
public
slots:
/*!
* Loads the version list.
* This is done asynchronously. On success, the loadListFinished() signal will
* be emitted. The list model will be reset as well, resulting in the modelReset()
* signal being emitted. Note that the model will be reset before loadListFinished() is emitted.
* be emitted. The list model will be reset as well, resulting in the modelReset()
* signal being emitted. Note that the model will be reset before loadListFinished() is
* emitted.
* If loading the list failed, the loadListFailed(QString msg),
* signal will be emitted.
*/
virtual void loadList();
signals:
/*!
* Emitted when the list either starts or finishes loading.
* \param loading Whether or not the list is loading.
*/
void loadingStateUpdated(bool loading);
void loadListFinished();
void loadListFailed(QString msg);
private:
QList<PtrLWJGLVersion> m_vlist;
QNetworkReply *m_netReply;
QNetworkReply *reply;
bool m_loading;
bool m_errored;
QString m_lastErrorMsg;
void failed(QString msg);
void finished();
void setLoading(bool loading);
private slots:
private
slots:
virtual void netRequestComplete();
};

View File

@ -1,4 +1,4 @@
/* Copyright 2013 Andrew Okin
/* 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.
@ -14,7 +14,7 @@
*/
#include "MinecraftVersionList.h"
#include <MultiMC.h>
#include "MultiMC.h"
#include <QtXml>

View File

@ -1,9 +1,9 @@
/* Copyright 2013 Andrew Okin
/* 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
@ -32,43 +32,44 @@ class MinecraftVersionList : public BaseVersionList
Q_OBJECT
public:
friend class MCVListLoadTask;
explicit MinecraftVersionList(QObject *parent = 0);
virtual Task *getLoadTask();
virtual bool isLoaded();
virtual const BaseVersionPtr at(int i) const;
virtual int count() const;
virtual void sort();
virtual BaseVersionPtr getLatestStable() const;
protected:
QList<BaseVersionPtr> m_vlist;
bool m_loaded = false;
protected slots:
protected
slots:
virtual void updateListData(QList<BaseVersionPtr> versions);
};
class MCVListLoadTask : public Task
{
Q_OBJECT
public:
explicit MCVListLoadTask(MinecraftVersionList *vlist);
~MCVListLoadTask();
virtual void executeTask();
protected slots:
protected
slots:
void list_downloaded();
protected:
QNetworkReply *vlistReply;
MinecraftVersionList *m_list;
MinecraftVersion *m_currentStable;
QSet<QString> legacyWhitelist;
};

View File

@ -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 "ByteArrayDownload.h"
#include "MultiMC.h"
#include <logger/QsLog.h>
#include "logger/QsLog.h"
ByteArrayDownload::ByteArrayDownload(QUrl url) : NetAction()
{

View File

@ -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 "NetAction.h"

View File

@ -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 "MultiMC.h"
#include "CacheDownload.h"
#include <pathutils.h>
@ -5,7 +20,7 @@
#include <QCryptographicHash>
#include <QFileInfo>
#include <QDateTime>
#include <logger/QsLog.h>
#include "logger/QsLog.h"
CacheDownload::CacheDownload(QUrl url, MetaEntryPtr entry)
: NetAction(), md5sum(QCryptographicHash::Md5)
@ -33,12 +48,13 @@ void CacheDownload::start()
}
QLOG_INFO() << "Downloading " << m_url.toString();
QNetworkRequest request(m_url);
if(m_entry->remote_changed_timestamp.size())
request.setRawHeader(QString("If-Modified-Since").toLatin1(), m_entry->remote_changed_timestamp.toLatin1());
if(m_entry->etag.size())
if (m_entry->remote_changed_timestamp.size())
request.setRawHeader(QString("If-Modified-Since").toLatin1(),
m_entry->remote_changed_timestamp.toLatin1());
if (m_entry->etag.size())
request.setRawHeader(QString("If-None-Match").toLatin1(), m_entry->etag.toLatin1());
request.setHeader(QNetworkRequest::UserAgentHeader,"MultiMC/5.0 (Cached)");
request.setHeader(QNetworkRequest::UserAgentHeader, "MultiMC/5.0 (Cached)");
auto worker = MMC->qnam();
QNetworkReply *rep = worker->get(request);
@ -91,7 +107,7 @@ void CacheDownload::downloadFinished()
QFileInfo output_file_info(m_target_path);
m_entry->etag = m_reply->rawHeader("ETag").constData();
if(m_reply->hasRawHeader("Last-Modified"))
if (m_reply->hasRawHeader("Last-Modified"))
{
m_entry->remote_changed_timestamp = m_reply->rawHeader("Last-Modified").constData();
}

View File

@ -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 "NetAction.h"

View File

@ -1,12 +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.
*/
#include "MultiMC.h"
#include "FileDownload.h"
#include <pathutils.h>
#include <QCryptographicHash>
#include <logger/QsLog.h>
#include "logger/QsLog.h"
FileDownload::FileDownload ( QUrl url, QString target_path )
:NetAction()
FileDownload::FileDownload(QUrl url, QString target_path) : NetAction()
{
m_url = url;
m_target_path = target_path;
@ -18,15 +31,18 @@ FileDownload::FileDownload ( QUrl url, QString target_path )
void FileDownload::start()
{
QString filename = m_target_path;
m_output_file.setFileName ( filename );
m_output_file.setFileName(filename);
// if there already is a file and md5 checking is in effect and it can be opened
if ( m_output_file.exists() && m_output_file.open ( QIODevice::ReadOnly ) )
if (m_output_file.exists() && m_output_file.open(QIODevice::ReadOnly))
{
// check the md5 against the expected one
QString hash = QCryptographicHash::hash ( m_output_file.readAll(), QCryptographicHash::Md5 ).toHex().constData();
QString hash =
QCryptographicHash::hash(m_output_file.readAll(), QCryptographicHash::Md5)
.toHex()
.constData();
m_output_file.close();
// skip this file if they match
if ( m_check_md5 && hash == m_expected_md5 )
if (m_check_md5 && hash == m_expected_md5)
{
QLOG_INFO() << "Skipping " << m_url.toString() << ": md5 match.";
emit succeeded(index_within_job);
@ -37,33 +53,35 @@ void FileDownload::start()
m_expected_md5 = hash;
}
}
if(!ensureFilePathExists(filename))
if (!ensureFilePathExists(filename))
{
emit failed(index_within_job);
return;
}
QLOG_INFO() << "Downloading " << m_url.toString();
QNetworkRequest request ( m_url );
request.setRawHeader(QString("If-None-Match").toLatin1(), m_expected_md5.toLatin1());
request.setHeader(QNetworkRequest::UserAgentHeader,"MultiMC/5.0 (Uncached)");
QNetworkRequest request(m_url);
request.setRawHeader(QString("If-None-Match").toLatin1(), m_expected_md5.toLatin1());
request.setHeader(QNetworkRequest::UserAgentHeader, "MultiMC/5.0 (Uncached)");
auto worker = MMC->qnam();
QNetworkReply * rep = worker->get ( request );
m_reply = std::shared_ptr<QNetworkReply> ( rep );
connect ( rep, SIGNAL ( downloadProgress ( qint64,qint64 ) ), SLOT ( downloadProgress ( qint64,qint64 ) ) );
connect ( rep, SIGNAL ( finished() ), SLOT ( downloadFinished() ) );
connect ( rep, SIGNAL ( error ( QNetworkReply::NetworkError ) ), SLOT ( downloadError ( QNetworkReply::NetworkError ) ) );
connect ( rep, SIGNAL ( readyRead() ), SLOT ( downloadReadyRead() ) );
QNetworkReply *rep = worker->get(request);
m_reply = std::shared_ptr<QNetworkReply>(rep);
connect(rep, SIGNAL(downloadProgress(qint64, qint64)),
SLOT(downloadProgress(qint64, qint64)));
connect(rep, SIGNAL(finished()), SLOT(downloadFinished()));
connect(rep, SIGNAL(error(QNetworkReply::NetworkError)),
SLOT(downloadError(QNetworkReply::NetworkError)));
connect(rep, SIGNAL(readyRead()), SLOT(downloadReadyRead()));
}
void FileDownload::downloadProgress ( qint64 bytesReceived, qint64 bytesTotal )
void FileDownload::downloadProgress(qint64 bytesReceived, qint64 bytesTotal)
{
emit progress (index_within_job, bytesReceived, bytesTotal );
emit progress(index_within_job, bytesReceived, bytesTotal);
}
void FileDownload::downloadError ( QNetworkReply::NetworkError error )
void FileDownload::downloadError(QNetworkReply::NetworkError error)
{
// error happened during download.
// TODO: log the reason why
@ -73,7 +91,7 @@ void FileDownload::downloadError ( QNetworkReply::NetworkError error )
void FileDownload::downloadFinished()
{
// if the download succeeded
if ( m_status != Job_Failed )
if (m_status != Job_Failed)
{
// nothing went wrong...
m_status = Job_Finished;
@ -95,9 +113,9 @@ void FileDownload::downloadFinished()
void FileDownload::downloadReadyRead()
{
if(!m_opened_for_saving)
if (!m_opened_for_saving)
{
if ( !m_output_file.open ( QIODevice::WriteOnly ) )
if (!m_output_file.open(QIODevice::WriteOnly))
{
/*
* Can't open the file... the job failed
@ -108,5 +126,5 @@ void FileDownload::downloadReadyRead()
}
m_opened_for_saving = true;
}
m_output_file.write ( m_reply->readAll() );
m_output_file.write(m_reply->readAll());
}

View File

@ -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 "NetAction.h"

View File

@ -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 "MultiMC.h"
#include "ForgeXzDownload.h"
#include <pathutils.h>
@ -5,10 +20,9 @@
#include <QCryptographicHash>
#include <QFileInfo>
#include <QDateTime>
#include <logger/QsLog.h>
#include "logger/QsLog.h"
ForgeXzDownload::ForgeXzDownload(QUrl url, MetaEntryPtr entry)
: NetAction()
ForgeXzDownload::ForgeXzDownload(QUrl url, MetaEntryPtr entry) : NetAction()
{
QString urlstr = url.toString();
urlstr.append(".pack.xz");
@ -35,7 +49,7 @@ void ForgeXzDownload::start()
QLOG_INFO() << "Downloading " << m_url.toString();
QNetworkRequest request(m_url);
request.setRawHeader(QString("If-None-Match").toLatin1(), m_entry->etag.toLatin1());
request.setHeader(QNetworkRequest::UserAgentHeader,"MultiMC/5.0 (Cached)");
request.setHeader(QNetworkRequest::UserAgentHeader, "MultiMC/5.0 (Cached)");
auto worker = MMC->qnam();
QNetworkReply *rep = worker->get(request);
@ -96,7 +110,7 @@ void ForgeXzDownload::downloadFinished()
void ForgeXzDownload::downloadReadyRead()
{
if (!m_opened_for_saving)
{
if (!m_pack200_xz_file.open())
@ -154,7 +168,7 @@ void ForgeXzDownload::decompressAndInstall()
{
if (b.in_pos == b.in_size)
{
b.in_size = m_pack200_xz_file.read((char*)in, sizeof(in));
b.in_size = m_pack200_xz_file.read((char *)in, sizeof(in));
b.in_pos = 0;
}
@ -162,7 +176,7 @@ void ForgeXzDownload::decompressAndInstall()
if (b.out_pos == sizeof(out))
{
if (pack200_file.write((char*)out, b.out_pos) != b.out_pos)
if (pack200_file.write((char *)out, b.out_pos) != b.out_pos)
{
// msg = "Write error\n";
xz_dec_end(s);
@ -182,7 +196,7 @@ void ForgeXzDownload::decompressAndInstall()
continue;
}
if (pack200_file.write((char*)out, b.out_pos) != b.out_pos )
if (pack200_file.write((char *)out, b.out_pos) != b.out_pos)
{
// write error
pack200_file.close();
@ -236,7 +250,7 @@ void ForgeXzDownload::decompressAndInstall()
}
}
}
// revert pack200
pack200_file.close();
QString pack_name = pack200_file.fileName();
@ -244,16 +258,16 @@ void ForgeXzDownload::decompressAndInstall()
{
unpack_200(pack_name.toStdString(), m_target_path.toStdString());
}
catch(std::runtime_error & err)
catch (std::runtime_error &err)
{
QLOG_ERROR() << "Error unpacking " << pack_name.toUtf8() << " : " << err.what();
QFile f(m_target_path);
if(f.exists())
if (f.exists())
f.remove();
emit failed(index_within_job);
return;
}
QFile jar_file(m_target_path);
if (!jar_file.open(QIODevice::ReadOnly))
@ -263,10 +277,10 @@ void ForgeXzDownload::decompressAndInstall()
return;
}
m_entry->md5sum = QCryptographicHash::hash(jar_file.readAll(), QCryptographicHash::Md5)
.toHex()
.constData();
.toHex()
.constData();
jar_file.close();
QFileInfo output_file_info(m_target_path);
m_entry->etag = m_reply->rawHeader("ETag").constData();
m_entry->local_changed_timestamp =

View File

@ -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 "NetAction.h"

View File

@ -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 "MultiMC.h"
#include "HttpMetaCache.h"
#include <pathutils.h>
@ -9,7 +24,7 @@
#include <QDateTime>
#include <QCryptographicHash>
#include <logger/QsLog.h>
#include "logger/QsLog.h"
#include <QJsonDocument>
#include <QJsonArray>
@ -20,14 +35,12 @@ QString MetaEntry::getFullPath()
return PathCombine(MMC->metacache()->getBasePath(base), path);
}
HttpMetaCache::HttpMetaCache(QString path)
:QObject()
HttpMetaCache::HttpMetaCache(QString path) : QObject()
{
m_index_file = path;
saveBatchingTimer.setSingleShot(true);
saveBatchingTimer.setTimerType(Qt::VeryCoarseTimer);
connect(&saveBatchingTimer,SIGNAL(timeout()),SLOT(SaveNow()));
connect(&saveBatchingTimer, SIGNAL(timeout()), SLOT(SaveNow()));
}
HttpMetaCache::~HttpMetaCache()
@ -36,58 +49,61 @@ HttpMetaCache::~HttpMetaCache()
SaveNow();
}
MetaEntryPtr HttpMetaCache::getEntry ( QString base, QString resource_path )
MetaEntryPtr HttpMetaCache::getEntry(QString base, QString resource_path)
{
// no base. no base path. can't store
if(!m_entries.contains(base))
if (!m_entries.contains(base))
{
// TODO: log problem
return MetaEntryPtr();
}
EntryMap & map = m_entries[base];
if(map.entry_list.contains(resource_path))
EntryMap &map = m_entries[base];
if (map.entry_list.contains(resource_path))
{
return map.entry_list[resource_path];
}
return MetaEntryPtr();
}
MetaEntryPtr HttpMetaCache::resolveEntry ( QString base, QString resource_path, QString expected_etag )
MetaEntryPtr HttpMetaCache::resolveEntry(QString base, QString resource_path,
QString expected_etag)
{
auto entry = getEntry(base, resource_path);
// it's not present? generate a default stale entry
if(!entry)
if (!entry)
{
return staleEntry(base, resource_path);
}
auto & selected_base = m_entries[base];
auto &selected_base = m_entries[base];
QString real_path = PathCombine(selected_base.base_path, resource_path);
QFileInfo finfo(real_path);
// is the file really there? if not -> stale
if(!finfo.isFile() || !finfo.isReadable())
if (!finfo.isFile() || !finfo.isReadable())
{
// if the file doesn't exist, we disown the entry
selected_base.entry_list.remove(resource_path);
return staleEntry(base, resource_path);
}
if(!expected_etag.isEmpty() && expected_etag != entry->etag)
if (!expected_etag.isEmpty() && expected_etag != entry->etag)
{
// if the etag doesn't match expected, we disown the entry
selected_base.entry_list.remove(resource_path);
return staleEntry(base, resource_path);
}
// if the file changed, check md5sum
qint64 file_last_changed = finfo.lastModified().toUTC().toMSecsSinceEpoch();
if(file_last_changed != entry->local_changed_timestamp)
if (file_last_changed != entry->local_changed_timestamp)
{
QFile input(real_path);
input.open(QIODevice::ReadOnly);
QString md5sum = QCryptographicHash::hash(input.readAll(), QCryptographicHash::Md5).toHex().constData();
if(entry->md5sum != md5sum)
QString md5sum = QCryptographicHash::hash(input.readAll(), QCryptographicHash::Md5)
.toHex()
.constData();
if (entry->md5sum != md5sum)
{
selected_base.entry_list.remove(resource_path);
return staleEntry(base, resource_path);
@ -101,14 +117,15 @@ MetaEntryPtr HttpMetaCache::resolveEntry ( QString base, QString resource_path,
return entry;
}
bool HttpMetaCache::updateEntry ( MetaEntryPtr stale_entry )
bool HttpMetaCache::updateEntry(MetaEntryPtr stale_entry)
{
if(!m_entries.contains(stale_entry->base))
if (!m_entries.contains(stale_entry->base))
{
QLOG_ERROR() << "Cannot add entry with unknown base: " << stale_entry->base.toLocal8Bit();
QLOG_ERROR() << "Cannot add entry with unknown base: "
<< stale_entry->base.toLocal8Bit();
return false;
}
if(stale_entry->stale)
if (stale_entry->stale)
{
QLOG_ERROR() << "Cannot add stale entry: " << stale_entry->getFullPath().toLocal8Bit();
return false;
@ -127,10 +144,10 @@ MetaEntryPtr HttpMetaCache::staleEntry(QString base, QString resource_path)
return MetaEntryPtr(foo);
}
void HttpMetaCache::addBase ( QString base, QString base_root )
void HttpMetaCache::addBase(QString base, QString base_root)
{
// TODO: report error
if(m_entries.contains(base))
if (m_entries.contains(base))
return;
// TODO: check if the base path is valid
EntryMap foo;
@ -138,57 +155,57 @@ void HttpMetaCache::addBase ( QString base, QString base_root )
m_entries[base] = foo;
}
QString HttpMetaCache::getBasePath ( QString base )
QString HttpMetaCache::getBasePath(QString base)
{
if(m_entries.contains(base))
if (m_entries.contains(base))
{
return m_entries[base].base_path;
}
return QString();
}
void HttpMetaCache::Load()
{
QFile index(m_index_file);
if(!index.open(QIODevice::ReadOnly))
if (!index.open(QIODevice::ReadOnly))
return;
QJsonDocument json = QJsonDocument::fromJson(index.readAll());
if(!json.isObject())
if (!json.isObject())
return;
auto root = json.object();
// check file version first
auto version_val =root.value("version");
if(!version_val.isString())
auto version_val = root.value("version");
if (!version_val.isString())
return;
if(version_val.toString() != "1")
if (version_val.toString() != "1")
return;
// read the entry array
auto entries_val =root.value("entries");
if(!entries_val.isArray())
auto entries_val = root.value("entries");
if (!entries_val.isArray())
return;
QJsonArray array = entries_val.toArray();
for(auto element: array)
for (auto element : array)
{
if(!element.isObject())
if (!element.isObject())
return;
auto element_obj = element.toObject();
QString base = element_obj.value("base").toString();
if(!m_entries.contains(base))
if (!m_entries.contains(base))
continue;
auto & entrymap = m_entries[base];
auto &entrymap = m_entries[base];
auto foo = new MetaEntry;
foo->base = base;
QString path = foo->path = element_obj.value("path").toString();
foo->md5sum = element_obj.value("md5sum").toString();
foo->etag = element_obj.value("etag").toString();
foo->local_changed_timestamp = element_obj.value("last_changed_timestamp").toDouble();
foo->remote_changed_timestamp = element_obj.value("remote_changed_timestamp").toString();
foo->remote_changed_timestamp =
element_obj.value("remote_changed_timestamp").toString();
// presumed innocent until closer examination
foo->stale = false;
entrymap.entry_list[path] = MetaEntryPtr( foo );
entrymap.entry_list[path] = MetaEntryPtr(foo);
}
}
@ -202,33 +219,35 @@ void HttpMetaCache::SaveEventually()
void HttpMetaCache::SaveNow()
{
QSaveFile tfile(m_index_file);
if(!tfile.open(QIODevice::WriteOnly | QIODevice::Truncate))
if (!tfile.open(QIODevice::WriteOnly | QIODevice::Truncate))
return;
QJsonObject toplevel;
toplevel.insert("version",QJsonValue(QString("1")));
toplevel.insert("version", QJsonValue(QString("1")));
QJsonArray entriesArr;
for(auto group : m_entries)
for (auto group : m_entries)
{
for(auto entry : group.entry_list)
for (auto entry : group.entry_list)
{
QJsonObject entryObj;
entryObj.insert("base", QJsonValue(entry->base));
entryObj.insert("path", QJsonValue(entry->path));
entryObj.insert("md5sum", QJsonValue(entry->md5sum));
entryObj.insert("etag", QJsonValue(entry->etag));
entryObj.insert("last_changed_timestamp", QJsonValue(double(entry->local_changed_timestamp)));
if(!entry->remote_changed_timestamp.isEmpty())
entryObj.insert("remote_changed_timestamp", QJsonValue(entry->remote_changed_timestamp));
entryObj.insert("last_changed_timestamp",
QJsonValue(double(entry->local_changed_timestamp)));
if (!entry->remote_changed_timestamp.isEmpty())
entryObj.insert("remote_changed_timestamp",
QJsonValue(entry->remote_changed_timestamp));
entriesArr.append(entryObj);
}
}
toplevel.insert("entries",entriesArr);
toplevel.insert("entries", entriesArr);
QJsonDocument doc(toplevel);
QByteArray jsonData = doc.toJson();
qint64 result = tfile.write(jsonData);
if(result == -1)
if (result == -1)
return;
if(result != jsonData.size())
if (result != jsonData.size())
return;
tfile.commit();
}

View File

@ -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 <QString>
#include <QSharedPointer>

View File

@ -100,7 +100,9 @@ void LoginTask::processYggdrasilReply(QNetworkReply *reply)
processReply(reply, &LoginTask::parseYggdrasilReply, &LoginTask::parseYggdrasilError);
}
void LoginTask::processReply(QNetworkReply *reply, std::function<void (LoginTask*, QByteArray)> parser, std::function<QString (LoginTask*, QNetworkReply*)> errorHandler)
void LoginTask::processReply(QNetworkReply *reply,
std::function<void(LoginTask *, QByteArray)> parser,
std::function<QString(LoginTask *, QNetworkReply *)> errorHandler)
{
if (netReply != reply)
return;
@ -147,7 +149,7 @@ QString LoginTask::parseLegacyError(QNetworkReply *reply)
case 503:
return tr("The login servers are currently unavailable. Check "
"http://help.mojang.com/ for more info.");
"http://help.mojang.com/ for more info.");
default:
QLOG_DEBUG() << "Login failed with QNetworkReply code:" << reply->error();
@ -161,7 +163,8 @@ QString LoginTask::parseYggdrasilError(QNetworkReply *reply)
QJsonParseError jsonError;
QJsonDocument jsonDoc = QJsonDocument::fromJson(data, &jsonError);
// If there are JSON errors fall back to using the legacy error handling using HTTP status codes
// If there are JSON errors fall back to using the legacy error handling using HTTP status
// codes
if (jsonError.error != QJsonParseError::NoError)
{
return parseLegacyError(reply);
@ -174,10 +177,10 @@ QString LoginTask::parseYggdrasilError(QNetworkReply *reply)
QJsonObject root = jsonDoc.object();
//QString error = root.value("error").toString();
// QString error = root.value("error").toString();
QString errorMessage = root.value("errorMessage").toString();
if(errorMessage.isEmpty())
if (errorMessage.isEmpty())
{
return parseLegacyError(reply);
}
@ -230,14 +233,14 @@ void LoginTask::yggdrasilLogin()
"accessToken": "random access token", // hexadecimal
"clientToken": "client identifier", // identical to the one received
"availableProfiles": [ // only present if the agent field was received
{
"id": "profile identifier", // hexadecimal
"name": "player name"
}
{
"id": "profile identifier", // hexadecimal
"name": "player name"
}
],
"selectedProfile": { // only present if the agent field was received
"id": "profile identifier",
"name": "player name"
"id": "profile identifier",
"name": "player name"
}
}
*/
@ -264,7 +267,7 @@ void LoginTask::parseYggdrasilReply(QByteArray data)
QString playerID;
QString playerName;
auto selectedProfile = root.value("selectedProfile");
if(selectedProfile.isObject())
if (selectedProfile.isObject())
{
auto selectedProfileO = selectedProfile.toObject();
playerID = selectedProfileO.value("id").toString();
@ -281,7 +284,7 @@ void LoginTask::parseYggdrasilReply(QByteArray data)
QString client_id;
};
*/
result = {uInfo.username, sessionID, playerName, playerID, accessToken};
emitSucceeded();
}

View File

@ -45,7 +45,8 @@ public:
return result;
}
protected slots:
protected
slots:
void legacyLogin();
void processLegacyReply(QNetworkReply *reply);
void parseLegacyReply(QByteArray data);
@ -56,7 +57,8 @@ protected slots:
void parseYggdrasilReply(QByteArray data);
QString parseYggdrasilError(QNetworkReply *reply);
void processReply(QNetworkReply *reply, std::function<void(LoginTask*, QByteArray)>, std::function<QString(LoginTask*, QNetworkReply*)>);
void processReply(QNetworkReply *reply, std::function<void(LoginTask *, QByteArray)>,
std::function<QString(LoginTask *, QNetworkReply *)>);
protected:
void executeTask();

View File

@ -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 <QObject>
@ -42,12 +57,14 @@ signals:
void succeeded(int index);
void failed(int index);
protected slots:
protected
slots:
virtual void downloadProgress(qint64 bytesReceived, qint64 bytesTotal) = 0;
virtual void downloadError(QNetworkReply::NetworkError error) = 0;
virtual void downloadFinished() = 0;
virtual void downloadReadyRead() = 0;
public slots:
public
slots:
virtual void start() = 0;
};

View File

@ -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 "NetJob.h"
#include "pathutils.h"
#include "MultiMC.h"
@ -5,7 +20,7 @@
#include "ByteArrayDownload.h"
#include "CacheDownload.h"
#include <logger/QsLog.h>
#include "logger/QsLog.h"
void NetJob::partSucceeded(int index)
{
@ -15,7 +30,7 @@ void NetJob::partSucceeded(int index)
num_succeeded++;
QLOG_INFO() << m_job_name.toLocal8Bit() << "progress:" << num_succeeded << "/"
<< downloads.size();
<< downloads.size();
emit filesProgress(num_succeeded, num_failed, downloads.size());
if (num_failed + num_succeeded == downloads.size())
@ -50,7 +65,7 @@ void NetJob::partFailed(int index)
else
{
QLOG_ERROR() << "Part" << index << "failed, restarting (" << downloads[index]->m_url
<< ")";
<< ")";
// restart the job
slot.failures++;
downloads[index]->start();

View File

@ -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 <QtNetwork>
#include <QLabel>
@ -18,10 +33,9 @@ class NetJob : public ProgressProvider
public:
explicit NetJob(QString job_name) : ProgressProvider(), m_job_name(job_name) {};
template <typename T>
bool addNetAction(T action)
template <typename T> bool addNetAction(T action)
{
NetActionPtr base = std::static_pointer_cast<NetAction>(action);
NetActionPtr base = std::static_pointer_cast<NetAction>(action);
base->index_within_job = downloads.size();
downloads.append(action);
parts_progress.append(part_info());

View File

@ -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 "S3ListBucket.h"
#include "MultiMC.h"
#include <logger/QsLog.h>
#include "logger/QsLog.h"
#include <QUrlQuery>
#include <qxmlstream.h>
#include <QDomDocument>
@ -123,7 +138,7 @@ void S3ListBucket::processValidReply()
emit failed(index_within_job);
return;
}
if(is_truncated)
if (is_truncated)
{
current_marker = objects.last().Key;
bytesSoFar += m_reply->size();

View File

@ -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 "NetAction.h"

View File

@ -1,20 +1,41 @@
/* Copyright 2013 MultiMC Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once
#include <QObject>
class ProgressProvider : public QObject
{
Q_OBJECT
protected:
explicit ProgressProvider(QObject* parent = 0): QObject(parent){}
explicit ProgressProvider(QObject *parent = 0) : QObject(parent)
{
}
signals:
void started();
void progress(qint64 current, qint64 total);
void succeeded();
void failed(QString reason);
void status(QString status);
public:
virtual QString getStatus() const = 0;
virtual void getProgress(qint64 &current, qint64 &total) = 0;
virtual bool isRunning() const = 0;
public slots:
public
slots:
virtual void start() = 0;
};

View File

@ -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,12 +14,10 @@
*/
#include "Task.h"
#include <logger/QsLog.h>
#include "logger/QsLog.h"
Task::Task(QObject *parent) :
ProgressProvider(parent)
Task::Task(QObject *parent) : ProgressProvider(parent)
{
}
QString Task::getStatus() const
@ -39,13 +37,12 @@ void Task::setProgress(int new_progress)
emit progress(new_progress, 100);
}
void Task::getProgress(qint64& current, qint64& total)
void Task::getProgress(qint64 &current, qint64 &total)
{
current = m_progress;
total = 100;
}
void Task::start()
{
m_running = true;
@ -66,7 +63,6 @@ void Task::emitSucceeded()
emit succeeded();
}
bool Task::isRunning() const
{
return m_running;

View File

@ -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
@ -24,24 +24,26 @@ class Task : public ProgressProvider
Q_OBJECT
public:
explicit Task(QObject *parent = 0);
virtual QString getStatus() const;
virtual void getProgress(qint64& current, qint64& total);
virtual void getProgress(qint64 &current, qint64 &total);
virtual bool isRunning() const;
public slots:
public
slots:
virtual void start();
protected:
virtual void executeTask() = 0;
virtual void emitSucceeded();
virtual void emitFailed(QString reason);
protected slots:
void setStatus(const QString& status);
protected
slots:
void setStatus(const QString &status);
void setProgress(int progress);
protected:
QString m_status;
int m_progress = 0;