/********* ** Private methods *********/ /// <summary>Get whether the given file path exists.</summary> /// <param name="path">A relative file path.</param> /// <exception cref="InvalidOperationException">The path is not relative or contains directory climbing (../).</exception> private bool GetPathExists(string path) { if (string.IsNullOrWhiteSpace(path)) { return(false); } // parse tokens TokenString tokenStr = new TokenString(path, this.TokenContext); if (tokenStr.InvalidTokens.Any()) { return(false); } tokenStr.UpdateContext(this.TokenContext); path = tokenStr.Value; // get normalised path if (string.IsNullOrWhiteSpace(path)) { return(false); } path = PathUtilities.NormalisePathSeparators(path); // validate if (Path.IsPathRooted(path)) { throw new InvalidOperationException($"The {ConditionType.HasFile} token requires a relative path."); } if (!PathUtilities.IsSafeRelativePath(path)) { throw new InvalidOperationException($"The {ConditionType.HasFile} token requires a relative path and cannot contain directory climbing (../)."); } // check file existence string fullPath = Path.Combine(this.ModFolder, PathUtilities.NormalisePathSeparators(path)); return(File.Exists(fullPath)); }