From 19a7408c6d427cc1e80e7e61cba604d342300ab8 Mon Sep 17 00:00:00 2001 From: Adam Michaud Date: Sun, 20 Mar 2016 23:19:25 -0400 Subject: [PATCH] More ROM Extensions Fixes the issue reported by feos (http://tasvideos.org/forum/viewtopic.php?p=430806#430806) where some ROM extensions were not being recognized. I had generated the list of ROM extensions based on the cases in RomLoader->LoadRom(), but am now using the non-developer build list in MainForm->RomFilter(). Unfortunately, this means that if someone adds a file extension in the future (by, say, adding a new core), this list will need updating as well. Also, spaces were replaced by tabs where appropriate. --- BizHawk.Client.EmuHawk/FileLoader.cs | 567 +++++++++++++-------------- 1 file changed, 283 insertions(+), 284 deletions(-) diff --git a/BizHawk.Client.EmuHawk/FileLoader.cs b/BizHawk.Client.EmuHawk/FileLoader.cs index b8935bcb91..a3b347e219 100644 --- a/BizHawk.Client.EmuHawk/FileLoader.cs +++ b/BizHawk.Client.EmuHawk/FileLoader.cs @@ -28,323 +28,322 @@ using BizHawk.Client.ApiHawk; namespace BizHawk.Client.EmuHawk { - partial class MainForm - { - private enum LoadOrdering - { - ROM, - STATE, - WATCH, - CDLFILE, - LUASESSION, - LUASCRIPT, - CHEAT, - MOVIEFILE, - LEGACYMOVIEFILE - } + partial class MainForm + { + private enum LoadOrdering + { + ROM, + STATE, + WATCH, + CDLFILE, + LUASESSION, + LUASCRIPT, + CHEAT, + MOVIEFILE, + LEGACYMOVIEFILE + } - public struct FileInformation - { - public string directoryName; - public string fileName; - public string archiveName; + public struct FileInformation + { + public string directoryName; + public string fileName; + public string archiveName; - public FileInformation(string directory, string file, string archive) - { - directoryName = directory; - fileName = file; - archiveName = archive; - } - } + public FileInformation(string directory, string file, string archive) + { + directoryName = directory; + fileName = file; + archiveName = archive; + } + } - readonly string[] knownROMExtensions = { ".M3U", ".ISO", ".CUE", ".CCD", ".XML", ".PSF", ".MINIPSF", - ".EXE", ".NES", ".83P", ".SNES", ".GB", ".GBC", ".A78", - ".C64", ".GBA", ".PSX" }; - readonly string[] nonArchive = { ".ISO", ".CUE", ".CCD" }; + // 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" }; - #region Loaders + #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; + // 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(); - (GlobalWin.Tools.Get() as CDL).LoadFile(filename); - } + GlobalWin.Tools.Load(); + (GlobalWin.Tools.Get() as CDL).LoadFile(filename); + } - private void _LoadCheats(string filename, string archive = null) - { - Global.CheatList.Load(filename, false); - GlobalWin.Tools.Load(); - } + private void _LoadCheats(string filename, string archive = null) + { + Global.CheatList.Load(filename, false); + GlobalWin.Tools.Load(); + } - private void _LoadLegacyMovie(string filename, string archive = null) - { - if (Global.Emulator.IsNull()) - { - OpenRom(); - } + private void _LoadLegacyMovie(string filename, string archive = null) + { + if (Global.Emulator.IsNull()) + { + OpenRom(); + } - if (Global.Emulator.IsNull()) - { - return; - } + if (Global.Emulator.IsNull()) + { + return; + } - // tries to open a legacy movie format by importing it - string errorMsg; - string warningMsg; - var movie = MovieImport.ImportFile(filename, out errorMsg, out warningMsg); - if (!string.IsNullOrEmpty(errorMsg)) - { - MessageBox.Show(errorMsg, "Conversion error", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - else - { - // fix movie extension to something palatable for these purposes. - // for instance, something which doesnt clobber movies you already may have had. - // i'm evenly torn between this, and a file in %TEMP%, but since we dont really have a way to clean up this tempfile, i choose this: - StartNewMovie(movie, false); - } + // tries to open a legacy movie format by importing it + string errorMsg; + string warningMsg; + var movie = MovieImport.ImportFile(filename, out errorMsg, out warningMsg); + if (!string.IsNullOrEmpty(errorMsg)) + { + MessageBox.Show(errorMsg, "Conversion error", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + else + { + // fix movie extension to something palatable for these purposes. + // for instance, something which doesnt clobber movies you already may have had. + // i'm evenly torn between this, and a file in %TEMP%, but since we dont really have a way to clean up this tempfile, i choose this: + StartNewMovie(movie, false); + } - GlobalWin.OSD.AddMessage(warningMsg); - } + GlobalWin.OSD.AddMessage(warningMsg); + } - private void _LoadLuaFile(string filename, string archive = null) - { - OpenLuaConsole(); - if (GlobalWin.Tools.Has()) - { - GlobalWin.Tools.LuaConsole.LoadLuaFile(filename); - } - } + private void _LoadLuaFile(string filename, string archive = null) + { + OpenLuaConsole(); + if (GlobalWin.Tools.Has()) + { + GlobalWin.Tools.LuaConsole.LoadLuaFile(filename); + } + } - private void _LoadLuaSession(string filename, string archive = null) - { - OpenLuaConsole(); - if (GlobalWin.Tools.Has()) - { - GlobalWin.Tools.LuaConsole.LoadLuaSession(filename); - } - } + private void _LoadLuaSession(string filename, string archive = null) + { + OpenLuaConsole(); + if (GlobalWin.Tools.Has()) + { + GlobalWin.Tools.LuaConsole.LoadLuaSession(filename); + } + } - private void _LoadMovie(string filename, string archive = null) - { - if (Global.Emulator.IsNull()) - { - OpenRom(); - } + private void _LoadMovie(string filename, string archive = null) + { + if (Global.Emulator.IsNull()) + { + OpenRom(); + } - if (Global.Emulator.IsNull()) - { - return; - } + if (Global.Emulator.IsNull()) + { + return; + } - StartNewMovie(MovieService.Get(filename), false); - } + StartNewMovie(MovieService.Get(filename), false); + } - private void _LoadRom(string filename, string archive = null) - { - var args = new LoadRomArgs(); - args.OpenAdvanced = new OpenAdvanced_OpenRom { Path = filename }; - LoadRom(filename, args); - } + private void _LoadRom(string filename, string archive = null) + { + var args = new LoadRomArgs(); + args.OpenAdvanced = new OpenAdvanced_OpenRom { Path = filename }; + LoadRom(filename, args); + } - private void _LoadState(string filename, string archive = null) - { - LoadState(filename, Path.GetFileName(filename)); - } + private void _LoadState(string filename, string archive = null) + { + LoadState(filename, Path.GetFileName(filename)); + } - private void _LoadWatch(string filename, string archive = null) - { - GlobalWin.Tools.LoadRamWatch(true); - (GlobalWin.Tools.Get() as RamWatch).LoadWatchFile(new FileInfo(filename), false); - } + private void _LoadWatch(string filename, string archive = null) + { + GlobalWin.Tools.LoadRamWatch(true); + (GlobalWin.Tools.Get() as RamWatch).LoadWatchFile(new FileInfo(filename), false); + } - #endregion + #endregion - private void ProcessFileList(string[] fileList, ref Dictionary> sortedFiles, string archive = null) - { - foreach (string file in fileList) - { - var ext = Path.GetExtension(file).ToUpper() ?? String.Empty; - FileInformation fileInformation = new FileInformation(Path.GetDirectoryName(file), Path.GetFileName(file), archive); + private void ProcessFileList(string[] fileList, ref Dictionary> sortedFiles, string archive = null) + { + foreach (string file in fileList) + { + var ext = Path.GetExtension(file).ToUpper() ?? String.Empty; + FileInformation fileInformation = new FileInformation(Path.GetDirectoryName(file), Path.GetFileName(file), archive); - switch (ext) - { - case ".LUA": - sortedFiles[LoadOrdering.LUASCRIPT].Add(fileInformation); - break; - case ".LUASES": - sortedFiles[LoadOrdering.LUASESSION].Add(fileInformation); - break; - case ".STATE": - sortedFiles[LoadOrdering.STATE].Add(fileInformation); - break; - case ".CHT": - sortedFiles[LoadOrdering.CHEAT].Add(fileInformation); - break; - case ".WCH": - sortedFiles[LoadOrdering.WATCH].Add(fileInformation); - break; - case ".CDL": - sortedFiles[LoadOrdering.CDLFILE].Add(fileInformation); - break; - default: - if (MovieService.IsValidMovieExtension(ext)) - sortedFiles[LoadOrdering.MOVIEFILE].Add(fileInformation); - else if (MovieImport.IsValidMovieExtension(ext)) - sortedFiles[LoadOrdering.LEGACYMOVIEFILE].Add(fileInformation); - else if (knownROMExtensions.Contains(ext)) - { - if (String.IsNullOrEmpty(archive) || !nonArchive.Contains(ext)) - sortedFiles[LoadOrdering.ROM].Add(fileInformation); - } - else - { - /* Because the existing behaviour for archives is to try loading - * ROMs out of them, that is exactly what we are going to continue - * to do at present. Ideally, the archive should be scanned and - * relevant files should be extracted, but see the note below for - * further details. - */ - int offset = 0; - bool executable = false; - var archiveHandler = new SevenZipSharpArchiveHandler(); + switch (ext) + { + case ".LUA": + sortedFiles[LoadOrdering.LUASCRIPT].Add(fileInformation); + break; + case ".LUASES": + sortedFiles[LoadOrdering.LUASESSION].Add(fileInformation); + break; + case ".STATE": + sortedFiles[LoadOrdering.STATE].Add(fileInformation); + break; + case ".CHT": + sortedFiles[LoadOrdering.CHEAT].Add(fileInformation); + break; + case ".WCH": + sortedFiles[LoadOrdering.WATCH].Add(fileInformation); + break; + case ".CDL": + sortedFiles[LoadOrdering.CDLFILE].Add(fileInformation); + break; + default: + if (MovieService.IsValidMovieExtension(ext)) + sortedFiles[LoadOrdering.MOVIEFILE].Add(fileInformation); + else if (MovieImport.IsValidMovieExtension(ext)) + sortedFiles[LoadOrdering.LEGACYMOVIEFILE].Add(fileInformation); + else if (knownROMExtensions.Contains(ext)) + { + if (String.IsNullOrEmpty(archive) || !nonArchive.Contains(ext)) + sortedFiles[LoadOrdering.ROM].Add(fileInformation); + } + else + { + /* Because the existing behaviour for archives is to try loading + * ROMs out of them, that is exactly what we are going to continue + * to do at present. Ideally, the archive should be scanned and + * relevant files should be extracted, but see the note below for + * further details. + */ + int offset = 0; + bool executable = false; + var archiveHandler = new SevenZipSharpArchiveHandler(); - if (String.IsNullOrEmpty(archive) && archiveHandler.CheckSignature(file, out offset, out executable)) - sortedFiles[LoadOrdering.ROM].Add(fileInformation); + if (String.IsNullOrEmpty(archive) && archiveHandler.CheckSignature(file, out offset, out executable)) + sortedFiles[LoadOrdering.ROM].Add(fileInformation); - /* - * This is where handling archives would go. - * Right now, that's going to be a HUGE hassle, because of the problem with - * saving things into the archive (no) and with everything requiring filenames - * and not streams (also no), so for the purposes of making drag/drop more robust, - * I am not building this out just yet. - * -- Adam Michaud (Invariel) - - int offset = 0; - bool executable = false; - var archiveHandler = new SevenZipSharpArchiveHandler(); + /* + * This is where handling archives would go. + * Right now, that's going to be a HUGE hassle, because of the problem with + * saving things into the archive (no) and with everything requiring filenames + * and not streams (also no), so for the purposes of making drag/drop more robust, + * I am not building this out just yet. + * -- Adam Michaud (Invariel) + + int offset = 0; + bool executable = false; + var archiveHandler = new SevenZipSharpArchiveHandler(); - // Not going to process nested archives at the moment. - if (String.IsNullOrEmpty (archive) && archiveHandler.CheckSignature(file, out offset, out executable)) - { - List fileNames = new List(); - var openedArchive = archiveHandler.Construct (file); + // Not going to process nested archives at the moment. + if (String.IsNullOrEmpty (archive) && archiveHandler.CheckSignature(file, out offset, out executable)) + { + List fileNames = new List(); + var openedArchive = archiveHandler.Construct (file); - foreach (BizHawk.Common.HawkFileArchiveItem item in openedArchive.Scan ()) - fileNames.Add(item.Name); + foreach (BizHawk.Common.HawkFileArchiveItem item in openedArchive.Scan ()) + fileNames.Add(item.Name); - ProcessFileList(fileNames.ToArray(), ref sortedFiles, file); + ProcessFileList(fileNames.ToArray(), ref sortedFiles, file); - openedArchive.Dispose(); - } - archiveHandler.Dispose(); - */ - } - break; - } - } - } + openedArchive.Dispose(); + } + archiveHandler.Dispose(); + */ + } + break; + } + } + } - private void _FormDragDrop_internal(object sender, DragEventArgs e) - { - /* - * Refactor, moving the loading of particular files into separate functions that can - * then be used by this code, and loading individual files through the file dialogue. - * - * Step 1: - * Build a dictionary of relevant files from everything that was dragged and dropped. - * This includes peeking into all relevant archives and using their files. - * - * Step 2: - * Perhaps ask the user which of a particular file type they want to use. - * Example: rom1.nes, rom2.smc, rom3.cue are drag-dropped, ask the user which they want to use. - * - * Step 3: - * Load all of the relevant files, in priority order: - * 1) The ROM - * 2) State - * 3) Watch files - * 4) Code Data Logger (CDL) - * 5) LUA sessions - * 6) LUA scripts - * 7) Cheat files - * 8) Movie Playback Files - * - * Bonus: - * Make that order easy to change in the code, heavily suggesting ROM and playback as first and last respectively. - */ + private void _FormDragDrop_internal(object sender, DragEventArgs e) + { + /* + * Refactor, moving the loading of particular files into separate functions that can + * then be used by this code, and loading individual files through the file dialogue. + * + * Step 1: + * Build a dictionary of relevant files from everything that was dragged and dropped. + * This includes peeking into all relevant archives and using their files. + * + * Step 2: + * Perhaps ask the user which of a particular file type they want to use. + * Example: rom1.nes, rom2.smc, rom3.cue are drag-dropped, ask the user which they want to use. + * + * Step 3: + * Load all of the relevant files, in priority order: + * 1) The ROM + * 2) State + * 3) Watch files + * 4) Code Data Logger (CDL) + * 5) LUA sessions + * 6) LUA scripts + * 7) Cheat files + * 8) Movie Playback Files + * + * Bonus: + * Make that order easy to change in the code, heavily suggesting ROM and playback as first and last respectively. + */ - var filePaths = (string[])e.Data.GetData(DataFormats.FileDrop); - Dictionary> sortedFiles = new Dictionary>(); + var filePaths = (string[])e.Data.GetData(DataFormats.FileDrop); + Dictionary> sortedFiles = new Dictionary>(); - // Initialize the dictionary's lists. - foreach (LoadOrdering value in Enum.GetValues(typeof(LoadOrdering))) - { - sortedFiles.Add(value, new List()); - } + // Initialize the dictionary's lists. + foreach (LoadOrdering value in Enum.GetValues(typeof(LoadOrdering))) + { + sortedFiles.Add(value, new List()); + } - ProcessFileList(filePaths, ref sortedFiles, null); + ProcessFileList(filePaths, ref sortedFiles, null); - // For each of the different types of item, if there are no items of that type, skip them. - // If there is exactly one of that type of item, load it. - // If there is more than one, ask. + // For each of the different types of item, if there are no items of that type, skip them. + // If there is exactly one of that type of item, load it. + // If there is more than one, ask. - foreach (LoadOrdering value in Enum.GetValues(typeof(LoadOrdering))) - { - switch (sortedFiles[value].Count) - { - case 0: - break; - case 1: - FileInformation fileInformation = sortedFiles[value].First(); - string filename = Path.Combine(new string[] { fileInformation.directoryName, fileInformation.fileName }); + foreach (LoadOrdering value in Enum.GetValues(typeof(LoadOrdering))) + { + switch (sortedFiles[value].Count) + { + case 0: + break; + case 1: + FileInformation fileInformation = sortedFiles[value].First(); + string filename = Path.Combine(new string[] { fileInformation.directoryName, fileInformation.fileName }); - switch (value) - { - case LoadOrdering.ROM: - _LoadRom(filename, fileInformation.archiveName); - break; - case LoadOrdering.STATE: - _LoadState(filename, fileInformation.archiveName); - break; - case LoadOrdering.WATCH: - _LoadWatch(filename, fileInformation.archiveName); - break; - case LoadOrdering.CDLFILE: - _LoadCDL(filename, fileInformation.archiveName); - break; - case LoadOrdering.LUASESSION: - _LoadLuaSession(filename, fileInformation.archiveName); - break; - case LoadOrdering.LUASCRIPT: - _LoadLuaFile(filename, fileInformation.archiveName); - break; - case LoadOrdering.CHEAT: - _LoadCheats(filename, fileInformation.archiveName); - break; - case LoadOrdering.MOVIEFILE: - case LoadOrdering.LEGACYMOVIEFILE: - // I don't really like this hack, but for now, we only want to load one movie file. - if (sortedFiles[LoadOrdering.MOVIEFILE].Count + sortedFiles[LoadOrdering.LEGACYMOVIEFILE].Count > 1) - break; + switch (value) + { + case LoadOrdering.ROM: + _LoadRom(filename, fileInformation.archiveName); + break; + case LoadOrdering.STATE: + _LoadState(filename, fileInformation.archiveName); + break; + case LoadOrdering.WATCH: + _LoadWatch(filename, fileInformation.archiveName); + break; + case LoadOrdering.CDLFILE: + _LoadCDL(filename, fileInformation.archiveName); + break; + case LoadOrdering.LUASESSION: + _LoadLuaSession(filename, fileInformation.archiveName); + break; + case LoadOrdering.LUASCRIPT: + _LoadLuaFile(filename, fileInformation.archiveName); + break; + case LoadOrdering.CHEAT: + _LoadCheats(filename, fileInformation.archiveName); + break; + case LoadOrdering.MOVIEFILE: + case LoadOrdering.LEGACYMOVIEFILE: + // I don't really like this hack, but for now, we only want to load one movie file. + if (sortedFiles[LoadOrdering.MOVIEFILE].Count + sortedFiles[LoadOrdering.LEGACYMOVIEFILE].Count > 1) + break; - if (value == LoadOrdering.MOVIEFILE) - _LoadMovie(filename, fileInformation.archiveName); - else - _LoadLegacyMovie(filename, fileInformation.archiveName); - break; - } - break; - default: - break; - } - } - } - } -} \ No newline at end of file + if (value == LoadOrdering.MOVIEFILE) + _LoadMovie(filename, fileInformation.archiveName); + else + _LoadLegacyMovie(filename, fileInformation.archiveName); + break; + } + break; + default: + break; + } + } + } + } +}