From 0b560cb1c5028ba669fbf0561a3be12545a33582 Mon Sep 17 00:00:00 2001 From: yeziuku Date: Sat, 21 Oct 2023 16:37:02 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=88=E5=88=9B=E5=BB=BAutf-16=E7=9A=84ini?= =?UTF-8?q?=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Api/Utility/TextReader.cs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/Api/Utility/TextReader.cs b/Api/Utility/TextReader.cs index 7e75ab0..5720434 100644 --- a/Api/Utility/TextReader.cs +++ b/Api/Utility/TextReader.cs @@ -1,5 +1,6 @@ using System.IO; using System.Runtime.InteropServices; +using System.Text; using Milimoe.FunGame.Core.Library.Constant; namespace Milimoe.FunGame.Core.Api.Utility @@ -9,11 +10,16 @@ namespace Milimoe.FunGame.Core.Api.Utility /* * 声明API函数 */ - [LibraryImport("kernel32", EntryPoint = "WritePrivateProfileStringW", StringMarshalling = StringMarshalling.Utf16)] + [LibraryImport("kernel32.dll", EntryPoint = "WritePrivateProfileStringW", StringMarshalling = StringMarshalling.Utf16)] private static partial long WritePrivateProfileString(string section, string key, string val, string filePath); [LibraryImport("Kernel32.dll", EntryPoint = "GetPrivateProfileStringW", StringMarshalling = StringMarshalling.Utf16)] private static partial int GetPrivateProfileString(string section, string key, string def, char[] val, int size, string filePath); + /// + /// 默认的配置文件名称 + /// + public const string DefaultFileName = @"FunGame.ini"; + /// /// 写入ini文件 /// @@ -21,7 +27,7 @@ namespace Milimoe.FunGame.Core.Api.Utility /// 键 /// 值 /// 文件名,缺省为FunGame.ini - public static void WriteINI(string Section, string Key, string Value, string FileName = @"FunGame.ini") + public static void WriteINI(string Section, string Key, string Value, string FileName = DefaultFileName) { WritePrivateProfileString(Section, Key, Value, Environment.CurrentDirectory.ToString() + @"\" + FileName); } @@ -33,7 +39,7 @@ namespace Milimoe.FunGame.Core.Api.Utility /// 键 /// 文件名,缺省为FunGame.ini /// 读取到的值 - public static string ReadINI(string Section, string Key, string FileName = @"FunGame.ini") + public static string ReadINI(string Section, string Key, string FileName = DefaultFileName) { char[] val = new char[General.StreamByteSize]; _ = GetPrivateProfileString(Section, Key, "", val, General.StreamByteSize, Environment.CurrentDirectory.ToString() + @"\" + FileName); @@ -46,13 +52,16 @@ namespace Milimoe.FunGame.Core.Api.Utility /// /// 文件名,缺省为FunGame.ini /// 是否存在 - public static bool ExistINIFile(string FileName = @"FunGame.ini") => File.Exists($@"{Environment.CurrentDirectory}\{FileName}"); + public static bool ExistINIFile(string FileName = DefaultFileName) => File.Exists($@"{Environment.CurrentDirectory}\{FileName}"); /// /// 初始化ini模板文件 /// public static void Init(FunGameInfo.FunGame FunGameType) { + StreamWriter writer = new(DefaultFileName, false, General.DefaultEncoding); + writer.Write("[Server]"); + writer.Close(); switch (FunGameType) { case FunGameInfo.FunGame.FunGame_Core: