feat: merge resources into main assembly
This commit is contained in:
parent
2ba1d0ddbc
commit
49d75638c9
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd">
|
||||
<Resourcer/>
|
||||
<ILMerge/>
|
||||
<ILMerge ExcludeResources="^NAudio\.WinForms\..+"/>
|
||||
</Weavers>
|
||||
|
|
|
@ -46,6 +46,7 @@
|
|||
<PackageReference Include="DalamudPackager" Version="1.2.1"/>
|
||||
<PackageReference Include="Fody" Version="6.5.1" PrivateAssets="all"/>
|
||||
<PackageReference Include="ILMerge.Fody" Version="1.16.0" PrivateAssets="all"/>
|
||||
<PackageReference Include="ILRepack.Lib.MSBuild.Task" Version="2.0.18.2"/>
|
||||
<PackageReference Include="NAudio" Version="2.0.0"/>
|
||||
<PackageReference Include="Resourcer.Fody" Version="1.8.0" PrivateAssets="all"/>
|
||||
<PackageReference Include="XivCommon" Version="1.2.0"/>
|
||||
|
@ -57,4 +58,17 @@
|
|||
<DependentUpon>Language.resx</DependentUpon>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
<Target Name="MergeLocalisedResources" AfterTargets="Build">
|
||||
<ItemGroup>
|
||||
<InputAssemblies Include="$(OutputPath)\$(AssemblyName).dll"/>
|
||||
<InputAssemblies Include="$(OutputPath)\*\$(AssemblyName).resources.dll"/>
|
||||
</ItemGroup>
|
||||
<ILRepack
|
||||
Parallel="true"
|
||||
InputAssemblies="@(InputAssemblies)"
|
||||
LibraryPath="$(OutputPath);$(AppData)\XIVLauncher\addon\Hooks\dev"
|
||||
TargetKind="Dll"
|
||||
OutputFile="$(OutputPath)\$(AssemblyName).dll"
|
||||
/>
|
||||
</Target>
|
||||
</Project>
|
||||
|
|
|
@ -2,7 +2,9 @@
|
|||
using Dalamud.Plugin;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using Lumina.Excel.GeneratedSheets;
|
||||
using PeepingTom.Resources;
|
||||
using XivCommon;
|
||||
|
||||
namespace PeepingTom {
|
||||
|
@ -26,6 +28,10 @@ namespace PeepingTom {
|
|||
this.Watcher = new TargetWatcher(this);
|
||||
this.Ui = new PluginUi(this);
|
||||
|
||||
Util.PreLoadResourcesFromMainAssembly("PeepingTom.Resources.Language.");
|
||||
OnLanguageChange(this.Interface.UiLanguage);
|
||||
this.Interface.OnLanguageChanged += OnLanguageChange;
|
||||
|
||||
this.Interface.CommandManager.AddHandler("/ppeepingtom", new CommandInfo(this.OnCommand) {
|
||||
HelpMessage = "Use with no arguments to show the list. Use with \"c\" or \"config\" to show the config",
|
||||
});
|
||||
|
@ -59,6 +65,11 @@ namespace PeepingTom {
|
|||
this.Interface.CommandManager.RemoveHandler("/ptom");
|
||||
this.Interface.CommandManager.RemoveHandler("/ppeep");
|
||||
this.Ui.Dispose();
|
||||
this.Interface.OnLanguageChanged -= OnLanguageChange;
|
||||
}
|
||||
|
||||
private static void OnLanguageChange(string langCode) {
|
||||
Language.Culture = new CultureInfo(langCode);
|
||||
}
|
||||
|
||||
private void OnTerritoryChange(object sender, ushort e) {
|
||||
|
|
|
@ -1,4 +1,50 @@
|
|||
namespace PeepingTom {
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Globalization;
|
||||
using System.Reflection;
|
||||
|
||||
namespace PeepingTom {
|
||||
internal static class Util {
|
||||
internal static void PreLoadResourcesFromMainAssembly(string resourcesPrefix, string resourcesExtension = ".resources") {
|
||||
// get loaded resource sets from resource manager
|
||||
var resourceManager = Resources.Language.ResourceManager;
|
||||
|
||||
if ((
|
||||
resourceManager.GetType().GetField("_resourceSets", BindingFlags.Instance | BindingFlags.NonPublic) ??
|
||||
// ReSharper disable once PossibleNullReferenceException
|
||||
resourceManager.GetType().GetField("ResourceSets", BindingFlags.Instance | BindingFlags.NonPublic)
|
||||
).GetValue(resourceManager) is not IDictionary resourceSetByCulture) {
|
||||
return;
|
||||
}
|
||||
|
||||
var resourceAssembly = typeof(PeepingTomPlugin).Assembly; // get assembly with localization resources
|
||||
foreach (var embeddedResourceName in resourceAssembly.GetManifestResourceNames()) {
|
||||
if (embeddedResourceName.StartsWith(resourcesPrefix, StringComparison.Ordinal) == false ||
|
||||
embeddedResourceName.EndsWith(resourcesExtension, StringComparison.Ordinal) == false) {
|
||||
continue; // not localized resource
|
||||
}
|
||||
|
||||
var locale = embeddedResourceName.Substring(resourcesPrefix.Length, Math.Max(0, embeddedResourceName.Length - resourcesPrefix.Length - resourcesExtension.Length));
|
||||
if (string.IsNullOrEmpty(locale)) {
|
||||
continue; // default locale
|
||||
}
|
||||
|
||||
var resourceStream = resourceAssembly.GetManifestResourceStream(embeddedResourceName);
|
||||
if (resourceStream == null) {
|
||||
continue; // no resource stream
|
||||
}
|
||||
|
||||
var resourceSet = new System.Resources.ResourceSet(resourceStream);
|
||||
var culture = CultureInfo.GetCultureInfo(locale);
|
||||
if (resourceSetByCulture is Hashtable) {
|
||||
resourceSetByCulture.Add(culture, resourceSet);
|
||||
} else {
|
||||
resourceSetByCulture.Add(culture.Name, resourceSet);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Naming", "CA1716:Identifiers should not match keywords")]
|
||||
public class Optional<T> where T : class {
|
||||
public bool Present { get; }
|
||||
|
|
Loading…
Reference in New Issue