mirror of
				https://github.com/subsurface/subsurface.git
				synced 2025-02-19 22:16:15 +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 "globe.h" | ||||||
| #include "maintab.h" | #include "maintab.h" | ||||||
| #include "display.h" | #include "display.h" | ||||||
|  | #include "membuffer.h" | ||||||
| #include <errno.h> | #include <errno.h> | ||||||
| 
 | 
 | ||||||
| #include <QDir> | #include <QDir> | ||||||
|  | @ -145,11 +146,12 @@ bool DivelogsDeWebServices::prepare_dives_for_divelogs(const QString &tempfile, | ||||||
| 	/* walk the dive list in chronological order */ | 	/* walk the dive list in chronological order */ | ||||||
| 	int i; | 	int i; | ||||||
| 	struct dive *dive; | 	struct dive *dive; | ||||||
|  | 	struct membuffer mb = { 0 }; | ||||||
| 	for_each_dive (i, dive) { | 	for_each_dive (i, dive) { | ||||||
| 		FILE *f; | 		FILE *f; | ||||||
| 		char filename[PATH_MAX]; | 		char filename[PATH_MAX]; | ||||||
| 		int streamsize; | 		int streamsize; | ||||||
| 		char *membuf; | 		const char *membuf; | ||||||
| 		xmlDoc *transformed; | 		xmlDoc *transformed; | ||||||
| 		struct zip_source *s; | 		struct zip_source *s; | ||||||
| 
 | 
 | ||||||
|  | @ -159,29 +161,11 @@ bool DivelogsDeWebServices::prepare_dives_for_divelogs(const QString &tempfile, | ||||||
| 		 */ | 		 */ | ||||||
| 		if (selected && !dive->selected) | 		if (selected && !dive->selected) | ||||||
| 			continue; | 			continue; | ||||||
| 		QString innerTmpFile = tempfile; | 		/* make sure the buffer is empty and add the dive */ | ||||||
| 		QString tmpSuffix = QString::number(qrand() % 9999) + ".tmp"; | 		mb.len = 0; | ||||||
| 		innerTmpFile.replace(".dld", tmpSuffix); | 		save_one_dive_to_mb(&mb, dive); | ||||||
| 		f = subsurface_fopen(QFile::encodeName(QDir::toNativeSeparators(innerTmpFile)), "w+"); | 		membuf = mb_cstring(&mb); | ||||||
| 		if (!f) { | 		streamsize = strlen(membuf); | ||||||
| 			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))); |  | ||||||
| 		/*
 | 		/*
 | ||||||
| 		 * Parse the memory buffer into XML document and | 		 * Parse the memory buffer into XML document and | ||||||
| 		 * transform it to divelogs.de format, finally dumping | 		 * transform it to divelogs.de format, finally dumping | ||||||
|  | @ -191,7 +175,6 @@ bool DivelogsDeWebServices::prepare_dives_for_divelogs(const QString &tempfile, | ||||||
| 		if (!doc) { | 		if (!doc) { | ||||||
| 			qWarning() << errPrefix << "could not parse back into memory the XML file we've just created!"; | 			qWarning() << errPrefix << "could not parse back into memory the XML file we've just created!"; | ||||||
| 			report_error(tr("internal error").toUtf8()); | 			report_error(tr("internal error").toUtf8()); | ||||||
| 			free((void *)membuf); |  | ||||||
| 			goto error_close_zip; | 			goto error_close_zip; | ||||||
| 		} | 		} | ||||||
| 		free((void *)membuf); | 		free((void *)membuf); | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue