using BetterGenshinImpact.Core.Script.Utils; using System; using System.IO; using System.Threading.Tasks; namespace BetterGenshinImpact.Core.Script.Dependence; public class LimitedFile(string rootPath) { /// /// Normalize and validate a path. /// private string NormalizePath(string path) { return ScriptUtils.NormalizePath(rootPath, path); } /// /// Read all text from a file. /// /// File path. /// Text read from file. public string ReadTextSync(string path) { path = NormalizePath(path); return File.ReadAllText(path); } /// /// Read all text from a file. /// /// File path. /// Text read from file. public async Task ReadText(string path) { path = NormalizePath(path); var ret = await File.ReadAllTextAsync(path); return ret; } /// /// Read all text from a file. /// /// File path. /// Callback function. /// Text read from file. public async Task ReadText(string path, dynamic callbackFunc) { try { path = NormalizePath(path); var ret = await File.ReadAllTextAsync(path); callbackFunc(null, ret); return ret; } catch (Exception ex) { callbackFunc(ex.ToString(), null); return string.Empty; } } }