Skip to content

Commit fbcc068

Browse files
committed
Add backwards compatibility for legacy XML project files (data levels 3-5)
Reintroduce read-only support for the old XML-based .mbs project file format. The XML parser converts legacy files into the same ProjectSettings structure used by the JSON parser, including constructing the adapter settings JSON blob from XML connection/device elements. Saving always produces JSON v6, effectively auto-migrating old files. All XML-specific code is isolated in separate files (ProjectFileXmlParser) for easy future removal. The only change to existing code is a small format-detection branch in ProjectFileHandler::openProjectFile(). https://claude.ai/code/session_01Lyu9U25MtH34zG7gUFLe2u
1 parent 8de9368 commit fbcc068

9 files changed

Lines changed: 1512 additions & 2 deletions

src/importexport/projectfiledefinitions.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,26 @@ const char cModbusScopeTag[] = "modbusscope";
1010
const char cModbusTag[] = "modbus";
1111
const char cScopeTag[] = "scope";
1212
const char cViewTag[] = "view";
13+
const char cConnectionTag[] = "connection";
1314
const char cDeviceTag[] = "device";
1415
const char cDeviceIdTag[] = "deviceid";
1516
const char cDeviceNameTag[] = "name";
1617
const char cLogTag[] = "log";
18+
const char cConnectionIdTag[] = "connectionid";
19+
const char cConnectionEnabledTag[] = "enabled";
20+
const char cConnectionTypeTag[] = "type";
21+
const char cIpTag[] = "ip";
22+
const char cPortTag[] = "port";
23+
const char cPortNameTag[] = "portname";
24+
const char cBaudrateTag[] = "baudrate";
25+
const char cParityTag[] = "parity";
26+
const char cDataBitsTag[] = "databits";
27+
const char cStopBitsTag[] = "stopbits";
28+
const char cSlaveIdTag[] = "slaveid";
29+
const char cTimeoutTag[] = "timeout";
30+
const char cConsecutiveMaxTag[] = "consecutivemax";
31+
const char cInt32LittleEndianTag[] = "int32littleendian";
32+
const char cPersistentConnectionTag[] = "persistentconnection";
1733
const char cPollTimeTag[] = "polltime";
1834
const char cAbsoluteTimesTag[] = "absolutetimes";
1935
const char cLogToFileTag[] = "logtofile";
@@ -58,7 +74,9 @@ const char cAdapterSettingsKey[] = "settings";
5874
const char cAdapterIdKey[] = "adapterId";
5975
const char cAdapterKey[] = "adapter";
6076
const char cIdJsonKey[] = "id";
77+
const char cConnectionsJsonKey[] = "connections";
6178
const char cDevicesJsonKey[] = "devices";
79+
const char cConnectionTypeJsonKey[] = "connectiontype";
6280

6381
/* JSON constant values */
6482
const quint32 cMinimumJsonVersion = 6;

src/importexport/projectfilehandler.cpp

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "importexport/projectfiledata.h"
55
#include "importexport/projectfilejsonexporter.h"
66
#include "importexport/projectfilejsonparser.h"
7+
#include "importexport/projectfilexmlparser.h"
78
#include "models/device.h"
89
#include "models/graphdatamodel.h"
910
#include "models/guimodel.h"
@@ -35,8 +36,22 @@ void ProjectFileHandler::openProjectFile(QString projectFilePath)
3536
QTextStream in(&file);
3637
QString projectFileContents = in.readAll();
3738

38-
ProjectFileJsonParser jsonParser;
39-
GeneralError parseErr = jsonParser.parseFile(projectFileContents, &loadedSettings);
39+
GeneralError parseErr;
40+
QString trimmed = projectFileContents.trimmed();
41+
if (trimmed.startsWith('{'))
42+
{
43+
ProjectFileJsonParser jsonParser;
44+
parseErr = jsonParser.parseFile(projectFileContents, &loadedSettings);
45+
}
46+
else if (trimmed.startsWith('<'))
47+
{
48+
ProjectFileXmlParser xmlParser;
49+
parseErr = xmlParser.parseFile(projectFileContents, &loadedSettings);
50+
}
51+
else
52+
{
53+
parseErr.reportError(tr("The file is not a valid MBS project file."));
54+
}
4055

4156
if (parseErr.result())
4257
{

0 commit comments

Comments
 (0)