diff --git a/Apewer/Apewer.csproj b/Apewer/Apewer.csproj index 549a148..f5d3a33 100644 --- a/Apewer/Apewer.csproj +++ b/Apewer/Apewer.csproj @@ -20,7 +20,7 @@ Apewer Apewer Libraries - 6.3.0 + 6.3.1 diff --git a/Apewer/Internals/AccessHelper.cs b/Apewer/Internals/AccessHelper.cs index 28e9f1b..864df94 100644 --- a/Apewer/Internals/AccessHelper.cs +++ b/Apewer/Internals/AccessHelper.cs @@ -44,11 +44,15 @@ namespace Apewer.Internals { file.Position = 0L; file.Seek(0L, SeekOrigin.Begin); - var password = func(file); + try + { + var password = func(file); - if (string.IsNullOrEmpty(password)) return; - if (list.Contains(password)) return; - list.Add(password); + if (string.IsNullOrEmpty(password)) return; + if (list.Contains(password)) return; + list.Add(password); + } + catch { } } #region 方式 1 diff --git a/Apewer/Json.cs b/Apewer/Json.cs index ee942ee..f6f89f4 100644 --- a/Apewer/Json.cs +++ b/Apewer/Json.cs @@ -1430,26 +1430,18 @@ namespace Apewer { return json._jvalue.Value.ToString(); } + return json._jtoken.ToString(indented ? Formatting.Indented : Formatting.None); } /// 从 Json 到 String 的隐式转换,默认不缩进。 - public static implicit operator string(Json json) - { - return Export(json, false); - } + public static implicit operator string(Json json) => Export(json, false); /// 生成字符串,默认不缩进。若类型为 String,则导出 String 值。 - public override string ToString() - { - return Export(this, false); - } + public override string ToString() => Export(this, false); /// 生成字符串,可指定缩进。若类型为 String,则导出 String 值,忽略缩进。 - public string ToString(bool indented) - { - return Export(this, indented); - } + public string ToString(bool indented) => Export(this, indented); #endregion diff --git a/Apewer/Source/Access.cs b/Apewer/Source/Access.cs index a4ab779..21698a2 100644 --- a/Apewer/Source/Access.cs +++ b/Apewer/Source/Access.cs @@ -17,6 +17,7 @@ namespace Apewer.Source { /// 尝试解析 Access 文件的密码。 + /// 当操作系统启用随机化内存分配时,此方法可能会产生异常。 public static string[] ParsePassword(string path) => AccessHelper.GetPassword(path); } diff --git a/Apewer/Web/ApiProcessor.cs b/Apewer/Web/ApiProcessor.cs index ae258e6..bcbef68 100644 --- a/Apewer/Web/ApiProcessor.cs +++ b/Apewer/Web/ApiProcessor.cs @@ -647,7 +647,8 @@ namespace Apewer.Web // 用户数据。 json.SetProperty("data", response.Data); - var text = json.ToString(ApiOptions.JsonIndent); + var indented = ApiOptions.JsonIndent || response.Indented; + var text = json.ToString(indented); return text; } diff --git a/Apewer/Web/ApiResponse.cs b/Apewer/Web/ApiResponse.cs index 552bf04..556019d 100644 --- a/Apewer/Web/ApiResponse.cs +++ b/Apewer/Web/ApiResponse.cs @@ -44,6 +44,9 @@ namespace Apewer.Web /// 在 .NET Framework 中,此设置可能无效。 public int Expires { get; set; } + /// 当响应 Json 时,强制缩进排版。 + public bool Indented { get; set; } = false; + /// 自定义数据。 public Json Data { diff --git a/Apewer/_ChangeLog.md b/Apewer/_ChangeLog.md index 4e99709..6f12933 100644 --- a/Apewer/_ChangeLog.md +++ b/Apewer/_ChangeLog.md @@ -1,6 +1,10 @@  ### 最新提交 +### 6.3.1 +- Source:修正了多次获取 Access 密码会报错的问题; +- Web:对 ApiResponse 中增加 Indented,支持对单个 API 的响应强制缩进排版。 + ### 6.3.0 - 调整变量命名方式,统一采用 Camel 风格; - 代码优化,删除 Internals 类,降低了栈空间的占用;