error.cpp 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // Copyright 2019 yuzu Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #include <QDateTime>
  5. #include "core/hle/lock.h"
  6. #include "yuzu/applets/error.h"
  7. #include "yuzu/main.h"
  8. QtErrorDisplay::QtErrorDisplay(GMainWindow& parent) {
  9. connect(this, &QtErrorDisplay::MainWindowDisplayError, &parent,
  10. &GMainWindow::ErrorDisplayDisplayError, Qt::QueuedConnection);
  11. connect(&parent, &GMainWindow::ErrorDisplayFinished, this,
  12. &QtErrorDisplay::MainWindowFinishedError, Qt::DirectConnection);
  13. }
  14. QtErrorDisplay::~QtErrorDisplay() = default;
  15. void QtErrorDisplay::ShowError(ResultCode error, std::function<void()> finished) const {
  16. callback = std::move(finished);
  17. emit MainWindowDisplayError(
  18. tr("An error has occurred.\nPlease try again or contact the developer of the "
  19. "software.\n\nError Code: %1-%2 (0x%3)")
  20. .arg(static_cast<u32>(error.module.Value()) + 2000, 4, 10, QChar::fromLatin1('0'))
  21. .arg(error.description, 4, 10, QChar::fromLatin1('0'))
  22. .arg(error.raw, 8, 16, QChar::fromLatin1('0')));
  23. }
  24. void QtErrorDisplay::ShowErrorWithTimestamp(ResultCode error, std::chrono::seconds time,
  25. std::function<void()> finished) const {
  26. callback = std::move(finished);
  27. const QDateTime date_time = QDateTime::fromSecsSinceEpoch(time.count());
  28. emit MainWindowDisplayError(
  29. tr("An error occurred on %1 at %2.\nPlease try again or contact the "
  30. "developer of the software.\n\nError Code: %3-%4 (0x%5)")
  31. .arg(date_time.toString(QStringLiteral("dddd, MMMM d, yyyy")))
  32. .arg(date_time.toString(QStringLiteral("h:mm:ss A")))
  33. .arg(static_cast<u32>(error.module.Value()) + 2000, 4, 10, QChar::fromLatin1('0'))
  34. .arg(error.description, 4, 10, QChar::fromLatin1('0'))
  35. .arg(error.raw, 8, 16, QChar::fromLatin1('0')));
  36. }
  37. void QtErrorDisplay::ShowCustomErrorText(ResultCode error, std::string dialog_text,
  38. std::string fullscreen_text,
  39. std::function<void()> finished) const {
  40. callback = std::move(finished);
  41. emit MainWindowDisplayError(
  42. tr("An error has occurred.\nError Code: %1-%2 (0x%3)\n\n%4\n\n%5")
  43. .arg(static_cast<u32>(error.module.Value()) + 2000, 4, 10, QChar::fromLatin1('0'))
  44. .arg(error.description, 4, 10, QChar::fromLatin1('0'))
  45. .arg(error.raw, 8, 16, QChar::fromLatin1('0'))
  46. .arg(QString::fromStdString(dialog_text))
  47. .arg(QString::fromStdString(fullscreen_text)));
  48. }
  49. void QtErrorDisplay::MainWindowFinishedError() {
  50. // Acquire the HLE mutex
  51. std::lock_guard lock{HLE::g_hle_lock};
  52. callback();
  53. }