From d1451edb03aa22d484b3f3b32050d9899a88f576 Mon Sep 17 00:00:00 2001 From: Murbong Date: Wed, 13 Mar 2024 20:34:04 +0900 Subject: [PATCH] =?UTF-8?q?=EB=B2=84=EA=B7=B8=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Global.cs | 36 ++++++++++++++++++++++++++---------- KekboomKawaii.csproj | 10 +++++----- 2 files changed, 31 insertions(+), 15 deletions(-) diff --git a/Global.cs b/Global.cs index 850e832..a9ffe2c 100644 --- a/Global.cs +++ b/Global.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; using System.IO; +using System.Reflection; using System.Runtime.InteropServices; using System.Text; using System.Text.RegularExpressions; @@ -103,11 +104,11 @@ public static void ShowToast(string appId, string title, string message, string public static Dictionary WeaponImageDic = new Dictionary(); - public static string AvatarJsonPath = @"../../Resources/Database/AvatarConfigDataTable.json"; - public static string AvatarFrameJsonPath = @"../../Resources/Database/AvatarFrameConfigDataTable.json"; - public static string StaticWeaponJsonPath = @"../../Resources/Database/StaticWeaponDataTable.json"; - public static string TitleJsonPath = @"../../Resources/Database/DT_Title.json"; - public static string LocalJsonPath = @"../../Resources/Database/Game.json"; + public static string AvatarJsonPath = @"Resources.Database.AvatarConfigDataTable.json"; + public static string AvatarFrameJsonPath = @"Resources.Database.AvatarFrameConfigDataTable.json"; + public static string StaticWeaponJsonPath = @"Resources.Database.StaticWeaponDataTable.json"; + public static string TitleJsonPath = @"Resources.Database.DT_Title.json"; + public static string LocalJsonPath = @"Resources.Database.Game.json"; public static Regex regex = new Regex("^\\/(.+\\/)*(.+)\\.(.+)$"); @@ -150,6 +151,21 @@ private static void SetiniValue(string section, string key, string value) WritePrivateProfileString(section, key, value, AppDomain.CurrentDomain.BaseDirectory + UserSettingsFileName); } + private static string GetEmbeddedResource(string fileName) + { + var assembly = Assembly.GetExecutingAssembly(); + var resourceName = "KekboomKawaii." + fileName; + + using (Stream stream = assembly.GetManifestResourceStream(resourceName)) + { + using (StreamReader reader = new StreamReader(stream, encoding: Encoding.UTF8)) + { + string result = reader.ReadToEnd(); + return result; + } + } + } + static Global() { @@ -165,19 +181,19 @@ static Global() public static void Initlaize() { - dynamic avatar = JsonConvert.DeserializeObject(File.ReadAllText(AvatarJsonPath, Encoding.UTF8)); + dynamic avatar = JsonConvert.DeserializeObject(GetEmbeddedResource(AvatarJsonPath)); foreach (dynamic item in avatar[0].Rows) { AvatarDic.Add(item.Name.ToLower(), regex.Match(item.Value.BigImage.AssetPathName.ToString()).Groups[3].Value); } - dynamic avatarFrame = JsonConvert.DeserializeObject(File.ReadAllText(AvatarFrameJsonPath, Encoding.UTF8)); + dynamic avatarFrame = JsonConvert.DeserializeObject(GetEmbeddedResource(AvatarFrameJsonPath)); foreach (dynamic item in avatarFrame[0].Rows) { AvatarFrameDic.Add(item.Name.ToLower(), regex.Match(item.Value.BigImage.AssetPathName.ToString()).Groups[3].Value); } - dynamic staticWeapon = JsonConvert.DeserializeObject(File.ReadAllText(StaticWeaponJsonPath, Encoding.UTF8)); + dynamic staticWeapon = JsonConvert.DeserializeObject(GetEmbeddedResource(StaticWeaponJsonPath)); foreach (dynamic item in staticWeapon[0].Rows) { @@ -185,9 +201,9 @@ public static void Initlaize() WeaponImageDic.Add(item.Name.ToLower(), regex.Match(item.Value.WeaponIconForMatrix.AssetPathName.ToString()).Groups[3].Value); } - dynamic title = JsonConvert.DeserializeObject(File.ReadAllText(TitleJsonPath, Encoding.UTF8)); + dynamic title = JsonConvert.DeserializeObject(GetEmbeddedResource(TitleJsonPath)); - dynamic titleLoc = JsonConvert.DeserializeObject(File.ReadAllText(LocalJsonPath, Encoding.UTF8)); + dynamic titleLoc = JsonConvert.DeserializeObject(GetEmbeddedResource(LocalJsonPath)); foreach (dynamic item in title[0].Rows) diff --git a/KekboomKawaii.csproj b/KekboomKawaii.csproj index fe43b1b..84c7177 100644 --- a/KekboomKawaii.csproj +++ b/KekboomKawaii.csproj @@ -224,11 +224,11 @@ SettingsSingleFileGenerator Settings.Designer.cs - - - - - + + + + +