mirror of https://github.com/xzeldon/htop.git
Introduce versioned config files and config_reader_min_version
This commit is contained in:
parent
dd91e9a9da
commit
4b59a2e6b7
12
Settings.c
12
Settings.c
|
@ -166,7 +166,15 @@ static bool Settings_read(Settings* this, const char* fileName, unsigned int ini
|
||||||
String_freeArray(option);
|
String_freeArray(option);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (String_eq(option[0], "fields")) {
|
if (String_eq(option[0], "config_reader_min_version")) {
|
||||||
|
this->config_version = atoi(option[1]);
|
||||||
|
if (this->config_version > CONFIG_READER_MIN_VERSION) {
|
||||||
|
// the version of the config file on disk is newer than what we can read
|
||||||
|
fprintf(stderr, "WARNING: The config file %s requires support for a newer format (v%d) than what this version of htop can read (v%d).\n", fileName, this->config_version, CONFIG_READER_MIN_VERSION);
|
||||||
|
fprintf(stderr, " It will be overwritten when this version of htop exits.\n");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else if (String_eq(option[0], "fields")) {
|
||||||
Settings_readFields(this, option[1]);
|
Settings_readFields(this, option[1]);
|
||||||
didReadFields = true;
|
didReadFields = true;
|
||||||
} else if (String_eq(option[0], "sort_key")) {
|
} else if (String_eq(option[0], "sort_key")) {
|
||||||
|
@ -326,6 +334,8 @@ int Settings_write(const Settings* this, bool onCrash) {
|
||||||
fprintf(fd, "# Beware! This file is rewritten by htop when settings are changed in the interface.\n");
|
fprintf(fd, "# Beware! This file is rewritten by htop when settings are changed in the interface.\n");
|
||||||
fprintf(fd, "# The parser is also very primitive, and not human-friendly.\n");
|
fprintf(fd, "# The parser is also very primitive, and not human-friendly.\n");
|
||||||
}
|
}
|
||||||
|
fprintf(fd, "htop_version=%s\n", VERSION);
|
||||||
|
fprintf(fd, "config_reader_min_version=%d\n", CONFIG_READER_MIN_VERSION);
|
||||||
writeFields(fd, this->fields, this->dynamicColumns, "fields");
|
writeFields(fd, this->fields, this->dynamicColumns, "fields");
|
||||||
// This "-1" is for compatibility with the older enum format.
|
// This "-1" is for compatibility with the older enum format.
|
||||||
fprintf(fd, "sort_key=%d\n", (int) this->sortKey - 1);
|
fprintf(fd, "sort_key=%d\n", (int) this->sortKey - 1);
|
||||||
|
|
|
@ -18,6 +18,8 @@ in the source distribution for its full text.
|
||||||
|
|
||||||
#define DEFAULT_DELAY 15
|
#define DEFAULT_DELAY 15
|
||||||
|
|
||||||
|
#define CONFIG_READER_MIN_VERSION 2
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int len;
|
int len;
|
||||||
char** names;
|
char** names;
|
||||||
|
@ -26,6 +28,7 @@ typedef struct {
|
||||||
|
|
||||||
typedef struct Settings_ {
|
typedef struct Settings_ {
|
||||||
char* filename;
|
char* filename;
|
||||||
|
int config_version;
|
||||||
MeterColumnSettings columns[2];
|
MeterColumnSettings columns[2];
|
||||||
Hashtable* dynamicColumns;
|
Hashtable* dynamicColumns;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue