Move IResourceManager.GetContentRoots() to be internal, make it return strings instead

Previous API shouldn't have been content-accessible. It also returned OS paths over ResPath which is incorrect.
This commit is contained in:
PJB3005
2025-09-23 15:07:58 +02:00
parent 318c37e686
commit c8db7f98db
6 changed files with 26 additions and 23 deletions

View File

@@ -47,11 +47,11 @@ END TEMPLATE-->
### Other
*None yet*
* `IResourceManager.GetContentRoots()` has been obsoleted and returns no more results.
### Internal
*None yet*
* `IResourceManager.GetContentRoots()` has been replaced with a similar method on `IResourceManagerInternal`. This new method returns `string`s instead of `ResPath`s, and usage code has been updated to use these paths correctly.
## 267.1.0

View File

@@ -22,7 +22,7 @@ internal sealed class XamlHotReloadManager : IXamlHotReloadManager
{
[Dependency] private readonly IConfigurationManager _cfg = null!;
[Dependency] private readonly ILogManager _logManager = null!;
[Dependency] private readonly IResourceManager _resources = null!;
[Dependency] private readonly IResourceManagerInternal _resources = null!;
[Dependency] private readonly ITaskManager _taskManager = null!;
[Dependency] private readonly IXamlProxyManager _xamlProxyManager = null!;
@@ -120,9 +120,9 @@ internal sealed class XamlHotReloadManager : IXamlHotReloadManager
private string? InferCodeLocation()
{
// ascend upwards from each content root until the solution file is found
foreach (var contentRoot in _resources.GetContentRoots())
foreach (var baseSystemPath in _resources.GetContentRoots())
{
var systemPath = contentRoot.ToRelativeSystemPath();
var systemPath = baseSystemPath;
while (true)
{
var files = Array.Empty<string>();

View File

@@ -19,7 +19,7 @@ internal sealed class ReloadManager : IReloadManager
[Dependency] private readonly IClyde _clyde = default!;
[Dependency] private readonly IConfigurationManager _cfg = default!;
[Dependency] private readonly ILogManager _logMan = default!;
[Dependency] private readonly IResourceManager _res = default!;
[Dependency] private readonly IResourceManagerInternal _res = default!;
#pragma warning disable CS0414
[Dependency] private readonly ITaskManager _tasks = default!;
#pragma warning restore CS0414
@@ -72,7 +72,7 @@ internal sealed class ReloadManager : IReloadManager
public void Register(ResPath directory, string filter)
{
Register(directory.ToString(), filter);
Register(directory.ToRelativeSystemPath(), filter);
}
public void Register(string directory, string filter)
@@ -83,7 +83,7 @@ internal sealed class ReloadManager : IReloadManager
#if TOOLS
foreach (var root in _res.GetContentRoots())
{
var path = root + directory;
var path = Path.Join(root, directory);
if (!Directory.Exists(path))
{
@@ -128,17 +128,17 @@ internal sealed class ReloadManager : IReloadManager
_tasks.RunOnMainThread(() =>
{
var fullPath = args.FullPath.Replace(Path.DirectorySeparatorChar, '/');
var file = new ResPath(fullPath);
foreach (var rootIter in _res.GetContentRoots())
{
if (!file.TryRelativeTo(rootIter, out var relative))
var relPath = Path.GetRelativePath(rootIter, args.FullPath);
if (relPath == args.FullPath)
{
// Not relative.
continue;
}
_reloadQueue.Add(relative.Value);
var file = ResPath.FromRelativeSystemPath(relPath);
_reloadQueue.Add(file);
}
});
}

View File

@@ -139,6 +139,7 @@ namespace Robust.Shared.ContentPack
/// Returns a list of paths to all top-level content directories
/// </summary>
/// <returns></returns>
[Obsolete("This API is no longer content-accessible")]
IEnumerable<ResPath> GetContentRoots();
/// <summary>

View File

@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using Robust.Shared.Utility;
@@ -69,5 +70,7 @@ namespace Robust.Shared.ContentPack
/// </para>
/// </remarks>
bool TryGetDiskFilePath(ResPath path, [NotNullWhen(true)] out string? diskPath);
new IEnumerable<string> GetContentRoots();
}
}

View File

@@ -371,20 +371,19 @@ namespace Robust.Shared.ContentPack
AddRoot(ResPath.Root, loader);
}
public IEnumerable<ResPath> GetContentRoots()
IEnumerable<ResPath> IResourceManager.GetContentRoots()
{
return [];
}
public IEnumerable<string> GetContentRoots()
{
foreach (var (_, root) in _contentRoots)
{
if (root is DirLoader loader)
{
var rootDir = loader.GetPath(new ResPath(@"/"));
if (root is not DirLoader loader)
continue;
// TODO: GET RID OF THIS.
// This code shouldn't be passing OS disk paths through ResPath.
rootDir = rootDir.Replace(Path.DirectorySeparatorChar, '/');
yield return new ResPath(rootDir);
}
yield return loader.GetPath(ResPath.Root);
}
}