mirror of
https://github.com/PrismLauncher/PrismLauncher.git
synced 2025-04-29 22:24:26 +02:00
fix: load world size async
Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>
This commit is contained in:
parent
6e00f94a57
commit
efeaefbf2e
@ -198,22 +198,6 @@ bool putLevelDatDataToFS(const QFileInfo& file, QByteArray& data)
|
|||||||
return f.commit();
|
return f.commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t calculateWorldSize(const QFileInfo& file)
|
|
||||||
{
|
|
||||||
if (file.isFile() && file.suffix() == "zip") {
|
|
||||||
return file.size();
|
|
||||||
} else if (file.isDir()) {
|
|
||||||
QDirIterator it(file.absoluteFilePath(), QDir::Files, QDirIterator::Subdirectories);
|
|
||||||
int64_t total = 0;
|
|
||||||
while (it.hasNext()) {
|
|
||||||
it.next();
|
|
||||||
total += it.fileInfo().size();
|
|
||||||
}
|
|
||||||
return total;
|
|
||||||
}
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
World::World(const QFileInfo& file)
|
World::World(const QFileInfo& file)
|
||||||
{
|
{
|
||||||
repath(file);
|
repath(file);
|
||||||
@ -223,7 +207,6 @@ void World::repath(const QFileInfo& file)
|
|||||||
{
|
{
|
||||||
m_containerFile = file;
|
m_containerFile = file;
|
||||||
m_folderName = file.fileName();
|
m_folderName = file.fileName();
|
||||||
m_size = calculateWorldSize(file);
|
|
||||||
if (file.isFile() && file.suffix() == "zip") {
|
if (file.isFile() && file.suffix() == "zip") {
|
||||||
m_iconFile = QString();
|
m_iconFile = QString();
|
||||||
readFromZip(file);
|
readFromZip(file);
|
||||||
@ -531,3 +514,8 @@ bool World::isMoreThanOneHardLink() const
|
|||||||
}
|
}
|
||||||
return FS::hardLinkCount(m_containerFile.absoluteFilePath()) > 1;
|
return FS::hardLinkCount(m_containerFile.absoluteFilePath()) > 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void World::setSize(int64_t size)
|
||||||
|
{
|
||||||
|
m_size = size;
|
||||||
|
}
|
||||||
|
@ -54,6 +54,8 @@ class World {
|
|||||||
bool rename(const QString& to);
|
bool rename(const QString& to);
|
||||||
bool install(const QString& to, const QString& name = QString());
|
bool install(const QString& to, const QString& name = QString());
|
||||||
|
|
||||||
|
void setSize(int64_t size);
|
||||||
|
|
||||||
// WEAK compare operator - used for replacing worlds
|
// WEAK compare operator - used for replacing worlds
|
||||||
bool operator==(const World& other) const;
|
bool operator==(const World& other) const;
|
||||||
|
|
||||||
|
@ -37,13 +37,14 @@
|
|||||||
|
|
||||||
#include <FileSystem.h>
|
#include <FileSystem.h>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
#include <QDirIterator>
|
||||||
#include <QFileSystemWatcher>
|
#include <QFileSystemWatcher>
|
||||||
#include <QMimeData>
|
#include <QMimeData>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
#include <QThreadPool>
|
||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
#include <QUuid>
|
#include <QUuid>
|
||||||
#include <Qt>
|
#include <Qt>
|
||||||
#include "Application.h"
|
|
||||||
|
|
||||||
WorldList::WorldList(const QString& dir, BaseInstance* instance) : QAbstractListModel(), m_instance(instance), m_dir(dir)
|
WorldList::WorldList(const QString& dir, BaseInstance* instance) : QAbstractListModel(), m_instance(instance), m_dir(dir)
|
||||||
{
|
{
|
||||||
@ -103,6 +104,7 @@ bool WorldList::update()
|
|||||||
beginResetModel();
|
beginResetModel();
|
||||||
m_worlds.swap(newWorlds);
|
m_worlds.swap(newWorlds);
|
||||||
endResetModel();
|
endResetModel();
|
||||||
|
loadWorldsAsync();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -416,4 +418,44 @@ bool WorldList::dropMimeData(const QMimeData* data,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int64_t calculateWorldSize(const QFileInfo& file)
|
||||||
|
{
|
||||||
|
if (file.isFile() && file.suffix() == "zip") {
|
||||||
|
return file.size();
|
||||||
|
} else if (file.isDir()) {
|
||||||
|
QDirIterator it(file.absoluteFilePath(), QDir::Files, QDirIterator::Subdirectories);
|
||||||
|
int64_t total = 0;
|
||||||
|
while (it.hasNext()) {
|
||||||
|
it.next();
|
||||||
|
total += it.fileInfo().size();
|
||||||
|
}
|
||||||
|
return total;
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void WorldList::loadWorldsAsync()
|
||||||
|
{
|
||||||
|
for (int i = 0; i < m_worlds.size(); ++i) {
|
||||||
|
auto file = m_worlds.at(i).container();
|
||||||
|
int row = i;
|
||||||
|
QThreadPool::globalInstance()->start([this, file, row]() mutable {
|
||||||
|
auto size = calculateWorldSize(file);
|
||||||
|
|
||||||
|
QMetaObject::invokeMethod(
|
||||||
|
this,
|
||||||
|
[this, size, row, file]() {
|
||||||
|
if (row < m_worlds.size() && m_worlds[row].container() == file) {
|
||||||
|
m_worlds[row].setSize(size);
|
||||||
|
|
||||||
|
// Notify views
|
||||||
|
QModelIndex modelIndex = index(row);
|
||||||
|
emit dataChanged(modelIndex, modelIndex, { SizeRole });
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Qt::QueuedConnection);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#include "WorldList.moc"
|
#include "WorldList.moc"
|
||||||
|
@ -86,6 +86,7 @@ class WorldList : public QAbstractListModel {
|
|||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void directoryChanged(QString path);
|
void directoryChanged(QString path);
|
||||||
|
void loadWorldsAsync();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void changed();
|
void changed();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user