2013-12-02 05:25:24 +05:30
|
|
|
#include "UpdateDialog.h"
|
|
|
|
#include "ui_UpdateDialog.h"
|
2015-02-09 06:21:14 +05:30
|
|
|
#include "Platform.h"
|
2015-02-02 06:44:14 +05:30
|
|
|
#include <QDebug>
|
2014-07-09 23:18:46 +05:30
|
|
|
#include "MultiMC.h"
|
2015-02-09 06:21:14 +05:30
|
|
|
#include <settings/SettingsObject.h>
|
2013-12-02 05:25:24 +05:30
|
|
|
|
2014-07-14 04:27:54 +05:30
|
|
|
UpdateDialog::UpdateDialog(bool hasUpdate, QWidget *parent) : QDialog(parent), ui(new Ui::UpdateDialog)
|
2013-12-02 05:25:24 +05:30
|
|
|
{
|
|
|
|
MultiMCPlatform::fixWM_CLASS(this);
|
|
|
|
ui->setupUi(this);
|
2014-07-09 23:18:46 +05:30
|
|
|
auto channel = MMC->settings()->get("UpdateChannel").toString();
|
2014-07-14 04:27:54 +05:30
|
|
|
if(hasUpdate)
|
|
|
|
{
|
|
|
|
ui->label->setText(tr("A new %1 update is available!").arg(channel));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ui->label->setText(tr("No %1 updates found. You are running the latest version.").arg(channel));
|
|
|
|
ui->btnUpdateNow->setDisabled(true);
|
|
|
|
ui->btnUpdateOnExit->setDisabled(true);
|
|
|
|
}
|
2014-07-09 04:19:37 +05:30
|
|
|
loadChangelog();
|
2013-12-02 05:25:24 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
UpdateDialog::~UpdateDialog()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-07-09 04:19:37 +05:30
|
|
|
void UpdateDialog::loadChangelog()
|
|
|
|
{
|
2014-07-09 23:18:46 +05:30
|
|
|
auto channel = MMC->settings()->get("UpdateChannel").toString();
|
2014-07-09 04:19:37 +05:30
|
|
|
dljob.reset(new NetJob("Changelog"));
|
2014-07-09 23:18:46 +05:30
|
|
|
auto url = QString("https://raw.githubusercontent.com/MultiMC/MultiMC5/%1/changelog.md").arg(channel);
|
2014-07-09 04:19:37 +05:30
|
|
|
changelogDownload = ByteArrayDownload::make(QUrl(url));
|
|
|
|
dljob->addNetAction(changelogDownload);
|
|
|
|
connect(dljob.get(), &NetJob::succeeded, this, &UpdateDialog::changelogLoaded);
|
|
|
|
connect(dljob.get(), &NetJob::failed, this, &UpdateDialog::changelogFailed);
|
|
|
|
dljob->start();
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: this will be replaced.
|
|
|
|
QString reprocessMarkdown(QString markdown)
|
|
|
|
{
|
|
|
|
QString htmlData;
|
|
|
|
QTextStream html(&htmlData);
|
|
|
|
auto lines = markdown.split(QRegExp("[\r]?[\n]"),QString::KeepEmptyParts);
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
BASE,
|
|
|
|
LIST1,
|
|
|
|
LIST2
|
|
|
|
}state = BASE;
|
|
|
|
html << "<html>";
|
|
|
|
int i = 0;
|
|
|
|
auto procLine = [&](QString line) -> QString
|
|
|
|
{
|
|
|
|
// [GitHub issues](https://github.com/MultiMC/MultiMC5/issues)
|
2014-07-09 04:47:59 +05:30
|
|
|
line.replace(QRegExp("\\[([^\\]]+)\\]\\(([^\\)]+)\\)"), "<a href=\"\\2\">\\1</a>");
|
2014-07-09 04:19:37 +05:30
|
|
|
return line;
|
|
|
|
};
|
|
|
|
for(auto line: lines)
|
|
|
|
{
|
|
|
|
if(line.isEmpty())
|
|
|
|
{
|
|
|
|
// html << "<br />\n";
|
|
|
|
}
|
|
|
|
else switch (state)
|
|
|
|
{
|
|
|
|
case BASE:
|
|
|
|
if(line.startsWith("##"))
|
|
|
|
{
|
|
|
|
html << "<h2>" << procLine(line.mid(2)) << "</h2>\n";
|
|
|
|
}
|
|
|
|
else if(line.startsWith("#"))
|
|
|
|
{
|
|
|
|
html << "<h1>" << procLine(line.mid(1)) << "</h1>\n";
|
|
|
|
}
|
|
|
|
else if(line.startsWith("- "))
|
|
|
|
{
|
|
|
|
state = LIST1;
|
|
|
|
html << "<ul>\n";
|
|
|
|
html << "<li>" << procLine(line.mid(2)) << "</li>\n";
|
|
|
|
}
|
2015-02-02 06:44:14 +05:30
|
|
|
else qCritical() << "Invalid input on line " << i << ": " << line;
|
2014-07-09 04:19:37 +05:30
|
|
|
break;
|
|
|
|
case LIST1:
|
|
|
|
if(line.startsWith("##"))
|
|
|
|
{
|
|
|
|
state = BASE;
|
|
|
|
html << "</ul>\n";
|
|
|
|
html << "<h2>" << procLine(line.mid(2)) << "</h2>\n";
|
|
|
|
}
|
|
|
|
else if(line.startsWith("#"))
|
|
|
|
{
|
|
|
|
state = BASE;
|
|
|
|
html << "</ul>\n";
|
|
|
|
html << "<h1>" << procLine(line.mid(1)) << "</h1>\n";
|
|
|
|
}
|
|
|
|
else if(line.startsWith("- "))
|
|
|
|
{
|
|
|
|
html << "<li>" << procLine(line.mid(2)) << "</li>\n";
|
|
|
|
}
|
|
|
|
else if(line.startsWith(" - "))
|
|
|
|
{
|
|
|
|
state = LIST2;
|
|
|
|
html << "<ul>\n";
|
|
|
|
html << "<li>" << procLine(line.mid(4)) << "</li>\n";
|
|
|
|
}
|
2015-02-02 06:44:14 +05:30
|
|
|
else qCritical() << "Invalid input on line " << i << ": " << line;
|
2014-07-09 04:19:37 +05:30
|
|
|
break;
|
|
|
|
case LIST2:
|
|
|
|
if(line.startsWith("##"))
|
|
|
|
{
|
|
|
|
state = BASE;
|
|
|
|
html << "</ul>\n";
|
|
|
|
html << "</ul>\n";
|
|
|
|
html << "<h2>" << procLine(line.mid(2)) << "</h2>\n";
|
|
|
|
}
|
|
|
|
else if(line.startsWith("#"))
|
|
|
|
{
|
|
|
|
state = BASE;
|
|
|
|
html << "</ul>\n";
|
|
|
|
html << "</ul>\n";
|
|
|
|
html << "<h1>" << procLine(line.mid(1)) << "</h1>\n";
|
|
|
|
}
|
|
|
|
else if(line.startsWith("- "))
|
|
|
|
{
|
|
|
|
state = LIST1;
|
|
|
|
html << "</ul>\n";
|
|
|
|
html << "<li>" << procLine(line.mid(2)) << "</li>\n";
|
|
|
|
}
|
|
|
|
else if(line.startsWith(" - "))
|
|
|
|
{
|
|
|
|
html << "<li>" << procLine(line.mid(4)) << "</li>\n";
|
|
|
|
}
|
2015-02-02 06:44:14 +05:30
|
|
|
else qCritical() << "Invalid input on line " << i << ": " << line;
|
2014-07-09 04:19:37 +05:30
|
|
|
break;
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
if(state == LIST2)
|
|
|
|
{
|
|
|
|
html << "</ul>\n";
|
|
|
|
state = LIST1;
|
|
|
|
}
|
|
|
|
if(state == LIST1)
|
|
|
|
{
|
|
|
|
html << "</ul>\n";
|
|
|
|
state = BASE;
|
|
|
|
}
|
|
|
|
if (state != BASE)
|
|
|
|
{
|
2015-02-02 06:44:14 +05:30
|
|
|
qCritical() << "Reprocessing markdown didn't end in a final state!";
|
2014-07-09 04:19:37 +05:30
|
|
|
}
|
|
|
|
html << "</html>\n";
|
2015-02-02 06:44:14 +05:30
|
|
|
qDebug() << htmlData;
|
2014-07-09 04:19:37 +05:30
|
|
|
return htmlData;
|
|
|
|
}
|
|
|
|
|
|
|
|
void UpdateDialog::changelogLoaded()
|
|
|
|
{
|
|
|
|
auto rawMarkdown = QString::fromUtf8(changelogDownload->m_data);
|
|
|
|
auto html = reprocessMarkdown(rawMarkdown);
|
|
|
|
ui->changelogBrowser->setHtml(html);
|
|
|
|
}
|
|
|
|
|
2015-04-26 17:17:14 +05:30
|
|
|
void UpdateDialog::changelogFailed(QString reason)
|
2014-07-09 04:19:37 +05:30
|
|
|
{
|
2015-04-26 17:17:14 +05:30
|
|
|
ui->changelogBrowser->setHtml(tr("<p align=\"center\" <span style=\"font-size:22pt;\">Failed to fetch changelog... Error: %1</span></p>").arg(reason));
|
2014-07-09 04:19:37 +05:30
|
|
|
}
|
|
|
|
|
2013-12-02 05:25:24 +05:30
|
|
|
void UpdateDialog::on_btnUpdateLater_clicked()
|
|
|
|
{
|
|
|
|
reject();
|
|
|
|
}
|
|
|
|
|
|
|
|
void UpdateDialog::on_btnUpdateNow_clicked()
|
|
|
|
{
|
|
|
|
done(UPDATE_NOW);
|
|
|
|
}
|
|
|
|
|
|
|
|
void UpdateDialog::on_btnUpdateOnExit_clicked()
|
|
|
|
{
|
|
|
|
done(UPDATE_ONEXIT);
|
|
|
|
}
|