mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Git storage: implement picture loading from git
The interesting challenge here is what to do with the picture data stored in the git repository. If the pictures are already in the file system (for example because Subsurface is runnin on the same machine that this data file was saved on) it would be silly to extract them again every time the dive log is opened. So instead we try to figure out if the pictures can be located and only create local copies of them if that isn't the case. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
785f9ba835
commit
31fbc16785
3 changed files with 88 additions and 1 deletions
30
qthelper.cpp
30
qthelper.cpp
|
|
@ -377,7 +377,8 @@ extern "C" void copy_image_and_overwrite(const char *cfileName, const char *cnew
|
|||
QFile file(newName);
|
||||
if (file.exists())
|
||||
file.remove();
|
||||
QFile::copy(fileName, newName);
|
||||
if (!QFile::copy(fileName, newName))
|
||||
qDebug() << "copy of" << fileName << "to" << newName << "failed";
|
||||
}
|
||||
|
||||
extern "C" bool string_sequence_contains(const char *string_sequence, const char *text)
|
||||
|
|
@ -887,6 +888,33 @@ extern "C" const char *local_file_path(struct picture *picture)
|
|||
return strdup(qPrintable(localFileName));
|
||||
}
|
||||
|
||||
extern "C" bool picture_exists(struct picture *picture)
|
||||
{
|
||||
QString localFilename = fileFromHash(picture->hash);
|
||||
QByteArray hash = hashFile(localFilename);
|
||||
return same_string(hash.toHex().data(), picture->hash);
|
||||
}
|
||||
|
||||
/* when we get a picture from git storage (local or remote) and can't find the picture
|
||||
* based on its hash, we create a local copy with the hash as filename and the appropriate
|
||||
* suffix */
|
||||
extern "C" void savePictureLocal(struct picture *picture, const char *data, int len)
|
||||
{
|
||||
QString dirname(system_default_directory());
|
||||
dirname += "/picturedata/";
|
||||
QDir localPictureDir(dirname);
|
||||
localPictureDir.mkpath(dirname);
|
||||
QString suffix(picture->filename);
|
||||
suffix.replace(QRegularExpression(".*\\."), "");
|
||||
QString filename(dirname + picture->hash + "." + suffix);
|
||||
QSaveFile out(filename);
|
||||
if (out.open(QIODevice::WriteOnly)) {
|
||||
out.write(data, len);
|
||||
out.commit();
|
||||
add_hash(filename, QByteArray::fromHex(picture->hash));
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" void picture_load_exif_data(struct picture *p)
|
||||
{
|
||||
EXIFInfo exif;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue