Skip to content

Commit

Permalink
减少反射
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoye97 committed Nov 28, 2021
1 parent 6de2cb5 commit b8cda63
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 37 deletions.
8 changes: 4 additions & 4 deletions VRoidChinese/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
// 控制。更改这些特性值可修改
// 与程序集关联的信息。
[assembly: AssemblyTitle("VRoidChinese")]
[assembly: AssemblyDescription("VRoidStudio汉化插件,最后编译于BepInEx_x64_5.4.3.0,VRoidStudio-v0.11.3-win")]
[assembly: AssemblyDescription("VRoidStudio汉化插件")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("https://github.com/xiaoye97")]
[assembly: AssemblyProduct("VRoidChinese")]
[assembly: AssemblyCopyright("Copyright © 2020")]
[assembly: AssemblyCopyright("Copyright © xiaoye97 2021")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

Expand All @@ -32,5 +32,5 @@
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值
//通过使用 "*",如下所示:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.3.0.0")]
[assembly: AssemblyFileVersion("1.3.0.0")]
[assembly: AssemblyVersion("1.7.0.0")]
[assembly: AssemblyFileVersion("1.7.0.0")]
54 changes: 22 additions & 32 deletions VRoidChinese/VRoidChinese.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,19 +99,22 @@ private void Start()
{
try
{
System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
sw.Start();
if (!WorkDir.Exists)
{
WorkDir.Create();
}
// 备份原文
Backup();
// 读取配置
ShowOnceTip = Config.Bind<bool>("config", "ShowOnceTip", false, "仅提示一次的消息");
OnStartDump = Config.Bind<bool>("config", "OnStartDump", false, "当启动时进行转储(原词条)");
OnHasNullValueDump = Config.Bind<bool>("config", "OnHasNullValueDump", false, "当缺失词条时进行转储(合并后词条)");
DevMode = Config.Bind<bool>("config", "DevMode", false, "汉化者开发模式");
RefreshLangKey = Config.Bind<KeyCode>("config", "RefreshLangKey", KeyCode.F10, "[仅限开发模式]刷新语言快捷键");
SwitchLangKey = Config.Bind<KeyCode>("config", "SwitchLangKey", KeyCode.F11, "[仅限开发模式]切换语言快捷键");

// 备份原文
Backup();
if (OnStartDump.Value)
{
// Dump原文到硬盘
Expand All @@ -124,9 +127,12 @@ private void Start()
// 切换到中文
VRoid.UI.EditorOption.EditorOptionManager.Instance.EditorOption.Preference.languageMode = VRoid.UI.EditorOption.LanguageMode.En;
Messages.CurrentCrowdinLanguageCode = "en";
sw.Stop();
Logger.LogInfo($"总耗时 {sw.ElapsedMilliseconds}ms");
}
catch
catch (Exception e)
{
Logger.LogError(e);
ShowUpdateTip = true;
}
}
Expand Down Expand Up @@ -179,6 +185,7 @@ public void ExceptionTipWindowFunc(int id)
GUILayout.Label("GitHub:xiaoye97");
GUILayout.Label("QQ:1066666683");
GUILayout.Label("B站:宵夜97");
GUILayout.Label("宵夜食堂:528385469");
GUILayout.Label("VRoid交流群:684544577");
GUILayout.Label("汉化插件网址:https://github.com/xiaoye97/VRoidChinese");
GUILayout.Label(" ");
Expand Down Expand Up @@ -213,10 +220,11 @@ public void OnceTipWindowFunc(int id)
/// </summary>
public void Backup()
{
Debug.Log("开始备份原文...");
Logger.LogInfo("开始备份原文...");
System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
sw.Start();
ENMessage = JsonConvert.SerializeObject(Messages.All["en"], Formatting.Indented);
var s_localeStringDictionary = Traverse.Create(typeof(Messages)).Field("s_localeStringDictionary").GetValue<Dictionary<string, Dictionary<string, string>>>();
var enDict = s_localeStringDictionary["en"];
var enDict = Messages.s_localeStringDictionary["en"];
StringBuilder sb = new StringBuilder();
foreach (var kv in enDict)
{
Expand All @@ -225,6 +233,8 @@ public void Backup()
sb.AppendLine($"{kv.Key}={value}");
}
ENString = sb.ToString();
sw.Stop();
Logger.LogInfo($"备份耗时{sw.ElapsedMilliseconds}ms");
}

/// <summary>
Expand All @@ -247,9 +257,8 @@ public void DumpMerge()
string messagesStr = JsonConvert.SerializeObject(messages, Formatting.Indented);
File.WriteAllText($"{WorkDir.FullName}/DumpMergeMessages.json", messagesStr);
Debug.Log("开始Dump Merge String...");
var s_localeStringDictionary = Traverse.Create(typeof(Messages)).Field("s_localeStringDictionary").GetValue<Dictionary<string, Dictionary<string, string>>>();
var strDict = s_localeStringDictionary["en"];
StringBuilder sb = new StringBuilder();
var strDict = Messages.s_localeStringDictionary["en"];
StringBuilder sb = new StringBuilder();
foreach (var kv in strDict)
{
string value = kv.Value.Replace("\r\n", "\\r\\n");
Expand Down Expand Up @@ -288,18 +297,12 @@ public void ToCN()
public void ToEN()
{
Logger.LogInfo("切换到英文...");
var ori = Traverse.Create(typeof(Messages)).Field("s_localeDictionary").GetValue<Dictionary<string, Messages>>();
ori["en"] = JsonConvert.DeserializeObject<Messages>(ENMessage);
Traverse.Create(typeof(Messages)).Field("s_localeDictionary").SetValue(ori);
Messages.s_localeDictionary["en"] = JsonConvert.DeserializeObject<Messages>(ENMessage);
Messages.OnMessagesLanguageChange();

var s_localeStringDictionary = Traverse.Create(typeof(Messages)).Field("s_localeStringDictionary").GetValue<Dictionary<string, Dictionary<string, string>>>();
var strDict = s_localeStringDictionary["en"];
foreach (var kv in ENStringDict)
{
strDict[kv.Key] = kv.Value;
Messages.s_localeStringDictionary["en"][kv.Key] = kv.Value;
}
Traverse.Create(typeof(Messages)).Field("s_localeStringDictionary").SetValue(s_localeStringDictionary);
nowCN = false;
}

Expand Down Expand Up @@ -357,9 +360,7 @@ public void FixMessages()
Logger.LogInfo("开始将中文Messages对象替换到英文对象...");
try
{
var ori = Traverse.Create(typeof(Messages)).Field("s_localeDictionary").GetValue<Dictionary<string, Messages>>();
ori["en"] = cn;
Traverse.Create(typeof(Messages)).Field("s_localeDictionary").SetValue(ori);
Messages.s_localeDictionary["en"] = cn;
}
catch (Exception e)
{
Expand Down Expand Up @@ -394,8 +395,7 @@ public void FixString()
return;
}
Logger.LogInfo("开始解析String汉化文件...");
var s_localeStringDictionary = Traverse.Create(typeof(Messages)).Field("s_localeStringDictionary").GetValue<Dictionary<string, Dictionary<string, string>>>();
var strDict = s_localeStringDictionary["en"];
var strDict = Messages.s_localeStringDictionary["en"];
try
{
foreach (var line in lines)
Expand All @@ -415,16 +415,6 @@ public void FixString()
Logger.LogError($"解析String汉化文件出现异常:{e.Message}\n{e.StackTrace}");
return;
}
Logger.LogInfo("开始将中文String替换到英文...");
try
{
Traverse.Create(typeof(Messages)).Field("s_localeStringDictionary").SetValue(s_localeStringDictionary);
}
catch (Exception e)
{
Logger.LogError($"将中文String替换到英文出现异常:{e.Message}\n{e.StackTrace}");
return;
}
Logger.LogInfo("String汉化完毕.");
}
else
Expand Down
3 changes: 2 additions & 1 deletion VRoidChinese/VRoidChinese.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>VRoidChinese</RootNamespace>
<AssemblyName>VRoidChinese</AssemblyName>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
<TargetFrameworkProfile />
Expand All @@ -22,6 +22,7 @@
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
Expand Down

0 comments on commit b8cda63

Please sign in to comment.