From 617eb00f21cf0890f58d23ea73b5a4372761955a Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Tue, 18 Feb 2020 11:15:26 -0800 Subject: [PATCH] Fix PS regex matching (fixes #192) --- DICUI.Library/Utilities/DumpEnvironment.cs | 34 ++++++++++++++-------- 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/DICUI.Library/Utilities/DumpEnvironment.cs b/DICUI.Library/Utilities/DumpEnvironment.cs index 1f6d37a2..f7e66352 100644 --- a/DICUI.Library/Utilities/DumpEnvironment.cs +++ b/DICUI.Library/Utilities/DumpEnvironment.cs @@ -2366,20 +2366,26 @@ namespace DICUI.Utilities // Try both of the common paths that contain information string exeName = null; + + // Try reading SYSTEM.CNF to find the "BOOT" value if (File.Exists(systemCnfPath)) { - // Let's try reading SYSTEM.CNF to find the "BOOT" value try { using (StreamReader sr = File.OpenText(systemCnfPath)) { - // Not assuming proper ordering, just in case + // Not assuming any ordering, just in case string line = sr.ReadLine(); while (!line.StartsWith("BOOT")) line = sr.ReadLine(); - // Once it finds the "BOOT" line, extract the name - exeName = Regex.Match(line, @"BOOT.*?=\s*cdrom.?:\\?(.*?);.*").Groups[1].Value; + // Once it finds the "BOOT" line, extract the name, if possible + var match = Regex.Match(line, @"BOOT.*?=\s*cdrom.?:\\?(.*?)"); + if (match != null && match.Groups.Count > 1) + { + exeName = match.Groups[1].Value; + exeName = exeName.Split(';')[0]; + } } } catch @@ -2388,14 +2394,14 @@ namespace DICUI.Utilities return false; } } - else if (File.Exists(psxExePath)) - { + + // If the SYSTEM.CNF value can't be found, try PSX.EXE + if (string.IsNullOrWhiteSpace(exeName) && File.Exists(psxExePath)) exeName = "PSX.EXE"; - } - else - { + + // If neither can be found, we return false + if (string.IsNullOrWhiteSpace(exeName)) return false; - } // Standardized "S" serials if (exeName.StartsWith("S")) @@ -2484,7 +2490,7 @@ namespace DICUI.Utilities if (!File.Exists(systemCnfPath)) return null; - // Let's try reading SYSTEM.CNF to find the "VER" value + // Try reading SYSTEM.CNF to find the "VER" value try { using (StreamReader sr = File.OpenText(systemCnfPath)) @@ -2495,7 +2501,11 @@ namespace DICUI.Utilities line = sr.ReadLine(); // Once it finds the "VER" line, extract the version - return Regex.Match(line, @"VER\s*=\s*(.*)").Groups[1].Value; + var match = Regex.Match(line, @"VER\s*=\s*(.*)"); + if (match != null && match.Groups.Count > 1) + return match.Groups[1].Value; + + return null; } } catch