Movie import cleanup
This commit is contained in:
parent
0043c1de1e
commit
f93766e5bb
|
@ -13,34 +13,9 @@ namespace BizHawk.Client.Common
|
|||
/// </summary>
|
||||
public static bool IsValidMovieExtension(string extension)
|
||||
{
|
||||
return SupportedExtensions.Any(e => string.Equals(extension, e, StringComparison.OrdinalIgnoreCase));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Attempts to convert a movie with the given filename to a support
|
||||
/// <seealso cref="IMovie"/> type
|
||||
/// </summary>
|
||||
/// <param name="fn">The path to the file to import</param>
|
||||
/// <param name="conversionErrorCallback">The callback that will be called if an error occurs</param>
|
||||
/// <param name="messageCallback">The callback that will be called if any messages need to be presented to the user</param>
|
||||
public static void Import(string fn, Action<string> conversionErrorCallback, Action<string> messageCallback)
|
||||
{
|
||||
var d = PathManager.MakeAbsolutePath(Global.Config.PathEntries.MoviesPathFragment, null);
|
||||
var m = ImportFile(fn, out var errorMsg, out var warningMsg);
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(errorMsg))
|
||||
{
|
||||
conversionErrorCallback(errorMsg);
|
||||
}
|
||||
|
||||
messageCallback(!string.IsNullOrWhiteSpace(warningMsg)
|
||||
? warningMsg
|
||||
: $"{Path.GetFileName(fn)} imported as {m.Filename}");
|
||||
|
||||
if (!Directory.Exists(d))
|
||||
{
|
||||
Directory.CreateDirectory(d);
|
||||
}
|
||||
return Importers
|
||||
.Select(i => i.Value)
|
||||
.Any(e => string.Equals(extension, e, StringComparison.OrdinalIgnoreCase));
|
||||
}
|
||||
|
||||
// Attempt to import another type of movie file into a movie object.
|
||||
|
@ -106,10 +81,5 @@ namespace BizHawk.Client.Common
|
|||
.Any())
|
||||
.ToDictionary(tkey => tkey, tvalue => ((ImportExtensionAttribute)tvalue.GetCustomAttributes(typeof(ImportExtensionAttribute))
|
||||
.First()).Extension);
|
||||
|
||||
|
||||
private static IEnumerable<string> SupportedExtensions => Importers
|
||||
.Select(i => i.Value)
|
||||
.ToList();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3852,14 +3852,24 @@ namespace BizHawk.Client.EmuHawk
|
|||
}
|
||||
}
|
||||
|
||||
private static void ShowConversionError(string errorMsg)
|
||||
{
|
||||
MessageBox.Show(errorMsg, "Conversion error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
|
||||
private static void ProcessMovieImport(string fn)
|
||||
{
|
||||
MovieImport.Import(fn, ShowConversionError, GlobalWin.OSD.AddMessage);
|
||||
var directory = PathManager.MakeAbsolutePath(Global.Config.PathEntries.MoviesPathFragment, null);
|
||||
var movie = MovieImport.ImportFile(fn, out var errorMsg, out var warningMsg);
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(errorMsg))
|
||||
{
|
||||
MessageBox.Show(errorMsg, "Conversion error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
|
||||
GlobalWin.OSD.AddMessage(!string.IsNullOrWhiteSpace(warningMsg)
|
||||
? warningMsg
|
||||
: $"{Path.GetFileName(fn)} imported as {movie.Filename}");
|
||||
|
||||
if (!Directory.Exists(directory))
|
||||
{
|
||||
Directory.CreateDirectory(directory);
|
||||
}
|
||||
}
|
||||
|
||||
public void EnableRewind(bool enabled)
|
||||
|
|
Loading…
Reference in New Issue