2019-10-22 03:54:16 +00:00
using System ;
using System.Drawing ;
2019-12-21 08:17:43 +00:00
using System.IO ;
using System.Text ;
2019-10-22 03:54:16 +00:00
using System.Windows.Forms ;
using BizHawk.Client.Common ;
using BizHawk.Client.EmuHawk.CustomControls ;
2019-12-21 08:17:43 +00:00
using BizHawk.Common ;
2019-10-22 03:54:16 +00:00
using BizHawk.Emulation.Common ;
using Cores = BizHawk . Emulation . Cores ;
namespace BizHawk.Client.EmuHawk
{
public static class EmuHawkUtil
{
public static bool EnsureCoreIsAccurate ( IEmulator emulator )
{
2019-10-27 16:05:06 +00:00
static bool PromptToSwitchCore ( string currentCore , string recommendedCore , Action disableCurrentCore )
2019-10-22 03:54:16 +00:00
{
2019-10-27 18:00:02 +00:00
using var box = new MsgBox (
$"While the {currentCore} core is faster, it is not nearly as accurate as {recommendedCore}.{Environment.NewLine}It is recommended that you switch to the {recommendedCore} core for movie recording.{Environment.NewLine}Switch to {recommendedCore}?" ,
2019-10-22 03:54:16 +00:00
"Accuracy Warning" ,
MessageBoxIcon . Warning ) ;
box . SetButtons (
new [ ] { "Switch" , "Continue" } ,
new [ ] { DialogResult . Yes , DialogResult . Cancel } ) ;
box . MaximumSize = UIHelper . Scale ( new Size ( 575 , 175 ) ) ;
box . SetMessageToAutoSize ( ) ;
var result = box . ShowDialog ( ) ;
if ( result ! = DialogResult . Yes )
{
return false ;
}
disableCurrentCore ( ) ;
GlobalWin . MainForm . RebootCore ( ) ;
return true ;
}
if ( emulator is Cores . Nintendo . SNES9X . Snes9x )
{
return PromptToSwitchCore ( "Snes9x" , "bsnes" , ( ) = > Global . Config . SNES_InSnes9x = false ) ;
}
if ( emulator is Cores . Consoles . Nintendo . QuickNES . QuickNES )
{
return PromptToSwitchCore ( "QuickNes" , "NesHawk" , ( ) = > Global . Config . NES_InQuickNES = false ) ;
}
return true ;
}
2019-12-21 08:17:43 +00:00
/// <remarks>http://stackoverflow.com/questions/139010/how-to-resolve-a-lnk-in-c-sharp</remarks>
public static string ResolveShortcut ( string filename )
{
if ( filename . Contains ( "|" ) | | OSTailoredCode . IsUnixHost | | ! ".lnk" . Equals ( Path . GetExtension ( filename ) , StringComparison . InvariantCultureIgnoreCase ) ) return filename ; // archive internal files are never shortcuts (and choke when analyzing any further)
var link = new ShellLinkImports . ShellLink ( ) ;
const uint STGM_READ = 0 ;
( ( ShellLinkImports . IPersistFile ) link ) . Load ( filename , STGM_READ ) ;
#if false
// TODO: if I can get hold of the hwnd call resolve first. This handles moved and renamed files.
( ( ShellLinkImports . IShellLinkW ) link ) . Resolve ( hwnd , 0 ) ;
#endif
var sb = new StringBuilder ( Win32Imports . MAX_PATH ) ;
( ( ShellLinkImports . IShellLinkW ) link ) . GetPath ( sb , sb . Capacity , out _ , 0 ) ;
return sb . Length = = 0 ? filename : sb . ToString ( ) ; // maybe? what if it's invalid?
}
2019-10-22 03:54:16 +00:00
}
}