fix RDR 2 photo import, little code rework

This commit is contained in:
Syping 2023-10-07 15:24:07 +02:00
parent 61387ee711
commit 446f0b07b0
3 changed files with 66 additions and 57 deletions

View file

@ -82,13 +82,12 @@ ProfileInterface::ProfileInterface(ProfileDatabase *profileDB, CrewDatabase *cre
contextMenuOpened = false; contextMenuOpened = false;
isProfileLoaded = false; isProfileLoaded = false;
previousWidget = nullptr; previousWidget = nullptr;
profileLoader = nullptr;
saSpacerItem = nullptr; saSpacerItem = nullptr;
updatePalette(); updatePalette();
QString appVersion = QApplication::applicationVersion(); QString appVersion = QApplication::applicationVersion();
const char* literalBuildType = GTA5SYNC_BUILDTYPE;
#ifdef GTA5SYNC_COMMIT #ifdef GTA5SYNC_COMMIT
const char* literalBuildType = GTA5SYNC_BUILDTYPE;
if ((strcmp(literalBuildType, REL_BUILDTYPE) != 0) && !appVersion.contains("-")) if ((strcmp(literalBuildType, REL_BUILDTYPE) != 0) && !appVersion.contains("-"))
appVersion = appVersion % "-" % GTA5SYNC_COMMIT; appVersion = appVersion % "-" % GTA5SYNC_COMMIT;
#endif #endif
@ -164,10 +163,26 @@ ProfileInterface::~ProfileInterface()
} }
pictures.clear(); pictures.clear();
delete profileLoader;
delete ui; delete ui;
} }
inline QString getFileFormat(quint32 photoFormat)
{
QString fileFormat;
switch (photoFormat) {
case RagePhoto::PhotoFormat::GTA5:
fileFormat = "PGTA5%1";
break;
case RagePhoto::PhotoFormat::RDR2:
fileFormat = "PRDR3%1_1";
break;
default:
fileFormat = "%1.lrpx";
break;
}
return fileFormat;
}
void ProfileInterface::setProfileFolder(QString folder, QString profile, quint32 format) void ProfileInterface::setProfileFolder(QString folder, QString profile, quint32 format)
{ {
profileFolder = folder; profileFolder = folder;
@ -179,13 +194,16 @@ void ProfileInterface::setupProfileInterface()
{ {
fixedPictures.clear(); fixedPictures.clear();
ui->labProfileLoading->setText(tr("Loading...")); ui->labProfileLoading->setText(tr("Loading..."));
profileLoader = new ProfileLoader(profileFolder, crewDB); ProfileLoader *profileLoader = new ProfileLoader(profileFolder, crewDB);
QObject::connect(profileLoader, SIGNAL(directoryScanned(QVector<QString>,QVector<QString>)), this, SLOT(directoryScanned(QVector<QString>,QVector<QString>))); QObject::connect(profileLoader, &ProfileLoader::directoryScanned, this, &ProfileInterface::directoryScanned);
QObject::connect(profileLoader, SIGNAL(savegameLoaded(SavegameData*, QString)), this, SLOT(savegameLoaded_event(SavegameData*, QString))); QObject::connect(profileLoader, &ProfileLoader::savegameLoaded, this, &ProfileInterface::savegameLoaded_event);
QObject::connect(profileLoader, SIGNAL(pictureLoaded(SnapmaticPicture*)), this, SLOT(pictureLoaded_event(SnapmaticPicture*))); QObject::connect(profileLoader, &ProfileLoader::pictureLoaded, this, &ProfileInterface::pictureLoaded_event);
QObject::connect(profileLoader, SIGNAL(pictureFixed(SnapmaticPicture*)), this, SLOT(pictureFixed_event(SnapmaticPicture*))); QObject::connect(profileLoader, &ProfileLoader::pictureFixed, this, &ProfileInterface::pictureFixed_event);
QObject::connect(profileLoader, SIGNAL(loadingProgress(int,int)), this, SLOT(loadingProgress(int,int))); QObject::connect(profileLoader, &ProfileLoader::loadingProgress, this, &ProfileInterface::loadingProgress);
QObject::connect(profileLoader, SIGNAL(finished()), this, SLOT(profileLoaded_p())); QObject::connect(profileLoader, &ProfileLoader::finished, this, [=](){
profileLoaded_p();
profileLoader->deleteLater();
});
profileLoader->start(); profileLoader->start();
} }
@ -205,12 +223,12 @@ void ProfileInterface::savegameLoaded(SavegameData *savegame, QString savegamePa
savegames += savegame; savegames += savegame;
if (selectedWidgts != 0 || contentMode == 2) if (selectedWidgts != 0 || contentMode == 2)
sgdWidget->setSelectionMode(true); sgdWidget->setSelectionMode(true);
QObject::connect(sgdWidget, SIGNAL(savegameDeleted()), this, SLOT(savegameDeleted_event())); QObject::connect(sgdWidget, &SavegameWidget::savegameDeleted, this, &ProfileInterface::savegameDeleted_event);
QObject::connect(sgdWidget, SIGNAL(widgetSelected()), this, SLOT(profileWidgetSelected())); QObject::connect(sgdWidget, &SavegameWidget::widgetSelected, this, &ProfileInterface::profileWidgetSelected);
QObject::connect(sgdWidget, SIGNAL(widgetDeselected()), this, SLOT(profileWidgetDeselected())); QObject::connect(sgdWidget, &SavegameWidget::widgetDeselected, this, &ProfileInterface::profileWidgetDeselected);
QObject::connect(sgdWidget, SIGNAL(allWidgetsSelected()), this, SLOT(selectAllWidgets())); QObject::connect(sgdWidget, &SavegameWidget::allWidgetsSelected, this, &ProfileInterface::selectAllWidgets);
QObject::connect(sgdWidget, SIGNAL(allWidgetsDeselected()), this, SLOT(deselectAllWidgets())); QObject::connect(sgdWidget, &SavegameWidget::allWidgetsDeselected, this, &ProfileInterface::deselectAllWidgets);
QObject::connect(sgdWidget, SIGNAL(contextMenuTriggered(QContextMenuEvent*)), this, SLOT(contextMenuTriggeredSGD(QContextMenuEvent*))); QObject::connect(sgdWidget, &SavegameWidget::contextMenuTriggered, this, &ProfileInterface::contextMenuTriggeredSGD);
if (inserted) if (inserted)
insertSavegameIPI(sgdWidget); insertSavegameIPI(sgdWidget);
} }
@ -237,14 +255,14 @@ void ProfileInterface::pictureLoaded(SnapmaticPicture *picture, bool inserted)
pictures += picture; pictures += picture;
if (selectedWidgts != 0 || contentMode == 2) if (selectedWidgts != 0 || contentMode == 2)
picWidget->setSelectionMode(true); picWidget->setSelectionMode(true);
QObject::connect(picWidget, SIGNAL(pictureDeleted()), this, SLOT(pictureDeleted_event())); QObject::connect(picWidget, &SnapmaticWidget::pictureDeleted, this, &ProfileInterface::pictureDeleted_event);
QObject::connect(picWidget, SIGNAL(widgetSelected()), this, SLOT(profileWidgetSelected())); QObject::connect(picWidget, &SnapmaticWidget::widgetSelected, this, &ProfileInterface::profileWidgetSelected);
QObject::connect(picWidget, SIGNAL(widgetDeselected()), this, SLOT(profileWidgetDeselected())); QObject::connect(picWidget, &SnapmaticWidget::widgetDeselected, this, &ProfileInterface::profileWidgetDeselected);
QObject::connect(picWidget, SIGNAL(allWidgetsSelected()), this, SLOT(selectAllWidgets())); QObject::connect(picWidget, &SnapmaticWidget::allWidgetsSelected, this, &ProfileInterface::selectAllWidgets);
QObject::connect(picWidget, SIGNAL(allWidgetsDeselected()), this, SLOT(deselectAllWidgets())); QObject::connect(picWidget, &SnapmaticWidget::allWidgetsDeselected, this, &ProfileInterface::deselectAllWidgets);
QObject::connect(picWidget, SIGNAL(nextPictureRequested(QWidget*)), this, SLOT(dialogNextPictureRequested(QWidget*))); QObject::connect(picWidget, &SnapmaticWidget::nextPictureRequested, this, &ProfileInterface::dialogNextPictureRequested);
QObject::connect(picWidget, SIGNAL(previousPictureRequested(QWidget*)), this, SLOT(dialogPreviousPictureRequested(QWidget*))); QObject::connect(picWidget, &SnapmaticWidget::previousPictureRequested, this, &ProfileInterface::dialogPreviousPictureRequested);
QObject::connect(picWidget, SIGNAL(contextMenuTriggered(QContextMenuEvent*)), this, SLOT(contextMenuTriggeredPIC(QContextMenuEvent*))); QObject::connect(picWidget, &SnapmaticWidget::contextMenuTriggered, this, &ProfileInterface::contextMenuTriggeredPIC);
if (inserted) if (inserted)
insertSnapmaticIPI(picWidget); insertSnapmaticIPI(picWidget);
} }
@ -266,6 +284,8 @@ void ProfileInterface::directoryChanged(const QString &path)
QVector<QString> n_savegameFiles; QVector<QString> n_savegameFiles;
QVector<QString> n_snapmaticPics; QVector<QString> n_snapmaticPics;
// TODO: We want exclude GTA V Snapmatic in RDR profiles and the other way around
const QStringList files = dir.entryList(QDir::Files); const QStringList files = dir.entryList(QDir::Files);
for (const QString &fileName : files) { for (const QString &fileName : files) {
if ((fileName.startsWith("SGTA5") || fileName.startsWith("SRDR3")) && !fileName.endsWith(".bak")) { if ((fileName.startsWith("SGTA5") || fileName.startsWith("SRDR3")) && !fileName.endsWith(".bak")) {
@ -549,9 +569,9 @@ fileDialogPreOpen: //Work?
for (const QByteArray &imageFormat : QImageReader::supportedImageFormats()) { for (const QByteArray &imageFormat : QImageReader::supportedImageFormats()) {
imageFormatsStr += QString("*.") % QString::fromUtf8(imageFormat).toLower() % " "; imageFormatsStr += QString("*.") % QString::fromUtf8(imageFormat).toLower() % " ";
} }
QString importableFormatsStr = QString("*.g5e PGTA5*"); QString importableFormatsStr = QString("*.g5e PGTA5* PRDR3*");
if (!imageFormatsStr.trimmed().isEmpty()) { if (!imageFormatsStr.trimmed().isEmpty()) {
importableFormatsStr = QString("*.g5e%1PGTA5*").arg(imageFormatsStr); importableFormatsStr = QString("*.g5e%1PGTA5* PRDR3*").arg(imageFormatsStr);
} }
QStringList filters; QStringList filters;
@ -638,7 +658,7 @@ bool ProfileInterface::importFile(QString selectedFile, QDateTime importDateTime
{ {
QString selectedFileName = QFileInfo(selectedFile).fileName(); QString selectedFileName = QFileInfo(selectedFile).fileName();
if (QFile::exists(selectedFile)) { if (QFile::exists(selectedFile)) {
if ((selectedFileName.left(4) == "PGTA" && !selectedFileName.contains('.')) || selectedFileName.right(4) == ".g5e") { if ((selectedFileName.startsWith("PGTA5") && !selectedFileName.contains('.')) || selectedFileName.endsWith(".g5e")) {
SnapmaticPicture *picture = new SnapmaticPicture(selectedFile); SnapmaticPicture *picture = new SnapmaticPicture(selectedFile);
if (picture->readingPicture(true)) { if (picture->readingPicture(true)) {
bool success = importSnapmaticPicture(picture, notMultiple); bool success = importSnapmaticPicture(picture, notMultiple);
@ -735,22 +755,23 @@ bool ProfileInterface::importFile(QString selectedFile, QDateTime importDateTime
} }
SnapmaticProperties spJson = picture->getSnapmaticProperties(); SnapmaticProperties spJson = picture->getSnapmaticProperties();
spJson.uid = getRandomUid(); spJson.uid = getRandomUid();
bool fExists = QFile::exists(profileFolder % "/PGTA5" % QString::number(spJson.uid)); const QString fileFormat = getFileFormat(photoFormat);
bool fExistsBackup = QFile::exists(profileFolder % "/PGTA5" % QString::number(spJson.uid) % ".bak"); bool fExists = QFile::exists(profileFolder % "/" % fileFormat.arg(QString::number(spJson.uid)));
bool fExistsHidden = QFile::exists(profileFolder % "/PGTA5" % QString::number(spJson.uid) % ".hidden"); bool fExistsBackup = QFile::exists(profileFolder % "/" % fileFormat.arg(QString::number(spJson.uid)) % ".bak");
bool fExistsHidden = QFile::exists(profileFolder % "/" % fileFormat.arg(QString::number(spJson.uid)) % ".hidden");
int cEnough = 0; int cEnough = 0;
while ((fExists || fExistsBackup || fExistsHidden) && cEnough < findRetryLimit) { while ((fExists || fExistsBackup || fExistsHidden) && cEnough < findRetryLimit) {
spJson.uid = getRandomUid(); spJson.uid = getRandomUid();
fExists = QFile::exists(profileFolder % "/PGTA5" % QString::number(spJson.uid)); fExists = QFile::exists(profileFolder % "/" % fileFormat.arg(QString::number(spJson.uid)));
fExistsBackup = QFile::exists(profileFolder % "/PGTA5" % QString::number(spJson.uid) % ".bak"); fExistsBackup = QFile::exists(profileFolder % "/" % fileFormat.arg(QString::number(spJson.uid)) % ".bak");
fExistsHidden = QFile::exists(profileFolder % "/PGTA5" % QString::number(spJson.uid) % ".hidden"); fExistsHidden = QFile::exists(profileFolder % "/" % fileFormat.arg(QString::number(spJson.uid)) % ".hidden");
cEnough++; cEnough++;
} }
spJson.createdDateTime = importDateTime; spJson.createdDateTime = importDateTime;
qint64 timestamp = spJson.createdDateTime.toSecsSinceEpoch(); qint64 timestamp = spJson.createdDateTime.toSecsSinceEpoch();
spJson.createdTimestamp = timestamp; spJson.createdTimestamp = timestamp;
picture->setSnapmaticProperties(spJson); picture->setSnapmaticProperties(spJson);
const QString picFileName = QString("PGTA5%1").arg(QString::number(spJson.uid)); const QString picFileName = fileFormat.arg(QString::number(spJson.uid));
picture->setPicFileName(picFileName); picture->setPicFileName(picFileName);
picture->setPictureTitle(customImageTitle); picture->setPictureTitle(customImageTitle);
picture->updateStrings(); picture->updateStrings();
@ -786,22 +807,23 @@ bool ProfileInterface::importFile(QString selectedFile, QDateTime importDateTime
if (picture->setImage(importDialog->image(), importDialog->isUnlimitedBuffer())) { if (picture->setImage(importDialog->image(), importDialog->isUnlimitedBuffer())) {
SnapmaticProperties spJson = picture->getSnapmaticProperties(); SnapmaticProperties spJson = picture->getSnapmaticProperties();
spJson.uid = getRandomUid(); spJson.uid = getRandomUid();
bool fExists = QFile::exists(profileFolder % "/PGTA5" % QString::number(spJson.uid)); const QString fileFormat = getFileFormat(photoFormat);
bool fExistsBackup = QFile::exists(profileFolder % "/PGTA5" % QString::number(spJson.uid) % ".bak"); bool fExists = QFile::exists(profileFolder % "/" % fileFormat.arg(QString::number(spJson.uid)));
bool fExistsHidden = QFile::exists(profileFolder % "/PGTA5" % QString::number(spJson.uid) % ".hidden"); bool fExistsBackup = QFile::exists(profileFolder % "/" % fileFormat.arg(QString::number(spJson.uid)) % ".bak");
bool fExistsHidden = QFile::exists(profileFolder % "/" % fileFormat.arg(QString::number(spJson.uid)) % ".hidden");
int cEnough = 0; int cEnough = 0;
while ((fExists || fExistsBackup || fExistsHidden) && cEnough < findRetryLimit) { while ((fExists || fExistsBackup || fExistsHidden) && cEnough < findRetryLimit) {
spJson.uid = getRandomUid(); spJson.uid = getRandomUid();
fExists = QFile::exists(profileFolder % "/PGTA5" % QString::number(spJson.uid)); fExists = QFile::exists(profileFolder % "/" % fileFormat.arg(QString::number(spJson.uid)));
fExistsBackup = QFile::exists(profileFolder % "/PGTA5" % QString::number(spJson.uid) % ".bak"); fExistsBackup = QFile::exists(profileFolder % "/" % fileFormat.arg(QString::number(spJson.uid)) % ".bak");
fExistsHidden = QFile::exists(profileFolder % "/PGTA5" % QString::number(spJson.uid) % ".hidden"); fExistsHidden = QFile::exists(profileFolder % "/" % fileFormat.arg(QString::number(spJson.uid)) % ".hidden");
cEnough++; cEnough++;
} }
spJson.createdDateTime = importDateTime; spJson.createdDateTime = importDateTime;
qint64 timestamp = spJson.createdDateTime.toSecsSinceEpoch(); qint64 timestamp = spJson.createdDateTime.toSecsSinceEpoch();
spJson.createdTimestamp = timestamp; spJson.createdTimestamp = timestamp;
picture->setSnapmaticProperties(spJson); picture->setSnapmaticProperties(spJson);
const QString picFileName = QString("PGTA5%1").arg(QString::number(spJson.uid)); const QString picFileName = fileFormat.arg(QString::number(spJson.uid));
picture->setPicFileName(picFileName); picture->setPicFileName(picFileName);
picture->setPictureTitle(importDialog->getImageTitle()); picture->setPictureTitle(importDialog->getImageTitle());
picture->updateStrings(); picture->updateStrings();
@ -972,18 +994,7 @@ bool ProfileInterface::importImage(QImage *snapmaticImage, QDateTime importDateT
bool success = false; bool success = false;
if (importDialog.isImportAgreed()) { if (importDialog.isImportAgreed()) {
if (picture->setImage(importDialog.image(), importDialog.isUnlimitedBuffer())) { if (picture->setImage(importDialog.image(), importDialog.isUnlimitedBuffer())) {
QString fileFormat; const QString fileFormat = getFileFormat(photoFormat);
switch (photoFormat) {
case RagePhoto::PhotoFormat::GTA5:
fileFormat = "PGTA5%1";
break;
case RagePhoto::PhotoFormat::RDR2:
fileFormat = "PRDR3%1_1";
break;
default:
fileFormat = "%1.lrpx";
break;
}
SnapmaticProperties spJson = picture->getSnapmaticProperties(); SnapmaticProperties spJson = picture->getSnapmaticProperties();
spJson.uid = getRandomUid(); spJson.uid = getRandomUid();
bool fExists = QFile::exists(profileFolder % "/" % fileFormat.arg(QString::number(spJson.uid))); bool fExists = QFile::exists(profileFolder % "/" % fileFormat.arg(QString::number(spJson.uid)));

View file

@ -24,7 +24,6 @@
#include "ProfileDatabase.h" #include "ProfileDatabase.h"
#include "DatabaseThread.h" #include "DatabaseThread.h"
#include "SavegameWidget.h" #include "SavegameWidget.h"
#include "ProfileLoader.h"
#include "ProfileWidget.h" #include "ProfileWidget.h"
#include "ExportThread.h" #include "ExportThread.h"
#include "SavegameData.h" #include "SavegameData.h"
@ -102,7 +101,6 @@ private:
DatabaseThread *threadDB; DatabaseThread *threadDB;
Ui::ProfileInterface *ui; Ui::ProfileInterface *ui;
ProfileLoader *profileLoader;
ProfileWidget *previousWidget; ProfileWidget *previousWidget;
QList<SavegameData*> savegames; QList<SavegameData*> savegames;
QList<SnapmaticPicture*> pictures; QList<SnapmaticPicture*> pictures;

View file

@ -849,7 +849,7 @@ void UserInterface::on_actionSelect_Game_Folder_triggered()
gtaFolderLayout.addWidget(gtaLocation); gtaFolderLayout.addWidget(gtaLocation);
QToolButton *gtaSelectButton = new QToolButton(&gameFolderDialog); QToolButton *gtaSelectButton = new QToolButton(&gameFolderDialog);
gtaSelectButton->setText(QStringLiteral("...")); gtaSelectButton->setText(QStringLiteral("..."));
QObject::connect(gtaSelectButton, &QPushButton::clicked, &gameFolderDialog, [&](){ QObject::connect(gtaSelectButton, &QPushButton::clicked, &gameFolderDialog, [&,gtaLocation](){
const QString GTAV_Folder_Temp = QFileDialog::getExistingDirectory(&gameFolderDialog, tr("Select GTA V Folder..."), StandardPaths::documentsLocation(), QFileDialog::ShowDirsOnly); const QString GTAV_Folder_Temp = QFileDialog::getExistingDirectory(&gameFolderDialog, tr("Select GTA V Folder..."), StandardPaths::documentsLocation(), QFileDialog::ShowDirsOnly);
if (!GTAV_Folder_Temp.isEmpty() && QDir(GTAV_Folder_Temp).exists()) if (!GTAV_Folder_Temp.isEmpty() && QDir(GTAV_Folder_Temp).exists())
gtaLocation->setText(GTAV_Folder_Temp); gtaLocation->setText(GTAV_Folder_Temp);
@ -866,7 +866,7 @@ void UserInterface::on_actionSelect_Game_Folder_triggered()
rdrFolderLayout.addWidget(rdrLocation); rdrFolderLayout.addWidget(rdrLocation);
QToolButton *rdrSelectButton = new QToolButton(&gameFolderDialog); QToolButton *rdrSelectButton = new QToolButton(&gameFolderDialog);
rdrSelectButton->setText(QStringLiteral("...")); rdrSelectButton->setText(QStringLiteral("..."));
QObject::connect(rdrSelectButton, &QPushButton::clicked, &gameFolderDialog, [&](){ QObject::connect(rdrSelectButton, &QPushButton::clicked, &gameFolderDialog, [&,rdrLocation](){
const QString RDR2_Folder_Temp = QFileDialog::getExistingDirectory(&gameFolderDialog, tr("Select RDR 2 Folder..."), StandardPaths::documentsLocation(), QFileDialog::ShowDirsOnly); const QString RDR2_Folder_Temp = QFileDialog::getExistingDirectory(&gameFolderDialog, tr("Select RDR 2 Folder..."), StandardPaths::documentsLocation(), QFileDialog::ShowDirsOnly);
if (!RDR2_Folder_Temp.isEmpty() && QDir(RDR2_Folder_Temp).exists()) if (!RDR2_Folder_Temp.isEmpty() && QDir(RDR2_Folder_Temp).exists())
rdrLocation->setText(RDR2_Folder_Temp); rdrLocation->setText(RDR2_Folder_Temp);