Misc. cleanups

This commit is contained in:
YoshiRulz 2020-02-21 04:50:50 +10:00
parent b75b41ad64
commit f71cc532a8
No known key found for this signature in database
GPG Key ID: C4DE31C245353FB7
3 changed files with 11 additions and 17 deletions

View File

@ -20,12 +20,12 @@ namespace BizHawk.Client.Common
/// <summary>
/// Gets the file extension for the default movie implementation used in the client
/// </summary>
public static string DefaultExtension => "bk2";
public const string DefaultExtension = "bk2";
/// <summary>
/// Gets a list of extensions for all <seealso cref="IMovie"/> implementations
/// </summary>
public static IEnumerable<string> MovieExtensions => new[] { "bk2", "tasproj" };
public static IEnumerable<string> MovieExtensions => new[] { DefaultExtension, TasMovie.Extension };
public static bool IsValidMovieExtension(string ext)
{

View File

@ -8,6 +8,11 @@ namespace BizHawk.Client.Common
{
public static class MovieImport
{
private static readonly Dictionary<Type, ImporterForAttribute> Importers = Assembly.GetAssembly(typeof(ImporterForAttribute)).GetTypes()
.Select(t => (t, attr: (ImporterForAttribute) t.GetCustomAttributes(typeof(ImporterForAttribute)).FirstOrDefault()))
.Where(tuple => tuple.attr != null)
.ToDictionary(tuple => tuple.t, tuple => tuple.attr);
/// <summary>
/// Returns a value indicating whether or not there is an importer for the given extension
/// </summary>
@ -54,12 +59,5 @@ namespace BizHawk.Client.Common
{
return Importers.FirstOrDefault(i => string.Equals(i.Value.Extension, ext, StringComparison.OrdinalIgnoreCase)).Key;
}
private static readonly Dictionary<Type, ImporterForAttribute> Importers = Assembly.GetAssembly(typeof(ImporterForAttribute))
.GetTypes()
.Where(t => t.GetCustomAttributes(typeof(ImporterForAttribute))
.Any())
.ToDictionary(tkey => tkey, tvalue => ((ImporterForAttribute)tvalue.GetCustomAttributes(typeof(ImporterForAttribute))
.First()));
}
}

View File

@ -391,12 +391,11 @@ namespace BizHawk.Client.EmuHawk
return (int)form.Handle;
}
[LuaMethodExample("local stforope = forms.openfile( \"C:\\filename.bin\", \"C:\\\", \"All files ( *.* )|*.*\");")]
[LuaMethodExample(@"local filename = forms.openfile(""C:\filename.bin"", ""C:\"", ""Raster Images (*.bmp;*.gif;*.jpg;*.png)|*.bmp;*.gif;*.jpg;*.png|All Files (*.*)|*.*"")")]
[LuaMethod(
"openfile", "Creates a standard openfile dialog with optional parameters for the filename, directory, and filter. The return value is the directory that the user picked. If they chose to cancel, it will return an empty string")]
public string OpenFile(string fileName = null, string initialDirectory = null, string filter = "All files (*.*)|*.*")
public string OpenFile(string fileName = null, string initialDirectory = null, string filter = null)
{
// filterext format ex: "Image Files(*.BMP;*.JPG;*.GIF)|*.BMP;*.JPG;*.GIF|All files (*.*)|*.*"
var openFileDialog1 = new OpenFileDialog();
if (initialDirectory != null)
{
@ -408,11 +407,8 @@ namespace BizHawk.Client.EmuHawk
openFileDialog1.FileName = fileName;
}
if (filter != null)
{
openFileDialog1.AddExtension = true;
openFileDialog1.Filter = filter;
}
openFileDialog1.AddExtension = true;
openFileDialog1.Filter = filter ?? "All Files (*.*)|*";
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{