ddabapps / duse

A little tool for Delphi programmer to find the possible unit scopes that a unit belongs to
https://delphidabbler.com/software/unit2ns
MIT License
14 stars 2 forks source link

Add a version number to config file #26

Closed delphidabbler closed 1 year ago

delphidabbler commented 2 years ago

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.

delphidabbler commented 2 years 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;
delphidabbler commented 1 year ago

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.

delphidabbler commented 1 year ago

Got a bit confused. There are two files here to consider:

  1. The config.data file, which has no header.
  2. The map files, which have the Unit2NS unit map file v1 header
delphidabbler commented 1 year ago

Implemented by merge commit 1242ba6