Logbook file open/close changes

Fixed seg fault opening invalid or empty logbook file
Changed to allow saving an empty adif logbook file
pull/2/head
David Freese 2008-12-08 04:02:32 -06:00
rodzic 90224b77dc
commit bd3a8a292b
2 zmienionych plików z 10 dodań i 2 usunięć

Wyświetl plik

@ -1,5 +1,7 @@
#include <FL/Fl.H>
#include <FL/filename.H>
#include <FL/fl_ask.H>
#include "adif_io.h"
#include "config.h"
@ -118,7 +120,12 @@ void cAdifIO::readFile (const char *fname, cQsoDb *db) {
fread (buff, filesize, 1, adiFile);
fclose (adiFile);
char *p1 = buff, *p2;
if (filesize == 0 || (strstr( buff, "<ADIF_VERS:")) == 0) {
fl_message("Not an ADIF log file");
return;
}
char *p1 = buff, *p2;
// is there a header?
if (*p1 != '<') { // yes find the start of the records
p1 = strchr(buff, '<');

Wyświetl plik

@ -130,10 +130,11 @@ void cb_mnuOpenLogbook(Fl_Menu_* m, void* d)
}
void cb_mnuSaveLogbook(Fl_Menu_*m, void* d) {
if (qsodb.nbrRecs() == 0) return;
const char* p = FSEL::saveas("Save logbook file", "ADIF\t*." ADIF_SUFFIX,
logbook_filename.c_str());
if (p) {
logbook_filename = p;
dlgLogbook->label(fl_filename_name(logbook_filename.c_str()));
if (adifFile.writeLog (p, &qsodb))
fl_message ("Could not write to %s", p);
qsodb.isdirty(0);