2022-10-06 17:44:08 +08:00
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Configuration;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
2023-08-17 20:33:30 +08:00
|
|
|
using BarrageGrab.Modles.JsonEntity;
|
2022-10-06 17:44:08 +08:00
|
|
|
using static System.Configuration.ConfigurationManager;
|
2023-11-23 16:43:21 +08:00
|
|
|
using System.Drawing;
|
|
|
|
|
|
2022-10-06 17:44:08 +08:00
|
|
|
namespace BarrageGrab
|
|
|
|
|
{
|
|
|
|
|
internal class Appsetting
|
|
|
|
|
{
|
|
|
|
|
private static readonly Appsetting ins = new Appsetting();
|
|
|
|
|
|
2023-11-16 09:26:40 +08:00
|
|
|
public static Appsetting Current { get { return ins; } }
|
2022-11-05 16:39:35 +08:00
|
|
|
|
|
|
|
|
public Appsetting()
|
|
|
|
|
{
|
2023-03-09 00:32:02 +08:00
|
|
|
try
|
|
|
|
|
{
|
2023-03-09 01:23:46 +08:00
|
|
|
ProcessFilter = AppSettings["processFilter"].Trim().Split(',');
|
2023-03-09 00:32:02 +08:00
|
|
|
WsProt = int.Parse(AppSettings["wsListenPort"]);
|
|
|
|
|
PrintBarrage = AppSettings["printBarrage"].ToLower() == "true";
|
2023-03-09 01:23:46 +08:00
|
|
|
ProxyPort = int.Parse(AppSettings["proxyPort"]);
|
2023-11-23 16:43:21 +08:00
|
|
|
PrintFilter = Enum.GetValues(typeof(PackMsgType)).Cast<int>().Where(w=>w>0).ToArray();
|
|
|
|
|
PushFilter = Enum.GetValues(typeof(PackMsgType)).Cast<int>().Where(w => w > 0).ToArray();
|
|
|
|
|
LogFilter = Enum.GetValues(typeof(PackMsgType)).Cast<int>().Where(w => w > 0).ToArray();
|
2023-03-09 01:23:46 +08:00
|
|
|
FilterHostName = bool.Parse(AppSettings["filterHostName"].Trim());
|
2023-08-17 20:33:30 +08:00
|
|
|
HostNameFilter = AppSettings["hostNameFilter"].Trim().Split(',').Where(w => !string.IsNullOrWhiteSpace(w)).ToArray();
|
2023-11-23 16:43:21 +08:00
|
|
|
UsedProxy = bool.Parse(AppSettings["usedProxy"].Trim());
|
2023-08-17 20:33:30 +08:00
|
|
|
ListenAny = bool.Parse(AppSettings["listenAny"].Trim());
|
2023-09-24 12:47:55 +08:00
|
|
|
UpstreamProxy = AppSettings["upstreamProxy"].Trim();
|
2023-11-14 20:29:18 +08:00
|
|
|
HideConsole = bool.Parse(AppSettings["hideConsole"].Trim());
|
2023-11-23 16:43:21 +08:00
|
|
|
BarrageLog = bool.Parse(AppSettings["barrageFileLog"].Trim());
|
|
|
|
|
ShowWindow = bool.Parse(AppSettings["showWindow"].Trim());
|
2024-03-10 03:41:40 +08:00
|
|
|
AutoPause = bool.Parse(AppSettings["autoPause"].Trim());
|
|
|
|
|
ForcePolling = bool.Parse(AppSettings["forcePolling"].Trim());
|
|
|
|
|
PollingInterval = int.Parse(AppSettings["pollingInterval"].Trim());
|
|
|
|
|
DisableLivePageScriptCache = bool.Parse(AppSettings["disableLivePageScriptCache"].Trim());
|
|
|
|
|
WebRoomIds = AppSettings["webRoomIds"].Trim().Split(',').Where(w=>!string.IsNullOrWhiteSpace(w)).Select(x => long.Parse(x)).ToArray();
|
2022-11-05 16:39:35 +08:00
|
|
|
|
2023-03-09 00:32:02 +08:00
|
|
|
var printFilter = AppSettings["printFilter"].Trim().ToLower();
|
2023-11-23 16:43:21 +08:00
|
|
|
var pushFilter = AppSettings["pushFilter"].Trim().ToLower();
|
|
|
|
|
var logFilter = AppSettings["logFilter"].Trim().ToLower();
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(printFilter))
|
2023-03-09 00:32:02 +08:00
|
|
|
{
|
|
|
|
|
if (string.IsNullOrWhiteSpace(printFilter)) PrintFilter = new int[0];
|
|
|
|
|
else PrintFilter = printFilter.Split(',').Select(x => int.Parse(x)).ToArray();
|
|
|
|
|
}
|
2023-11-23 16:43:21 +08:00
|
|
|
if (!string.IsNullOrWhiteSpace(pushFilter))
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrWhiteSpace(pushFilter)) PushFilter = new int[0];
|
|
|
|
|
else PushFilter = pushFilter.Split(',').Select(x => int.Parse(x)).ToArray();
|
|
|
|
|
}
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(logFilter))
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrWhiteSpace(logFilter)) LogFilter = new int[0];
|
|
|
|
|
else LogFilter = logFilter.Split(',').Select(x => int.Parse(x)).ToArray();
|
|
|
|
|
}
|
2023-03-09 00:32:02 +08:00
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
2024-03-10 03:41:40 +08:00
|
|
|
Logger.PrintColor("配置文件读取失败,请检查配置文件是否正确");
|
2023-03-09 00:32:02 +08:00
|
|
|
throw ex;
|
2023-08-17 20:33:30 +08:00
|
|
|
}
|
2022-10-06 17:44:08 +08:00
|
|
|
}
|
|
|
|
|
|
2023-11-23 16:43:21 +08:00
|
|
|
public void Save()
|
|
|
|
|
{
|
|
|
|
|
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
|
|
|
|
|
|
|
|
|
|
config.AppSettings.Settings["wsListenPort"].Value = WsProt.ToString();
|
|
|
|
|
config.AppSettings.Settings["printBarrage"].Value = PrintBarrage.ToString().ToLower();
|
|
|
|
|
config.AppSettings.Settings["printFilter"].Value = string.Join("", PrintFilter);
|
|
|
|
|
config.AppSettings.Settings["pushFilter"].Value = string.Join("", PushFilter);
|
|
|
|
|
config.AppSettings.Settings["logFilter"].Value = string.Join("", LogFilter);
|
|
|
|
|
config.AppSettings.Settings["upstreamProxy"].Value = UpstreamProxy;
|
|
|
|
|
config.AppSettings.Settings["listenAny"].Value = ListenAny.ToString().ToLower();
|
|
|
|
|
config.AppSettings.Settings["hideConsole"].Value = HideConsole.ToString().ToLower();
|
|
|
|
|
config.AppSettings.Settings["barrageFileLog"].Value = HideConsole.ToString().ToLower();
|
|
|
|
|
|
|
|
|
|
config.Save(ConfigurationSaveMode.Modified);
|
|
|
|
|
ConfigurationManager.RefreshSection(config.AppSettings.SectionInformation.Name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 弹幕颜色映射
|
|
|
|
|
/// </summary>
|
|
|
|
|
public Dictionary<PackMsgType, Tuple<ConsoleColor, Color>> ColorMap = new Dictionary<PackMsgType, Tuple<ConsoleColor, Color>>()
|
|
|
|
|
{
|
|
|
|
|
{ PackMsgType.弹幕消息, Tuple.Create(ConsoleColor.White, Color.White) },
|
|
|
|
|
{ PackMsgType.点赞消息, Tuple.Create(ConsoleColor.Cyan, Color.Cyan) },
|
|
|
|
|
{ PackMsgType.进直播间, Tuple.Create(ConsoleColor.Green, Color.Green) },
|
|
|
|
|
{ PackMsgType.关注消息, Tuple.Create(ConsoleColor.Yellow, Color.Yellow) },
|
|
|
|
|
{ PackMsgType.礼物消息, Tuple.Create(ConsoleColor.Red, Color.Red) },
|
|
|
|
|
{ PackMsgType.直播间统计, Tuple.Create(ConsoleColor.Magenta, Color.Magenta) },
|
|
|
|
|
{ PackMsgType.粉丝团消息, Tuple.Create(ConsoleColor.Blue, Color.Blue) },
|
|
|
|
|
{ PackMsgType.直播间分享, Tuple.Create(ConsoleColor.DarkBlue, Color.DarkBlue) },
|
|
|
|
|
{ PackMsgType.下播, Tuple.Create(ConsoleColor.DarkCyan, Color.DarkCyan) }
|
|
|
|
|
};
|
|
|
|
|
|
2023-08-17 20:33:30 +08:00
|
|
|
/// <summary>
|
|
|
|
|
/// 使用系统代理
|
|
|
|
|
/// </summary>
|
|
|
|
|
public bool UsedProxy { get; private set; } = true;
|
|
|
|
|
|
2022-10-06 17:44:08 +08:00
|
|
|
/// <summary>
|
|
|
|
|
/// 过滤的进程
|
|
|
|
|
/// </summary>
|
2023-03-09 01:23:46 +08:00
|
|
|
public string[] ProcessFilter { get; private set; }
|
2022-10-06 17:44:08 +08:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 端口号
|
|
|
|
|
/// </summary>
|
2023-11-23 16:43:21 +08:00
|
|
|
public int WsProt { get; set; } = 8888;
|
2023-08-17 20:33:30 +08:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// true:监听在0.0.0.0,接受任意Ip连接,false:监听在127.0.0.1,仅接受本机连接
|
|
|
|
|
/// </summary>
|
2023-11-23 16:43:21 +08:00
|
|
|
public bool ListenAny { get; set; } = true;
|
2022-11-05 16:39:35 +08:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 控制台打印消息开关
|
|
|
|
|
/// </summary>
|
2023-11-23 16:43:21 +08:00
|
|
|
public bool PrintBarrage { get; set; }
|
2023-03-04 14:52:04 +08:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 代理端口
|
|
|
|
|
/// </summary>
|
|
|
|
|
public int ProxyPort { get; private set; } = 8827;
|
2023-03-09 00:32:02 +08:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 控制台输出过滤器
|
|
|
|
|
/// </summary>
|
2023-11-23 16:43:21 +08:00
|
|
|
public int[] PrintFilter { get; set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 推送弹幕过滤器
|
|
|
|
|
/// </summary>
|
|
|
|
|
public int[] PushFilter { get; set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 弹幕日志过滤器
|
|
|
|
|
/// </summary>
|
|
|
|
|
public int[] LogFilter { get; set; }
|
2023-03-09 00:32:02 +08:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 监听的房间号
|
|
|
|
|
/// </summary>
|
2024-03-10 03:41:40 +08:00
|
|
|
public long[] WebRoomIds { get; private set; } = new long[0];
|
2023-03-09 01:23:46 +08:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 使用域名过滤
|
|
|
|
|
/// </summary>
|
|
|
|
|
public bool FilterHostName { get; private set; } = true;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 域名白名单列表
|
|
|
|
|
/// </summary>
|
|
|
|
|
public string[] HostNameFilter { get; private set; } = new string[0];
|
2023-09-24 12:47:55 +08:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 上游代理地址
|
|
|
|
|
/// </summary>
|
2023-11-23 16:43:21 +08:00
|
|
|
public string UpstreamProxy { get; set; }
|
2023-11-14 20:29:18 +08:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 隐藏控制台
|
|
|
|
|
/// </summary>
|
2023-11-23 16:43:21 +08:00
|
|
|
public bool HideConsole { get; set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 弹幕日志
|
|
|
|
|
/// </summary>
|
|
|
|
|
public bool BarrageLog { get; set; } = false;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 显示窗体
|
|
|
|
|
/// </summary>
|
|
|
|
|
public bool ShowWindow { get; private set; } = false;
|
2024-03-10 03:41:40 +08:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 进入直播间自动暂停播放
|
|
|
|
|
/// </summary>
|
|
|
|
|
public bool AutoPause { get; private set; } = false;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 强制启用轮询模式获取弹幕(仅对浏览器和客户端生效)
|
|
|
|
|
/// </summary>
|
|
|
|
|
public bool ForcePolling { get; private set; } = false;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 控制轮询间隔
|
|
|
|
|
/// </summary>
|
|
|
|
|
public int PollingInterval { get; private set; } = 1000;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 禁用直播页面脚本缓存
|
|
|
|
|
/// </summary>
|
|
|
|
|
public bool DisableLivePageScriptCache { get; private set; } = true;
|
2022-10-06 17:44:08 +08:00
|
|
|
}
|
|
|
|
|
}
|