Closed delphidabbler closed 1 year ago
Here's some possible code for writing the version number to the config file:
type
TConfig = class(TObject)
// ...
public
const
MapFilesRelativeRoot = 'config\mappings';
ConfigFileRelativeName = 'config\config.data';
ConfigFileVersion = 1;
ConfigFileVersionKey = 'config.version';
CurrentMappingKey = 'current.mapping';
KeyValueSeparator = ':';
// ...
end;
// ..
class procedure TConfig.TPersistentData.Save;
begin
Data[TConfig.ConfigFileVersionKey] := TConfig.ConfigFileVersion;
TDirectory.CreateDirectory(TPath.GetDirectoryName(ConfigFilePath));
Data.SaveToFile(ConfigFilePath, TConfig.TextFileEncoding);
end;
Version number is actually contained in header:
Unit2NS unit map file v1
so really, we need to get version from header instead of using a key in config file.
Also, we need to change "Unit2NS" to "DUSE".
Version number reading code will need to return 1 if header is
Unit2NS unit map file v1
and for version 2 or greater, parse version number from
DUSE unit map file vX
where X
is the version number from 2 upwards. Best to allow for possible two and three digit version numbers.
Got a bit confused. There are two files here to consider:
config.data
file, which has no header.Unit2NS unit map file v1
headerImplemented by merge commit 1242ba6
TConfig
does not write version numbers to the file. Version numbers could be useful in future, so I think they should be added now.In the future, the version when new items are added should be documented. The version number should be bumped by 1 when new keys are added.
Code that reads the file can make decisions on how to interpret older versions based on the version number.
We will assume that files without a version number are version 0. Luckily, there's only one config item at the time of writing and that has been there from the start.
Adding the version number config item should cause a version number bump to 1.