Skip to content

Commit 3c747b3

Browse files
committed
Qt: fix translation of update dialog if the language was changed between downloading the json and clicking on update
1 parent a859e14 commit 3c747b3

File tree

2 files changed

+83
-75
lines changed

2 files changed

+83
-75
lines changed

rpcs3/rpcs3qt/update_manager.cpp

Lines changed: 69 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,7 @@ void update_manager::check_for_updates(bool automatic, bool check_only, bool aut
5656
{
5757
update_log.notice("Checking for updates: automatic=%d, check_only=%d, auto_accept=%d", automatic, check_only, auto_accept);
5858

59-
m_update_message.clear();
60-
m_changelog.clear();
59+
m_update_info = {};
6160

6261
if (automatic)
6362
{
@@ -103,7 +102,7 @@ void update_manager::check_for_updates(bool automatic, bool check_only, bool aut
103102
}
104103
}
105104

106-
Q_EMIT signal_update_available(result_json && !m_update_message.isEmpty());
105+
Q_EMIT signal_update_available(result_json && m_update_info.update_found);
107106
});
108107

109108
const utils::OS_version os = utils::get_OS_version();
@@ -121,7 +120,7 @@ bool update_manager::handle_json(bool automatic, bool check_only, bool auto_acce
121120
const QJsonObject json_data = QJsonDocument::fromJson(data).object();
122121
const int return_code = json_data["return_code"].toInt(-255);
123122

124-
bool hash_found = true;
123+
m_update_info.hash_found = true;
125124

126125
if (return_code < 0)
127126
{
@@ -143,7 +142,7 @@ bool update_manager::handle_json(bool automatic, bool check_only, bool auto_acce
143142
// If a user clicks "Check for Updates" with a custom build ask him if he's sure he wants to update to latest version
144143
if (!automatic && return_code == -1)
145144
{
146-
hash_found = false;
145+
m_update_info.hash_found = false;
147146
}
148147
else
149148
{
@@ -187,7 +186,7 @@ bool update_manager::handle_json(bool automatic, bool check_only, bool auto_acce
187186
check_json(latest["version"].isString(), "Node 'latest_build: version' not found or not a string") &&
188187
check_json(latest["datetime"].isString(), "Node 'latest_build: datetime' not found or not a string")
189188
) ||
190-
(hash_found && !(
189+
(m_update_info.hash_found && !(
191190
check_json(current.isObject(), "JSON doesn't contain current_build section") &&
192191
check_json(current["version"].isString(), "Node 'current_build: datetime' not found or not a string") &&
193192
check_json(current["datetime"].isString(), "Node 'current_build: version' not found or not a string")
@@ -196,7 +195,7 @@ bool update_manager::handle_json(bool automatic, bool check_only, bool auto_acce
196195
return false;
197196
}
198197

199-
if (hash_found && return_code == 0)
198+
if (m_update_info.hash_found && return_code == 0)
200199
{
201200
update_log.success("RPCS3 is up to date!");
202201
m_downloader->close_progress_dialog();
@@ -210,59 +209,26 @@ bool update_manager::handle_json(bool automatic, bool check_only, bool auto_acce
210209
// Calculate how old the build is
211210
const QString date_fmt = QStringLiteral("yyyy-MM-dd hh:mm:ss");
212211

213-
const QDateTime cur_date = hash_found ? QDateTime::fromString(current["datetime"].toString(), date_fmt) : QDateTime::currentDateTimeUtc();
212+
const QDateTime cur_date = m_update_info.hash_found ? QDateTime::fromString(current["datetime"].toString(), date_fmt) : QDateTime::currentDateTimeUtc();
214213
const QDateTime lts_date = QDateTime::fromString(latest["datetime"].toString(), date_fmt);
215214

216-
const QString cur_str = cur_date.toString(date_fmt);
217-
const QString lts_str = lts_date.toString(date_fmt);
215+
m_update_info.update_found = true;
216+
m_update_info.cur_date = cur_date.toString(date_fmt);
217+
m_update_info.lts_date = lts_date.toString(date_fmt);
218+
m_update_info.diff_msec = cur_date.msecsTo(lts_date);
219+
m_update_info.new_version = latest["version"].toString();
218220

219-
const qint64 diff_msec = cur_date.msecsTo(lts_date);
220-
221-
update_log.notice("Current: %s, latest: %s, difference: %lld ms", cur_str, lts_str, diff_msec);
222-
223-
const Localized localized;
224-
225-
const QString new_version = latest["version"].toString();
226-
m_new_version = new_version.toStdString();
227-
const QString support_message = tr("<br>You can empower our project at <a href=\"https://rpcs3.net/patreon\">RPCS3 Patreon</a>.<br>");
228-
229-
if (hash_found)
221+
if (m_update_info.hash_found)
230222
{
231-
const QString old_version = current["version"].toString();
232-
m_old_version = old_version.toStdString();
233-
234-
if (diff_msec < 0)
235-
{
236-
// This usually means that the current version was marked as broken and won't be shipped anymore, so we need to downgrade to avoid certain bugs.
237-
m_update_message = tr("A better version of RPCS3 is available!<br><br>Current version: %0 (%1)<br>Better version: %2 (%3)<br>%4<br>Do you want to update?")
238-
.arg(old_version)
239-
.arg(cur_str)
240-
.arg(new_version)
241-
.arg(lts_str)
242-
.arg(support_message);
243-
}
244-
else
245-
{
246-
m_update_message = tr("A new version of RPCS3 is available!<br><br>Current version: %0 (%1)<br>Latest version: %2 (%3)<br>Your version is %4 behind.<br>%5<br>Do you want to update?")
247-
.arg(old_version)
248-
.arg(cur_str)
249-
.arg(new_version)
250-
.arg(lts_str)
251-
.arg(localized.GetVerboseTimeByMs(diff_msec, true))
252-
.arg(support_message);
253-
}
223+
m_update_info.old_version = current["version"].toString();
254224
}
255225
else
256226
{
257-
m_old_version = fmt::format("%s-%s-%s", rpcs3::get_full_branch(), rpcs3::get_branch(), rpcs3::get_version().to_string());
258-
259-
m_update_message = tr("You're currently using a custom or PR build.<br><br>Latest version: %0 (%1)<br>The latest version is %2 old.<br>%3<br>Do you want to update to the latest official RPCS3 version?")
260-
.arg(new_version)
261-
.arg(lts_str)
262-
.arg(localized.GetVerboseTimeByMs(std::abs(diff_msec), true))
263-
.arg(support_message);
227+
m_update_info.old_version = QString::fromStdString(fmt::format("%s-%s-%s", rpcs3::get_full_branch(), rpcs3::get_branch(), rpcs3::get_version().to_string()));
264228
}
265229

230+
update_log.notice("Current: %s, latest: %s, difference: %lld ms", m_update_info.cur_date, m_update_info.lts_date, m_update_info.diff_msec);
231+
266232
m_request_url = latest[os]["download"].toString().toStdString();
267233
m_expected_hash = latest[os]["checksum"].toString().toStdString();
268234
m_expected_size = latest[os]["size"].toInt();
@@ -277,9 +243,9 @@ bool update_manager::handle_json(bool automatic, bool check_only, bool auto_acce
277243

278244
if (!auto_accept)
279245
{
280-
if (automatic && m_gui_settings->GetValue(gui::ib_skip_version).toString() == new_version)
246+
if (automatic && m_gui_settings->GetValue(gui::ib_skip_version).toString() == m_update_info.new_version)
281247
{
282-
update_log.notice("Skipping automatic update notification for version '%s' due to user preference", new_version);
248+
update_log.notice("Skipping automatic update notification for version '%s' due to user preference", m_update_info.new_version);
283249
m_downloader->close_progress_dialog();
284250
return true;
285251
}
@@ -300,7 +266,6 @@ bool update_manager::handle_json(bool automatic, bool check_only, bool auto_acce
300266
}
301267
else
302268
{
303-
entry.version = tr("N/A");
304269
update_log.notice("JSON changelog entry does not contain a version string.");
305270
}
306271

@@ -310,11 +275,10 @@ bool update_manager::handle_json(bool automatic, bool check_only, bool auto_acce
310275
}
311276
else
312277
{
313-
entry.title = tr("N/A");
314278
update_log.notice("JSON changelog entry does not contain a title string.");
315279
}
316280

317-
m_changelog.push_back(entry);
281+
m_update_info.changelog.push_back(std::move(entry));
318282
}
319283
else
320284
{
@@ -351,25 +315,61 @@ void update_manager::update(bool auto_accept)
351315

352316
if (!auto_accept)
353317
{
354-
if (m_update_message.isEmpty())
318+
if (!m_update_info.update_found)
355319
{
356320
// This can happen if we abort the check_for_updates download. Just check again in this case.
357-
update_log.notice("Aborting update: Update message is empty. Trying again...");
321+
update_log.notice("Aborting update: Update not found. Trying again...");
358322
m_downloader->close_progress_dialog();
359323
check_for_updates(false, false, false, m_parent);
360324
return;
361325
}
362326

327+
const Localized localized;
328+
const QString support_message = tr("<br>You can empower our project at <a href=\"https://rpcs3.net/patreon\">RPCS3 Patreon</a>.<br>");
329+
QString update_message;
330+
331+
if (m_update_info.hash_found)
332+
{
333+
if (m_update_info.diff_msec < 0)
334+
{
335+
// This usually means that the current version was marked as broken and won't be shipped anymore, so we need to downgrade to avoid certain bugs.
336+
update_message = tr("A better version of RPCS3 is available!<br><br>Current version: %0 (%1)<br>Better version: %2 (%3)<br>%4<br>Do you want to update?")
337+
.arg(m_update_info.old_version)
338+
.arg(m_update_info.cur_date)
339+
.arg(m_update_info.new_version)
340+
.arg(m_update_info.lts_date)
341+
.arg(support_message);
342+
}
343+
else
344+
{
345+
update_message = tr("A new version of RPCS3 is available!<br><br>Current version: %0 (%1)<br>Latest version: %2 (%3)<br>Your version is %4 behind.<br>%5<br>Do you want to update?")
346+
.arg(m_update_info.old_version)
347+
.arg(m_update_info.cur_date)
348+
.arg(m_update_info.new_version)
349+
.arg(m_update_info.lts_date)
350+
.arg(localized.GetVerboseTimeByMs(m_update_info.diff_msec, true))
351+
.arg(support_message);
352+
}
353+
}
354+
else
355+
{
356+
update_message = tr("You're currently using a custom or PR build.<br><br>Latest version: %0 (%1)<br>The latest version is %2 old.<br>%3<br>Do you want to update to the latest official RPCS3 version?")
357+
.arg(m_update_info.new_version)
358+
.arg(m_update_info.lts_date)
359+
.arg(localized.GetVerboseTimeByMs(std::abs(m_update_info.diff_msec), true))
360+
.arg(support_message);
361+
}
362+
363363
QString changelog_content;
364364

365-
for (const changelog_data& entry : m_changelog)
365+
for (const changelog_data& entry : m_update_info.changelog)
366366
{
367367
if (!changelog_content.isEmpty())
368368
changelog_content.append('\n');
369-
changelog_content.append(tr("• %0: %1").arg(entry.version, entry.title));
369+
changelog_content.append(tr("• %0: %1").arg(entry.version.isEmpty() ? tr("N/A") : entry.version, entry.title.isEmpty() ? tr("N/A") : entry.title));
370370
}
371371

372-
QMessageBox mb(QMessageBox::Icon::Question, tr("Update Available"), m_update_message, QMessageBox::Yes | QMessageBox::No, m_downloader->get_progress_dialog() ? m_downloader->get_progress_dialog() : m_parent);
372+
QMessageBox mb(QMessageBox::Icon::Question, tr("Update Available"), update_message, QMessageBox::Yes | QMessageBox::No, m_downloader->get_progress_dialog() ? m_downloader->get_progress_dialog() : m_parent);
373373
mb.setTextFormat(Qt::RichText);
374374
mb.setCheckBox(new QCheckBox(tr("Don't show again for this version")));
375375

@@ -380,16 +380,16 @@ void update_manager::update(bool auto_accept)
380380

381381
// Smartass hack to make the unresizeable message box wide enough for the changelog
382382
const int changelog_width = QLabel(changelog_content).sizeHint().width();
383-
if (QLabel(m_update_message).sizeHint().width() < changelog_width)
383+
if (QLabel(update_message).sizeHint().width() < changelog_width)
384384
{
385-
m_update_message += " &nbsp;";
386-
while (QLabel(m_update_message).sizeHint().width() < changelog_width)
385+
update_message += " &nbsp;";
386+
while (QLabel(update_message).sizeHint().width() < changelog_width)
387387
{
388-
m_update_message += "&nbsp;";
388+
update_message += "&nbsp;";
389389
}
390390
}
391391

392-
mb.setText(m_update_message);
392+
mb.setText(update_message);
393393
}
394394

395395
update_log.notice("Asking user for permission to update...");
@@ -400,8 +400,8 @@ void update_manager::update(bool auto_accept)
400400

401401
if (mb.checkBox()->isChecked())
402402
{
403-
update_log.notice("User requested to skip further automatic update notifications for version '%s'", m_new_version);
404-
m_gui_settings->SetValue(gui::ib_skip_version, QString::fromStdString(m_new_version));
403+
update_log.notice("User requested to skip further automatic update notifications for version '%s'", m_update_info.new_version);
404+
m_gui_settings->SetValue(gui::ib_skip_version, m_update_info.new_version);
405405
}
406406

407407
m_downloader->close_progress_dialog();
@@ -751,7 +751,7 @@ bool update_manager::handle_rpcs3(const QByteArray& data, bool auto_accept)
751751
if (fs::file update_file{fs::get_config_dir() + "update_history.log", fs::create + fs::write + fs::append})
752752
{
753753
const std::string update_time = QDateTime::currentDateTime().toString("yyyy/MM/dd hh:mm:ss").toStdString();
754-
const std::string entry = fmt::format("%s: Updated from \"%s\" to \"%s\"", update_time, m_old_version, m_new_version);
754+
const std::string entry = fmt::format("%s: Updated from \"%s\" to \"%s\"", update_time, m_update_info.old_version, m_update_info.new_version);
755755
update_file.write(fmt::format("%s\n", entry));
756756
update_log.notice("Added entry '%s' to update_history.log", entry);
757757
}

rpcs3/rpcs3qt/update_manager.h

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,28 @@ class update_manager final : public QObject
1919

2020
std::shared_ptr<gui_settings> m_gui_settings;
2121

22-
// This message is empty if there is no download available
23-
QString m_update_message;
24-
2522
struct changelog_data
2623
{
2724
QString version;
2825
QString title;
2926
};
30-
std::vector<changelog_data> m_changelog;
27+
28+
struct update_info
29+
{
30+
bool update_found = false;
31+
bool hash_found = false;
32+
qint64 diff_msec = 0;
33+
QString cur_date;
34+
QString lts_date;
35+
QString old_version;
36+
QString new_version;
37+
std::vector<changelog_data> changelog;
38+
};
39+
40+
update_info m_update_info {};
3141

3242
std::string m_request_url;
3343
std::string m_expected_hash;
34-
std::string m_old_version;
35-
std::string m_new_version;
3644
u64 m_expected_size = 0;
3745

3846
bool handle_json(bool automatic, bool check_only, bool auto_accept, const QByteArray& data);

0 commit comments

Comments
 (0)