2015-11-06 14:31:50 +00:00
using System ;
using System.IO ;
using System.Collections.Generic ;
using System.Windows.Forms ;
2019-11-04 01:55:38 +00:00
2019-10-29 15:37:27 +00:00
using BizHawk.Emulation.Common ;
2017-04-18 03:49:08 +00:00
using BizHawk.Emulation.Cores.Libretro ;
2015-11-06 14:31:50 +00:00
using BizHawk.Client.Common ;
2020-01-03 20:19:42 +00:00
// these match strings from OpenAdvance. should we make them constants in there?
2015-11-06 14:31:50 +00:00
namespace BizHawk.Client.EmuHawk
{
2020-02-26 22:36:15 +00:00
/// <summary>
/// The Advanced ROM Loader type in MainForm/RomLoader/OpenAdvancedChooser
/// </summary>
public enum AdvancedRomLoaderType
{
None ,
LibretroLaunchNoGame ,
LibretroLaunchGame ,
ClassicLaunchGame ,
MameLaunchGame
}
2015-11-06 14:31:50 +00:00
public partial class OpenAdvancedChooser : Form
{
2019-12-31 16:17:55 +00:00
private readonly MainForm _mainForm ;
2020-01-03 20:19:42 +00:00
private readonly Config _config ;
2015-11-06 14:31:50 +00:00
2019-10-29 15:37:27 +00:00
public AdvancedRomLoaderType Result ;
2015-11-08 01:59:10 +00:00
public string SuggestedExtensionFilter ;
2020-01-03 20:19:42 +00:00
private RetroDescription _currentDescription ;
2015-11-06 14:31:50 +00:00
2020-01-03 20:19:42 +00:00
public OpenAdvancedChooser ( MainForm mainForm , Config config )
2015-11-06 14:31:50 +00:00
{
2019-12-31 16:17:55 +00:00
_mainForm = mainForm ;
2020-01-03 20:19:42 +00:00
_config = config ;
2015-11-06 14:31:50 +00:00
InitializeComponent ( ) ;
2015-11-08 01:59:10 +00:00
RefreshLibretroCore ( true ) ;
2015-11-06 14:31:50 +00:00
}
private void btnCancel_Click ( object sender , EventArgs e )
{
2019-12-31 16:17:55 +00:00
DialogResult = DialogResult . Cancel ;
2015-11-06 14:31:50 +00:00
Close ( ) ;
}
private void btnSetLibretroCore_Click ( object sender , EventArgs e )
{
2019-12-31 16:17:55 +00:00
if ( _mainForm . RunLibretroCoreChooser ( ) )
2015-11-17 23:26:03 +00:00
RefreshLibretroCore ( false ) ;
2015-11-06 14:31:50 +00:00
}
2020-01-03 20:19:42 +00:00
private void RefreshLibretroCore ( bool bootstrap )
2015-11-06 14:31:50 +00:00
{
txtLibretroCore . Text = "" ;
btnLibretroLaunchNoGame . Enabled = false ;
btnLibretroLaunchGame . Enabled = false ;
2020-01-03 20:19:42 +00:00
var core = _config . LibretroCore ;
2015-11-06 14:31:50 +00:00
if ( string . IsNullOrEmpty ( core ) )
2020-01-03 20:19:42 +00:00
{
2015-11-06 14:31:50 +00:00
return ;
2020-01-03 20:19:42 +00:00
}
2015-11-06 14:31:50 +00:00
txtLibretroCore . Text = core ;
2020-01-03 20:19:42 +00:00
_currentDescription = null ;
2015-11-06 14:31:50 +00:00
2020-01-03 20:19:42 +00:00
// scan the current libretro core to see if it can be launched with NoGame,and other stuff
2015-11-06 14:31:50 +00:00
try
{
2017-04-18 03:49:08 +00:00
//OLD COMMENTS:
////a stub corecomm. to reinforce that this won't touch the frontend at all!
////LibRetroEmulator should be able to survive having this stub corecomm
//NEW COMMENTS:
//nope, we need to navigate to the dll path. this was a bad idea anyway. so many dlls get loaded, something to resolve them is needed
2020-03-15 15:09:32 +00:00
var cfp = new CoreFileProvider ( s = > { } , Global . FirmwareManager ) ;
var coreComm = new CoreComm ( null , null , cfp ) ;
2020-03-14 19:22:23 +00:00
using var retro = new LibretroCore ( coreComm , Global . Game , core ) ;
2019-12-31 16:17:55 +00:00
btnLibretroLaunchGame . Enabled = true ;
if ( retro . Description . SupportsNoGame )
btnLibretroLaunchNoGame . Enabled = true ;
//print descriptive information
var descr = retro . Description ;
2020-01-03 20:19:42 +00:00
_currentDescription = descr ;
2019-12-31 16:17:55 +00:00
Console . WriteLine ( $"core name: {descr.LibraryName} version {descr.LibraryVersion}" ) ;
Console . WriteLine ( $"extensions: {descr.ValidExtensions}" ) ;
Console . WriteLine ( $"{nameof(descr.NeedsRomAsPath)}: {descr.NeedsRomAsPath}" ) ;
Console . WriteLine ( $"{nameof(descr.NeedsArchives)}: {descr.NeedsArchives}" ) ;
Console . WriteLine ( $"{nameof(descr.SupportsNoGame)}: {descr.SupportsNoGame}" ) ;
2015-11-08 01:59:10 +00:00
2019-12-31 16:17:55 +00:00
foreach ( var v in descr . Variables . Values )
Console . WriteLine ( v ) ;
2015-11-06 14:31:50 +00:00
}
2017-05-05 00:43:51 +00:00
catch ( Exception ex )
2015-11-08 01:59:10 +00:00
{
if ( ! bootstrap )
2017-05-05 00:43:51 +00:00
{
2019-03-18 14:06:37 +00:00
MessageBox . Show ( $"Couldn't load the selected Libretro core for analysis. It won't be available.\n\nError:\n\n{ex}" ) ;
2017-05-05 00:43:51 +00:00
}
2015-11-08 01:59:10 +00:00
}
2015-11-06 14:31:50 +00:00
}
private void btnLibretroLaunchGame_Click ( object sender , EventArgs e )
{
2020-02-20 21:04:30 +00:00
var entries = new List < FilesystemFilter > { new FilesystemFilter ( "ROMs" , _currentDescription . ValidExtensions . Split ( '|' ) ) } ;
if ( ! _currentDescription . NeedsArchives ) entries . Add ( FilesystemFilter . Archives ) ; // "needs archives" means the relevant archive extensions are already in the list, and we shouldn't scan archives for roms
SuggestedExtensionFilter = new FilesystemFilterSet ( entries . ToArray ( ) ) . ToString ( ) ;
2019-10-29 15:37:27 +00:00
Result = AdvancedRomLoaderType . LibretroLaunchGame ;
2019-12-06 18:34:20 +00:00
DialogResult = DialogResult . OK ;
2015-11-06 14:31:50 +00:00
Close ( ) ;
2019-11-04 01:55:38 +00:00
}
private void btnMAMELaunchGame_Click ( object sender , EventArgs e )
{
2020-02-26 22:36:15 +00:00
Result = AdvancedRomLoaderType . MameLaunchGame ;
2019-10-29 15:37:27 +00:00
DialogResult = DialogResult . OK ;
2019-11-04 01:55:38 +00:00
Close ( ) ;
2015-11-06 14:31:50 +00:00
}
private void btnClassicLaunchGame_Click ( object sender , EventArgs e )
{
2019-10-29 15:37:27 +00:00
Result = AdvancedRomLoaderType . ClassicLaunchGame ;
2017-05-04 22:54:21 +00:00
DialogResult = DialogResult . OK ;
2015-11-06 14:31:50 +00:00
Close ( ) ;
}
private void btnLibretroLaunchNoGame_Click ( object sender , EventArgs e )
{
2019-10-29 15:37:27 +00:00
Result = AdvancedRomLoaderType . LibretroLaunchNoGame ;
2017-05-04 22:54:21 +00:00
DialogResult = DialogResult . OK ;
2015-11-06 14:31:50 +00:00
Close ( ) ;
}
2017-05-04 22:54:21 +00:00
private void txtLibretroCore_DragEnter ( object sender , DragEventArgs e )
{
if ( e . Data . GetDataPresent ( DataFormats . FileDrop ) )
{
var filePaths = ( string [ ] ) e . Data . GetData ( DataFormats . FileDrop ) ;
if ( Path . GetExtension ( filePaths [ 0 ] ) . ToUpper ( ) = = ".DLL" )
{
e . Effect = DragDropEffects . Copy ;
return ;
}
}
e . Effect = DragDropEffects . None ;
}
private void txtLibretroCore_DragDrop ( object sender , DragEventArgs e )
{
var filePaths = ( string [ ] ) e . Data . GetData ( DataFormats . FileDrop ) ;
2020-01-03 20:19:42 +00:00
_config . LibretroCore = filePaths [ 0 ] ;
2017-05-04 22:54:21 +00:00
RefreshLibretroCore ( false ) ;
2019-11-04 01:55:38 +00:00
}
2015-11-06 14:31:50 +00:00
}
}