From e2c13a92cf2cef49fc560a79feb84bbd588215e1 Mon Sep 17 00:00:00 2001 From: Color_yr <26276037+Coloryr@users.noreply.github.com> Date: Thu, 15 Feb 2024 15:51:04 +0800 Subject: [PATCH 1/2] [OneBot] create a default config --- Lagrange.OneBot/Lagrange.OneBot.csproj | 15 +++ Lagrange.OneBot/Program.cs | 10 +- Lagrange.OneBot/Resource1.Designer.cs | 73 ++++++++++++ Lagrange.OneBot/Resource1.resx | 124 +++++++++++++++++++++ Lagrange.OneBot/Resources/appsettings.json | 47 ++++++++ 5 files changed, 267 insertions(+), 2 deletions(-) create mode 100644 Lagrange.OneBot/Resource1.Designer.cs create mode 100644 Lagrange.OneBot/Resource1.resx create mode 100644 Lagrange.OneBot/Resources/appsettings.json diff --git a/Lagrange.OneBot/Lagrange.OneBot.csproj b/Lagrange.OneBot/Lagrange.OneBot.csproj index fe211bf96..21792521b 100644 --- a/Lagrange.OneBot/Lagrange.OneBot.csproj +++ b/Lagrange.OneBot/Lagrange.OneBot.csproj @@ -23,4 +23,19 @@ + + + True + True + Resource1.resx + + + + + + ResXFileCodeGenerator + Resource1.Designer.cs + + + diff --git a/Lagrange.OneBot/Program.cs b/Lagrange.OneBot/Program.cs index 49c211344..d179f951b 100644 --- a/Lagrange.OneBot/Program.cs +++ b/Lagrange.OneBot/Program.cs @@ -12,12 +12,18 @@ public static void Main(string[] args) Console.InputEncoding = Encoding.UTF8; GCSettings.LatencyMode = GCLatencyMode.Batch; - + + if (!File.Exists("appsettings.json")) + { + Console.WriteLine("No exist config file, create it now..."); + File.WriteAllBytes("appsettings.json", Resource1.appsettings); + } + var hostBuilder = new LagrangeAppBuilder(args) .ConfigureConfiguration("appsettings.json", false, true) .ConfigureBots() .ConfigureOneBot(); - + hostBuilder.Build().Run(); } } \ No newline at end of file diff --git a/Lagrange.OneBot/Resource1.Designer.cs b/Lagrange.OneBot/Resource1.Designer.cs new file mode 100644 index 000000000..90426d3ce --- /dev/null +++ b/Lagrange.OneBot/Resource1.Designer.cs @@ -0,0 +1,73 @@ +//------------------------------------------------------------------------------ +// +// 此代码由工具生成。 +// 运行时版本:4.0.30319.42000 +// +// 对此文件的更改可能会导致不正确的行为,并且如果 +// 重新生成代码,这些更改将会丢失。 +// +//------------------------------------------------------------------------------ + +namespace Lagrange.OneBot { + using System; + + + /// + /// 一个强类型的资源类,用于查找本地化的字符串等。 + /// + // 此类是由 StronglyTypedResourceBuilder + // 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。 + // 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen + // (以 /str 作为命令选项),或重新生成 VS 项目。 + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resource1 { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resource1() { + } + + /// + /// 返回此类使用的缓存的 ResourceManager 实例。 + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Lagrange.OneBot.Resource1", typeof(Resource1).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// 重写当前线程的 CurrentUICulture 属性,对 + /// 使用此强类型资源类的所有资源查找执行重写。 + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + /// + /// 查找 System.Byte[] 类型的本地化资源。 + /// + internal static byte[] appsettings { + get { + object obj = ResourceManager.GetObject("appsettings", resourceCulture); + return ((byte[])(obj)); + } + } + } +} diff --git a/Lagrange.OneBot/Resource1.resx b/Lagrange.OneBot/Resource1.resx new file mode 100644 index 000000000..a0f66d000 --- /dev/null +++ b/Lagrange.OneBot/Resource1.resx @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + + Resources\appsettings.json;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Lagrange.OneBot/Resources/appsettings.json b/Lagrange.OneBot/Resources/appsettings.json new file mode 100644 index 000000000..c3756f241 --- /dev/null +++ b/Lagrange.OneBot/Resources/appsettings.json @@ -0,0 +1,47 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Trace", + "Microsoft": "Warning", + "Microsoft.Hosting.Lifetime": "Information" + } + }, + "SignServerUrl": "", + "Account": { + "Uin": 0, + "Password": "", + "Protocol": "Linux", + "AutoReconnect": true, + "GetOptimumServer": true + }, + "Message": { + "IgnoreSelf": true + }, + "Implementation": { + "ForwardWebSocket": { + "Host": "127.0.0.1", + "Port": 8081, + "HeartBeatInterval": 5000, + "AccessToken": "" + }, + "ReverseWebSocket": { + "Host": "127.0.0.1", + "Port": 8080, + "Suffix": "/onebot/v11/ws", + "ReconnectInterval": 5000, + "HeartBeatInterval": 5000, + "AccessToken": "" + }, + "Http": { + "Host": "", + "Port": 0, + "EventEnabled": false + }, + "HttpPost": { + "Host": "127.0.0.1", + "Port": 8080, + "Suffix": "/onebot/v11/http", + "Timeout": 0 + } + } +} \ No newline at end of file From 61fadeafbbe923f7bcc6f546aaadb33770a72abf Mon Sep 17 00:00:00 2001 From: Color_yr <26276037+Coloryr@users.noreply.github.com> Date: Thu, 15 Feb 2024 16:31:22 +0800 Subject: [PATCH 2/2] [OneBot] do not use resx --- Lagrange.OneBot/Lagrange.OneBot.csproj | 21 ++--- Lagrange.OneBot/Program.cs | 7 +- Lagrange.OneBot/Resource1.Designer.cs | 73 --------------- Lagrange.OneBot/Resource1.resx | 124 ------------------------- 4 files changed, 13 insertions(+), 212 deletions(-) delete mode 100644 Lagrange.OneBot/Resource1.Designer.cs delete mode 100644 Lagrange.OneBot/Resource1.resx diff --git a/Lagrange.OneBot/Lagrange.OneBot.csproj b/Lagrange.OneBot/Lagrange.OneBot.csproj index 21792521b..8c1c82b97 100644 --- a/Lagrange.OneBot/Lagrange.OneBot.csproj +++ b/Lagrange.OneBot/Lagrange.OneBot.csproj @@ -13,29 +13,22 @@ - - - - + - + - - True - True - Resource1.resx - + + + + - - ResXFileCodeGenerator - Resource1.Designer.cs - + diff --git a/Lagrange.OneBot/Program.cs b/Lagrange.OneBot/Program.cs index d179f951b..58cdd4695 100644 --- a/Lagrange.OneBot/Program.cs +++ b/Lagrange.OneBot/Program.cs @@ -1,3 +1,4 @@ +using System.Reflection; using System.Runtime; using System.Text; using Microsoft.Extensions.Hosting; @@ -16,7 +17,11 @@ public static void Main(string[] args) if (!File.Exists("appsettings.json")) { Console.WriteLine("No exist config file, create it now..."); - File.WriteAllBytes("appsettings.json", Resource1.appsettings); + + var assm = Assembly.GetExecutingAssembly(); + using var istr = assm.GetManifestResourceStream("Lagrange.OneBot.Resources.appsettings.json")!; + using var temp = File.Create("appsettings.json"); + istr.CopyTo(temp); } var hostBuilder = new LagrangeAppBuilder(args) diff --git a/Lagrange.OneBot/Resource1.Designer.cs b/Lagrange.OneBot/Resource1.Designer.cs deleted file mode 100644 index 90426d3ce..000000000 --- a/Lagrange.OneBot/Resource1.Designer.cs +++ /dev/null @@ -1,73 +0,0 @@ -//------------------------------------------------------------------------------ -// -// 此代码由工具生成。 -// 运行时版本:4.0.30319.42000 -// -// 对此文件的更改可能会导致不正确的行为,并且如果 -// 重新生成代码,这些更改将会丢失。 -// -//------------------------------------------------------------------------------ - -namespace Lagrange.OneBot { - using System; - - - /// - /// 一个强类型的资源类,用于查找本地化的字符串等。 - /// - // 此类是由 StronglyTypedResourceBuilder - // 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。 - // 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen - // (以 /str 作为命令选项),或重新生成 VS 项目。 - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - internal class Resource1 { - - private static global::System.Resources.ResourceManager resourceMan; - - private static global::System.Globalization.CultureInfo resourceCulture; - - [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] - internal Resource1() { - } - - /// - /// 返回此类使用的缓存的 ResourceManager 实例。 - /// - [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Resources.ResourceManager ResourceManager { - get { - if (object.ReferenceEquals(resourceMan, null)) { - global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Lagrange.OneBot.Resource1", typeof(Resource1).Assembly); - resourceMan = temp; - } - return resourceMan; - } - } - - /// - /// 重写当前线程的 CurrentUICulture 属性,对 - /// 使用此强类型资源类的所有资源查找执行重写。 - /// - [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Globalization.CultureInfo Culture { - get { - return resourceCulture; - } - set { - resourceCulture = value; - } - } - - /// - /// 查找 System.Byte[] 类型的本地化资源。 - /// - internal static byte[] appsettings { - get { - object obj = ResourceManager.GetObject("appsettings", resourceCulture); - return ((byte[])(obj)); - } - } - } -} diff --git a/Lagrange.OneBot/Resource1.resx b/Lagrange.OneBot/Resource1.resx deleted file mode 100644 index a0f66d000..000000000 --- a/Lagrange.OneBot/Resource1.resx +++ /dev/null @@ -1,124 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - - Resources\appsettings.json;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - \ No newline at end of file