Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Adjust ToolLocator for all platforms #2250

Merged
merged 1 commit into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions sources/core/Stride.Core.Design/IO/UPath.cs
Original file line number Diff line number Diff line change
Expand Up @@ -290,11 +290,25 @@ public override string ToString()
/// </summary>
/// <returns>A string representation of this path in windows form.</returns>
[NotNull]
[Obsolete("Use ToOSPath() instead")]
public string ToWindowsPath()
{
return FullPath.Replace('/', '\\');
}

/// <summary>
/// Converts this path to a OS path,
/// by replacing each separator with the current operating system
/// <see cref="Path.DirectorySeparatorChar"/>
/// </summary>
///<returns>A normalized string path</returns>

[NotNull]
public string ToOSPath()
{
return FullPath.Replace('/', Path.DirectorySeparatorChar);
}

/// <summary>
/// Implements the ==.
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion sources/engine/Stride.Assets/Media/SoundAssetCompiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public DecodeSoundFileCommand(string url, SoundAsset parameters, IAssetFinder as
protected override async Task<ResultStatus> DoCommandOverride(ICommandContext commandContext)
{
// Get path to ffmpeg
var ffmpeg = ToolLocator.LocateTool("ffmpeg.exe")?.ToWindowsPath() ?? throw new AssetException("Failed to compile a sound asset, ffmpeg was not found.");
var ffmpeg = ToolLocator.LocateTool("ffmpeg")?.ToOSPath() ?? throw new AssetException("Failed to compile a sound asset, ffmpeg was not found.");

// Get absolute path of asset source on disk
var assetDirectory = Parameters.Source.GetParent();
Expand Down
2 changes: 1 addition & 1 deletion sources/engine/Stride.Assets/Media/VideoAssetCompiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ protected override async Task<ResultStatus> DoCommandOverride(ICommandContext co
try
{
// Get path to ffmpeg
var ffmpeg = ToolLocator.LocateTool("ffmpeg.exe")?.ToWindowsPath() ?? throw new AssetException("Failed to compile a video asset, ffmpeg was not found.");
var ffmpeg = ToolLocator.LocateTool("ffmpeg")?.ToOSPath() ?? throw new AssetException("Failed to compile a video asset, ffmpeg was not found.");

// Get absolute path of asset source on disk
var assetDirectory = videoAsset.Source.GetParent();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public void Import(SpriteFontAsset options, List<char> characters)
return;

// Get the msdfgen.exe location
var msdfgen = ToolLocator.LocateTool("msdfgen.exe") ?? throw new AssetException("Failed to compile a font asset, msdfgen was not found.");
var msdfgen = ToolLocator.LocateTool("msdfgen").ToOSPath() ?? throw new AssetException("Failed to compile a font asset, msdfgen was not found.");

msdfgenExe = msdfgen.FullPath;
tempDir = $"{Environment.GetEnvironmentVariable("TEMP")}\\";
Expand Down
33 changes: 22 additions & 11 deletions sources/engine/Stride.Assets/ToolLocator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,32 @@
using System.Threading.Tasks;
using Stride.Core.IO;

namespace Stride.Assets
namespace Stride.Assets;

static class ToolLocator
{
static class ToolLocator
public static UFile LocateTool(string toolName)
{
public static UFile LocateTool(string toolName)
if(!OperatingSystem.IsWindows())
{
var tool = UPath.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), new UFile(toolName));
if (File.Exists(tool))
return tool;

tool = UPath.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), new UFile($"../../content/{toolName}"));
if (File.Exists(tool))
return tool;
var pathDirectories = Environment.GetEnvironmentVariable("PATH")?.Split(':') ?? Array.Empty<string>();

return null;
foreach (var directory in pathDirectories)
{
var toolLocation = Path.Combine(directory, toolName);
if (File.Exists(toolLocation))
return new UFile(toolLocation);
}
}

var tool = UPath.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), new UFile($"{toolName}.exe"));
if (File.Exists(tool))
return tool;

tool = UPath.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), new UFile($"../../content/{toolName}.exe"));
if (File.Exists(tool))
return tool;

return null;
}
}