From 464e5bf6ddabb849e741ac9bad16c320bc60d6a5 Mon Sep 17 00:00:00 2001 From: Syping Date: Fri, 3 Sep 2021 18:36:00 +0200 Subject: [PATCH] add format() function --- README.md | 1 + src/RagePhoto-Extract.cpp | 5 ++++- src/RagePhoto.cpp | 9 ++++++++- src/RagePhoto.h | 3 +++ 4 files changed, 16 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 329790a..e27f99d 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,7 @@ uint32_t photoSize = ragePhoto.photoSize(); std::string json = ragePhoto.json(); std::string title = ragePhoto.title(); RagePhoto::Error error = ragePhoto.error(); +RagePhoto::PhotoFormat format = ragePhoto.format(); ``` #### How to Use ragephoto-extract diff --git a/src/RagePhoto-Extract.cpp b/src/RagePhoto-Extract.cpp index 260fec3..2130d1a 100644 --- a/src/RagePhoto-Extract.cpp +++ b/src/RagePhoto-Extract.cpp @@ -92,7 +92,10 @@ int main(int argc, char *argv[]) return -1; } - std::cout << "Photo successfully exported" << std::endl; + if (ragePhoto.format() == RagePhoto::PhotoFormat::GTA5) + std::cout << "GTA V Photo successfully exported" << std::endl; + else + std::cout << "RDR 2 Photo successfully exported" << std::endl; // Clear RagePhoto (provocate crash when pointer leak) ragePhoto.clear(); diff --git a/src/RagePhoto.cpp b/src/RagePhoto.cpp index 20881ee..8e081a5 100644 --- a/src/RagePhoto.cpp +++ b/src/RagePhoto.cpp @@ -36,7 +36,6 @@ RagePhoto::RagePhoto() { p_photoLoaded = false; p_photoData = nullptr; - p_error = Error::Uninitialised; } RagePhoto::~RagePhoto() @@ -56,6 +55,7 @@ void RagePhoto::clear() p_photoString.clear(); p_titleString.clear(); p_error = Error::Uninitialised; + p_photoFormat = PhotoFormat::Undefined; } bool RagePhoto::load(const char *data, size_t length) @@ -82,6 +82,8 @@ bool RagePhoto::load(const char *data, size_t length) uint32_t format = charToUInt32LE(uInt32Buffer); #endif if (format == static_cast(PhotoFormat::GTA5) || format == static_cast(PhotoFormat::RDR2)) { + p_photoFormat = static_cast(format); + char photoHeader[256]; size = readBuffer(data, photoHeader, &pos, 256, length); if (size != 256) { @@ -359,6 +361,11 @@ RagePhoto::Error RagePhoto::error() return p_error; } +RagePhoto::PhotoFormat RagePhoto::format() +{ + return p_photoFormat; +} + const char* RagePhoto::photoData() { if (p_photoLoaded) diff --git a/src/RagePhoto.h b/src/RagePhoto.h index 2b244c1..6d6108a 100644 --- a/src/RagePhoto.h +++ b/src/RagePhoto.h @@ -67,6 +67,7 @@ public: enum class PhotoFormat : uint32_t { GTA5 = 0x01000000U, RDR2 = 0x04000000U, + Undefined = 0, }; RagePhoto(); ~RagePhoto(); @@ -74,6 +75,7 @@ public: bool load(const char *data, size_t length); bool load(const std::string &data); Error error(); + PhotoFormat format(); const char *photoData(); const uint32_t photoSize(); const std::string description(); @@ -90,6 +92,7 @@ protected: bool p_photoLoaded; char* p_photoData; Error p_error; + PhotoFormat p_photoFormat; std::string p_descriptionString; std::string p_jsonString; std::string p_photoString;