Drag and Drop - check if CDL is available when dropping a cdl file, instead of hardcoding what platforms has it, also some cleanup in relevant file

This commit is contained in:
adelikat 2017-05-10 15:06:00 -05:00
parent 22e2df3868
commit eef79d25e0
1 changed files with 26 additions and 47 deletions

View File

@ -1,33 +1,14 @@
using System;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
using System.Reflection;
using System.Linq;
using System.Collections.Generic;
using BizHawk.Common;
using BizHawk.Emulation.Common;
using BizHawk.Emulation.Common.IEmulatorExtensions;
using BizHawk.Emulation.Cores.Calculators;
using BizHawk.Emulation.Cores.ColecoVision;
using BizHawk.Emulation.Cores.Nintendo.Gameboy;
using BizHawk.Emulation.Cores.Nintendo.NES;
using BizHawk.Emulation.Cores.Nintendo.N64;
using BizHawk.Emulation.Cores.Nintendo.SNES;
using BizHawk.Emulation.Cores.PCEngine;
using BizHawk.Emulation.Cores.Sega.MasterSystem;
using BizHawk.Emulation.Cores.Consoles.Nintendo.QuickNES;
using BizHawk.Client.Common;
using BizHawk.Client.EmuHawk.CustomControls;
using BizHawk.Client.EmuHawk.WinFormExtensions;
using BizHawk.Client.EmuHawk.ToolExtensions;
using BizHawk.Emulation.Cores.Computers.AppleII;
using BizHawk.Client.ApiHawk;
namespace BizHawk.Client.EmuHawk
{
partial class MainForm
@ -47,34 +28,31 @@ namespace BizHawk.Client.EmuHawk
public struct FileInformation
{
public string directoryName;
public string fileName;
public string archiveName;
public string DirectoryName { get; }
public string FileName { get; }
public string ArchiveName { get; }
public FileInformation(string directory, string file, string archive)
{
directoryName = directory;
fileName = file;
archiveName = archive;
DirectoryName = directory;
FileName = file;
ArchiveName = archive;
}
}
// This is the list from MainForm->RomFilter()'s non-developer build. It needs to be kept up-to-date when new cores are added.
readonly string[] knownROMExtensions = { ".NES", ".FDS", ".UNF", ".SMS", ".GG", ".SG", ".GB", ".GBC", ".GBA", ".PCE", ".SGX", ".BIN", ".SMD", ".GEN", ".MD", ".SMC", ".SFC", ".A26", ".A78", ".LNX", ".COL", ".ROM", ".M3U", ".CUE", ".CCD", ".SGB", ".Z64", ".V64", ".N64", ".WS", ".WSC", ".XML", ".DSK", ".DO", ".PO", ".PSF", ".MINIPSF", ".NSF" };
readonly string[] nonArchive = { ".ISO", ".CUE", ".CCD" };
private readonly string[] _knownROMExtensions = { ".NES", ".FDS", ".UNF", ".SMS", ".GG", ".SG", ".GB", ".GBC", ".GBA", ".PCE", ".SGX", ".BIN", ".SMD", ".GEN", ".MD", ".SMC", ".SFC", ".A26", ".A78", ".LNX", ".COL", ".ROM", ".M3U", ".CUE", ".CCD", ".SGB", ".Z64", ".V64", ".N64", ".WS", ".WSC", ".XML", ".DSK", ".DO", ".PO", ".PSF", ".MINIPSF", ".NSF" };
private readonly string[] _nonArchive = { ".ISO", ".CUE", ".CCD" };
#region Loaders
// According to the documentation (http://tasvideos.org/Bizhawk/CodeDataLogger.html),
// Currently supported for: PCE, GB/GBC, SMS/GG, Genesis, SNES
// Perhaps the 'is PCEngine' requirement needs to be expanded.
private void _LoadCDL(string filename, string archive = null)
{
if (!(Global.Emulator is PCEngine))
return;
GlobalWin.Tools.Load<CDL>();
(GlobalWin.Tools.Get<CDL>() as CDL).LoadFile(filename);
if (GlobalWin.Tools.IsAvailable<CDL>())
{
CDL cdl = GlobalWin.Tools.Load<CDL>();
cdl.LoadFile(filename);
}
}
private void _LoadCheats(string filename, string archive = null)
@ -199,9 +177,9 @@ namespace BizHawk.Client.EmuHawk
sortedFiles[LoadOrdering.MOVIEFILE].Add(fileInformation);
else if (MovieImport.IsValidMovieExtension(ext))
sortedFiles[LoadOrdering.LEGACYMOVIEFILE].Add(fileInformation);
else if (knownROMExtensions.Contains(ext))
else if (_knownROMExtensions.Contains(ext))
{
if (String.IsNullOrEmpty(archive) || !nonArchive.Contains(ext))
if (String.IsNullOrEmpty(archive) || !_nonArchive.Contains(ext))
sortedFiles[LoadOrdering.ROM].Add(fileInformation);
}
else
@ -304,30 +282,31 @@ namespace BizHawk.Client.EmuHawk
break;
case 1:
FileInformation fileInformation = sortedFiles[value].First<FileInformation>();
string filename = Path.Combine(new string[] { fileInformation.directoryName, fileInformation.fileName });
string filename = Path.Combine(new string[] { fileInformation.DirectoryName, fileInformation.FileName });
switch (value)
{
case LoadOrdering.ROM:
_LoadRom(filename, fileInformation.archiveName);
MessageBox.Show("hi");
_LoadRom(filename, fileInformation.ArchiveName);
break;
case LoadOrdering.STATE:
_LoadState(filename, fileInformation.archiveName);
_LoadState(filename, fileInformation.ArchiveName);
break;
case LoadOrdering.WATCH:
_LoadWatch(filename, fileInformation.archiveName);
_LoadWatch(filename, fileInformation.ArchiveName);
break;
case LoadOrdering.CDLFILE:
_LoadCDL(filename, fileInformation.archiveName);
_LoadCDL(filename, fileInformation.ArchiveName);
break;
case LoadOrdering.LUASESSION:
_LoadLuaSession(filename, fileInformation.archiveName);
_LoadLuaSession(filename, fileInformation.ArchiveName);
break;
case LoadOrdering.LUASCRIPT:
_LoadLuaFile(filename, fileInformation.archiveName);
_LoadLuaFile(filename, fileInformation.ArchiveName);
break;
case LoadOrdering.CHEAT:
_LoadCheats(filename, fileInformation.archiveName);
_LoadCheats(filename, fileInformation.ArchiveName);
break;
case LoadOrdering.MOVIEFILE:
case LoadOrdering.LEGACYMOVIEFILE:
@ -336,9 +315,9 @@ namespace BizHawk.Client.EmuHawk
break;
if (value == LoadOrdering.MOVIEFILE)
_LoadMovie(filename, fileInformation.archiveName);
_LoadMovie(filename, fileInformation.ArchiveName);
else
_LoadLegacyMovie(filename, fileInformation.archiveName);
_LoadLegacyMovie(filename, fileInformation.ArchiveName);
break;
}
break;