/* ┌──────────────────────────────────────────────────────────────────┐ │ Author: Ivan Murzak (https://github.com/IvanMurzak) │ │ Repository: GitHub (https://github.com/IvanMurzak/Unity-MCP) │ │ Copyright (c) 2025 Ivan Murzak │ │ Licensed under the Apache License, Version 2.0. │ │ See the LICENSE file in the project root for more information. │ └──────────────────────────────────────────────────────────────────┘ */ using System.Text.RegularExpressions; namespace com.IvanMurzak.Unity.MCP.Runtime.Utils { public static partial class ErrorUtils { /// /// Extracts a process ID from file lock error messages. /// /// The error message to parse. /// The extracted process ID, or -1 if not found. /// True if a process ID was successfully extracted, false otherwise. public static bool ExtractProcessId(string error, out int processId) { processId = -1; if (string.IsNullOrWhiteSpace(error)) return false; try { // Define a regex pattern to match the process ID in file lock messages var pattern = @"The file is locked by: ""[^""]+ \((\d+)\)"""; var match = Regex.Match(error, pattern); return match.Success && int.TryParse(match.Groups[1].Value, out processId); } catch (RegexMatchTimeoutException) { // Handle regex timeout gracefully return false; } } } }