mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 08:33:21 +08:00
Read rulesets from AppDomain in addition to disk (#5216)
Read rulesets from AppDomain in addition to disk Co-authored-by: Dean Herbert <pe@ppy.sh>
This commit is contained in:
commit
99ff59be87
@ -22,9 +22,11 @@ namespace osu.Game.Rulesets
|
|||||||
{
|
{
|
||||||
AppDomain.CurrentDomain.AssemblyResolve += currentDomain_AssemblyResolve;
|
AppDomain.CurrentDomain.AssemblyResolve += currentDomain_AssemblyResolve;
|
||||||
|
|
||||||
foreach (string file in Directory.GetFiles(Environment.CurrentDirectory, $"{ruleset_library_prefix}.*.dll")
|
// On android in release configuration assemblies are loaded from the apk directly into memory.
|
||||||
.Where(f => !Path.GetFileName(f).Contains("Tests")))
|
// We cannot read assemblies from cwd, so should check loaded assemblies instead.
|
||||||
loadRulesetFromFile(file);
|
loadFromAppDomain();
|
||||||
|
|
||||||
|
loadFromDisk();
|
||||||
}
|
}
|
||||||
|
|
||||||
public RulesetStore(IDatabaseContextFactory factory)
|
public RulesetStore(IDatabaseContextFactory factory)
|
||||||
@ -111,6 +113,34 @@ namespace osu.Game.Rulesets
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void loadFromAppDomain()
|
||||||
|
{
|
||||||
|
foreach (var ruleset in AppDomain.CurrentDomain.GetAssemblies())
|
||||||
|
{
|
||||||
|
string rulesetName = ruleset.GetName().Name;
|
||||||
|
|
||||||
|
if (!rulesetName.StartsWith(ruleset_library_prefix, StringComparison.InvariantCultureIgnoreCase) || ruleset.GetName().Name.Contains("Tests"))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
addRuleset(ruleset);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void loadFromDisk()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
string[] files = Directory.GetFiles(Environment.CurrentDirectory, $"{ruleset_library_prefix}.*.dll");
|
||||||
|
|
||||||
|
foreach (string file in files.Where(f => !Path.GetFileName(f).Contains("Tests")))
|
||||||
|
loadRulesetFromFile(file);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
Logger.Log($"Could not load rulesets from directory {Environment.CurrentDirectory}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static void loadRulesetFromFile(string file)
|
private static void loadRulesetFromFile(string file)
|
||||||
{
|
{
|
||||||
var filename = Path.GetFileNameWithoutExtension(file);
|
var filename = Path.GetFileNameWithoutExtension(file);
|
||||||
@ -120,13 +150,27 @@ namespace osu.Game.Rulesets
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var assembly = Assembly.LoadFrom(file);
|
addRuleset(Assembly.LoadFrom(file));
|
||||||
loaded_assemblies[assembly] = assembly.GetTypes().First(t => t.IsPublic && t.IsSubclassOf(typeof(Ruleset)));
|
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
Logger.Error(e, $"Failed to load ruleset {filename}");
|
Logger.Error(e, $"Failed to load ruleset {filename}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void addRuleset(Assembly assembly)
|
||||||
|
{
|
||||||
|
if (loaded_assemblies.ContainsKey(assembly))
|
||||||
|
return;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
loaded_assemblies[assembly] = assembly.GetTypes().First(t => t.IsPublic && t.IsSubclassOf(typeof(Ruleset)));
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Logger.Error(e, $"Failed to add ruleset {assembly}");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user