core: move data file version functions into version.cpp/h

It is unclear why these were located in divelist.cpp/h.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2024-06-25 14:33:36 +02:00 committed by bstoeger
parent 72bb38601d
commit 60c7b503cf
9 changed files with 44 additions and 34 deletions

View file

@ -21,6 +21,7 @@
#include "selection.h"
#include "sample.h"
#include "trip.h"
#include "version.h"
#include <time.h>
@ -767,19 +768,6 @@ dive *dive_table::get_by_uniq_id(int id) const
return it != end() ? it->get() : nullptr;
}
static int min_datafile_version;
int get_min_datafile_version()
{
return min_datafile_version;
}
void report_datafile_version(int version)
{
if (min_datafile_version == 0 || min_datafile_version > version)
min_datafile_version = version;
}
void clear_dive_file_data()
{
fulltext_unregister_all();
@ -790,7 +778,7 @@ void clear_dive_file_data()
clear_event_types();
min_datafile_version = 0;
clear_min_datafile_version();
clear_git_id();
reset_tank_info_table(tank_info_table);

View file

@ -48,11 +48,6 @@ private:
std::array<std::unique_ptr<dive>, 2> split_dive_at(const struct dive &dive, int a, int b) const;
};
/* this is used for both git and xml format */
#define DATAFORMAT_VERSION 3
int get_min_datafile_version();
void report_datafile_version(int version);
void clear_dive_file_data();
extern bool has_dive(unsigned int deviceid, unsigned int diveid);

View file

@ -15,21 +15,22 @@
#include "gettext.h"
#include "device.h"
#include "dive.h"
#include "divelog.h"
#include "divesite.h"
#include "event.h"
#include "errorhelper.h"
#include "sample.h"
#include "subsurface-string.h"
#include "event.h"
#include "format.h"
#include "trip.h"
#include "device.h"
#include "git-access.h"
#include "picture.h"
#include "qthelper.h"
#include "tag.h"
#include "sample.h"
#include "subsurface-string.h"
#include "subsurface-time.h"
#include "tag.h"
#include "trip.h"
#include "version.h"
// TODO: Should probably be moved to struct divelog to allow for multi-document
std::string saved_git_id;
@ -920,8 +921,8 @@ static void parse_settings_version(char *line, struct git_parser_state *)
{
int version = atoi(line);
report_datafile_version(version);
if (version > DATAFORMAT_VERSION)
report_error("Git save file version %d is newer than version %d I know about", version, DATAFORMAT_VERSION);
if (version > dataformat_version)
report_error("Git save file version %d is newer than version %d I know about", version, dataformat_version);
}
/* The argument string is the version string of subsurface that saved things, just FYI */

View file

@ -35,6 +35,7 @@
#include "range.h"
#include "sample.h"
#include "tag.h"
#include "version.h"
#include "xmlparams.h"
int last_xml_version = -1;

View file

@ -857,7 +857,7 @@ static void save_settings(git_repository *repo, struct dir *tree)
{
membuffer b;
put_format(&b, "version %d\n", DATAFORMAT_VERSION);
put_format(&b, "version %d\n", dataformat_version);
for (auto &dev: divelog.devices)
save_one_device(&b, dev);
/* save the fingerprint data */

View file

@ -12,19 +12,19 @@
#include <unistd.h>
#include <fcntl.h>
#include "device.h"
#include "dive.h"
#include "divelog.h"
#include "divesite.h"
#include "errorhelper.h"
#include "extradata.h"
#include "event.h"
#include "filterconstraint.h"
#include "filterpreset.h"
#include "sample.h"
#include "subsurface-string.h"
#include "subsurface-time.h"
#include "trip.h"
#include "device.h"
#include "event.h"
#include "file.h"
#include "membuffer.h"
#include "picture.h"
@ -32,6 +32,7 @@
#include "qthelper.h"
#include "gettext.h"
#include "tag.h"
#include "version.h"
#include "xmlparams.h"
/*
@ -632,7 +633,7 @@ static void save_filter_presets(struct membuffer *b)
static void save_dives_buffer(struct membuffer *b, bool select_only, bool anonymize)
{
put_format(b, "<divelog program='subsurface' version='%d'>\n<settings>\n", DATAFORMAT_VERSION);
put_format(b, "<divelog program='subsurface' version='%d'>\n<settings>\n", dataformat_version);
/* save the dive computer nicknames, if any */
for (auto &d: divelog.devices) {
@ -743,7 +744,7 @@ static void try_to_backup(const char *filename)
while (extension[i][0] != '\0') {
int elen = strlen(extension[i]);
if (strcasecmp(filename + flen - elen, extension[i]) == 0) {
if (last_xml_version < DATAFORMAT_VERSION) {
if (last_xml_version < dataformat_version) {
std::string special_ext = std::string(extension[i]) + ".v" + std::to_string(last_xml_version);
save_backup(filename, extension[i], special_ext.c_str());
} else {
@ -851,7 +852,7 @@ static int export_dives_xslt_doit(const char *filename, struct xml_params *param
static void save_dive_sites_buffer(struct membuffer *b, const struct dive_site *sites[], int nr_sites, bool anonymize)
{
int i;
put_format(b, "<divesites program='subsurface' version='%d'>\n", DATAFORMAT_VERSION);
put_format(b, "<divesites program='subsurface' version='%d'>\n", dataformat_version);
/* save the dive sites */
for (i = 0; i < nr_sites; i++) {

View file

@ -11,3 +11,21 @@ const char *subsurface_canonical_version()
{
return CANONICAL_VERSION_STRING;
}
static int min_datafile_version = 0;
int get_min_datafile_version()
{
return min_datafile_version;
}
void report_datafile_version(int version)
{
if (min_datafile_version == 0 || min_datafile_version > version)
min_datafile_version = version;
}
int clear_min_datafile_version()
{
return min_datafile_version;
}

View file

@ -1,7 +1,13 @@
#ifndef VERSION_H
#define VERSION_H
/* this is used for both git and xml format */
static constexpr int dataformat_version = 3;
const char *subsurface_git_version();
const char *subsurface_canonical_version();
int get_min_datafile_version();
void report_datafile_version(int version);
int clear_min_datafile_version();
#endif

View file

@ -1328,7 +1328,7 @@ void MainWindow::loadFiles(const std::vector<std::string> &fileNames)
updateAutogroup();
int min_datafile_version = get_min_datafile_version();
if (min_datafile_version >0 && min_datafile_version < DATAFORMAT_VERSION) {
if (min_datafile_version >0 && min_datafile_version < dataformat_version) {
QMessageBox::warning(this, tr("Opening datafile from older version"),
tr("You opened a data file from an older version of Subsurface. We recommend "
"you read the manual to learn about the changes in the new version, especially "