BizHawk/BizHawk.Client.Common/movie/MovieService.cs

101 lines
2.0 KiB
C#
Raw Normal View History

2014-06-11 02:33:57 +00:00
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
2014-06-14 19:13:21 +00:00
using System.Reflection;
2014-06-11 02:33:57 +00:00
using System.Text;
2014-06-12 11:53:25 +00:00
using BizHawk.Common;
using BizHawk.Client.Common.MovieConversionExtensions;
2014-06-12 11:53:25 +00:00
2014-06-11 02:33:57 +00:00
namespace BizHawk.Client.Common
{
2014-06-11 21:14:13 +00:00
public static class MovieService
2014-06-11 02:33:57 +00:00
{
2014-06-12 11:53:25 +00:00
public static IMovie Get(string path)
2014-06-11 02:33:57 +00:00
{
// TODO: open the file and determine the format, and instantiate the appropriate implementation
// Currently we just use the file extension
2014-06-12 11:53:25 +00:00
// TODO: change IMovies to take HawkFiles only and not path
if (Path.GetExtension(path).EndsWith("bk2"))
{
return new Bk2Movie(path);
}
2014-06-14 20:17:07 +00:00
else if (Path.GetExtension(path).EndsWith("tasproj"))
{
return new TasMovie(path);
}
else
{
var movie = new BkmMovie(path);
if (VersionInfo.DeveloperBuild)
{
movie.Load();
return movie.ToBk2();
}
else
{
return movie;
}
}
2014-06-11 02:33:57 +00:00
}
2014-06-12 11:53:25 +00:00
/// <summary>
/// Gets the file extension for the default movie implementation used in the client
/// </summary>
public static string DefaultExtension
{
get
{
if (VersionInfo.DeveloperBuild)
{
return "bk2";
}
return "bkm";
}
2014-06-12 11:53:25 +00:00
}
/// <summary>
/// Returns a list of extensions for all IMovie implementations
/// </summary>
public static IEnumerable<string> MovieExtensions
{
get
{
yield return "bkm";
yield return "bk2";
yield return "tasproj";
}
}
2014-06-12 21:45:47 +00:00
2014-06-14 14:09:55 +00:00
public static bool IsValidMovieExtension(string ext)
{
if (MovieExtensions.Contains(ext.ToLower().Replace(".", "")))
{
return true;
}
return false;
}
2014-06-12 21:45:47 +00:00
/// <summary>
/// Creates a default instance of the default implementation,
/// no path is specified so this is in a minimal state that would not be able to be saved
/// </summary>
public static IMovie DefaultInstance
{
get
{
if (VersionInfo.DeveloperBuild)
{
return new Bk2Movie();
}
2014-06-13 00:15:55 +00:00
return new BkmMovie();
2014-06-12 21:45:47 +00:00
}
}
2014-06-11 02:33:57 +00:00
}
}