Skip to content
Permalink
Browse files

[Assets] Properly find ffmpeg.exe and msdfgen.exe

  • Loading branch information
xen2 committed Nov 2, 2018
1 parent a88632d commit b55ab0c7866b655f5ee540c253b0842ee5f36272
@@ -40,14 +40,7 @@ public DecodeSoundFileCommand(string url, SoundAsset parameters, IAssetFinder as
protected override async Task<ResultStatus> DoCommandOverride(ICommandContext commandContext)
{
// Get path to ffmpeg
var installationDir = DirectoryHelper.GetPackageDirectory("Xenko");
var binDir = UPath.Combine(installationDir, new UDirectory("Bin"));
binDir = UPath.Combine(binDir, new UDirectory("Windows"));
var ffmpeg = UPath.Combine(binDir, new UFile("ffmpeg.exe")).ToWindowsPath();
if (!File.Exists(ffmpeg))
{
throw new AssetException("Failed to compile a sound asset. ffmpeg was not found.");
}
var ffmpeg = ToolLocator.LocateTool("ffmpeg.exe")?.ToWindowsPath() ?? 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();
@@ -83,12 +83,7 @@ protected override async Task<ResultStatus> DoCommandOverride(ICommandContext co
try
{
// Get path to ffmpeg
var installationDir = DirectoryHelper.GetPackageDirectory("Xenko");
var binDir = UPath.Combine(installationDir, new UDirectory("Bin"));
binDir = UPath.Combine(binDir, new UDirectory("Windows"));
var ffmpeg = UPath.Combine(binDir, new UFile("ffmpeg.exe")).ToWindowsPath();
if (!File.Exists(ffmpeg))
throw new AssetException("Failed to compile a video asset. ffmpeg was not found.");
var ffmpeg = ToolLocator.LocateTool("ffmpeg.exe")?.ToWindowsPath() ?? 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();
@@ -12,6 +12,7 @@ namespace Xenko.Assets.SpriteFont.Compiler
{
using System.Drawing;
using System.Drawing.Imaging;
using System.Reflection;
using SharpDX.DirectWrite;
using Factory = SharpDX.DirectWrite.Factory;

@@ -128,14 +129,7 @@ public void Import(SpriteFontAsset options, List<char> characters)
return;

// Get the msdfgen.exe location
var installationDir = DirectoryHelper.GetPackageDirectory("Xenko");
var binDir = UPath.Combine(installationDir, new UDirectory("Bin"));
binDir = UPath.Combine(binDir, new UDirectory("Windows"));
var msdfgen = UPath.Combine(binDir, new UFile("msdfgen.exe"));
if (!File.Exists(msdfgen))
{
throw new AssetException("Failed to compile a font asset, msdfgen was not found.");
}
var msdfgen = ToolLocator.LocateTool("msdfgen.exe") ?? throw new AssetException("Failed to compile a font asset, msdfgen was not found.");

msdfgenExe = msdfgen.FullPath;
tempDir = $"{Environment.GetEnvironmentVariable("TEMP")}\\";
@@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using Xenko.Core.IO;

namespace Xenko.Assets
{
static class ToolLocator
{
public static UFile LocateTool(string toolName)
{
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;

return null;
}
}
}

0 comments on commit b55ab0c

Please sign in to comment.
You can’t perform that action at this time.