add format() function

This commit is contained in:
Syping 2021-09-03 18:36:00 +02:00
parent 1049c8e383
commit 464e5bf6dd
4 changed files with 16 additions and 2 deletions

View file

@ -29,6 +29,7 @@ uint32_t photoSize = ragePhoto.photoSize();
std::string json = ragePhoto.json(); std::string json = ragePhoto.json();
std::string title = ragePhoto.title(); std::string title = ragePhoto.title();
RagePhoto::Error error = ragePhoto.error(); RagePhoto::Error error = ragePhoto.error();
RagePhoto::PhotoFormat format = ragePhoto.format();
``` ```
#### How to Use ragephoto-extract #### How to Use ragephoto-extract

View file

@ -92,7 +92,10 @@ int main(int argc, char *argv[])
return -1; 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) // Clear RagePhoto (provocate crash when pointer leak)
ragePhoto.clear(); ragePhoto.clear();

View file

@ -36,7 +36,6 @@ RagePhoto::RagePhoto()
{ {
p_photoLoaded = false; p_photoLoaded = false;
p_photoData = nullptr; p_photoData = nullptr;
p_error = Error::Uninitialised;
} }
RagePhoto::~RagePhoto() RagePhoto::~RagePhoto()
@ -56,6 +55,7 @@ void RagePhoto::clear()
p_photoString.clear(); p_photoString.clear();
p_titleString.clear(); p_titleString.clear();
p_error = Error::Uninitialised; p_error = Error::Uninitialised;
p_photoFormat = PhotoFormat::Undefined;
} }
bool RagePhoto::load(const char *data, size_t length) 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); uint32_t format = charToUInt32LE(uInt32Buffer);
#endif #endif
if (format == static_cast<uint32_t>(PhotoFormat::GTA5) || format == static_cast<uint32_t>(PhotoFormat::RDR2)) { if (format == static_cast<uint32_t>(PhotoFormat::GTA5) || format == static_cast<uint32_t>(PhotoFormat::RDR2)) {
p_photoFormat = static_cast<PhotoFormat>(format);
char photoHeader[256]; char photoHeader[256];
size = readBuffer(data, photoHeader, &pos, 256, length); size = readBuffer(data, photoHeader, &pos, 256, length);
if (size != 256) { if (size != 256) {
@ -359,6 +361,11 @@ RagePhoto::Error RagePhoto::error()
return p_error; return p_error;
} }
RagePhoto::PhotoFormat RagePhoto::format()
{
return p_photoFormat;
}
const char* RagePhoto::photoData() const char* RagePhoto::photoData()
{ {
if (p_photoLoaded) if (p_photoLoaded)

View file

@ -67,6 +67,7 @@ public:
enum class PhotoFormat : uint32_t { enum class PhotoFormat : uint32_t {
GTA5 = 0x01000000U, GTA5 = 0x01000000U,
RDR2 = 0x04000000U, RDR2 = 0x04000000U,
Undefined = 0,
}; };
RagePhoto(); RagePhoto();
~RagePhoto(); ~RagePhoto();
@ -74,6 +75,7 @@ public:
bool load(const char *data, size_t length); bool load(const char *data, size_t length);
bool load(const std::string &data); bool load(const std::string &data);
Error error(); Error error();
PhotoFormat format();
const char *photoData(); const char *photoData();
const uint32_t photoSize(); const uint32_t photoSize();
const std::string description(); const std::string description();
@ -90,6 +92,7 @@ protected:
bool p_photoLoaded; bool p_photoLoaded;
char* p_photoData; char* p_photoData;
Error p_error; Error p_error;
PhotoFormat p_photoFormat;
std::string p_descriptionString; std::string p_descriptionString;
std::string p_jsonString; std::string p_jsonString;
std::string p_photoString; std::string p_photoString;