From 7813c7b7b817154e6b8d8ba0dd982748a1dc20d0 Mon Sep 17 00:00:00 2001 From: Neil Date: Sat, 19 Aug 2023 15:35:29 -0700 Subject: [PATCH] Exception when loading config from an Uno Fixes #1275 --- MobiFlight/Config/Config.cs | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/MobiFlight/Config/Config.cs b/MobiFlight/Config/Config.cs index 5b9408027..b27aac4bd 100644 --- a/MobiFlight/Config/Config.cs +++ b/MobiFlight/Config/Config.cs @@ -44,8 +44,9 @@ public List ToInternal(int MaxMessageLength) // Its data is embedded (redundantly) in mux client devices String current = item.ToInternal(); - - if ((message.Length + current.Length) > MaxMessageLength && message.Length > 0) { + + if ((message.Length + current.Length) > MaxMessageLength && message.Length > 0) + { result.Add(message); message = ""; } @@ -150,13 +151,14 @@ public Config FromInternal(String value, bool throwException = false) case DeviceType.InputMultiplexer: // If the multiplexerDriver is to be implicitly defined by clients: // Build multiplexerDriver if none found yet - if (multiplexerDriver == null) { + if (multiplexerDriver == null) + { // Store it, so another clients will not create a new one multiplexerDriver = new MobiFlight.Config.MultiplexerDriver(); // The MultiplexerDriver is registered as a "ghost" device in Config's items list; it won't be shown in the GUI tree. Items.Add(multiplexerDriver); - //} else { - // multiplexerDriver.registerClient(); + //} else { + // multiplexerDriver.registerClient(); } multiplexerDriver.FromInternal(InputMultiplexer.GetMultiplexerDriverConfig(item + BaseDevice.End)); @@ -174,16 +176,16 @@ public Config FromInternal(String value, bool throwException = false) currentItem.FromInternal(item + BaseDevice.End); break; - // If the multiplexerDriver is to be explicitly defined by its own config line, - // following 'case' is required: + // If the multiplexerDriver is to be explicitly defined by its own config line, + // following 'case' is required: - //case DeviceType.MultiplexerDriver: + //case DeviceType.MultiplexerDriver: //if (multiplexerDriver == null) { // multiplexerDriver = new MobiFlight.Config.MultiplexerDriver(); // currentItem = multiplexerDriver; // currentItem.FromInternal(item + BaseDevice.End); - //} else { - // multiplexerDriver.registerClient(); + //} else { + // multiplexerDriver.registerClient(); //} //break; } @@ -207,6 +209,13 @@ public Config FromInternal(String value, bool throwException = false) else return this; } + catch (Exception ex) + { + if (throwException) + throw new Exception("Config not valid.", ex); + else + return this; + } } return this;