From 45218be5e3c0e4e52571755737532a1d3d5ea80d Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Mon, 27 Jun 2016 00:01:09 -0700 Subject: [PATCH] Send a CRC hash with compatibility reports. --- Core/FileSystems/BlockDevices.cpp | 15 +++++++ Core/FileSystems/BlockDevices.h | 2 + Core/Reporting.cpp | 72 ++++++++++++++++++++++++++++++- Core/Reporting.h | 2 +- UI/ReportScreen.cpp | 1 + 5 files changed, 89 insertions(+), 3 deletions(-) diff --git a/Core/FileSystems/BlockDevices.cpp b/Core/FileSystems/BlockDevices.cpp index f1b0279309..ac50efb5f7 100644 --- a/Core/FileSystems/BlockDevices.cpp +++ b/Core/FileSystems/BlockDevices.cpp @@ -45,6 +45,21 @@ BlockDevice *constructBlockDevice(FileLoader *fileLoader) { return new FileBlockDevice(fileLoader); } +u32 BlockDevice::CalculateCRC() { + u32 crc = crc32(0, Z_NULL, 0); + + u8 block[2048]; + for (u32 i = 0; i < GetNumBlocks(); ++i) { + if (!ReadBlock(i, block, true)) { + ERROR_LOG(HLE, "Failed to read block for CRC"); + return 0; + } + crc = crc32(crc, block, 2048); + } + + return crc; +} + FileBlockDevice::FileBlockDevice(FileLoader *fileLoader) : fileLoader_(fileLoader) { diff --git a/Core/FileSystems/BlockDevices.h b/Core/FileSystems/BlockDevices.h index 57cc5baefe..81f5465515 100644 --- a/Core/FileSystems/BlockDevices.h +++ b/Core/FileSystems/BlockDevices.h @@ -45,6 +45,8 @@ public: } int GetBlockSize() const { return 2048;} // forced, it cannot be changed by subclasses virtual u32 GetNumBlocks() = 0; + + u32 CalculateCRC(); }; diff --git a/Core/Reporting.cpp b/Core/Reporting.cpp index 300774c978..3cfca69963 100644 --- a/Core/Reporting.cpp +++ b/Core/Reporting.cpp @@ -21,8 +21,10 @@ #include "Core/CoreTiming.h" #include "Core/Config.h" #include "Core/CwCheat.h" +#include "Core/Loaders.h" #include "Core/SaveState.h" #include "Core/System.h" +#include "Core/FileSystems/BlockDevices.h" #include "Core/FileSystems/MetaFileSystem.h" #include "Core/HLE/sceDisplay.h" #include "Core/HLE/sceKernelMemory.h" @@ -37,6 +39,7 @@ #include "base/stringutil.h" #include "base/buffer.h" #include "thread/thread.h" +#include "thread/threadutil.h" #include "file/zip_read.h" #include @@ -79,6 +82,68 @@ namespace Reporting static Payload payloadBuffer[PAYLOAD_BUFFER_SIZE]; static int payloadBufferPos = 0; + static recursive_mutex crcLock; + static condition_variable crcCond; + static std::string crcFilename; + static std::map crcResults; + + static int CalculateCRCThread() { + setCurrentThreadName("ReportCRC"); + + // TODO: Use the blockDevice from pspFileSystem? + FileLoader *fileLoader = ConstructFileLoader(crcFilename); + BlockDevice *blockDevice = constructBlockDevice(fileLoader); + + u32 crc = 0; + if (blockDevice) { + crc = blockDevice->CalculateCRC(); + } + + delete blockDevice; + delete fileLoader; + + lock_guard guard(crcLock); + crcResults[crcFilename] = crc; + crcCond.notify_one(); + + return 0; + } + + void QueueCRC() { + lock_guard guard(crcLock); + + const std::string &gamePath = PSP_CoreParameter().fileToStart; + auto it = crcResults.find(gamePath); + if (it != crcResults.end()) { + // Nothing to do, we've already calculated it. + // Note: we assume it stays static until the app is closed. + return; + } + + if (crcFilename == gamePath) { + // Already in process. + return; + } + + crcFilename = gamePath; + std::thread th(CalculateCRCThread); + th.detach(); + } + + u32 RetrieveCRC() { + const std::string &gamePath = PSP_CoreParameter().fileToStart; + QueueCRC(); + + lock_guard guard(crcLock); + auto it = crcResults.find(gamePath); + while (it == crcResults.end()) { + crcCond.wait(crcLock); + it = crcResults.find(gamePath); + } + + return it->second; + } + // Returns the full host (e.g. report.ppsspp.org:80.) std::string ServerHost() { @@ -324,6 +389,8 @@ namespace Reporting int Process(int pos) { + setCurrentThreadName("Report"); + Payload &payload = payloadBuffer[pos]; MultipartFormDataEncoder postdata; @@ -335,6 +402,7 @@ namespace Reporting switch (payload.type) { case RequestType::MESSAGE: + // TODO: Add CRC? postdata.Add("message", payload.string1); postdata.Add("value", payload.string2); // We tend to get corrupted data, this acts as a very primitive verification check. @@ -353,6 +421,7 @@ namespace Reporting postdata.Add("graphics", StringFromFormat("%d", payload.int1)); postdata.Add("speed", StringFromFormat("%d", payload.int2)); postdata.Add("gameplay", StringFromFormat("%d", payload.int3)); + postdata.Add("crc", StringFromFormat("%08x", RetrieveCRC())); AddScreenshotData(postdata, payload.string2); payload.string1.clear(); payload.string2.clear(); @@ -484,7 +553,7 @@ namespace Reporting th.detach(); } - void ReportCompatibility(const char *compat, int graphics, int speed, int gameplay, std::string screenshotFilename) + void ReportCompatibility(const char *compat, int graphics, int speed, int gameplay, const std::string &screenshotFilename) { if (!IsEnabled()) return; @@ -503,5 +572,4 @@ namespace Reporting std::thread th(Process, pos); th.detach(); } - } diff --git a/Core/Reporting.h b/Core/Reporting.h index d8141cdcf9..a669ddbefa 100644 --- a/Core/Reporting.h +++ b/Core/Reporting.h @@ -70,7 +70,7 @@ namespace Reporting void ReportMessageFormatted(const char *message, const char *formatted); // Report the compatibility of the current game / configuration. - void ReportCompatibility(const char *compat, int graphics, int speed, int gameplay, std::string screenshotFilename); + void ReportCompatibility(const char *compat, int graphics, int speed, int gameplay, const std::string &screenshotFilename); // Returns true if that identifier has not been logged yet. bool ShouldLogOnce(const char *identifier); diff --git a/UI/ReportScreen.cpp b/UI/ReportScreen.cpp index a8e630face..4bbe248140 100644 --- a/UI/ReportScreen.cpp +++ b/UI/ReportScreen.cpp @@ -309,6 +309,7 @@ void ReportFinishScreen::CreateViews() { LinearLayout *rightColumnItems = new LinearLayout(ORIENT_VERTICAL); leftColumnItems->Add(new TextView(rp->T("FeedbackThanks", "Thanks for your feedback."), new LinearLayoutParams(Margins(12, 5, 0, 5)))); + leftColumnItems->Add(new TextView(rp->T("FeedbackDelayInfo", "Your data is being submitted in the background."), new LinearLayoutParams(Margins(12, 5, 0, 5)))); rightColumnItems->SetSpacing(0.0f); rightColumnItems->Add(new Choice(rp->T("View Feedback")))->OnClick.Handle(this, &ReportFinishScreen::HandleViewFeedback);