error.cpp 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. this->callback = std::move(finished);
  17. emit MainWindowDisplayError(
  18. tr("An error has occured.\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. this->callback = std::move(finished);
  27. emit MainWindowDisplayError(
  28. tr("An error occured on %1 at %2.\nPlease try again or contact the "
  29. "developer of the software.\n\nError Code: %3-%4 (0x%5)")
  30. .arg(QDateTime::fromSecsSinceEpoch(time.count()).toString("dddd, MMMM d, yyyy"))
  31. .arg(QDateTime::fromSecsSinceEpoch(time.count()).toString("h:mm:ss A"))
  32. .arg(static_cast<u32>(error.module.Value()) + 2000, 4, 10, QChar::fromLatin1('0'))
  33. .arg(error.description, 4, 10, QChar::fromLatin1('0'))
  34. .arg(error.raw, 8, 16, QChar::fromLatin1('0')));
  35. }
  36. void QtErrorDisplay::ShowCustomErrorText(ResultCode error, std::string dialog_text,
  37. std::string fullscreen_text,
  38. std::function<void()> finished) const {
  39. this->callback = std::move(finished);
  40. emit MainWindowDisplayError(
  41. tr("An error has occured.\nError Code: %1-%2 (0x%3)\n\n%4\n\n%5")
  42. .arg(static_cast<u32>(error.module.Value()) + 2000, 4, 10, QChar::fromLatin1('0'))
  43. .arg(error.description, 4, 10, QChar::fromLatin1('0'))
  44. .arg(error.raw, 8, 16, QChar::fromLatin1('0'))
  45. .arg(QString::fromStdString(dialog_text))
  46. .arg(QString::fromStdString(fullscreen_text)));
  47. }
  48. void QtErrorDisplay::MainWindowFinishedError() {
  49. // Acquire the HLE mutex
  50. std::lock_guard lock{HLE::g_hle_lock};
  51. callback();
  52. }