remove template and add initialise function

This commit is contained in:
Syping 2023-10-02 19:21:36 +02:00
parent 12c6b7425c
commit 01424ef51f
6 changed files with 317 additions and 212 deletions

View file

@ -172,7 +172,6 @@ set(GTA5VIEW_TRANSLATIONS
list(APPEND GTA5VIEW_RESOURCES list(APPEND GTA5VIEW_RESOURCES
res/global.qrc res/global.qrc
res/template.qrc
) )
set_property(SOURCE res/global.qrc PROPERTY AUTORCC_OPTIONS "-threshold;0;-compress;9") set_property(SOURCE res/global.qrc PROPERTY AUTORCC_OPTIONS "-threshold;0;-compress;9")

Binary file not shown.

View file

@ -1,5 +0,0 @@
<RCC>
<qresource prefix="/template">
<file>template.g5e</file>
</qresource>
</RCC>

View file

@ -725,8 +725,8 @@ bool ProfileInterface::importFile(QString selectedFile, QDateTime importDateTime
} }
} }
else if (isSupportedImageFile(selectedFileName)) { else if (isSupportedImageFile(selectedFileName)) {
SnapmaticPicture *picture = new SnapmaticPicture(":/template/template.g5e"); SnapmaticPicture *picture = new SnapmaticPicture();
if (picture->readingPicture(false)) { picture->initialise(RagePhoto::PhotoFormat::GTA5); // TODO: check which game we want create for
if (!notMultiple) { if (!notMultiple) {
QFile snapmaticFile(selectedFile); QFile snapmaticFile(selectedFile);
if (!snapmaticFile.open(QFile::ReadOnly)) { if (!snapmaticFile.open(QFile::ReadOnly)) {
@ -890,11 +890,6 @@ bool ProfileInterface::importFile(QString selectedFile, QDateTime importDateTime
return success; return success;
} }
} }
else {
delete picture;
return false;
}
}
else { else {
SnapmaticPicture *picture = new SnapmaticPicture(selectedFile); SnapmaticPicture *picture = new SnapmaticPicture(selectedFile);
SavegameData *savegame = new SavegameData(selectedFile); SavegameData *savegame = new SavegameData(selectedFile);
@ -1050,9 +1045,9 @@ bool ProfileInterface::importRemote(QUrl remoteUrl)
bool ProfileInterface::importImage(QImage *snapmaticImage, QDateTime importDateTime) bool ProfileInterface::importImage(QImage *snapmaticImage, QDateTime importDateTime)
{ {
SnapmaticPicture *picture = new SnapmaticPicture(":/template/template.g5e");
if (picture->readingPicture(false)) {
bool success = false; 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 *importDialog = new ImportDialog(profileName, this);
importDialog->setImage(snapmaticImage); importDialog->setImage(snapmaticImage);
importDialog->setModal(true); importDialog->setModal(true);
@ -1099,11 +1094,6 @@ bool ProfileInterface::importImage(QImage *snapmaticImage, QDateTime importDateT
if (!success) if (!success)
delete picture; delete picture;
return success; return success;
}
else {
delete picture;
return false;
}
} }
bool ProfileInterface::importSnapmaticPicture(SnapmaticPicture *picture, bool warn) bool ProfileInterface::importSnapmaticPicture(SnapmaticPicture *picture, bool warn)

View file

@ -17,10 +17,12 @@
*****************************************************************************/ *****************************************************************************/
#include "SnapmaticPicture.h" #include "SnapmaticPicture.h"
#include "pcg_basic.h"
#include <QStringBuilder> #include <QStringBuilder>
#include <QStringList> #include <QStringList>
#include <QVariantMap> #include <QVariantMap>
#include <QFileInfo> #include <QFileInfo>
#include <QDateTime>
#include <QString> #include <QString>
#include <cstring> #include <cstring>
#include <QBuffer> #include <QBuffer>
@ -845,7 +847,125 @@ const QString SnapmaticPicture::getLastStep(bool readable)
return lastStep; return lastStep;
} }
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() const QImage SnapmaticPicture::getImage()

View file

@ -90,6 +90,7 @@ public:
const QString getExportPictureFileName(); const QString getExportPictureFileName();
const QString getOriginalPictureFileName(); const QString getOriginalPictureFileName();
const QString getOriginalPictureFilePath(); const QString getOriginalPictureFilePath();
void initialise(uint32_t photoFormat);
bool setImage(const QImage &picture, bool eXtendMode = false); bool setImage(const QImage &picture, bool eXtendMode = false);
bool setPictureTitl(const QString &newTitle); // Please use setPictureTitle instead bool setPictureTitl(const QString &newTitle); // Please use setPictureTitle instead
bool setPictureStream(const QByteArray &streamArray, int width, int height); bool setPictureStream(const QByteArray &streamArray, int width, int height);