Skip to content

Commit 0b018ce

Browse files
committed
Format code
1 parent e57cf1b commit 0b018ce

4 files changed

Lines changed: 366 additions & 358 deletions

File tree

dev/index.ts

Lines changed: 40 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { EditorState } from '@codemirror/state';
22
import { EditorView } from '@codemirror/view';
33
import { basicSetup } from 'codemirror';
4-
import { indentUnit } from "@codemirror/language";
5-
import { csharp, parser } from "../dist/";
6-
import { printTree } from "./print-lezer-tree";
4+
import { indentUnit } from '@codemirror/language';
5+
import { csharp, parser } from '../dist/';
6+
import { printTree } from './print-lezer-tree';
77
import { oneDark } from '@codemirror/theme-one-dark';
88

99
const doc = /*`
@@ -29,7 +29,7 @@ public sealed class InterrogateHelpUrls
2929
}
3030
}
3131
`*/`
32-
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
32+
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
3333
// See the LICENCE file in the repository root for full licence text.
3434
3535
using System;
@@ -38,6 +38,7 @@ using System.IO;
3838
using System.Linq;
3939
using System.Reflection;
4040
using osu.Framework;
41+
using osu.Framework.Extensions.ObjectExtensions;
4142
using osu.Framework.Logging;
4243
using osu.Framework.Platform;
4344
@@ -48,6 +49,8 @@ namespace osu.Game.Rulesets
4849
private const string ruleset_library_prefix = @"osu.Game.Rulesets";
4950
5051
protected readonly Dictionary<Assembly, Type> LoadedAssemblies = new Dictionary<Assembly, Type>();
52+
protected readonly HashSet<Assembly> UserRulesetAssemblies = new HashSet<Assembly>();
53+
protected readonly Storage? RulesetStorage;
5154
5255
/// <summary>
5356
/// All available rulesets.
@@ -56,33 +59,24 @@ namespace osu.Game.Rulesets
5659
5760
protected RulesetStore(Storage? storage = null)
5861
{
59-
A.B c = 1;
60-
A.B(1);
61-
A.B c = 1;
62-
A.B(1);
63-
A.B c = 1;
6462
// On android in release configuration assemblies are loaded from the apk directly into memory.
6563
// We cannot read assemblies from cwd, so should check loaded assemblies instead.
6664
loadFromAppDomain();
67-
A.B c = 1;
68-
A.B(1);
69-
A.B c = 1;
70-
A.B(1);
71-
A.B c = 1;
65+
7266
// This null check prevents Android from attempting to load the rulesets from disk,
7367
// as the underlying path "AppContext.BaseDirectory", despite being non-nullable, it returns null on android.
7468
// See https://github.com/xamarin/xamarin-android/issues/3489.
75-
if (RuntimeInfo.StartupDirectory is int (a, b, c) a)
69+
if (RuntimeInfo.StartupDirectory.IsNotNull())
7670
loadFromDisk();
7771
7872
// the event handler contains code for resolving dependency on the game assembly for rulesets located outside the base game directory.
7973
// It needs to be attached to the assembly lookup event before the actual call to loadUserRulesets() else rulesets located out of the base game directory will fail
8074
// to load as unable to locate the game core assembly.
8175
AppDomain.CurrentDomain.AssemblyResolve += resolveRulesetDependencyAssembly;
8276
83-
var rulesetStorage = storage?.GetStorageForDirectory(@"rulesets");
84-
if (rulesetStorage != null)
85-
loadUserRulesets(rulesetStorage);
77+
RulesetStorage = storage?.GetStorageForDirectory(@"rulesets");
78+
if (RulesetStorage != null)
79+
loadUserRulesets(RulesetStorage);
8680
}
8781
8882
/// <summary>
@@ -115,10 +109,7 @@ A.B c = 1;
115109
return false;
116110
117111
return args.Name.Contains(name, StringComparison.Ordinal);
118-
})
119-
// Pick the greatest assembly version.
120-
.OrderByDescending(a => a.GetName().Version)
121-
.FirstOrDefault();
112+
}).MaxBy(a => a.GetName().Version);
122113
123114
if (domainAssembly != null)
124115
return domainAssembly;
@@ -147,14 +138,21 @@ A.B c = 1;
147138
var rulesets = rulesetStorage.GetFiles(@".", @$"{ruleset_library_prefix}.*.dll");
148139
149140
foreach (string? ruleset in rulesets.Where(f => !f.Contains(@"Tests")))
150-
loadRulesetFromFile(rulesetStorage.GetFullPath(ruleset));
141+
{
142+
var assembly = loadRulesetFromFile(rulesetStorage.GetFullPath(ruleset));
143+
if (assembly != null)
144+
UserRulesetAssemblies.Add(assembly);
145+
}
151146
}
152147
153148
private void loadFromDisk()
154149
{
155150
try
156151
{
157-
string[] files = Directory.GetFiles(RuntimeInfo.StartupDirectory, @$"{ruleset_library_prefix}.*.dll");
152+
// On net6-android (Debug), StartupDirectory can be different from where assemblies are placed.
153+
// Search sub-directories too.
154+
155+
string[] files = Directory.GetFiles(RuntimeInfo.StartupDirectory, @$"{ruleset_library_prefix}.*.dll", SearchOption.AllDirectories);
158156
159157
foreach (string file in files.Where(f => !Path.GetFileName(f).Contains("Tests")))
160158
loadRulesetFromFile(file);
@@ -165,21 +163,25 @@ A.B c = 1;
165163
}
166164
}
167165
168-
private void loadRulesetFromFile(string file)
166+
private Assembly? loadRulesetFromFile(string file)
169167
{
170-
string? filename = Path.GetFileNameWithoutExtension(file);
168+
string filename = Path.GetFileNameWithoutExtension(file);
171169
172170
if (LoadedAssemblies.Values.Any(t => Path.GetFileNameWithoutExtension(t.Assembly.Location) == filename))
173-
return;
171+
return null;
174172
175173
try
176174
{
177-
addRuleset(Assembly.LoadFrom(file));
175+
var assembly = Assembly.LoadFrom(file);
176+
addRuleset(assembly);
177+
return assembly;
178178
}
179179
catch (Exception e)
180180
{
181-
LogFailedLoad(filename, e);
181+
logRulesetFailure(filename, e);
182182
}
183+
184+
return null;
183185
}
184186
185187
private void addRuleset(Assembly assembly)
@@ -198,7 +200,7 @@ A.B c = 1;
198200
}
199201
catch (Exception e)
200202
{
201-
LogFailedLoad(assembly.GetName().Name.Split('.').Last(), e);
203+
logRulesetFailure(assembly.GetName().Name!.Split('.').Last(), e);
202204
}
203205
}
204206
@@ -213,17 +215,19 @@ A.B c = 1;
213215
AppDomain.CurrentDomain.AssemblyResolve -= resolveRulesetDependencyAssembly;
214216
}
215217
216-
protected void LogFailedLoad(string name, Exception exception)
218+
public static void LogRulesetFailure(RulesetInfo ruleset, Exception e) => logRulesetFailure(ruleset.Name, e);
219+
220+
private static void logRulesetFailure(string name, Exception exception)
217221
{
218-
Logger.Log($"Could not load ruleset \\"{name}\\". Please check for an update from the developer.", level: LogLevel.Error);
219-
Logger.Log($"Ruleset load failed: {exception}");
222+
Logger.Log($"An issue with ruleset \"{name}\" occurred. Please check for an update from the developer.", level: LogLevel.Error);
223+
Logger.Log(exception.ToString());
220224
}
221225
222226
#region Implementation of IRulesetStore
223227
224228
IRulesetInfo? IRulesetStore.GetRuleset(int id) => GetRuleset(id);
225-
IRulesetInfo? IRulesetStore<T>.GetRuleset(string shortName) => GetRuleset(shortName);
226-
IEnumerable<IRulesetInfo> IRulesetStore<T>.AvailableRulesets => AvailableRulesets;
229+
IRulesetInfo? IRulesetStore.GetRuleset(string shortName) => GetRuleset(shortName);
230+
IEnumerable<IRulesetInfo> IRulesetStore.AvailableRulesets => AvailableRulesets;
227231
228232
#endregion
229233
}
@@ -233,7 +237,7 @@ A.B c = 1;
233237
new EditorView({
234238
state: EditorState.create({
235239
doc,
236-
extensions: [basicSetup, csharp(), oneDark, indentUnit.of(" "), EditorView.lineWrapping],
240+
extensions: [basicSetup, csharp(), oneDark, indentUnit.of(' '), EditorView.lineWrapping],
237241
}),
238242
parent: document.querySelector('#editor')!,
239243
});

dev/vite.config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
export default {
22
plugins: [],
3-
root: "dev",
4-
base: "./",
3+
root: 'dev',
4+
base: './',
55
server: {
66
host: '0.0.0.0',
77
hmr: {

0 commit comments

Comments
 (0)