2025-11-26 18:45:19 -06:00
|
|
|
using System.IO;
|
|
|
|
|
using System.Text.RegularExpressions;
|
|
|
|
|
|
|
|
|
|
namespace LANCommander.SDK.Helpers;
|
|
|
|
|
|
|
|
|
|
internal static class TextFileHelper
|
|
|
|
|
{
|
2025-11-26 22:38:04 -06:00
|
|
|
internal static string ReplaceAll(string path, string regexPattern, string substitution, RegexOptions options = RegexOptions.Multiline | RegexOptions.IgnoreCase)
|
2025-11-26 18:45:19 -06:00
|
|
|
{
|
|
|
|
|
if (!File.Exists(path))
|
|
|
|
|
throw new FileNotFoundException("File not found", path);
|
|
|
|
|
|
|
|
|
|
var text = File.ReadAllText(path);
|
|
|
|
|
var update = Regex.Replace(text, regexPattern, substitution, options);
|
|
|
|
|
|
|
|
|
|
if (text != update)
|
|
|
|
|
{
|
|
|
|
|
File.WriteAllText(path, update);
|
2025-11-26 22:38:04 -06:00
|
|
|
|
|
|
|
|
return update;
|
2025-11-26 18:45:19 -06:00
|
|
|
}
|
|
|
|
|
|
2025-11-26 22:38:04 -06:00
|
|
|
return text;
|
2025-11-26 18:45:19 -06:00
|
|
|
}
|
|
|
|
|
}
|