From 01424ef51fb693aeb6b985f98972b4f59c8a5a06 Mon Sep 17 00:00:00 2001 From: Syping Date: Mon, 2 Oct 2023 19:21:36 +0200 Subject: [PATCH] remove template and add initialise function --- CMakeLists.txt | 1 - res/template.g5e | Bin 717 -> 0 bytes res/template.qrc | 5 - src/ProfileInterface.cpp | 402 +++++++++++++++++++-------------------- src/SnapmaticPicture.cpp | 120 ++++++++++++ src/SnapmaticPicture.h | 1 + 6 files changed, 317 insertions(+), 212 deletions(-) delete mode 100644 res/template.g5e delete mode 100644 res/template.qrc diff --git a/CMakeLists.txt b/CMakeLists.txt index 63160ad..1c2f7ad 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -172,7 +172,6 @@ set(GTA5VIEW_TRANSLATIONS list(APPEND GTA5VIEW_RESOURCES res/global.qrc - res/template.qrc ) set_property(SOURCE res/global.qrc PROPERTY AUTORCC_OPTIONS "-threshold;0;-compress;9") diff --git a/res/template.g5e b/res/template.g5e deleted file mode 100644 index c74ba7fd8c1ffa8c11259f561b5491c5780f2128..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 717 zcmV;;0y6yoM>Rz=0003c00000000?y+6(aT5Aj#fRWLBpH!##UG*>XNure{SGBE)F zNXZ3DWdDyr000O8d;tIe0007cc-s4a zq}Y%H41ydCj0}v-j7khlf{e_9jQ@`?$TKi7vO*LvKmj8YGYcylI|nBhH&DS=0R|>U zW@aW9W>!`f7NBe`P@aKBkX1<0(2-3zFp*uUP{gQl;zAB(r;P_igD!qhF-|IK;^Yz& zmyncFRa4i{)G{$OGqmaka3YSZQ|TeofBv2)jsb9I2=o^d3kx#~JIG&*OywX2 zf-J0xhHOHPf$WKe!b(Ps93oB=7j8VrscandK{To8BA1wo$wSqTAg_UaMx4i*$nqK7 zV+eoUV&GwB1V$dSAcH-_e+K(s8jBk2|K9`v@4UV18~_La01N;C)Bpeg0003xc-l>n zOKZb05QP8BoPDqpXhAnaoLf_9jv)sjZ5o3fMGs=f3>n8;=1F#zST}GBhlO-QpiP4foPp3 zjV0OwEje+=mb=fzyDLFmPAqRBn$`u z009616aWAK00008c-jj|%`M1DEJ+0b4oL$&EDZ<%009611ONa400000I1UH^-2Nwj diff --git a/res/template.qrc b/res/template.qrc deleted file mode 100644 index 06dcf5a..0000000 --- a/res/template.qrc +++ /dev/null @@ -1,5 +0,0 @@ - - - template.g5e - - diff --git a/src/ProfileInterface.cpp b/src/ProfileInterface.cpp index 2c5c352..31d57da 100644 --- a/src/ProfileInterface.cpp +++ b/src/ProfileInterface.cpp @@ -725,174 +725,169 @@ bool ProfileInterface::importFile(QString selectedFile, QDateTime importDateTime } } else if (isSupportedImageFile(selectedFileName)) { - SnapmaticPicture *picture = new SnapmaticPicture(":/template/template.g5e"); - if (picture->readingPicture(false)) { - if (!notMultiple) { - QFile snapmaticFile(selectedFile); - if (!snapmaticFile.open(QFile::ReadOnly)) { - delete picture; - return false; + SnapmaticPicture *picture = new SnapmaticPicture(); + picture->initialise(RagePhoto::PhotoFormat::GTA5); // TODO: check which game we want create for + if (!notMultiple) { + QFile snapmaticFile(selectedFile); + if (!snapmaticFile.open(QFile::ReadOnly)) { + delete picture; + return false; + } + QImage snapmaticImage; + QImageReader snapmaticImageReader; + snapmaticImageReader.setDecideFormatFromContent(true); + snapmaticImageReader.setDevice(&snapmaticFile); + if (!snapmaticImageReader.read(&snapmaticImage)) { + delete picture; + return false; + } + QString customImageTitle; + QPixmap snapmaticPixmap(960, 536); + snapmaticPixmap.fill(Qt::black); + QPainter snapmaticPainter(&snapmaticPixmap); + if (snapmaticImage.height() == snapmaticImage.width()) { + // Avatar mode + int diffWidth = 0; + int diffHeight = 0; + snapmaticImage = snapmaticImage.scaled(470, 470, Qt::KeepAspectRatio, Qt::SmoothTransformation); + if (snapmaticImage.width() > snapmaticImage.height()) { + diffHeight = 470 - snapmaticImage.height(); + diffHeight = diffHeight / 2; } - QImage snapmaticImage; - QImageReader snapmaticImageReader; - snapmaticImageReader.setDecideFormatFromContent(true); - snapmaticImageReader.setDevice(&snapmaticFile); - if (!snapmaticImageReader.read(&snapmaticImage)) { - delete picture; - return false; + else if (snapmaticImage.width() < snapmaticImage.height()) { + diffWidth = 470 - snapmaticImage.width(); + diffWidth = diffWidth / 2; } - QString customImageTitle; - QPixmap snapmaticPixmap(960, 536); - snapmaticPixmap.fill(Qt::black); - QPainter snapmaticPainter(&snapmaticPixmap); - if (snapmaticImage.height() == snapmaticImage.width()) { - // Avatar mode - int diffWidth = 0; - int diffHeight = 0; - snapmaticImage = snapmaticImage.scaled(470, 470, Qt::KeepAspectRatio, Qt::SmoothTransformation); - if (snapmaticImage.width() > snapmaticImage.height()) { - diffHeight = 470 - snapmaticImage.height(); - diffHeight = diffHeight / 2; - } - else if (snapmaticImage.width() < snapmaticImage.height()) { - diffWidth = 470 - snapmaticImage.width(); - diffWidth = diffWidth / 2; - } - snapmaticPainter.drawImage(145 + diffWidth, 66 + diffHeight, snapmaticImage); - customImageTitle = ImportDialog::tr("Custom Avatar", "Custom Avatar Description in SC, don't use Special Character!"); - } - else { - // Picture mode - int diffWidth = 0; - int diffHeight = 0; - snapmaticImage = snapmaticImage.scaled(960, 536, Qt::KeepAspectRatio, Qt::SmoothTransformation); - if (snapmaticImage.width() != 960) { - diffWidth = 960 - snapmaticImage.width(); - diffWidth = diffWidth / 2; - } - else if (snapmaticImage.height() != 536) { - diffHeight = 536 - snapmaticImage.height(); - diffHeight = diffHeight / 2; - } - snapmaticPainter.drawImage(0 + diffWidth, 0 + diffHeight, snapmaticImage); - customImageTitle = ImportDialog::tr("Custom Picture", "Custom Picture Description in SC, don't use Special Character!"); - } - snapmaticPainter.end(); - if (!picture->setImage(snapmaticPixmap.toImage())) { - delete picture; - return false; - } - SnapmaticProperties spJson = picture->getSnapmaticProperties(); - spJson.uid = getRandomUid(); - bool fExists = QFile::exists(profileFolder % "/PGTA5" % QString::number(spJson.uid)); - bool fExistsBackup = QFile::exists(profileFolder % "/PGTA5" % QString::number(spJson.uid) % ".bak"); - bool fExistsHidden = QFile::exists(profileFolder % "/PGTA5" % QString::number(spJson.uid) % ".hidden"); - int cEnough = 0; - while ((fExists || fExistsBackup || fExistsHidden) && cEnough < findRetryLimit) { - spJson.uid = getRandomUid(); - fExists = QFile::exists(profileFolder % "/PGTA5" % QString::number(spJson.uid)); - fExistsBackup = QFile::exists(profileFolder % "/PGTA5" % QString::number(spJson.uid) % ".bak"); - fExistsHidden = QFile::exists(profileFolder % "/PGTA5" % QString::number(spJson.uid) % ".hidden"); - cEnough++; - } - spJson.createdDateTime = importDateTime; - qint64 timestamp = spJson.createdDateTime.toSecsSinceEpoch(); - spJson.createdTimestamp = timestamp; - picture->setSnapmaticProperties(spJson); - const QString picFileName = QString("PGTA5%1").arg(QString::number(spJson.uid)); - picture->setPicFileName(picFileName); - picture->setPictureTitle(customImageTitle); - picture->updateStrings(); - bool success = importSnapmaticPicture(picture, notMultiple); - if (!success) - delete picture; - return success; + snapmaticPainter.drawImage(145 + diffWidth, 66 + diffHeight, snapmaticImage); + customImageTitle = ImportDialog::tr("Custom Avatar", "Custom Avatar Description in SC, don't use Special Character!"); } else { - bool success = false; - QFile snapmaticFile(selectedFile); - if (!snapmaticFile.open(QFile::ReadOnly)) { - QMessageBox::warning(this, tr("Import..."), tr("Can't import %1 because file can't be open").arg("\""+selectedFileName+"\"")); - delete picture; - return false; + // Picture mode + int diffWidth = 0; + int diffHeight = 0; + snapmaticImage = snapmaticImage.scaled(960, 536, Qt::KeepAspectRatio, Qt::SmoothTransformation); + if (snapmaticImage.width() != 960) { + diffWidth = 960 - snapmaticImage.width(); + diffWidth = diffWidth / 2; } - QImage *snapmaticImage = new QImage(); - QImageReader snapmaticImageReader; - snapmaticImageReader.setDecideFormatFromContent(true); - snapmaticImageReader.setDevice(&snapmaticFile); - if (!snapmaticImageReader.read(snapmaticImage)) { - QMessageBox::warning(this, tr("Import..."), tr("Can't import %1 because file can't be parsed properly").arg("\""+selectedFileName+"\"")); - delete snapmaticImage; - delete picture; - return false; + else if (snapmaticImage.height() != 536) { + diffHeight = 536 - snapmaticImage.height(); + diffHeight = diffHeight / 2; } - ImportDialog *importDialog = new ImportDialog(profileName, this); - importDialog->setImage(snapmaticImage); - importDialog->setModal(true); - importDialog->show(); - importDialog->exec(); - if (importDialog->isImportAgreed()) { - if (picture->setImage(importDialog->image(), importDialog->isUnlimitedBuffer())) { - SnapmaticProperties spJson = picture->getSnapmaticProperties(); - spJson.uid = getRandomUid(); - bool fExists = QFile::exists(profileFolder % "/PGTA5" % QString::number(spJson.uid)); - bool fExistsBackup = QFile::exists(profileFolder % "/PGTA5" % QString::number(spJson.uid) % ".bak"); - bool fExistsHidden = QFile::exists(profileFolder % "/PGTA5" % QString::number(spJson.uid) % ".hidden"); - int cEnough = 0; - while ((fExists || fExistsBackup || fExistsHidden) && cEnough < findRetryLimit) { - spJson.uid = getRandomUid(); - fExists = QFile::exists(profileFolder % "/PGTA5" % QString::number(spJson.uid)); - fExistsBackup = QFile::exists(profileFolder % "/PGTA5" % QString::number(spJson.uid) % ".bak"); - fExistsHidden = QFile::exists(profileFolder % "/PGTA5" % QString::number(spJson.uid) % ".hidden"); - cEnough++; - } - spJson.createdDateTime = importDateTime; - qint64 timestamp = spJson.createdDateTime.toSecsSinceEpoch(); - spJson.createdTimestamp = timestamp; - picture->setSnapmaticProperties(spJson); - const QString picFileName = QString("PGTA5%1").arg(QString::number(spJson.uid)); - picture->setPicFileName(picFileName); - picture->setPictureTitle(importDialog->getImageTitle()); - picture->updateStrings(); - success = importSnapmaticPicture(picture, notMultiple); -#ifdef GTA5SYNC_TELEMETRY - if (success) { - QSettings telemetrySettings(GTA5SYNC_APPVENDOR, GTA5SYNC_APPSTR); - telemetrySettings.beginGroup("Telemetry"); - bool pushUsageData = telemetrySettings.value("PushUsageData", false).toBool(); - telemetrySettings.endGroup(); - if (pushUsageData && Telemetry->canPush()) { - QJsonDocument jsonDocument; - QJsonObject jsonObject; - jsonObject["Type"] = "ImportSuccess"; - jsonObject["ExtraFlag"] = "Dialog"; - jsonObject["ImportSize"] = QString::number(picture->getPictureSize()); -#if QT_VERSION >= 0x060000 - jsonObject["ImportTime"] = QString::number(QDateTime::currentDateTimeUtc().toSecsSinceEpoch()); -#else - jsonObject["ImportTime"] = QString::number(QDateTime::currentDateTimeUtc().toTime_t()); -#endif - jsonObject["ImportType"] = "Image"; - jsonDocument.setObject(jsonObject); - Telemetry->push(TelemetryCategory::PersonalData, jsonDocument); - } - } -#endif - } - } - else { - delete picture; - success = true; - } - delete importDialog; - if (!success) - delete picture; - return success; + snapmaticPainter.drawImage(0 + diffWidth, 0 + diffHeight, snapmaticImage); + customImageTitle = ImportDialog::tr("Custom Picture", "Custom Picture Description in SC, don't use Special Character!"); } + snapmaticPainter.end(); + if (!picture->setImage(snapmaticPixmap.toImage())) { + delete picture; + return false; + } + SnapmaticProperties spJson = picture->getSnapmaticProperties(); + spJson.uid = getRandomUid(); + bool fExists = QFile::exists(profileFolder % "/PGTA5" % QString::number(spJson.uid)); + bool fExistsBackup = QFile::exists(profileFolder % "/PGTA5" % QString::number(spJson.uid) % ".bak"); + bool fExistsHidden = QFile::exists(profileFolder % "/PGTA5" % QString::number(spJson.uid) % ".hidden"); + int cEnough = 0; + while ((fExists || fExistsBackup || fExistsHidden) && cEnough < findRetryLimit) { + spJson.uid = getRandomUid(); + fExists = QFile::exists(profileFolder % "/PGTA5" % QString::number(spJson.uid)); + fExistsBackup = QFile::exists(profileFolder % "/PGTA5" % QString::number(spJson.uid) % ".bak"); + fExistsHidden = QFile::exists(profileFolder % "/PGTA5" % QString::number(spJson.uid) % ".hidden"); + cEnough++; + } + spJson.createdDateTime = importDateTime; + qint64 timestamp = spJson.createdDateTime.toSecsSinceEpoch(); + spJson.createdTimestamp = timestamp; + picture->setSnapmaticProperties(spJson); + const QString picFileName = QString("PGTA5%1").arg(QString::number(spJson.uid)); + picture->setPicFileName(picFileName); + picture->setPictureTitle(customImageTitle); + picture->updateStrings(); + bool success = importSnapmaticPicture(picture, notMultiple); + if (!success) + delete picture; + return success; } else { - delete picture; - return false; + bool success = false; + QFile snapmaticFile(selectedFile); + if (!snapmaticFile.open(QFile::ReadOnly)) { + QMessageBox::warning(this, tr("Import..."), tr("Can't import %1 because file can't be open").arg("\""+selectedFileName+"\"")); + delete picture; + return false; + } + QImage *snapmaticImage = new QImage(); + QImageReader snapmaticImageReader; + snapmaticImageReader.setDecideFormatFromContent(true); + snapmaticImageReader.setDevice(&snapmaticFile); + if (!snapmaticImageReader.read(snapmaticImage)) { + QMessageBox::warning(this, tr("Import..."), tr("Can't import %1 because file can't be parsed properly").arg("\""+selectedFileName+"\"")); + delete snapmaticImage; + delete picture; + return false; + } + ImportDialog *importDialog = new ImportDialog(profileName, this); + importDialog->setImage(snapmaticImage); + importDialog->setModal(true); + importDialog->show(); + importDialog->exec(); + if (importDialog->isImportAgreed()) { + if (picture->setImage(importDialog->image(), importDialog->isUnlimitedBuffer())) { + SnapmaticProperties spJson = picture->getSnapmaticProperties(); + spJson.uid = getRandomUid(); + bool fExists = QFile::exists(profileFolder % "/PGTA5" % QString::number(spJson.uid)); + bool fExistsBackup = QFile::exists(profileFolder % "/PGTA5" % QString::number(spJson.uid) % ".bak"); + bool fExistsHidden = QFile::exists(profileFolder % "/PGTA5" % QString::number(spJson.uid) % ".hidden"); + int cEnough = 0; + while ((fExists || fExistsBackup || fExistsHidden) && cEnough < findRetryLimit) { + spJson.uid = getRandomUid(); + fExists = QFile::exists(profileFolder % "/PGTA5" % QString::number(spJson.uid)); + fExistsBackup = QFile::exists(profileFolder % "/PGTA5" % QString::number(spJson.uid) % ".bak"); + fExistsHidden = QFile::exists(profileFolder % "/PGTA5" % QString::number(spJson.uid) % ".hidden"); + cEnough++; + } + spJson.createdDateTime = importDateTime; + qint64 timestamp = spJson.createdDateTime.toSecsSinceEpoch(); + spJson.createdTimestamp = timestamp; + picture->setSnapmaticProperties(spJson); + const QString picFileName = QString("PGTA5%1").arg(QString::number(spJson.uid)); + picture->setPicFileName(picFileName); + picture->setPictureTitle(importDialog->getImageTitle()); + picture->updateStrings(); + success = importSnapmaticPicture(picture, notMultiple); +#ifdef GTA5SYNC_TELEMETRY + if (success) { + QSettings telemetrySettings(GTA5SYNC_APPVENDOR, GTA5SYNC_APPSTR); + telemetrySettings.beginGroup("Telemetry"); + bool pushUsageData = telemetrySettings.value("PushUsageData", false).toBool(); + telemetrySettings.endGroup(); + if (pushUsageData && Telemetry->canPush()) { + QJsonDocument jsonDocument; + QJsonObject jsonObject; + jsonObject["Type"] = "ImportSuccess"; + jsonObject["ExtraFlag"] = "Dialog"; + jsonObject["ImportSize"] = QString::number(picture->getPictureSize()); +#if QT_VERSION >= 0x060000 + jsonObject["ImportTime"] = QString::number(QDateTime::currentDateTimeUtc().toSecsSinceEpoch()); +#else + jsonObject["ImportTime"] = QString::number(QDateTime::currentDateTimeUtc().toTime_t()); +#endif + jsonObject["ImportType"] = "Image"; + jsonDocument.setObject(jsonObject); + Telemetry->push(TelemetryCategory::PersonalData, jsonDocument); + } + } +#endif + } + } + else { + delete picture; + success = true; + } + delete importDialog; + if (!success) + delete picture; + return success; } } else { @@ -1050,60 +1045,55 @@ bool ProfileInterface::importRemote(QUrl remoteUrl) bool ProfileInterface::importImage(QImage *snapmaticImage, QDateTime importDateTime) { - SnapmaticPicture *picture = new SnapmaticPicture(":/template/template.g5e"); - if (picture->readingPicture(false)) { - bool success = false; - ImportDialog *importDialog = new ImportDialog(profileName, this); - importDialog->setImage(snapmaticImage); - importDialog->setModal(true); - importDialog->show(); - importDialog->exec(); - if (importDialog->isImportAgreed()) { - if (picture->setImage(importDialog->image(), importDialog->isUnlimitedBuffer())) { - SnapmaticProperties spJson = picture->getSnapmaticProperties(); + bool success = false; + SnapmaticPicture *picture = new SnapmaticPicture(); + picture->initialise(RagePhoto::PhotoFormat::GTA5); // TODO: check which game we want create for + ImportDialog *importDialog = new ImportDialog(profileName, this); + importDialog->setImage(snapmaticImage); + importDialog->setModal(true); + importDialog->show(); + importDialog->exec(); + if (importDialog->isImportAgreed()) { + if (picture->setImage(importDialog->image(), importDialog->isUnlimitedBuffer())) { + SnapmaticProperties spJson = picture->getSnapmaticProperties(); + spJson.uid = getRandomUid(); + bool fExists = QFile::exists(profileFolder % "/PGTA5" % QString::number(spJson.uid)); + bool fExistsBackup = QFile::exists(profileFolder % "/PGTA5" % QString::number(spJson.uid) % ".bak"); + bool fExistsHidden = QFile::exists(profileFolder % "/PGTA5" % QString::number(spJson.uid) % ".hidden"); + int cEnough = 0; + while ((fExists || fExistsBackup || fExistsHidden) && cEnough < findRetryLimit) { spJson.uid = getRandomUid(); - bool fExists = QFile::exists(profileFolder % "/PGTA5" % QString::number(spJson.uid)); - bool fExistsBackup = QFile::exists(profileFolder % "/PGTA5" % QString::number(spJson.uid) % ".bak"); - bool fExistsHidden = QFile::exists(profileFolder % "/PGTA5" % QString::number(spJson.uid) % ".hidden"); - int cEnough = 0; - while ((fExists || fExistsBackup || fExistsHidden) && cEnough < findRetryLimit) { - spJson.uid = getRandomUid(); - fExists = QFile::exists(profileFolder % "/PGTA5" % QString::number(spJson.uid)); - fExistsBackup = QFile::exists(profileFolder % "/PGTA5" % QString::number(spJson.uid) % ".bak"); - fExistsHidden = QFile::exists(profileFolder % "/PGTA5" % QString::number(spJson.uid) % ".hidden"); - cEnough++; - } - spJson.createdDateTime = importDateTime; -#if QT_VERSION >= 0x060000 - quint64 timestamp = spJson.createdDateTime.toSecsSinceEpoch(); - if (timestamp > UINT32_MAX) { - timestamp = UINT32_MAX; - } - spJson.createdTimestamp = (quint32)timestamp; -#else - spJson.createdTimestamp = spJson.createdDateTime.toTime_t(); -#endif - picture->setSnapmaticProperties(spJson); - const QString picFileName = QString("PGTA5%1").arg(QString::number(spJson.uid)); - picture->setPicFileName(picFileName); - picture->setPictureTitle(importDialog->getImageTitle()); - picture->updateStrings(); - success = importSnapmaticPicture(picture, true); + fExists = QFile::exists(profileFolder % "/PGTA5" % QString::number(spJson.uid)); + fExistsBackup = QFile::exists(profileFolder % "/PGTA5" % QString::number(spJson.uid) % ".bak"); + fExistsHidden = QFile::exists(profileFolder % "/PGTA5" % QString::number(spJson.uid) % ".hidden"); + cEnough++; } + spJson.createdDateTime = importDateTime; +#if QT_VERSION >= 0x060000 + quint64 timestamp = spJson.createdDateTime.toSecsSinceEpoch(); + if (timestamp > UINT32_MAX) { + timestamp = UINT32_MAX; + } + spJson.createdTimestamp = (quint32)timestamp; +#else + spJson.createdTimestamp = spJson.createdDateTime.toTime_t(); +#endif + picture->setSnapmaticProperties(spJson); + const QString picFileName = QString("PGTA5%1").arg(QString::number(spJson.uid)); + picture->setPicFileName(picFileName); + picture->setPictureTitle(importDialog->getImageTitle()); + picture->updateStrings(); + success = importSnapmaticPicture(picture, true); } - else { - delete picture; - success = true; - } - delete importDialog; - if (!success) - delete picture; - return success; } else { delete picture; - return false; + success = true; } + delete importDialog; + if (!success) + delete picture; + return success; } bool ProfileInterface::importSnapmaticPicture(SnapmaticPicture *picture, bool warn) diff --git a/src/SnapmaticPicture.cpp b/src/SnapmaticPicture.cpp index 65b2081..cdce002 100644 --- a/src/SnapmaticPicture.cpp +++ b/src/SnapmaticPicture.cpp @@ -17,10 +17,12 @@ *****************************************************************************/ #include "SnapmaticPicture.h" +#include "pcg_basic.h" #include #include #include #include +#include #include #include #include @@ -845,7 +847,125 @@ const QString SnapmaticPicture::getLastStep(bool readable) return lastStep; } return lastStep; +} +void SnapmaticPicture::initialise(uint32_t photoFormat) +{ + switch (photoFormat) { + case RagePhoto::PhotoFormat::GTA5: + case G5EPhotoFormat::G5EX: + { + p_ragePhoto.setFormat(photoFormat); + p_ragePhoto.setHeader("PHOTO - 09/20/23 04:41:35", 0x97D5BDBDUL, 0x00000000UL); + p_ragePhoto.setJpeg(std::string(), RagePhoto::DefaultSize::DEFAULT_GTA5_PHOTOBUFFER); + + boost::json::object t_jsonObject; + t_jsonObject["area"] = "SANAND"; + t_jsonObject["crewid"] = 0; + t_jsonObject["cv"] = true; + t_jsonObject["drctr"] = false; + + boost::json::object t_locObject; + t_locObject["x"] = 0; + t_locObject["y"] = 0; + t_locObject["z"] = 0; + + t_jsonObject["loc"] = t_locObject; + t_jsonObject["meme"] = false; + t_jsonObject["mid"] = ""; + t_jsonObject["mode"] = "FREEMODE"; + t_jsonObject["mug"] = false; + t_jsonObject["nm"] = ""; + t_jsonObject["rds"] = ""; + t_jsonObject["rsedtr"] = false; + t_jsonObject["scr"] = 1; + t_jsonObject["sid"] = "0x0"; + t_jsonObject["slf"] = true; + t_jsonObject["street"] = 0; + + pcg32_random_t rng; + pcg32_srandom_r(&rng, QDateTime::currentMSecsSinceEpoch(), (intptr_t)&rng); + uint32_t secondsInYear = pcg32_boundedrand_r(&rng, 31535999UL); + uint32_t timestamp = 1356998400UL + secondsInYear; + QDateTime dateTime = QDateTime::fromSecsSinceEpoch(timestamp, Qt::UTC); + + boost::json::object t_timeObject; + t_timeObject["day"] = dateTime.date().day(); + t_timeObject["hour"] = dateTime.time().hour(); + t_timeObject["minute"] = dateTime.time().minute(); + t_timeObject["month"] = dateTime.date().month(); + t_timeObject["second"] = dateTime.time().second(); + t_timeObject["year"] = dateTime.date().year(); + + t_jsonObject["time"] = t_timeObject; + + const std::string json = SnapmaticJson::serialize(t_jsonObject, false); + setJsonStr(json, true); + jsonOk = true; + + p_ragePhoto.setDescription(""); + + isPreLoaded = true; + picOk = true; // TODO: the picture is still "not ok", but soon after it will be, but we should not assume it + } + break; + case RagePhoto::PhotoFormat::RDR2: + { + p_ragePhoto.setFormat(photoFormat); + p_ragePhoto.setHeader("PHOTO - 09/20/23 04:39:16", 0x0F5B0A65UL, 0xDF91D3D2UL); + p_ragePhoto.setJpeg(std::string(), RagePhoto::DefaultSize::DEFAULT_RDR2_PHOTOBUFFER); + + boost::json::object t_jsonObject; + t_jsonObject["advanced"] = false; + t_jsonObject["crewid"] = 0; + t_jsonObject["districtname"] = 0; + t_jsonObject["drctr"] = false; + + boost::json::object t_locObject; + t_locObject["x"] = 0; + t_locObject["y"] = 0; + t_locObject["z"] = 0; + + t_jsonObject["inphotomode"] = true; + t_jsonObject["loc"] = t_locObject; + t_jsonObject["meme"] = false; + t_jsonObject["mid"] = ""; + t_jsonObject["mode"] = "SP"; + t_jsonObject["mug"] = false; + t_jsonObject["nm"] = ""; + t_jsonObject["regionname"] = 0; + t_jsonObject["rsedtr"] = false; + t_jsonObject["sid"] = "0x0"; + t_jsonObject["slf"] = false; + t_jsonObject["statename"] = 0; + + pcg32_random_t rng; + pcg32_srandom_r(&rng, QDateTime::currentMSecsSinceEpoch(), (intptr_t)&rng); + uint32_t secondsInYear = pcg32_boundedrand_r(&rng, 31535999UL); + int64_t timestamp = -2240524800L + secondsInYear; + QDateTime dateTime = QDateTime::fromSecsSinceEpoch(timestamp, Qt::UTC); + + boost::json::object t_timeObject; + t_timeObject["day"] = dateTime.date().day(); + t_timeObject["hour"] = dateTime.time().hour(); + t_timeObject["minute"] = dateTime.time().minute(); + t_timeObject["month"] = dateTime.date().month(); + t_timeObject["second"] = dateTime.time().second(); + t_timeObject["year"] = dateTime.date().year(); + + t_jsonObject["time"] = t_timeObject; + + const std::string json = SnapmaticJson::serialize(t_jsonObject, false); + setJsonStr(json, true); + jsonOk = true; + + p_ragePhoto.setDescription(""); + + isPreLoaded = true; + picOk = true; // TODO: the picture is still "not ok", but soon after it will be, but we should not assume it + } + break; + } } const QImage SnapmaticPicture::getImage() diff --git a/src/SnapmaticPicture.h b/src/SnapmaticPicture.h index 05161c3..e69d0dd 100644 --- a/src/SnapmaticPicture.h +++ b/src/SnapmaticPicture.h @@ -90,6 +90,7 @@ public: const QString getExportPictureFileName(); const QString getOriginalPictureFileName(); const QString getOriginalPictureFilePath(); + void initialise(uint32_t photoFormat); bool setImage(const QImage &picture, bool eXtendMode = false); bool setPictureTitl(const QString &newTitle); // Please use setPictureTitle instead bool setPictureStream(const QByteArray &streamArray, int width, int height);