|
21 | 21 | using System.Globalization; |
22 | 22 | using System.IO; |
23 | 23 | using System.Linq; |
| 24 | +using System.Text.RegularExpressions; |
24 | 25 | using System.Windows.Forms; |
25 | 26 | using GNU.Gettext; |
26 | 27 | using GNU.Gettext.WinForms; |
@@ -461,7 +462,7 @@ void buttonOK_Click(object sender, EventArgs e) |
461 | 462 | Settings.DistantMountainsViewingDistance = (int)numericDistantMountainsViewingDistance.Value * 1000; |
462 | 463 | Settings.ViewingFOV = (int)numericViewingFOV.Value; |
463 | 464 | Settings.WorldObjectDensity = (int)numericWorldObjectDensity.Value; |
464 | | - Settings.WindowSize = GetValidWindowSize(comboWindowSize); |
| 465 | + Settings.WindowSize = GetValidWindowSize(comboWindowSize.Text); |
465 | 466 |
|
466 | 467 | Settings.DayAmbientLight = (int)trackDayAmbientLight.Value; |
467 | 468 | Settings.DoubleWire = checkDoubleWire.Checked; |
@@ -541,14 +542,13 @@ void buttonOK_Click(object sender, EventArgs e) |
541 | 542 | /// <summary> |
542 | 543 | /// Returns user's [width]x[height] if expression is valid and values are sane, else returns previous value of setting. |
543 | 544 | /// </summary> |
544 | | - private string GetValidWindowSize(ComboBox comboWindowSize) |
| 545 | + private string GetValidWindowSize(string text) |
545 | 546 | { |
546 | | - // "1024X780" instead of "1024x780" then "Start" resulted in an immediate return to the Menu with no OpenRailsLog.txt and a baffled user. |
547 | | - var sizeArray = comboWindowSize.Text.ToLower().Replace(" ", "").Split('x'); |
548 | | - if (sizeArray.Count() == 2) |
549 | | - if (int.TryParse(sizeArray[0], out int width) && int.TryParse(sizeArray[1], out int height)) |
550 | | - if ((100 < width && width < 10000) && (100 < height && height < 100000)) // sanity check |
551 | | - return $"{width}x{height}"; |
| 547 | + var match = Regex.Match(text, @"^\s*([1-9]\d{2,3})\s*[Xx]\s*([1-]\d{2,3})\s*$");//capturing 2 groups of 3-4digits, separated by X or x, ignoring whitespace in beginning/end and in between |
| 548 | + if (match.Success) |
| 549 | + { |
| 550 | + return $"{match.Groups[1]}x{match.Groups[2]}"; |
| 551 | + } |
552 | 552 | return Settings.WindowSize; // i.e. no change or message. Just ignore non-numeric entries |
553 | 553 | } |
554 | 554 |
|
|
0 commit comments