latest changes from gta5sync

This commit is contained in:
Syping 2017-10-12 22:21:45 +02:00
parent cfdc36d207
commit 4169e86f31
28 changed files with 943 additions and 773 deletions

View file

@ -33,6 +33,12 @@
#include <QSize>
#include <QFile>
#if QT_VERSION >= 0x050000
#include <QSaveFile>
#else
#include "StandardPaths.h"
#endif
// PARSER ALLOCATIONS
#define snapmaticHeaderLength 278
#define snapmaticUsefulLength 260
@ -546,6 +552,34 @@ QString SnapmaticPicture::getExportPictureFileName()
return picExportFileName;
}
QString SnapmaticPicture::getOriginalPictureFileName()
{
QString newPicFileName = picFileName;
if (picFileName.right(4) == ".bak")
{
newPicFileName = QString(picFileName).remove(picFileName.length() - 4, 4);
}
if (picFileName.right(7) == ".hidden")
{
newPicFileName = QString(picFileName).remove(picFileName.length() - 7, 7);
}
return newPicFileName;
}
QString SnapmaticPicture::getOriginalPictureFilePath()
{
QString newPicFilePath = picFilePath;
if (picFilePath.right(4) == ".bak")
{
newPicFilePath = QString(picFilePath).remove(picFilePath.length() - 4, 4);
}
if (picFilePath.right(7) == ".hidden")
{
newPicFilePath = QString(picFilePath).remove(picFilePath.length() - 7, 7);
}
return newPicFilePath;
}
QString SnapmaticPicture::getPictureFileName()
{
return picFileName;
@ -887,7 +921,13 @@ bool SnapmaticPicture::exportPicture(const QString &fileName, SnapmaticFormat fo
}
}
QFile *picFile = new QFile(fileName);
bool saveSuccess = false;
bool writeFailure = false;
#if QT_VERSION >= 0x050000
QSaveFile *picFile = new QSaveFile(fileName);
#else
QFile *picFile = new QFile(StandardPaths::tempLocation() % "/" % QFileInfo(fileName).fileName() % ".tmp");
#endif
if (picFile->open(QIODevice::WriteOnly))
{
if (format == SnapmaticFormat::G5E_Format)
@ -913,16 +953,22 @@ bool SnapmaticPicture::exportPicture(const QString &fileName, SnapmaticFormat fo
g5eHeader += QByteArray("FIL"); // Before File Name
g5eHeader += stockFileNameUTF8; // File Name
g5eHeader += QByteArray("COM"); // Before Compressed
picFile->write(g5eHeader);
if (picFile->write(g5eHeader) == -1) { writeFailure = true; }
if (!lowRamMode)
{
picFile->write(qCompress(rawPicContent, 9)); // Compressed Snapmatic
if (picFile->write(qCompress(rawPicContent, 9)) == -1) { writeFailure = true; } // Compressed Snapmatic
}
else
{
picFile->write(rawPicContent);
if (picFile->write(rawPicContent) == -1) { writeFailure = true; }
}
#if QT_VERSION >= 0x050000
if (writeFailure) { picFile->cancelWriting(); }
else { saveSuccess = picFile->commit(); }
#else
if (!writeFailure) { saveSuccess = true; }
picFile->close();
#endif
delete picFile;
}
else if (format == SnapmaticFormat::JPEG_Format)
@ -937,9 +983,15 @@ bool SnapmaticPicture::exportPicture(const QString &fileName, SnapmaticFormat fo
{
jpegRawContent = jpegRawContent.left(jpegRawContentSizeE);
}
picFile->write(jpegRawContent);
if (picFile->write(jpegRawContent) == -1) { writeFailure = true; }
#if QT_VERSION >= 0x050000
if (writeFailure) { picFile->cancelWriting(); }
else { saveSuccess = picFile->commit(); }
#else
if (!writeFailure) { saveSuccess = true; }
picFile->close();
#endif
}
picFile->close();
delete picFile;
}
else
@ -947,21 +999,49 @@ bool SnapmaticPicture::exportPicture(const QString &fileName, SnapmaticFormat fo
// Classic straight export
if (!lowRamMode)
{
picFile->write(rawPicContent);
if (picFile->write(rawPicContent) == -1) { writeFailure = true; }
}
else
{
picFile->write(qUncompress(rawPicContent));
if (picFile->write(qUncompress(rawPicContent)) == -1) { writeFailure = true; }
}
#if QT_VERSION >= 0x050000
if (writeFailure) { picFile->cancelWriting(); }
else { saveSuccess = picFile->commit(); }
#else
if (!writeFailure) { saveSuccess = true; }
picFile->close();
#endif
delete picFile;
}
return true;
#if QT_VERSION <= 0x050000
if (saveSuccess)
{
bool tempBakCreated = false;
if (QFile::exists(fileName))
{
if (!QFile::rename(fileName, fileName % ".tmp"))
{
QFile::remove(StandardPaths::tempLocation() % "/" % QFileInfo(fileName).fileName() % ".tmp");
return false;
}
tempBakCreated = true;
}
if (!QFile::rename(StandardPaths::tempLocation() % "/" % QFileInfo(fileName).fileName() % ".tmp", fileName))
{
QFile::remove(StandardPaths::tempLocation() % "/" % QFileInfo(fileName).fileName() % ".tmp");
if (tempBakCreated) { QFile::rename(fileName % ".tmp", fileName); }
return false;
}
if (tempBakCreated) { QFile::remove(fileName % ".tmp"); }
}
#endif
return saveSuccess;
}
else
{
delete picFile;
return false;
return saveSuccess;
}
}