Basic principles of backward/downward compatibility of files
Requirement
After users installed the latest version of the software, accessing an older file or database requires that the software must ensure correct reading of these files. This is necessary for maintaining backward compatibility with files.
Basic Principle
First, it's necessary to save a file's version number into the directory. Perhaps we can refer to it as FileVersionNo. It must be clarified that this version number differs from a software version number.
2st, during the process of loading a file, access the FileVersionNo from the file and assign it to the variable LoadedFileVersionNo.
In step 3, we refer to the file version number that the current software supports as CurrentFileVersionNo. During the loading process, we compare LoadedFileVersionNo with CurrentFileVersionNo and then direct the code to execute a specific flow based on the outcome of this comparison.
if (LoadedFileVersionNo < CurrentFileVersionNo ) {
/// read the data according to old file version data format.
} else {
/// read the data according to the current file version data format.
}
Warm Tips
- The file header must include an identifier for verifying the file format.
- To manage this efficiently, the version number must be included within the header section. For reasons such as controlling the loading process effectively and ensuring proper initialization of data structures, placing it elsewhere would complicate operations and risk misalignment with subsequent processing steps.
