From 37ef9f585664a9b0ccc1a1ba844b6581102ec39e Mon Sep 17 00:00:00 2001 From: Matt Borgerson Date: Mon, 27 Apr 2020 16:26:17 -0700 Subject: [PATCH] ui: Add report submission error reporting --- ui/xemu-hud.cc | 34 ++++++++++++++++++++++++++++++---- ui/xemu-reporting.cc | 34 +++++++++++++++++++++++++++++----- ui/xemu-reporting.h | 7 ++++++- 3 files changed, 65 insertions(+), 10 deletions(-) diff --git a/ui/xemu-hud.cc b/ui/xemu-hud.cc index 21f11405af..886c43d058 100644 --- a/ui/xemu-hud.cc +++ b/ui/xemu-hud.cc @@ -944,6 +944,8 @@ public: CompatibilityReport report; bool dirty; bool is_open; + bool is_xbe_identified; + bool did_send, send_result; std::string serialized_report; CompatibilityReporter() @@ -967,6 +969,8 @@ public: report.os_version = xemu_get_os_info(); report.cpu = get_cpu_info(); dirty = true; + is_xbe_identified = false; + did_send = send_result = false; } ~CompatibilityReporter() @@ -991,11 +995,19 @@ public: report.gl_version = (const char *)glGetString(GL_VERSION); report.gl_shading_language_version = (const char *)glGetString(GL_SHADING_LANGUAGE_VERSION); struct xbe *xbe = xemu_get_xbe_info(); - if (xbe != NULL) { + is_xbe_identified = xbe != NULL; + if (is_xbe_identified) { report.SetXbeData(xbe); - } else { - // FIXME: Show message if XBE could not be identified } + did_send = send_result = false; + } + + if (!is_xbe_identified) { + ImGui::TextWrapped( + "An XBE could not be identified. Please launch an official " + "Xbox title to submit a compatibility report."); + ImGui::End(); + return; } ImGui::TextWrapped( @@ -1073,11 +1085,25 @@ public: ImGui::Columns(1); + ImGui::Dummy(ImVec2(0, 5*g_ui_scale)); + ImGui::Separator(); + ImGui::Dummy(ImVec2(0, 5*g_ui_scale)); + + if (did_send) { + if (send_result) { + ImGui::Text("Sent! Thanks."); + } else { + ImGui::Text("Error: %s (%d)", report.GetResultMessage().c_str(), report.GetResultCode()); + } + ImGui::SameLine(); + } + ImGui::SetCursorPosX(ImGui::GetWindowWidth()-(120+10)*g_ui_scale); ImGui::SetItemDefaultFocus(); if (ImGui::Button("Send", ImVec2(120*g_ui_scale, 0))) { - report.Send(); + did_send = true; + send_result = report.Send(); } ImGui::End(); diff --git a/ui/xemu-reporting.cc b/ui/xemu-reporting.cc index a4411612ed..9b0ef3d245 100644 --- a/ui/xemu-reporting.cc +++ b/ui/xemu-reporting.cc @@ -38,13 +38,11 @@ const std::string &CompatibilityReport::GetSerializedReport() return serialized; } -void CompatibilityReport::Send() +bool CompatibilityReport::Send() { // Serialize the report const std::string &s = GetSerializedReport(); - fprintf(stderr, "%s\n", s.c_str()); - httplib::SSLClient cli("127.0.0.1", 443); // httplib::SSLClient cli("reports.xemu.app", 443); @@ -63,10 +61,36 @@ void CompatibilityReport::Send() } #endif #endif - return; + + result_code = -1; + result_msg = "Failed to connect"; + return false; } - fprintf(stderr, "%d\n", res->status); + result_code = res->status; + + switch(res->status) { + case 200: + result_msg = "Ok"; + return true; + + case 400: + case 411: + result_msg = "Invalid request"; + return false; + + case 403: + result_msg = "Invalid token"; + return false; + + case 413: + result_msg = "Report too long"; + return false; + + default: + result_msg = "Unknown error occured"; + return false; + } } void CompatibilityReport::SetXbeData(struct xbe *xbe) diff --git a/ui/xemu-reporting.h b/ui/xemu-reporting.h index f7765cfec6..1554fe07ae 100644 --- a/ui/xemu-reporting.h +++ b/ui/xemu-reporting.h @@ -45,12 +45,17 @@ public: std::string compat_comments; std::string xbe_headers; +private: std::string serialized; + int result_code; + std::string result_msg; public: CompatibilityReport(); ~CompatibilityReport(); - void Send(); + bool Send(); + int GetResultCode() { return result_code; } + std::string &GetResultMessage() { return result_msg; } const std::string &GetSerializedReport(); void SetXbeData(struct xbe *xbe); };