diff --git a/ProfileInterface.cpp b/ProfileInterface.cpp index d51847c..3e52093 100644 --- a/ProfileInterface.cpp +++ b/ProfileInterface.cpp @@ -607,7 +607,7 @@ bool ProfileInterface::importFile(QString selectedFile, QDateTime importDateTime if ((selectedFileName.left(4) == "PGTA" && !selectedFileName.contains('.')) || selectedFileName.right(4) == ".g5e") { SnapmaticPicture *picture = new SnapmaticPicture(selectedFile); - if (picture->readingPicture(true, true, true)) + if (picture->readingPicture(true)) { bool success = importSnapmaticPicture(picture, notMultiple); if (!success) delete picture; @@ -678,7 +678,7 @@ bool ProfileInterface::importFile(QString selectedFile, QDateTime importDateTime else if (isSupportedImageFile(selectedFileName)) { SnapmaticPicture *picture = new SnapmaticPicture(":/template/template.g5e"); - if (picture->readingPicture(true, false, true, false)) + if (picture->readingPicture(false)) { if (!notMultiple) { @@ -1048,7 +1048,7 @@ bool ProfileInterface::importRemote(QUrl remoteUrl) bool ProfileInterface::importImage(QImage *snapmaticImage, QDateTime importDateTime) { SnapmaticPicture *picture = new SnapmaticPicture(":/template/template.g5e"); - if (picture->readingPicture(true, false, true, false)) + if (picture->readingPicture(false)) { bool success = false; ImportDialog *importDialog = new ImportDialog(profileName, this); diff --git a/ProfileLoader.cpp b/ProfileLoader.cpp index 9a290a0..78482d2 100644 --- a/ProfileLoader.cpp +++ b/ProfileLoader.cpp @@ -76,7 +76,7 @@ void ProfileLoader::run() emit loadingProgress(curFile, maximumV); QString picturePath = profileFolder % "/" % SnapmaticPic; SnapmaticPicture *picture = new SnapmaticPicture(picturePath); - if (picture->readingPicture(true, true, true)) + if (picture->readingPicture(true)) { if (picture->isFormatSwitched()) { diff --git a/RagePhoto.cpp b/RagePhoto.cpp index d3b270b..ff778c4 100644 --- a/RagePhoto.cpp +++ b/RagePhoto.cpp @@ -135,13 +135,13 @@ bool RagePhoto::load() size = dataBuffer.read(photoSize, 4); if (size != 4) return false; - p_photoSize = charToUInt32LE(photoSize); + quint32 t_photoSize = charToUInt32LE(photoSize); - char photoData[p_photoSize]; - size = dataBuffer.read(photoData, p_photoSize); - if (size != p_photoSize) + char photoData[t_photoSize]; + size = dataBuffer.read(photoData, t_photoSize); + if (size != t_photoSize) return false; - p_photoData = QByteArray(photoData, p_photoSize); + p_photoData = QByteArray(photoData, t_photoSize); dataBuffer.seek(p_jsonOffset + 264); char jsonMarker[4]; @@ -279,7 +279,6 @@ bool RagePhoto::load() return false; QByteArray t_photoData = QByteArray::fromRawData(compressedPhoto, i_photoSize); p_photoData = qUncompress(t_photoData); - p_photoSize = p_photoData.size(); char jsonOffset[4]; size = dataBuffer.read(jsonOffset, 4); @@ -419,7 +418,8 @@ bool RagePhoto::setJsonData(const QByteArray &data) bool RagePhoto::setPhotoData(const QByteArray &data) { - if ((quint32)data.size() > p_photoSize) + quint32 size = data.size(); + if (size > p_jpegBuffer) return false; p_photoData = data; return true; @@ -427,7 +427,7 @@ bool RagePhoto::setPhotoData(const QByteArray &data) bool RagePhoto::setPhotoData(const char *data, int size) { - if ((quint32)size > p_photoSize) + if ((quint32)size > p_jpegBuffer) return false; p_photoData = QByteArray(data, size); return true; @@ -478,6 +478,11 @@ quint32 RagePhoto::photoBuffer() return p_jpegBuffer; } +quint32 RagePhoto::photoSize() +{ + return p_photoData.size(); +} + RagePhoto::PhotoFormat RagePhoto::photoFormat() { return p_photoFormat; diff --git a/RagePhoto.h b/RagePhoto.h index c05198b..26491e0 100644 --- a/RagePhoto.h +++ b/RagePhoto.h @@ -62,6 +62,7 @@ public: const QString photoString(); const QString title(); quint32 photoBuffer(); + quint32 photoSize(); PhotoFormat photoFormat(); static RagePhoto* loadFile(const QString &filePath); @@ -85,7 +86,6 @@ private: quint32 p_headerSum; quint32 p_jpegBuffer; quint32 p_jsonOffset; - quint32 p_photoSize; quint32 p_titlOffset; bool p_isLoaded; int p_inputMode; diff --git a/SnapmaticPicture.cpp b/SnapmaticPicture.cpp index 15ed523..b193754 100644 --- a/SnapmaticPicture.cpp +++ b/SnapmaticPicture.cpp @@ -112,11 +112,8 @@ bool SnapmaticPicture::preloadFile() return ok; } -bool SnapmaticPicture::readingPicture(bool writeEnabled_, bool cacheEnabled_, bool fastLoad, bool lowRamMode_) +bool SnapmaticPicture::readingPicture(bool cacheEnabled_) { - Q_UNUSED(fastLoad) - Q_UNUSED(lowRamMode_) - Q_UNUSED(writeEnabled_) // Start opening file // lastStep is like currentStep @@ -166,12 +163,12 @@ void SnapmaticPicture::updateStrings() picExportFileName = exportStr % "_" % cmpPicTitl; } -bool SnapmaticPicture::readingPictureFromFile(const QString &fileName, bool writeEnabled_, bool cacheEnabled_, bool fastLoad, bool lowRamMode_) +bool SnapmaticPicture::readingPictureFromFile(const QString &fileName, bool cacheEnabled_) { if (!fileName.isEmpty()) { picFilePath = fileName; - return readingPicture(writeEnabled_, cacheEnabled_, fastLoad, lowRamMode_); + return readingPicture(cacheEnabled_); } else { @@ -221,6 +218,11 @@ bool SnapmaticPicture::setPictureTitl(const QString &newTitle_) return false; } +int SnapmaticPicture::getContentMaxLength() +{ + return ragePhoto.photoBuffer(); +} + QString SnapmaticPicture::getExportPictureFileName() { return picExportFileName; diff --git a/SnapmaticPicture.h b/SnapmaticPicture.h index 06eb934..15c4b27 100644 --- a/SnapmaticPicture.h +++ b/SnapmaticPicture.h @@ -58,8 +58,8 @@ public: ~SnapmaticPicture(); void reset(); bool preloadFile(); - bool readingPictureFromFile(const QString &fileName, bool writeEnabled = true, bool cacheEnabled = false, bool fastLoad = true, bool lowRamMode = false); - bool readingPicture(bool writeEnabled = true, bool cacheEnabled = false, bool fastLoad = true, bool lowRamMode = false); + bool readingPictureFromFile(const QString &fileName, bool cacheEnabled = false); + bool readingPicture(bool cacheEnabled = false); bool isPicOk(); // Please use isPictureOk instead void clearCache(); QImage getImage(bool fastLoad = false); @@ -73,6 +73,7 @@ public: QString getExportPictureFileName(); QString getOriginalPictureFileName(); QString getOriginalPictureFilePath(); + int getContentMaxLength(); bool setImage(const QImage &picture); bool setPictureTitl(const QString &newTitle); // Please use setPictureTitle instead bool setPictureStream(const QByteArray &streamArray);