mirror of
https://github.com/yaobiao131/downkyicore.git
synced 2025-08-10 00:52:31 +00:00
fix: 正确处理各个系统的文件路径并兼容8.0中断性变更
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using System.Collections.Concurrent;
|
||||
using System.Text.RegularExpressions;
|
||||
using DownKyi.Core.Storage;
|
||||
using static System.DateTime;
|
||||
|
||||
namespace DownKyi.Core.Logging;
|
||||
@@ -60,28 +61,10 @@ public class LogManager
|
||||
|
||||
private static AutoResetEvent Pause => new AutoResetEvent(false);
|
||||
|
||||
private static string logDirectory;
|
||||
|
||||
/// <summary>
|
||||
/// 日志存放目录,默认日志放在当前应用程序运行目录下的logs文件夹中
|
||||
/// 日志存放目录,windows默认日志放在当前应用程序运行目录下的Logs文件夹中,macOS、linux存放于applicationData目录下
|
||||
/// </summary>
|
||||
public static string LogDirectory
|
||||
{
|
||||
get => logDirectory ??
|
||||
(Directory.GetFiles(AppDomain.CurrentDomain.BaseDirectory).Any(s => s.Contains("Web.config"))
|
||||
? AppDomain.CurrentDomain.BaseDirectory + @"App_Data\Logs\"
|
||||
: Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "logs"));
|
||||
set
|
||||
{
|
||||
//自定义目录
|
||||
if (!Directory.Exists(value))
|
||||
{
|
||||
Directory.CreateDirectory(value);
|
||||
}
|
||||
|
||||
logDirectory = value;
|
||||
}
|
||||
}
|
||||
private static string LogDirectory => StorageManager.GetLogsDir();
|
||||
|
||||
/// <summary>
|
||||
/// 写入Info级别的日志
|
||||
|
||||
@@ -6,9 +6,30 @@
|
||||
internal static class Constant
|
||||
{
|
||||
// 根目录
|
||||
#if NET8_0_OR_GREATER //兼容8.0中断性变更https://learn.microsoft.com/zh-cn/dotnet/core/compatibility/core-libraries/8.0/getfolderpath-unix
|
||||
private static string Root => OperatingSystem.IsWindows()
|
||||
? AppDomain.CurrentDomain.BaseDirectory
|
||||
: Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Downkyi");
|
||||
: Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "DownKyi");
|
||||
#else
|
||||
private static string Root
|
||||
{
|
||||
get
|
||||
{
|
||||
if (OperatingSystem.IsWindows())
|
||||
{
|
||||
return AppDomain.CurrentDomain.BaseDirectory;
|
||||
}
|
||||
|
||||
if (OperatingSystem.IsMacOS())
|
||||
{
|
||||
return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "Library",
|
||||
"Application Support", "DownKyi");
|
||||
}
|
||||
|
||||
return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "DownKyi");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
// private static string Root { get; } = AppDomain.CurrentDomain.BaseDirectory;
|
||||
|
||||
// Aria
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
public static class StorageManager
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取历史记录的文件路径
|
||||
/// 获取Aria的文件路径
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static string GetAriaDir()
|
||||
@@ -11,6 +11,16 @@ public static class StorageManager
|
||||
CreateDirectory(Constant.Aria);
|
||||
return Constant.Aria;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取日志的文件路径
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static string GetLogsDir()
|
||||
{
|
||||
CreateDirectory(Constant.Logs);
|
||||
return Constant.Logs;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取历史记录的文件路径
|
||||
|
||||
Reference in New Issue
Block a user