Nuke skins.json, use nice yggdrasil implementation instead. Grabs all Mojang account skins on addition, active on startup
This commit is contained in:
parent
7d7579d7f0
commit
38732636d3
@ -178,7 +178,24 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
|
||||
actionManageAccounts->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
|
||||
actionManageAccounts->setLayoutDirection(Qt::RightToLeft);
|
||||
|
||||
activeAccountChanged();
|
||||
MojangAccountPtr account = MMC->accounts()->activeAccount();
|
||||
if(account != nullptr)
|
||||
{
|
||||
auto job = new NetJob("Startup player skins: " + account->username());
|
||||
|
||||
for(AccountProfile profile : account->profiles())
|
||||
{
|
||||
auto meta = MMC->metacache()->resolveEntry("skins", profile.name() + ".png");
|
||||
auto action = CacheDownload::make(
|
||||
QUrl("http://skins.minecraft.net/MinecraftSkins/" + profile.name() + ".png"),
|
||||
meta);
|
||||
job->addNetAction(action);
|
||||
meta->stale = true;
|
||||
}
|
||||
|
||||
connect(job, SIGNAL(succeeded()), SLOT(activeAccountChanged()));
|
||||
job->start();
|
||||
}
|
||||
|
||||
connect(actionManageAccounts, SIGNAL(clicked()), this, SLOT(on_actionManageAccounts_triggered()));
|
||||
ui->mainToolBar->addWidget(actionManageAccounts);
|
||||
@ -221,7 +238,11 @@ void MainWindow::activeAccountChanged()
|
||||
|
||||
if(account != nullptr)
|
||||
{
|
||||
actionManageAccounts->setIcon(SkinUtils::getFaceFromCache(account->username()));
|
||||
const AccountProfile *profile = account->currentProfile();
|
||||
if(profile != nullptr)
|
||||
{
|
||||
actionManageAccounts->setIcon(SkinUtils::getFaceFromCache(profile->name()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -642,52 +663,6 @@ void MainWindow::prepareLaunch(BaseInstance* instance, MojangAccountPtr account)
|
||||
tDialog.exec(updateTask);
|
||||
delete updateTask;
|
||||
}
|
||||
|
||||
QString playerName = account->currentProfile()->name();
|
||||
|
||||
auto job = new NetJob("Player skin: " + playerName);
|
||||
|
||||
auto meta = MMC->metacache()->resolveEntry("skins", playerName + ".png");
|
||||
auto action = CacheDownload::make(
|
||||
QUrl("http://skins.minecraft.net/MinecraftSkins/" + playerName + ".png"),
|
||||
meta);
|
||||
job->addNetAction(action);
|
||||
meta->stale = true;
|
||||
|
||||
connect(job, SIGNAL(succeeded()), SLOT(activeAccountChanged()));
|
||||
job->start();
|
||||
auto filename = MMC->metacache()->resolveEntry("skins", "skins.json")->getFullPath();
|
||||
QFile listFile(filename);
|
||||
|
||||
// Add skin mapping
|
||||
QByteArray data;
|
||||
{
|
||||
if (!listFile.open(QIODevice::ReadWrite))
|
||||
{
|
||||
QLOG_ERROR() << "Failed to open/make skins list JSON";
|
||||
return;
|
||||
}
|
||||
|
||||
data = listFile.readAll();
|
||||
}
|
||||
|
||||
QJsonParseError jsonError;
|
||||
QJsonDocument jsonDoc = QJsonDocument::fromJson(data, &jsonError);
|
||||
QJsonObject root = jsonDoc.object();
|
||||
QJsonObject mappings = root.value("mappings").toObject();
|
||||
QJsonArray usernames = mappings.value(account->username()).toArray();
|
||||
|
||||
if (!usernames.contains(playerName))
|
||||
{
|
||||
usernames.prepend(playerName);
|
||||
mappings[account->username()] = usernames;
|
||||
root["mappings"] = mappings;
|
||||
jsonDoc.setObject(root);
|
||||
|
||||
// QJson hack - shouldn't have to clear the file every time a save happens
|
||||
listFile.resize(0);
|
||||
listFile.write(jsonDoc.toJson());
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::launchInstance(BaseInstance *instance, MojangAccountPtr account)
|
||||
|
@ -21,6 +21,7 @@
|
||||
#include <logger/QsLog.h>
|
||||
|
||||
#include <logic/auth/AuthenticateTask.h>
|
||||
#include <logic/net/NetJob.h>
|
||||
|
||||
#include <gui/dialogs/LoginDialog.h>
|
||||
#include <gui/dialogs/ProgressDialog.h>
|
||||
@ -112,5 +113,21 @@ void AccountListDialog::onLoginComplete()
|
||||
MojangAccountPtr account = m_authTask->getMojangAccount();
|
||||
m_accounts->addAccount(account);
|
||||
//ui->listView->update();
|
||||
|
||||
// Grab associated player skins
|
||||
auto job = new NetJob("Player skins: " + account->username());
|
||||
|
||||
for(AccountProfile profile : account->profiles())
|
||||
{
|
||||
auto meta = MMC->metacache()->resolveEntry("skins", profile.name() + ".png");
|
||||
auto action = CacheDownload::make(
|
||||
QUrl("http://skins.minecraft.net/MinecraftSkins/" + profile.name() + ".png"),
|
||||
meta);
|
||||
job->addNetAction(action);
|
||||
meta->stale = true;
|
||||
}
|
||||
|
||||
connect(job, SIGNAL(succeeded()), SIGNAL(activeAccountChanged()));
|
||||
job->start();
|
||||
}
|
||||
|
||||
|
@ -24,52 +24,24 @@
|
||||
|
||||
namespace SkinUtils
|
||||
{
|
||||
/*
|
||||
* Given a username, return a pixmap of the cached skin (if it exists), QPixmap() otherwise
|
||||
*/
|
||||
QPixmap getFaceFromCache(QString username, int height, int width)
|
||||
{
|
||||
bool gotFace = false;
|
||||
QFile fskin(MMC->metacache()
|
||||
->resolveEntry("skins", username + ".png")
|
||||
->getFullPath());
|
||||
|
||||
QByteArray data;
|
||||
if (fskin.exists())
|
||||
{
|
||||
auto filename =
|
||||
MMC->metacache()->resolveEntry("skins", "skins.json")->getFullPath();
|
||||
QFile listFile(filename);
|
||||
if (!listFile.open(QIODevice::ReadOnly))
|
||||
return QPixmap();
|
||||
data = listFile.readAll();
|
||||
}
|
||||
|
||||
QJsonParseError jsonError;
|
||||
QJsonDocument jsonDoc = QJsonDocument::fromJson(data, &jsonError);
|
||||
QJsonObject root = jsonDoc.object();
|
||||
QJsonObject mappings = root.value("mappings").toObject();
|
||||
|
||||
if (!mappings[username].isUndefined())
|
||||
{
|
||||
QJsonArray usernames = mappings.value(username).toArray();
|
||||
if (!usernames.isEmpty())
|
||||
QPixmap skin(fskin.fileName());
|
||||
if(!skin.isNull())
|
||||
{
|
||||
QString mapped_username = usernames[0].toString();
|
||||
|
||||
if (!mapped_username.isEmpty())
|
||||
{
|
||||
QFile fskin(MMC->metacache()
|
||||
->resolveEntry("skins", mapped_username + ".png")
|
||||
->getFullPath());
|
||||
if (fskin.exists())
|
||||
{
|
||||
QPixmap skin(MMC->metacache()
|
||||
->resolveEntry("skins", mapped_username + ".png")
|
||||
->getFullPath());
|
||||
|
||||
QPixmap face =
|
||||
skin.copy(8, 8, 8, 8).scaled(height, width, Qt::KeepAspectRatio);
|
||||
|
||||
return face;
|
||||
}
|
||||
}
|
||||
return skin.copy(8, 8, 8, 8).scaled(height, width, Qt::KeepAspectRatio);
|
||||
}
|
||||
}
|
||||
|
||||
if(!gotFace) return QPixmap();
|
||||
return QPixmap();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user