Versioned configuration files
ZipJsonVersionedFile extends ZipJsonConfiguration and implements IVersionedFile. It validates file metadata at construction; it does not automatically migrate settings.
Create or open a file
lastVersion is the maximum version this reader accepts. fileType identifies the expected application format. createIfNotExist controls creation of missing metadata; it is not a file-system creation flag because the caller already supplies the stream.
Metadata representation
Metadata key lookup uses DefaultKeyComparer, so an existing fileinfo.json is recognized. Conflicting metadata entries are rejected before the constructor selects a value.
The reserved key FileInfo is stored as FileInfo.json and represented by the immutable ZipJsonFileInfo struct:
ZipJsonFileInfo.Empty contains two empty strings. The struct exposes value equality and equality operators. IVersionedFile.FileVersion returns the version accepted during construction.
Validation sequence
Load metadata, using
ZipJsonFileInfo.Emptyif it is absent.For empty metadata, create the requested version/type if creation is allowed; otherwise throw
ConfigurationException.For existing metadata, parse
FileVersionwithSemVersion.TryParseand reject an invalid version or a version newer thanlastVersion.Compare
FileTypewith the expected type usingCurrentCultureIgnoreCase; reject a mismatch.
Older versions are accepted without an upgrade. Opening an old file does not rewrite its metadata to lastVersion. Application code must interpret or migrate older settings explicitly.
Important limits
ReservedParts includes FileInfo, but normal Set and Remove operations do not enforce this reservation. Treat it as backend-owned metadata. Changing it after construction does not recalculate the instance's FileVersion field.
Loading missing metadata uses the regular default-creation path, which can add an empty FileInfo entry before creation is rejected. A failed open is therefore not guaranteed to leave the supplied archive untouched. Inspect untrusted files using a disposable copy when preserving the original bytes matters.
Keep migration logic version-specific and preserve a recoverable original before rewriting a file. Rejecting a future version protects format interpretation; it is not a signature or authenticity check. ZIP finalization and stream ownership follow Archive backends.