From 934c11a7d7ad1bc946ff0c330264e3b318503274 Mon Sep 17 00:00:00 2001
From: tuxuser <462620+tuxuser@users.noreply.github.com>
Date: Fri, 24 Jul 2026 07:54:43 +0200
Subject: [PATCH] feat: Enforce version check for FW + do not attempt to load
metadata of unknown format-version
---
.../Assets/Resources.pt-BR.resx | 2 +-
PostCodeSerialMonitor/Assets/Resources.resx | 2 +-
.../Services/MetaUpdateService.cs | 18 +++++++++++++++++-
.../Services/SerialService.cs | 4 +++-
4 files changed, 22 insertions(+), 4 deletions(-)
diff --git a/PostCodeSerialMonitor/Assets/Resources.pt-BR.resx b/PostCodeSerialMonitor/Assets/Resources.pt-BR.resx
index 6ba45a0..db3d41a 100644
--- a/PostCodeSerialMonitor/Assets/Resources.pt-BR.resx
+++ b/PostCodeSerialMonitor/Assets/Resources.pt-BR.resx
@@ -190,7 +190,7 @@
In Services/SerialService.cs
- Falha ao processar a informação sobre a versão. Você está usando o firwmare v0.2.3 ou superior?
+ Falha na verificação da versão do firmware. Você está com o firmware mais recente do PicoDurangoPOST?
In Services/SerialService.cs
diff --git a/PostCodeSerialMonitor/Assets/Resources.resx b/PostCodeSerialMonitor/Assets/Resources.resx
index 0ff1d4d..bba7703 100644
--- a/PostCodeSerialMonitor/Assets/Resources.resx
+++ b/PostCodeSerialMonitor/Assets/Resources.resx
@@ -190,7 +190,7 @@
In Services/SerialService.cs
- Failed to parse version information. Are you on FW v0.2.3 or greater?
+ Firmware version check failed. Are you on latest PicoDurangoPOST FW?
In Services/SerialService.cs
diff --git a/PostCodeSerialMonitor/Services/MetaUpdateService.cs b/PostCodeSerialMonitor/Services/MetaUpdateService.cs
index c2c87bb..ed48cb1 100644
--- a/PostCodeSerialMonitor/Services/MetaUpdateService.cs
+++ b/PostCodeSerialMonitor/Services/MetaUpdateService.cs
@@ -19,6 +19,7 @@ public class MetaUpdateService
private readonly HttpClient _httpClient;
private readonly ILogger _logger;
private const string META_FILENAME = "meta.json";
+ private const int SUPPORTED_META_FORMAT_VERSION = 2;
private MetaDefinition? _currentMeta;
public string LocalMetaPath => Path.Combine(_localPath, META_FILENAME);
@@ -130,6 +131,9 @@ private async Task DownloadMetaFilesAsync()
{
var json = await File.ReadAllTextAsync(LocalMetaPath);
var res = JsonSerializer.Deserialize(json, _jsonSerializeOptions);
+ if (res != null && !IsSupportedFormatVersion(res))
+ return null;
+
_currentMeta = res;
return res;
}
@@ -148,7 +152,8 @@ private async Task DownloadMetaFilesAsync()
response.EnsureSuccessStatusCode();
var json = await response.Content.ReadAsStringAsync();
- return JsonSerializer.Deserialize(json, _jsonSerializeOptions);
+ var res = JsonSerializer.Deserialize(json, _jsonSerializeOptions);
+ return res != null && !IsSupportedFormatVersion(res) ? null : res;
}
catch (Exception ex)
{
@@ -156,4 +161,15 @@ private async Task DownloadMetaFilesAsync()
return null;
}
}
+
+ private bool IsSupportedFormatVersion(MetaDefinition meta)
+ {
+ if (meta.FormatVersion == SUPPORTED_META_FORMAT_VERSION)
+ return true;
+
+ _logger.LogError(
+ "Metadata format version {ActualVersion} is not supported (expected {ExpectedVersion}). Please update the metadata.",
+ meta.FormatVersion, SUPPORTED_META_FORMAT_VERSION);
+ return false;
+ }
}
\ No newline at end of file
diff --git a/PostCodeSerialMonitor/Services/SerialService.cs b/PostCodeSerialMonitor/Services/SerialService.cs
index daa7d5a..6e5c23b 100644
--- a/PostCodeSerialMonitor/Services/SerialService.cs
+++ b/PostCodeSerialMonitor/Services/SerialService.cs
@@ -28,6 +28,8 @@ public class SerialService : IDisposable
public event Action? DeviceStateChanged;
public event Action? DeviceConfigChanged;
+ public const string MinimumFirmwareVersion = "v0.4.0";
+
public string FirmwareVersion { get; private set; } = string.Empty;
public string BuildDate { get; private set; } = string.Empty;
@@ -167,7 +169,7 @@ public async Task ConnectAsync(string portName, int baudRate = 115200)
_serialPort.WriteLine("version");
Thread.Sleep(100);
success = await ParseVersionInfo();
- if (!success)
+ if (!success || new SemanticVersion(FirmwareVersion) < new SemanticVersion(MinimumFirmwareVersion))
{
Disconnect();
throw new Exception(Assets.Resources.FailedFwVersion);