mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-28 05:00:20 +00:00
Simplify creation of the upload file for Divelogs.de
Instead of writing each dive out to a file and reading that file back in, let's just use the internal helper function that places the dive as XML into a membuffer. So much simpler, so much faster. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
f4677d7604
commit
3a715c2299
1 changed files with 8 additions and 25 deletions
|
@ -7,6 +7,7 @@
|
|||
#include "globe.h"
|
||||
#include "maintab.h"
|
||||
#include "display.h"
|
||||
#include "membuffer.h"
|
||||
#include <errno.h>
|
||||
|
||||
#include <QDir>
|
||||
|
@ -145,11 +146,12 @@ bool DivelogsDeWebServices::prepare_dives_for_divelogs(const QString &tempfile,
|
|||
/* walk the dive list in chronological order */
|
||||
int i;
|
||||
struct dive *dive;
|
||||
struct membuffer mb = { 0 };
|
||||
for_each_dive (i, dive) {
|
||||
FILE *f;
|
||||
char filename[PATH_MAX];
|
||||
int streamsize;
|
||||
char *membuf;
|
||||
const char *membuf;
|
||||
xmlDoc *transformed;
|
||||
struct zip_source *s;
|
||||
|
||||
|
@ -159,29 +161,11 @@ bool DivelogsDeWebServices::prepare_dives_for_divelogs(const QString &tempfile,
|
|||
*/
|
||||
if (selected && !dive->selected)
|
||||
continue;
|
||||
QString innerTmpFile = tempfile;
|
||||
QString tmpSuffix = QString::number(qrand() % 9999) + ".tmp";
|
||||
innerTmpFile.replace(".dld", tmpSuffix);
|
||||
f = subsurface_fopen(QFile::encodeName(QDir::toNativeSeparators(innerTmpFile)), "w+");
|
||||
if (!f) {
|
||||
report_error(tr("cannot create temporary file: %s").toUtf8(), qt_error_string().toUtf8().data());
|
||||
goto error_close_zip;
|
||||
}
|
||||
save_dive(f, dive);
|
||||
fseek(f, 0, SEEK_END);
|
||||
streamsize = ftell(f);
|
||||
rewind(f);
|
||||
|
||||
membuf = (char *)malloc(streamsize + 1);
|
||||
if (!membuf || (streamsize = fread(membuf, 1, streamsize, f)) == 0) {
|
||||
report_error(tr("internal error: %s").toUtf8(), qt_error_string().toUtf8().data());
|
||||
fclose(f);
|
||||
free((void *)membuf);
|
||||
goto error_close_zip;
|
||||
}
|
||||
membuf[streamsize] = 0;
|
||||
fclose(f);
|
||||
unlink(QFile::encodeName(QDir::toNativeSeparators(innerTmpFile)));
|
||||
/* make sure the buffer is empty and add the dive */
|
||||
mb.len = 0;
|
||||
save_one_dive_to_mb(&mb, dive);
|
||||
membuf = mb_cstring(&mb);
|
||||
streamsize = strlen(membuf);
|
||||
/*
|
||||
* Parse the memory buffer into XML document and
|
||||
* transform it to divelogs.de format, finally dumping
|
||||
|
@ -191,7 +175,6 @@ bool DivelogsDeWebServices::prepare_dives_for_divelogs(const QString &tempfile,
|
|||
if (!doc) {
|
||||
qWarning() << errPrefix << "could not parse back into memory the XML file we've just created!";
|
||||
report_error(tr("internal error").toUtf8());
|
||||
free((void *)membuf);
|
||||
goto error_close_zip;
|
||||
}
|
||||
free((void *)membuf);
|
||||
|
|
Loading…
Reference in a new issue