diff --git a/Apewer.Run/Batch.cs b/Apewer.Run/Batch.cs
index db2dd87..548b91e 100644
--- a/Apewer.Run/Batch.cs
+++ b/Apewer.Run/Batch.cs
@@ -29,7 +29,7 @@ namespace Apewer.Run
var cmd = "ffmpeg.exe";
var arg = $"-i \"{path}\" -vcodec copy -acodec copy \"{mp4path}\"";
- WindowsUtility.RunConsole(cmd, arg, (s) => Console.WriteLine(s));
+ SystemUtility.RunConsole(cmd, arg, (s) => Console.WriteLine(s));
continue;
}
@@ -40,7 +40,7 @@ namespace Apewer.Run
var vttpath = Path.Combine(outdir, name.Replace(".srt", ".vtt"));
var text = StorageUtility.ReadFile(path).ToText(Encoding.Default);
StorageUtility.WriteFile(srtpath, text.ToBinary());
- WindowsUtility.RunConsole("ffmpeg.exe", $"-i \"{srtpath}\" \"{vttpath}\"", (s) => Console.WriteLine(s));
+ SystemUtility.RunConsole("ffmpeg.exe", $"-i \"{srtpath}\" \"{vttpath}\"", (s) => Console.WriteLine(s));
continue;
}
}
diff --git a/Apewer.Run/Process.cs b/Apewer.Run/Process.cs
index 19619ce..5be123d 100644
--- a/Apewer.Run/Process.cs
+++ b/Apewer.Run/Process.cs
@@ -18,9 +18,9 @@ namespace Apewer.Run
return;
}
var args = TextUtility.MergeProcessArgument(@"f:\ewq.txt", "title\nbody", "", "quote\"'quote");
- Console.WriteLine(WindowsUtility.ExecutablePath);
+ Console.WriteLine(SystemUtility.ExecutablePath);
Console.WriteLine(args);
- WindowsUtility.StartProcess(WindowsUtility.ExecutablePath, args);
+ SystemUtility.StartProcess(SystemUtility.ExecutablePath, args);
}
}
diff --git a/Apewer/.editorconfig b/Apewer/.editorconfig
deleted file mode 100644
index 74c5994..0000000
--- a/Apewer/.editorconfig
+++ /dev/null
@@ -1,11 +0,0 @@
-[*.cs]
-
-# CS3019: CLS 遵从性检查在此程序集外部不可见,因此不会执行它
-dotnet_diagnostic.CS3019.severity = none
-
-# CS0414: 字段已被赋值,但从未使用过它的值
-dotnet_diagnostic.CS0414.severity = none
-
-# CS0612: 已过时
-dotnet_diagnostic.CS0612.severity = none
-
diff --git a/Apewer/Apewer.csproj b/Apewer/Apewer.csproj
index 10fa249..10f34e2 100644
--- a/Apewer/Apewer.csproj
+++ b/Apewer/Apewer.csproj
@@ -7,7 +7,7 @@
Apewer
Apewer
Apewer
- 6.1.0
+ 6.2.0
diff --git a/Apewer/ILogable.cs b/Apewer/ILogable.cs
deleted file mode 100644
index ec7f9bb..0000000
--- a/Apewer/ILogable.cs
+++ /dev/null
@@ -1,17 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Text;
-
-namespace Apewer
-{
-
- /// 可记录日志。
- public interface ILogable
- {
-
- /// 日志记录程序。
- Logger Logger { get; }
-
- }
-
-}
diff --git a/Apewer/Internals/LogProvider.cs b/Apewer/Internals/LogProvider.cs
deleted file mode 100644
index d31a907..0000000
--- a/Apewer/Internals/LogProvider.cs
+++ /dev/null
@@ -1,63 +0,0 @@
-using Apewer;
-using System;
-using System.Collections.Generic;
-using System.Text;
-using System.Threading;
-
-namespace Apewer.Internals
-{
-
- internal sealed class LogProvider
- {
-
- private static bool _running = false;
- private static Thread _thread = null;
- private static Queue _queue = new Queue();
-
- private static void Listener()
- {
- while (_running)
- {
- var item = (LogItem)null;
- lock (_queue)
- {
- if (_queue.Count > 0) item = _queue.Dequeue();
- else
- {
- _running = false;
- break;
- }
- }
-
- if (item == null) continue;
- if (item.Logger == null) continue;
- try
- {
- // item.Logger.Raise(item);
- }
- catch { }
- }
- }
-
- public static void Queue(LogItem argItem)
- {
- if (argItem == null) return;
- lock (_queue)
- {
- _queue.Enqueue(argItem);
- if (_thread == null)
- {
- _thread = new Thread(Listener);
- _thread.IsBackground = false;
- }
- if (!_running)
- {
- _running = true;
- _thread.Start();
- }
- }
- }
-
- }
-
-}
diff --git a/Apewer/KernelUtility.cs b/Apewer/KernelUtility.cs
index 4da155c..4b7bdcd 100644
--- a/Apewer/KernelUtility.cs
+++ b/Apewer/KernelUtility.cs
@@ -115,12 +115,30 @@ namespace Apewer
if (milliseconds > 0) Thread.Sleep(milliseconds);
}
- ///
+ /// 在后台线程中执行,指定 Try 将忽略异常。
[MethodImpl(MethodImplOptions.NoInlining)]
- public static Thread InBackground(Action action)
+ public static Thread InBackground(Action action, bool @try = false)
{
if (action == null) return null;
- var thread = new Thread(delegate (object v) { ((Action)v)(); });
+ Thread thread;
+ if (@try)
+ {
+ thread = new Thread(delegate (object v)
+ {
+ try
+ {
+ ((Action)v)();
+ }
+ catch { }
+ });
+ }
+ else
+ {
+ thread = new Thread(delegate (object v)
+ {
+ ((Action)v)();
+ });
+ }
thread.IsBackground = true;
thread.Start(action);
return thread;
@@ -215,13 +233,23 @@ namespace Apewer
#region Application
-#if NETFX || NETCORE
-
///
- /// System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase
- /// D:\Website\
+ /// 当前应用程序所在的目录。
+ /// 例:D:\App 或 D:\Website
///
- public static string ApplicationBasePath {get=> AppDomain.CurrentDomain.SetupInformation.ApplicationBase; }
+ public static string ApplicationPath
+ {
+ get
+ {
+#if NETSTD
+ return Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
+#else
+ return AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
+#endif
+ }
+ }
+
+#if NETFX || NETCORE
/// 处理当前在消息队列中的所有 Windows 消息。
public static void DoEvents() => Application.DoEvents();
diff --git a/Apewer/LogItem.cs b/Apewer/LogItem.cs
deleted file mode 100644
index ffd82c9..0000000
--- a/Apewer/LogItem.cs
+++ /dev/null
@@ -1,43 +0,0 @@
-using Apewer;
-using Apewer.Internals;
-using System;
-using System.Collections.Generic;
-using System.Text;
-
-namespace Apewer
-{
-
- internal class LogItem
- {
-
- private Logger _logger;
- private LogType _type;
-
- private Exception _exception = null;
- private DateTime _triggered = DateTime.Now;
- private string _content = null;
- private string _target = null;
- private object _custom = null;
-
- public DateTime Triggered { get { return _triggered; } }
-
- internal LogType Type { get { return _type; } }
-
- public Logger Logger { get { return _logger; } set { _logger = value; } }
-
- public Exception Exception { get { return _exception; } set { _exception = value; } }
-
- public string Content { get { return _content; } set { _content = value ?? ""; } }
-
- public string Target { get { return _target; } set { _target = value ?? ""; } }
-
- public object Custom { get { return _custom; } set { _custom = value; } }
-
- internal LogItem(LogType argType)
- {
- _type = argType;
- }
-
- }
-
-}
diff --git a/Apewer/Logger.cs b/Apewer/Logger.cs
index 0badc14..c7d827e 100644
--- a/Apewer/Logger.cs
+++ b/Apewer/Logger.cs
@@ -1,6 +1,7 @@
using Apewer.Internals;
using System;
using System.Collections.Generic;
+using System.IO;
using System.Text;
using System.Threading;
@@ -14,221 +15,207 @@ namespace Apewer
private string _key = Guid.NewGuid().ToString("n");
private string _target = "";
private bool _enabled = true;
+ private Func _preoutput = null;
- /// 异常。
- public event Event ExceptionEvent;
-
- /// 调试。
- public event Event DebugEvent;
+ /// 已启用。
+ public virtual bool Enabled { get; set; }
- /// 文本。
- public event Event TextEvent;
+ /// 使用控制台输出。默认值:TRUE。
+ public virtual bool UseConsole { get; set; } = true;
- /// 信息。
- public event Event InfomationEvent;
+ /// 使用日志文件。默认值:FALSE。
+ public virtual bool UseFile { get; set; } = false;
- /// 注意。
- public event Event WarningEvent;
+ /// 输出前的检查,返回值将确认输出。
+ public virtual Func PreOutput { get; set; }
- /// 错误。
- public event Event ErrorEvent;
+ /// 异常。设置处理方法以替代 UseConsole 和 UseFile。
+ public virtual Event OnException { get; set; }
- /// 自定义。
- public event Event