forked from BeyondDimension/SteamTools
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
73 changed files
with
3,295 additions
and
130 deletions.
There are no files selected for viewing
Submodule DirectoryPackages
updated
2 files
+37 −0 | .github/dependabot.yml | |
+1 −1 | Directory.Packages.props |
Binary file removed
BIN
-41.1 KB
ref/pkg/wtts/BD.WTTS.MicroServices.ClientSDK.1.23.10214.11101.nupkg
Binary file not shown.
Binary file removed
BIN
-18.1 KB
ref/pkg/wtts/BD.WTTS.MicroServices.ClientSDK.1.23.10214.11101.snupkg
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed
BIN
-6.4 KB
ref/pkg/wtts/BD.WTTS.MicroServices.Primitives.1.23.10214.11101.nupkg
Binary file not shown.
Binary file removed
BIN
-10.5 KB
ref/pkg/wtts/BD.WTTS.MicroServices.Primitives.1.23.10214.11101.snupkg
Binary file not shown.
Binary file not shown.
Binary file added
BIN
+10.5 KB
ref/pkg/wtts/BD.WTTS.MicroServices.Primitives.1.23.10215.11446.snupkg
Binary file not shown.
Binary file removed
BIN
-22.2 KB
ref/pkg/wtts/BD.WTTS.MicroServices.Primitives.Resources.1.23.10214.11101.nupkg
Binary file not shown.
Binary file removed
BIN
-10.9 KB
ref/pkg/wtts/BD.WTTS.MicroServices.Primitives.Resources.1.23.10214.11101.snupkg
Binary file not shown.
Binary file added
BIN
+22.3 KB
ref/pkg/wtts/BD.WTTS.MicroServices.Primitives.Resources.1.23.10215.11446.nupkg
Binary file not shown.
Binary file added
BIN
+10.9 KB
ref/pkg/wtts/BD.WTTS.MicroServices.Primitives.Resources.1.23.10215.11446.snupkg
Binary file not shown.
Binary file removed
BIN
-11 KB
ref/pkg/wtts/BD.WTTS.MicroServices.Primitives.ViewModels.1.23.10214.11101.nupkg
Binary file not shown.
Binary file removed
BIN
-14.5 KB
ref/pkg/wtts/BD.WTTS.MicroServices.Primitives.ViewModels.1.23.10214.11101.snupkg
Binary file not shown.
Binary file added
BIN
+11.4 KB
ref/pkg/wtts/BD.WTTS.MicroServices.Primitives.ViewModels.1.23.10215.11446.nupkg
Binary file not shown.
Binary file added
BIN
+14.6 KB
ref/pkg/wtts/BD.WTTS.MicroServices.Primitives.ViewModels.1.23.10215.11446.snupkg
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using AppResources = BD.WTTS.Client.Resources.Strings; | ||
|
||
// ReSharper disable once CheckNamespace | ||
namespace BD.WTTS; | ||
|
||
partial interface IApplication | ||
{ | ||
/// <summary> | ||
/// 通用复制字符串到剪贴板,并在成功后显示 toast | ||
/// </summary> | ||
/// <param name="text"></param> | ||
/// <param name="msgToast"></param> | ||
/// <param name="showToast"></param> | ||
/// <returns></returns> | ||
static async Task CopyToClipboardAsync(string? text, string? msgToast = null, bool showToast = true) | ||
{ | ||
if (!string.IsNullOrWhiteSpace(text)) | ||
{ | ||
await Clipboard2.SetTextAsync(text); | ||
if (showToast) Toast.Show(msgToast ?? AppResources.CopyToClipboard); | ||
} | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/BD.WTTS.Client/App/IApplication.InitSettingSubscribe.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// ReSharper disable once CheckNamespace | ||
namespace BD.WTTS; | ||
|
||
partial interface IApplication | ||
{ | ||
/// <summary> | ||
/// 初始化设置项变更时监听 | ||
/// </summary> | ||
void InitSettingSubscribe() | ||
{ | ||
UISettings.Theme.Subscribe(x => Theme = (AppTheme)x); | ||
UISettings.Language.Subscribe(ResourceService.ChangeLanguage); | ||
} | ||
|
||
/// <inheritdoc cref="IApplication.InitSettingSubscribe"/> | ||
void PlatformInitSettingSubscribe() => InitSettingSubscribe(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,242 @@ | ||
using ASFNLogManager = ArchiSteamFarm.LogManager; | ||
using LogLevel = Microsoft.Extensions.Logging.LogLevel; | ||
using NInternalLogger = NLog.Common.InternalLogger; | ||
using NLogLevel = NLog.LogLevel; | ||
using NLogManager = NLog.LogManager; | ||
|
||
// ReSharper disable once CheckNamespace | ||
namespace BD.WTTS; | ||
|
||
partial interface IApplication | ||
{ | ||
#region Logger | ||
|
||
const LogLevel DefaultLoggerMinLevel = AssemblyInfo.Debuggable ? LogLevel.Debug : LogLevel.Error; | ||
|
||
public static readonly NLogLevel DefaultNLoggerMinLevel = ConvertLogLevel(DefaultLoggerMinLevel); | ||
|
||
/// <summary> | ||
/// Convert log level to NLog variant. | ||
/// </summary> | ||
/// <param name="logLevel">level to be converted.</param> | ||
/// <returns></returns> | ||
static NLogLevel ConvertLogLevel(LogLevel logLevel) => logLevel switch | ||
{ | ||
// https://github.com/NLog/NLog.Extensions.Logging/blob/v1.7.0/src/NLog.Extensions.Logging/Logging/NLogLogger.cs#L416 | ||
LogLevel.Trace => NLogLevel.Trace, | ||
LogLevel.Debug => NLogLevel.Debug, | ||
LogLevel.Information => NLogLevel.Info, | ||
LogLevel.Warning => NLogLevel.Warn, | ||
LogLevel.Error => NLogLevel.Error, | ||
LogLevel.Critical => NLogLevel.Fatal, | ||
LogLevel.None => NLogLevel.Off, | ||
_ => NLogLevel.Debug, | ||
}; | ||
|
||
static void SetNLoggerMinLevel(LogLevel logLevel) => SetNLoggerMinLevel(ConvertLogLevel(logLevel)); | ||
|
||
static void SetNLoggerMinLevel(NLogLevel logLevel) | ||
{ | ||
NLogManager.GlobalThreshold = logLevel; | ||
NInternalLogger.LogLevel = logLevel; | ||
} | ||
|
||
public static void TrySetLoggerMinLevel(LogLevel logLevel) | ||
{ | ||
try | ||
{ | ||
var o = LoggerFilterOptions; | ||
if (o != null) o.MinLevel = logLevel; | ||
} | ||
catch | ||
{ | ||
} | ||
SetNLoggerMinLevel(ConvertLogLevel(logLevel)); | ||
} | ||
|
||
static LoggerFilterOptions? _LoggerFilterOptions; | ||
|
||
/// <summary> | ||
/// 日志过滤选项 | ||
/// </summary> | ||
static LoggerFilterOptions? LoggerFilterOptions | ||
{ | ||
get | ||
{ | ||
if (_LoggerFilterOptions != null) return _LoggerFilterOptions; | ||
return DI.Get_Nullable<IOptions<LoggerFilterOptions>>()?.Value; | ||
} | ||
set => _LoggerFilterOptions = value; | ||
} | ||
|
||
/// <summary> | ||
/// 配置 NLog 提供程序,仅初始化时调用 | ||
/// </summary> | ||
/// <returns></returns> | ||
public static (LogLevel minLevel, Action<ILoggingBuilder> cfg) ConfigureLogging() | ||
{ | ||
var minLevel = DefaultLoggerMinLevel; | ||
|
||
void _(ILoggingBuilder builder) | ||
{ | ||
builder.ClearProviders(); | ||
|
||
builder.SetMinimumLevel(minLevel); | ||
SetNLoggerMinLevel(minLevel); | ||
|
||
// 可以多个日志提供同时用,比如还可以在 Win 平台再添加一个 Windows 事件日志 | ||
|
||
builder.AddNLog(NLogManager.Configuration); // 添加 NLog 日志 | ||
} | ||
|
||
return (minLevel, (Action<ILoggingBuilder>)_); | ||
} | ||
|
||
/// <summary> | ||
/// 日志最低等级 | ||
/// </summary> | ||
public static LogLevel LoggerMinLevel | ||
{ | ||
get | ||
{ | ||
var o = LoggerFilterOptions; | ||
if (o == null) | ||
{ | ||
o = new(); | ||
LoggerFilterOptions = o; | ||
} | ||
return o.MinLevel; | ||
} | ||
|
||
set | ||
{ | ||
var o = LoggerFilterOptions; | ||
if (o != null) | ||
{ | ||
o.MinLevel = value; | ||
} | ||
SetNLoggerMinLevel(value); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// 启用日志 | ||
/// </summary> | ||
public static bool EnableLogger | ||
{ | ||
get => LoggerMinLevel > LogLevel.None; | ||
set | ||
{ | ||
LoggerMinLevel = value ? DefaultLoggerMinLevel : LogLevel.None; | ||
} | ||
} | ||
|
||
#endregion | ||
|
||
#region LogHelper | ||
|
||
/// <summary> | ||
/// 日志存放文件夹路径 | ||
/// </summary> | ||
public static string LogDirPath { get; private set; } = string.Empty; | ||
|
||
/// <summary> | ||
/// 日志存放文件夹路径(ASF) | ||
/// </summary> | ||
public static string LogDirPathASF { get; private set; } = string.Empty; | ||
|
||
#if DEBUG | ||
/// <summary> | ||
/// 日志文件夹是否存放在缓存文件夹中,通常日志文件夹将存放在基目录上,因某些平台基目录为只读,则只能放在缓存文件夹中 | ||
/// </summary> | ||
[Obsolete("only True.", true)] | ||
public static bool LogUnderCache => true; | ||
#endif | ||
|
||
public const string LogDirName = "Logs"; | ||
|
||
public static void InitLogDir(string? alias = null, bool isTrace = false) | ||
{ | ||
if (!string.IsNullOrEmpty(LogDirPath)) return; | ||
|
||
//var devicePlatform = DeviceInfo2.Platform(); | ||
//LogUnderCache = devicePlatform switch | ||
//{ | ||
// Platform.Windows => DesktopBridge.IsRunningAsUwp, | ||
// Platform.Linux or Platform.Android or Platform.Apple or Platform.UWP => true, | ||
// _ => throw new ArgumentOutOfRangeException(nameof(devicePlatform), devicePlatform, null), | ||
//}; | ||
|
||
//var logDirPath = Path.Combine(/*LogUnderCache ?*/ | ||
// IOPath.CacheDirectory /*:*/ | ||
// /*IOPath.BaseDirectory*/, | ||
// LogDirName); | ||
var logDirPath = Path.Combine(IOPath.CacheDirectory, LogDirName); | ||
IOPath.DirCreateByNotExists(logDirPath); | ||
if (isTrace) StartWatchTrace.Record("InitLogDir.IO"); | ||
var logDirPath_ = logDirPath + Path.DirectorySeparatorChar; | ||
|
||
NInternalLogger.LogFile = logDirPath_ + "internal-nlog" + alias + ".txt"; | ||
NInternalLogger.LogLevel = NLogLevel.Error; | ||
var objConfig = new LoggingConfiguration(); | ||
var defMinLevel = DefaultNLoggerMinLevel; | ||
var logfile = new FileTarget("logfile") | ||
{ | ||
FileName = logDirPath_ + "nlog-all-${shortdate}" + alias + ".log", | ||
Layout = "${longdate}|${level}|${logger}|${message} |${all-event-properties} ${exception:format=tostring}", | ||
ArchiveAboveSize = 10485760, | ||
MaxArchiveFiles = 14, | ||
MaxArchiveDays = 7, | ||
}; | ||
objConfig.AddTarget(logfile); | ||
InitializeTarget(objConfig, logfile, defMinLevel); | ||
if (isTrace) StartWatchTrace.Record("InitLogDir.CreateCfg"); | ||
NLogManager.Configuration = objConfig; | ||
|
||
LogDirPathASF = ASFPathHelper.GetLogDirectory(logDirPath_); | ||
IArchiSteamFarmService.InitCoreLoggers = () => | ||
{ | ||
if (ASFNLogManager.Configuration != null) return; | ||
LoggingConfiguration config = new(); | ||
FileTarget fileTarget = new("File") | ||
{ | ||
ArchiveFileName = ASFPathHelper.GetNLogArchiveFileName(LogDirPathASF), | ||
ArchiveNumbering = ArchiveNumberingMode.Rolling, | ||
ArchiveOldFileOnStartup = true, | ||
CleanupFileName = false, | ||
ConcurrentWrites = false, | ||
DeleteOldFileOnStartup = true, | ||
FileName = ASFPathHelper.GetNLogFileName(LogDirPathASF), | ||
Layout = ASFPathHelper.NLogGeneralLayout, | ||
ArchiveAboveSize = 10485760, | ||
MaxArchiveFiles = 10, | ||
MaxArchiveDays = 7, | ||
}; | ||
InitializeTarget(config, fileTarget, NLogLevel.Debug); | ||
var historyTarget = new HistoryTarget("History") | ||
{ | ||
Layout = ASFPathHelper.NLogGeneralLayout, | ||
MaxCount = 20, | ||
}; | ||
InitializeTarget(config, historyTarget, NLogLevel.Debug); | ||
ASFNLogManager.Configuration = config; | ||
}; | ||
|
||
LogDirPath = logDirPath; | ||
static void InitializeTarget(LoggingConfiguration config, Target target, NLogLevel minLevel) | ||
{ | ||
config.AddTarget(target); | ||
if (minLevel < NLogLevel.Warn) | ||
{ | ||
config.LoggingRules.Add(new LoggingRule("Microsoft*", target) { FinalMinLevel = NLogLevel.Warn }); | ||
config.LoggingRules.Add(new LoggingRule("Microsoft.Hosting.Lifetime*", target) { FinalMinLevel = NLogLevel.Info }); | ||
config.LoggingRules.Add(new LoggingRule("System*", target) { FinalMinLevel = NLogLevel.Warn }); | ||
} | ||
config.LoggingRules.Add(new LoggingRule("*", minLevel, target)); | ||
} | ||
|
||
Log.LoggerFactory = () => new LoggerFactory(new[] { new NLogLoggerProvider() }); | ||
} | ||
|
||
#endregion | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// ReSharper disable once CheckNamespace | ||
namespace BD.WTTS; | ||
|
||
/// <summary> | ||
/// 指定应用此特性的类需要指定的授权 | ||
/// </summary> | ||
[AttributeUsage(AttributeTargets.Class, Inherited = true)] | ||
public sealed class AuthorizeAttribute : Attribute | ||
{ | ||
public static bool HasAuthorize(object obj) | ||
=> obj.GetType().GetCustomAttributes<AuthorizeAttribute>(true).Any(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
namespace BD.WTTS.Enums; | ||
|
||
/// <summary> | ||
/// 代理模式 | ||
/// </summary> | ||
public enum ProxyMode : byte | ||
{ | ||
/// <summary> | ||
/// 通过注入驱动实现 DNS 拦截进行代理(Windows Only) | ||
/// </summary> | ||
[Description("ProxyMode_DNSIntercept")] | ||
DNSIntercept, | ||
|
||
/// <summary> | ||
/// 修改 Hosts 文件进行代理(Desktop Only) | ||
/// </summary> | ||
[Description("ProxyMode_Hosts")] | ||
Hosts, | ||
|
||
/// <summary> | ||
/// 系统代理模式(Desktop Only) | ||
/// </summary> | ||
[Description("ProxyMode_System")] | ||
System, | ||
|
||
/// <summary> | ||
/// VPN 代理模式(虚拟网卡) | ||
/// </summary> | ||
[Description("ProxyMode_VPN")] | ||
VPN, | ||
|
||
/// <summary> | ||
/// 仅代理模式 | ||
/// </summary> | ||
[Description("ProxyMode_ProxyOnly")] | ||
ProxyOnly, | ||
|
||
/// <summary> | ||
/// PAC代理模式(Desktop Only) | ||
/// </summary> | ||
[Description("ProxyMode_PAC")] | ||
PAC, | ||
} |
Oops, something went wrong.