Fix movie importer crashing on files with unrecognised extentions
This commit is contained in:
parent
d17352a204
commit
85caed48cc
|
@ -4,6 +4,8 @@ using System.Linq;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
|
||||||
|
using BizHawk.Common.CollectionExtensions;
|
||||||
|
|
||||||
namespace BizHawk.Client.Common
|
namespace BizHawk.Client.Common
|
||||||
{
|
{
|
||||||
public static class MovieImport
|
public static class MovieImport
|
||||||
|
@ -39,23 +41,12 @@ namespace BizHawk.Client.Common
|
||||||
Config config)
|
Config config)
|
||||||
{
|
{
|
||||||
string ext = Path.GetExtension(path) ?? "";
|
string ext = Path.GetExtension(path) ?? "";
|
||||||
var importerType = ImporterForExtension(ext);
|
var result = Importers.FirstOrNull(kvp => string.Equals(kvp.Value.Extension, ext, StringComparison.OrdinalIgnoreCase));
|
||||||
|
|
||||||
if (importerType == default)
|
|
||||||
{
|
|
||||||
return ImportResult.Error($"No importer found for file type {ext}");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create a new instance of the importer class using the no-argument constructor
|
// Create a new instance of the importer class using the no-argument constructor
|
||||||
|
return result is { Key: var importerType }
|
||||||
return importerType.GetConstructor(Array.Empty<Type>())?.Invoke(Array.Empty<object>()) is IMovieImport importer
|
&& importerType.GetConstructor(Array.Empty<Type>())?.Invoke(Array.Empty<object>()) is IMovieImport importer
|
||||||
? importer.Import(dialogParent, session, path, config)
|
? importer.Import(dialogParent, session, path, config)
|
||||||
: ImportResult.Error($"No importer found for file type {ext}");
|
: ImportResult.Error($"No importer found for file type {ext}");
|
||||||
}
|
|
||||||
|
|
||||||
private static Type ImporterForExtension(string ext)
|
|
||||||
{
|
|
||||||
return Importers.First(i => string.Equals(i.Value.Extension, ext, StringComparison.OrdinalIgnoreCase)).Key;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4162,6 +4162,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
if (result.Errors.Any())
|
if (result.Errors.Any())
|
||||||
{
|
{
|
||||||
ShowMessageBox(owner: null, string.Join("\n", result.Errors), "Conversion error", EMsgBoxIcon.Error);
|
ShowMessageBox(owner: null, string.Join("\n", result.Errors), "Conversion error", EMsgBoxIcon.Error);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result.Warnings.Any())
|
if (result.Warnings.Any())
|
||||||
|
|
Loading…
Reference in New Issue