movie import - cleanup
This commit is contained in:
parent
fb8111d630
commit
eb1b658f6e
|
@ -154,6 +154,7 @@
|
|||
<DependentUpon>Bk2Movie.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="movie\bk2\StringLogs.cs" />
|
||||
<Compile Include="movie\import\BkmImport.cs" />
|
||||
<Compile Include="movie\import\FcmImport.cs" />
|
||||
<Compile Include="movie\import\FmvImport.cs" />
|
||||
<Compile Include="movie\import\GmvImport.cs" />
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
using BizHawk.Client.Common.MovieConversionExtensions;
|
||||
|
||||
namespace BizHawk.Client.Common.movie.import
|
||||
{
|
||||
// ReSharper disable once UnusedMember.Global
|
||||
[ImportExtension(".bkm")]
|
||||
public class BkmImport : MovieImporter
|
||||
{
|
||||
protected override void RunImport()
|
||||
{
|
||||
var movie = new BkmMovie
|
||||
{
|
||||
Filename = SourceFile.FullName
|
||||
};
|
||||
|
||||
movie.Load(false);
|
||||
Result.Movie = movie.ToBk2();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -3,29 +3,17 @@ using System.Collections.Generic;
|
|||
using System.Linq;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using BizHawk.Common.BufferExtensions;
|
||||
using BizHawk.Common.IOExtensions;
|
||||
|
||||
using BizHawk.Emulation.Common;
|
||||
using BizHawk.Client.Common.MovieConversionExtensions;
|
||||
|
||||
namespace BizHawk.Client.Common
|
||||
{
|
||||
public static class MovieImport
|
||||
{
|
||||
// Movies 2.0 TODO: this is Movie.cs specific, can it be IMovie based? If not, needs to be refactored to a hardcoded 2.0 implementation, client needs to know what kind of type it imported to, or the mainform method needs to be moved here
|
||||
private const string EMULATIONORIGIN = "emuOrigin";
|
||||
private const string JAPAN = "Japan";
|
||||
private const string MD5 = "MD5";
|
||||
private const string MOVIEORIGIN = "MovieOrigin";
|
||||
|
||||
/// <summary>
|
||||
/// Returns a value indicating whether or not there is an importer for the given extension
|
||||
/// </summary>
|
||||
public static bool IsValidMovieExtension(string extension)
|
||||
{
|
||||
return SupportedExtensions.Any(e => string.Equals(extension, e, StringComparison.OrdinalIgnoreCase))
|
||||
|| UsesLegacyImporter(extension);
|
||||
return SupportedExtensions.Any(e => string.Equals(extension, e, StringComparison.OrdinalIgnoreCase));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -62,11 +50,6 @@ namespace BizHawk.Client.Common
|
|||
warningMsg = "";
|
||||
string ext = path != null ? Path.GetExtension(path).ToUpper() : "";
|
||||
|
||||
if (UsesLegacyImporter(ext))
|
||||
{
|
||||
return LegacyImportFile(ext, path, out errorMsg, out warningMsg).ToBk2();
|
||||
}
|
||||
|
||||
var importerType = ImporterForExtension(ext);
|
||||
|
||||
if (importerType == default)
|
||||
|
@ -117,40 +100,6 @@ namespace BizHawk.Client.Common
|
|||
return Importers.FirstOrDefault(i => string.Equals(i.Value, ext, StringComparison.OrdinalIgnoreCase)).Key;
|
||||
}
|
||||
|
||||
private static BkmMovie LegacyImportFile(string ext, string path, out string errorMsg, out string warningMsg)
|
||||
{
|
||||
errorMsg = "";
|
||||
warningMsg = "";
|
||||
|
||||
BkmMovie m = new BkmMovie();
|
||||
|
||||
try
|
||||
{
|
||||
switch (ext)
|
||||
{
|
||||
case ".BKM":
|
||||
m.Filename = path;
|
||||
m.Load(false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch (Exception except)
|
||||
{
|
||||
errorMsg = except.ToString();
|
||||
}
|
||||
|
||||
if (m != null)
|
||||
{
|
||||
m.Filename += $".{BkmMovie.Extension}";
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception(errorMsg);
|
||||
}
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
private static readonly Dictionary<Type, string> Importers = Assembly.GetAssembly(typeof(ImportExtensionAttribute))
|
||||
.GetTypes()
|
||||
.Where(t => t.GetCustomAttributes(typeof(ImportExtensionAttribute))
|
||||
|
@ -162,15 +111,5 @@ namespace BizHawk.Client.Common
|
|||
private static IEnumerable<string> SupportedExtensions => Importers
|
||||
.Select(i => i.Value)
|
||||
.ToList();
|
||||
|
||||
// Return whether or not the type of file provided is currently imported by a legacy (i.e. to BKM not BK2) importer
|
||||
private static bool UsesLegacyImporter(string extension)
|
||||
{
|
||||
string[] extensions =
|
||||
{
|
||||
"BKM"
|
||||
};
|
||||
return extensions.Any(ext => extension.ToUpper() == $".{ext}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue