using System;
using System.ComponentModel;
using System.Globalization;
using System.Resources;
using System.Collections.Generic;
namespace CKAN.GUI
{
internal class SingleAssemblyComponentResourceManager : ComponentResourceManager
{
public SingleAssemblyComponentResourceManager(Type t) : base(t)
{
contextTypeInfo = t;
}
protected override ResourceSet? InternalGetResourceSet(CultureInfo culture,
bool createIfNotExists, bool tryParents)
{
if (!myResourceSets.TryGetValue(culture, out ResourceSet? rs) && createIfNotExists && MainAssembly != null)
{
neutralResourcesCulture ??= GetNeutralResourcesLanguage(MainAssembly);
if (neutralResourcesCulture.Equals(culture))
{
culture = CultureInfo.InvariantCulture;
}
string resourceFileName = GetResourceFileName(culture);
var store = MainAssembly.GetManifestResourceStream(contextTypeInfo, resourceFileName);
if (store != null)
{
rs = new ResourceSet(store);
myResourceSets.Add(culture, rs);
}
else
{
rs = base.InternalGetResourceSet(culture, createIfNotExists, tryParents);
}
}
return rs;
}
private readonly Type contextTypeInfo;
private CultureInfo? neutralResourcesCulture;
private readonly Dictionary<CultureInfo, ResourceSet> myResourceSets = new Dictionary<CultureInfo, ResourceSet>();
}
}