Fix liteloader, some cleanups.

This commit is contained in:
Petr Mrázek 2014-07-06 11:15:15 +02:00
parent a218d7b7f6
commit cc499488db
18 changed files with 93 additions and 85 deletions

View File

@ -417,6 +417,9 @@ SET(MULTIMC_SOURCES
logic/MMCJson.h logic/MMCJson.h
logic/MMCJson.cpp logic/MMCJson.cpp
# RW lock protected map
logic/RWStorage.h
# network stuffs # network stuffs
logic/net/NetAction.h logic/net/NetAction.h
logic/net/MD5EtagDownload.h logic/net/MD5EtagDownload.h

View File

@ -19,7 +19,6 @@
#include <QDir> #include <QDir>
#include <QDesktopServices> #include <QDesktopServices>
#include <QUrl> #include <QUrl>
#include <QDebug>
QString PathCombine(QString path1, QString path2) QString PathCombine(QString path1, QString path2)
{ {

View File

@ -75,7 +75,6 @@ bool Util::createShortCut(QString location, QString dest, QStringList args, QStr
{ {
#if LINUX #if LINUX
location = PathCombine(location, name + ".desktop"); location = PathCombine(location, name + ".desktop");
qDebug("location: %s", qPrintable(location));
QFile f(location); QFile f(location);
f.open(QIODevice::WriteOnly | QIODevice::Text); f.open(QIODevice::WriteOnly | QIODevice::Text);

View File

@ -18,8 +18,6 @@
#include <QHeaderView> #include <QHeaderView>
#include <QDebug>
#include <gui/dialogs/ProgressDialog.h> #include <gui/dialogs/ProgressDialog.h>
#include "gui/Platform.h" #include "gui/Platform.h"

View File

@ -3,7 +3,6 @@
#include <QPainter> #include <QPainter>
#include <QApplication> #include <QApplication>
#include <QtMath> #include <QtMath>
#include <QDebug>
#include <QMouseEvent> #include <QMouseEvent>
#include <QListView> #include <QListView>
#include <QPersistentModelIndex> #include <QPersistentModelIndex>
@ -12,6 +11,7 @@
#include <QScrollBar> #include <QScrollBar>
#include "Group.h" #include "Group.h"
#include "logger/QsLog.h"
template <typename T> bool listsIntersect(const QList<T> &l1, const QList<T> t2) template <typename T> bool listsIntersect(const QList<T> &l1, const QList<T> t2)
{ {
@ -917,10 +917,10 @@ QModelIndex GroupView::moveCursor(QAbstractItemView::CursorAction cursorAction,
auto current = currentIndex(); auto current = currentIndex();
if(!current.isValid()) if(!current.isValid())
{ {
qDebug() << "model row: invalid"; QLOG_DEBUG() << "model row: invalid";
return current; return current;
} }
qDebug() << "model row: " << current.row(); QLOG_DEBUG() << "model row: " << current.row();
auto cat = category(current); auto cat = category(current);
int i = m_groups.indexOf(cat); int i = m_groups.indexOf(cat);
if(i >= 0) if(i >= 0)
@ -934,11 +934,11 @@ QModelIndex GroupView::moveCursor(QAbstractItemView::CursorAction cursorAction,
break; break;
beginning_row += group->numRows(); beginning_row += group->numRows();
} }
qDebug() << "category: " << real_group->text; QLOG_DEBUG() << "category: " << real_group->text;
QPair<int, int> pos = categoryInternalPosition(current); QPair<int, int> pos = categoryInternalPosition(current);
int row = beginning_row + pos.second; int row = beginning_row + pos.second;
qDebug() << "row: " << row; QLOG_DEBUG() << "row: " << row;
qDebug() << "column: " << pos.first; QLOG_DEBUG() << "column: " << pos.first;
} }
return current; return current;
} }

View File

@ -18,7 +18,6 @@
#include <pathutils.h> #include <pathutils.h>
#include <QFileDialog> #include <QFileDialog>
#include <QMessageBox> #include <QMessageBox>
#include <QDebug>
#include <QEvent> #include <QEvent>
#include <QKeyEvent> #include <QKeyEvent>
#include <QDesktopServices> #include <QDesktopServices>

View File

@ -21,66 +21,7 @@
#include "logic/screenshots/ImgurAlbumCreation.h" #include "logic/screenshots/ImgurAlbumCreation.h"
#include "logic/tasks/SequentialTask.h" #include "logic/tasks/SequentialTask.h"
template <typename K, typename V> #include "logic/RWStorage.h"
class RWStorage
{
public:
void add(K key, V value)
{
QWriteLocker l(&lock);
cache[key] = value;
stale_entries.remove(key);
}
V get(K key)
{
QReadLocker l(&lock);
if(cache.contains(key))
{
return cache[key];
}
else return V();
}
bool get(K key, V& value)
{
QReadLocker l(&lock);
if(cache.contains(key))
{
value = cache[key];
return true;
}
else return false;
}
bool has(K key)
{
QReadLocker l(&lock);
return cache.contains(key);
}
bool stale(K key)
{
QReadLocker l(&lock);
if(!cache.contains(key))
return true;
return stale_entries.contains(key);
}
void setStale(K key)
{
QReadLocker l(&lock);
if(cache.contains(key))
{
stale_entries.insert(key);
}
}
void clear()
{
QWriteLocker l(&lock);
cache.clear();
}
private:
QReadWriteLock lock;
QMap<K, V> cache;
QSet<K> stale_entries;
};
typedef RWStorage<QString, QIcon> SharedIconCache; typedef RWStorage<QString, QIcon> SharedIconCache;
typedef std::shared_ptr<SharedIconCache> SharedIconCachePtr; typedef std::shared_ptr<SharedIconCache> SharedIconCachePtr;

View File

@ -18,7 +18,6 @@
#include <pathutils.h> #include <pathutils.h>
#include <QFileDialog> #include <QFileDialog>
#include <QMessageBox> #include <QMessageBox>
#include <QDebug>
#include <QEvent> #include <QEvent>
#include <QKeyEvent> #include <QKeyEvent>

60
logic/RWStorage.h Normal file
View File

@ -0,0 +1,60 @@
#pragma once
template <typename K, typename V>
class RWStorage
{
public:
void add(K key, V value)
{
QWriteLocker l(&lock);
cache[key] = value;
stale_entries.remove(key);
}
V get(K key)
{
QReadLocker l(&lock);
if(cache.contains(key))
{
return cache[key];
}
else return V();
}
bool get(K key, V& value)
{
QReadLocker l(&lock);
if(cache.contains(key))
{
value = cache[key];
return true;
}
else return false;
}
bool has(K key)
{
QReadLocker l(&lock);
return cache.contains(key);
}
bool stale(K key)
{
QReadLocker l(&lock);
if(!cache.contains(key))
return true;
return stale_entries.contains(key);
}
void setStale(K key)
{
QReadLocker l(&lock);
if(cache.contains(key))
{
stale_entries.insert(key);
}
}
void clear()
{
QWriteLocker l(&lock);
cache.clear();
}
private:
QReadWriteLock lock;
QMap<K, V> cache;
QSet<K> stale_entries;
};

View File

@ -22,7 +22,6 @@
#include <QJsonObject> #include <QJsonObject>
#include <QJsonArray> #include <QJsonArray>
#include <QVariant> #include <QVariant>
#include <QDebug>
#include "logger/QsLog.h" #include "logger/QsLog.h"

View File

@ -21,7 +21,6 @@
#include <QJsonObject> #include <QJsonObject>
#include <QJsonArray> #include <QJsonArray>
#include <QVariant> #include <QVariant>
#include <QDebug>
#include "logger/QsLog.h" #include "logger/QsLog.h"

View File

@ -22,7 +22,6 @@
#include <QJsonObject> #include <QJsonObject>
#include <QJsonArray> #include <QJsonArray>
#include <QVariant> #include <QVariant>
#include <QDebug>
#include "logger/QsLog.h" #include "logger/QsLog.h"

View File

@ -49,13 +49,12 @@ bool LiteLoaderInstaller::add(OneSixInstance *to)
QJsonArray libraries; QJsonArray libraries;
for (auto libStr : m_version->libraries) for (auto rawLibrary : m_version->libraries)
{ {
OneSixLibrary lib(libStr); rawLibrary->insertType = RawLibrary::Prepend;
OneSixLibrary lib(rawLibrary);
lib.finalize(); lib.finalize();
QJsonObject libObj = lib.toJson(); libraries.append(lib.toJson());
libObj.insert("insert", QString("prepend"));
libraries.append(libObj);
} }
// liteloader // liteloader

View File

@ -16,6 +16,7 @@
#include "LiteLoaderVersionList.h" #include "LiteLoaderVersionList.h"
#include "MultiMC.h" #include "MultiMC.h"
#include "logic/net/URLConstants.h" #include "logic/net/URLConstants.h"
#include <MMCError.h>
#include <QtXml> #include <QtXml>
@ -206,7 +207,21 @@ void LLListLoadTask::listDownloaded()
const QJsonArray libs = artefact.value("libraries").toArray(); const QJsonArray libs = artefact.value("libraries").toArray();
for (auto lIt = libs.begin(); lIt != libs.end(); ++lIt) for (auto lIt = libs.begin(); lIt != libs.end(); ++lIt)
{ {
version->libraries.append((*lIt).toObject().value("name").toString()); auto libobject = (*lIt).toObject();
try
{
auto lib = RawLibrary::fromJson(libobject, "versions.json");
if(lib->m_name.startsWith("org.ow2.asm:asm-all:"))
{
lib->m_base_url = "http://repo.maven.apache.org/maven2/";
}
version->libraries.append(lib);
}
catch (MMCError &e)
{
QLOG_ERROR() << "Couldn't read JSON object:";
continue;
}
} }
perMcVersionList.append(version); perMcVersionList.append(version);
} }

View File

@ -23,6 +23,7 @@
#include "logic/BaseVersionList.h" #include "logic/BaseVersionList.h"
#include "logic/tasks/Task.h" #include "logic/tasks/Task.h"
#include "logic/net/NetJob.h" #include "logic/net/NetJob.h"
#include <logic/minecraft/RawLibrary.h>
class LLListLoadTask; class LLListLoadTask;
class QNetworkReply; class QNetworkReply;
@ -55,7 +56,7 @@ public:
int timestamp; int timestamp;
bool isLatest; bool isLatest;
QString tweakClass; QString tweakClass;
QStringList libraries; QList<RawLibraryPtr> libraries;
// meta // meta
QString defaultUrl; QString defaultUrl;

View File

@ -13,7 +13,6 @@
* limitations under the License. * limitations under the License.
*/ */
#include <QDebug>
#include <QFile> #include <QFile>
#include <QDir> #include <QDir>
#include <QUuid> #include <QUuid>

View File

@ -22,7 +22,6 @@
#include <QMessageBox> #include <QMessageBox>
#include <QObject> #include <QObject>
#include <QDir> #include <QDir>
#include <QDebug>
#include <qresource.h> #include <qresource.h>
#include <modutils.h> #include <modutils.h>

View File

@ -91,7 +91,7 @@ public:
/*! /*!
* \brief Sets the value of the setting with the given ID. * \brief Sets the value of the setting with the given ID.
* If no setting with the given ID exists, returns false and logs to qDebug * If no setting with the given ID exists, returns false
* \param id The ID of the setting to change. * \param id The ID of the setting to change.
* \param value The new value of the setting. * \param value The new value of the setting.
* \return True if successful, false if it failed. * \return True if successful, false if it failed.