2020-11-17 16:40:19 -05:00
using ARMeilleure.Translation ;
2020-06-16 14:28:02 -04:00
using ARMeilleure.Translation.PTC ;
2019-09-02 12:03:57 -04:00
using Gtk ;
2020-03-25 13:09:38 -04:00
using LibHac.Common ;
using LibHac.Ns ;
2019-09-02 12:03:57 -04:00
using Ryujinx.Audio ;
2020-08-30 12:51:53 -04:00
using Ryujinx.Common.Configuration ;
2019-09-02 12:03:57 -04:00
using Ryujinx.Common.Logging ;
2020-08-17 21:49:37 -04:00
using Ryujinx.Common.System ;
2020-01-05 06:49:44 -05:00
using Ryujinx.Configuration ;
2020-01-21 17:23:11 -05:00
using Ryujinx.Graphics.GAL ;
2019-10-13 02:02:07 -04:00
using Ryujinx.Graphics.OpenGL ;
2020-01-05 06:49:44 -05:00
using Ryujinx.HLE.FileSystem ;
2020-01-21 17:23:11 -05:00
using Ryujinx.HLE.FileSystem.Content ;
2020-09-20 23:45:30 -04:00
using Ryujinx.HLE.HOS ;
2021-01-08 03:14:13 -05:00
using Ryujinx.Modules ;
using Ryujinx.Ui.App ;
using Ryujinx.Ui.Applet ;
using Ryujinx.Ui.Helper ;
using Ryujinx.Ui.Widgets ;
using Ryujinx.Ui.Windows ;
2019-09-02 12:03:57 -04:00
using System ;
2020-01-05 06:49:44 -05:00
using System.Diagnostics ;
2019-09-02 12:03:57 -04:00
using System.IO ;
2021-01-08 03:14:13 -05:00
using System.Runtime.InteropServices ;
2019-09-02 12:03:57 -04:00
using System.Threading ;
2019-12-21 14:52:31 -05:00
using System.Threading.Tasks ;
2019-09-02 12:03:57 -04:00
2019-11-28 23:32:51 -05:00
using GUI = Gtk . Builder . ObjectAttribute ;
namespace Ryujinx.Ui
2019-09-02 12:03:57 -04:00
{
public class MainWindow : Window
{
2021-01-08 03:14:13 -05:00
private readonly VirtualFileSystem _virtualFileSystem ;
private readonly ContentManager _contentManager ;
2019-09-02 12:03:57 -04:00
2021-01-08 03:14:13 -05:00
private UserChannelPersistence _userChannelPersistence ;
2019-09-02 12:03:57 -04:00
2021-01-08 03:14:13 -05:00
private HLE . Switch _emulationContext ;
2019-09-02 12:03:57 -04:00
2021-01-08 03:14:13 -05:00
private WindowsMultimediaTimerResolution _windowsMultimediaTimerResolution ;
2020-09-20 23:45:30 -04:00
2021-01-08 03:14:13 -05:00
private readonly ApplicationLibrary _applicationLibrary ;
private readonly GtkHostUiHandler _uiHandler ;
private readonly AutoResetEvent _deviceExitStatus ;
private readonly ListStore _tableStore ;
2020-02-06 06:38:24 -05:00
2021-01-08 03:14:13 -05:00
private bool _updatingGameTable ;
private bool _gameLoaded ;
private bool _ending ;
2019-09-02 12:03:57 -04:00
2021-01-08 03:14:13 -05:00
private string _currentEmulatedGamePath = null ;
public GlRenderer GlRendererWidget ;
2020-05-02 22:00:53 -04:00
2020-04-20 17:59:59 -04:00
#pragma warning disable CS0169 , CS0649 , IDE0044
2020-02-11 19:56:19 -05:00
2020-09-29 16:05:25 -04:00
[GUI] public MenuItem ExitMenuItem ;
[GUI] public MenuItem UpdateMenuItem ;
[GUI] MenuBar _menuBar ;
[GUI] Box _footerBox ;
[GUI] Box _statusBar ;
[GUI] MenuItem _stopEmulation ;
2021-01-11 10:03:37 -05:00
[GUI] MenuItem _simulateWakeUpMessage ;
2020-09-29 16:05:25 -04:00
[GUI] MenuItem _fullScreen ;
2020-12-01 17:02:27 -05:00
[GUI] CheckMenuItem _startFullScreen ;
2020-09-29 16:05:25 -04:00
[GUI] CheckMenuItem _favToggle ;
[GUI] MenuItem _firmwareInstallDirectory ;
[GUI] MenuItem _firmwareInstallFile ;
2020-10-13 16:54:42 -04:00
[GUI] Label _fifoStatus ;
2020-09-29 16:05:25 -04:00
[GUI] CheckMenuItem _iconToggle ;
[GUI] CheckMenuItem _developerToggle ;
[GUI] CheckMenuItem _appToggle ;
[GUI] CheckMenuItem _timePlayedToggle ;
[GUI] CheckMenuItem _versionToggle ;
[GUI] CheckMenuItem _lastPlayedToggle ;
[GUI] CheckMenuItem _fileExtToggle ;
[GUI] CheckMenuItem _pathToggle ;
[GUI] CheckMenuItem _fileSizeToggle ;
[GUI] Label _dockedMode ;
2020-12-15 21:19:07 -05:00
[GUI] Label _aspectRatio ;
2020-09-29 16:05:25 -04:00
[GUI] Label _gameStatus ;
[GUI] TreeView _gameTable ;
[GUI] TreeSelection _gameTableSelection ;
[GUI] ScrolledWindow _gameTableWindow ;
[GUI] Label _gpuName ;
[GUI] Label _progressLabel ;
[GUI] Label _firmwareVersionLabel ;
[GUI] LevelBar _progressBar ;
[GUI] Box _viewBox ;
[GUI] Label _vSyncStatus ;
[GUI] Box _listStatusBox ;
2020-02-11 19:56:19 -05:00
2020-04-20 17:59:59 -04:00
#pragma warning restore CS0649 , IDE0044 , CS0169
2019-09-02 12:03:57 -04:00
2019-11-28 23:32:51 -05:00
public MainWindow ( ) : this ( new Builder ( "Ryujinx.Ui.MainWindow.glade" ) ) { }
2019-09-02 12:03:57 -04:00
2019-11-28 23:32:51 -05:00
private MainWindow ( Builder builder ) : base ( builder . GetObject ( "_mainWin" ) . Handle )
2019-09-02 12:03:57 -04:00
{
2019-11-28 23:32:51 -05:00
builder . Autoconnect ( this ) ;
2021-01-08 03:14:13 -05:00
// Apply custom theme if needed.
ThemeHelper . ApplyTheme ( ) ;
// Sets overridden fields.
2020-03-30 18:10:13 -04:00
int monitorWidth = Display . PrimaryMonitor . Geometry . Width * Display . PrimaryMonitor . ScaleFactor ;
int monitorHeight = Display . PrimaryMonitor . Geometry . Height * Display . PrimaryMonitor . ScaleFactor ;
2021-01-08 03:14:13 -05:00
DefaultWidth = monitorWidth < 1280 ? monitorWidth : 1280 ;
DefaultHeight = monitorHeight < 760 ? monitorHeight : 760 ;
2019-11-28 23:32:51 -05:00
2021-01-08 03:14:13 -05:00
Title = $"Ryujinx {Program.Version}" ;
2019-12-21 21:49:51 -05:00
2021-01-08 03:14:13 -05:00
// Hide emulation context status bar.
_statusBar . Hide ( ) ;
2020-01-05 06:49:44 -05:00
2021-01-08 03:14:13 -05:00
// Instanciate HLE objects.
2020-11-18 19:34:28 -05:00
_virtualFileSystem = VirtualFileSystem . CreateInstance ( ) ;
_contentManager = new ContentManager ( _virtualFileSystem ) ;
2021-01-08 03:14:13 -05:00
_userChannelPersistence = new UserChannelPersistence ( ) ;
2019-09-02 12:03:57 -04:00
2021-01-08 03:14:13 -05:00
// Instanciate GUI objects.
_applicationLibrary = new ApplicationLibrary ( _virtualFileSystem ) ;
_uiHandler = new GtkHostUiHandler ( this ) ;
_deviceExitStatus = new AutoResetEvent ( false ) ;
2020-01-05 06:49:44 -05:00
2021-01-08 03:14:13 -05:00
WindowStateEvent + = WindowStateEvent_Changed ;
DeleteEvent + = Window_Close ;
2020-01-05 06:49:44 -05:00
2021-01-08 03:14:13 -05:00
_applicationLibrary . ApplicationAdded + = Application_Added ;
_applicationLibrary . ApplicationCountUpdated + = ApplicationCount_Updated ;
_gameTable . ButtonReleaseEvent + = Row_Clicked ;
_fullScreen . Activated + = FullScreen_Toggled ;
2020-01-21 17:23:11 -05:00
2021-01-08 03:14:13 -05:00
GlRenderer . StatusUpdatedEvent + = Update_StatusBar ;
2019-09-02 12:03:57 -04:00
2020-12-01 17:02:27 -05:00
if ( ConfigurationState . Instance . Ui . StartFullscreen )
{
_startFullScreen . Active = true ;
}
2021-01-11 10:03:37 -05:00
_stopEmulation . Sensitive = false ;
_simulateWakeUpMessage . Sensitive = false ;
2019-09-02 12:03:57 -04:00
2019-12-21 14:52:31 -05:00
if ( ConfigurationState . Instance . Ui . GuiColumns . FavColumn ) _favToggle . Active = true ;
if ( ConfigurationState . Instance . Ui . GuiColumns . IconColumn ) _iconToggle . Active = true ;
if ( ConfigurationState . Instance . Ui . GuiColumns . AppColumn ) _appToggle . Active = true ;
if ( ConfigurationState . Instance . Ui . GuiColumns . DevColumn ) _developerToggle . Active = true ;
if ( ConfigurationState . Instance . Ui . GuiColumns . VersionColumn ) _versionToggle . Active = true ;
if ( ConfigurationState . Instance . Ui . GuiColumns . TimePlayedColumn ) _timePlayedToggle . Active = true ;
if ( ConfigurationState . Instance . Ui . GuiColumns . LastPlayedColumn ) _lastPlayedToggle . Active = true ;
if ( ConfigurationState . Instance . Ui . GuiColumns . FileExtColumn ) _fileExtToggle . Active = true ;
if ( ConfigurationState . Instance . Ui . GuiColumns . FileSizeColumn ) _fileSizeToggle . Active = true ;
if ( ConfigurationState . Instance . Ui . GuiColumns . PathColumn ) _pathToggle . Active = true ;
2019-11-28 23:32:51 -05:00
_gameTable . Model = _tableStore = new ListStore (
2019-12-21 14:52:31 -05:00
typeof ( bool ) ,
typeof ( Gdk . Pixbuf ) ,
typeof ( string ) ,
typeof ( string ) ,
typeof ( string ) ,
typeof ( string ) ,
typeof ( string ) ,
typeof ( string ) ,
typeof ( string ) ,
2020-03-25 13:09:38 -04:00
typeof ( string ) ,
typeof ( BlitStruct < ApplicationControlProperty > ) ) ;
2019-12-21 14:52:31 -05:00
2021-01-08 03:14:13 -05:00
_tableStore . SetSortFunc ( 5 , SortHelper . TimePlayedSort ) ;
_tableStore . SetSortFunc ( 6 , SortHelper . LastPlayedSort ) ;
_tableStore . SetSortFunc ( 8 , SortHelper . FileSizeSort ) ;
2020-06-26 06:30:16 -04:00
int columnId = ConfigurationState . Instance . Ui . ColumnSort . SortColumnId ;
bool ascending = ConfigurationState . Instance . Ui . ColumnSort . SortAscending ;
_tableStore . SetSortColumnId ( columnId , ascending ? SortType . Ascending : SortType . Descending ) ;
2019-11-28 23:32:51 -05:00
2020-04-25 09:02:44 -04:00
_gameTable . EnableSearch = true ;
_gameTable . SearchColumn = 2 ;
2019-11-28 23:32:51 -05:00
UpdateColumns ( ) ;
UpdateGameTable ( ) ;
2020-01-11 21:10:55 -05:00
2020-07-03 19:29:36 -04:00
ConfigurationState . Instance . Ui . GameDirs . Event + = ( sender , args ) = >
{
if ( args . OldValue ! = args . NewValue )
{
UpdateGameTable ( ) ;
}
} ;
2020-01-11 21:10:55 -05:00
Task . Run ( RefreshFirmwareLabel ) ;
2019-11-28 23:32:51 -05:00
}
2021-01-08 03:14:13 -05:00
private void WindowStateEvent_Changed ( object o , WindowStateEventArgs args )
2020-07-23 09:12:19 -04:00
{
_fullScreen . Label = args . Event . NewWindowState . HasFlag ( Gdk . WindowState . Fullscreen ) ? "Exit Fullscreen" : "Enter Fullscreen" ;
}
2019-11-28 23:32:51 -05:00
private void UpdateColumns ( )
2019-09-02 12:03:57 -04:00
{
2019-11-28 23:32:51 -05:00
foreach ( TreeViewColumn column in _gameTable . Columns )
{
_gameTable . RemoveColumn ( column ) ;
}
2019-09-02 12:03:57 -04:00
2019-11-28 23:32:51 -05:00
CellRendererToggle favToggle = new CellRendererToggle ( ) ;
favToggle . Toggled + = FavToggle_Toggled ;
2019-12-21 14:52:31 -05:00
if ( ConfigurationState . Instance . Ui . GuiColumns . FavColumn ) _gameTable . AppendColumn ( "Fav" , favToggle , "active" , 0 ) ;
if ( ConfigurationState . Instance . Ui . GuiColumns . IconColumn ) _gameTable . AppendColumn ( "Icon" , new CellRendererPixbuf ( ) , "pixbuf" , 1 ) ;
if ( ConfigurationState . Instance . Ui . GuiColumns . AppColumn ) _gameTable . AppendColumn ( "Application" , new CellRendererText ( ) , "text" , 2 ) ;
if ( ConfigurationState . Instance . Ui . GuiColumns . DevColumn ) _gameTable . AppendColumn ( "Developer" , new CellRendererText ( ) , "text" , 3 ) ;
if ( ConfigurationState . Instance . Ui . GuiColumns . VersionColumn ) _gameTable . AppendColumn ( "Version" , new CellRendererText ( ) , "text" , 4 ) ;
if ( ConfigurationState . Instance . Ui . GuiColumns . TimePlayedColumn ) _gameTable . AppendColumn ( "Time Played" , new CellRendererText ( ) , "text" , 5 ) ;
if ( ConfigurationState . Instance . Ui . GuiColumns . LastPlayedColumn ) _gameTable . AppendColumn ( "Last Played" , new CellRendererText ( ) , "text" , 6 ) ;
if ( ConfigurationState . Instance . Ui . GuiColumns . FileExtColumn ) _gameTable . AppendColumn ( "File Ext" , new CellRendererText ( ) , "text" , 7 ) ;
if ( ConfigurationState . Instance . Ui . GuiColumns . FileSizeColumn ) _gameTable . AppendColumn ( "File Size" , new CellRendererText ( ) , "text" , 8 ) ;
if ( ConfigurationState . Instance . Ui . GuiColumns . PathColumn ) _gameTable . AppendColumn ( "Path" , new CellRendererText ( ) , "text" , 9 ) ;
2019-11-28 23:32:51 -05:00
foreach ( TreeViewColumn column in _gameTable . Columns )
2019-09-02 12:03:57 -04:00
{
2020-06-26 06:30:16 -04:00
switch ( column . Title )
{
case "Fav" :
column . SortColumnId = 0 ;
column . Clicked + = Column_Clicked ;
break ;
case "Application" :
column . SortColumnId = 2 ;
column . Clicked + = Column_Clicked ;
break ;
case "Developer" :
column . SortColumnId = 3 ;
column . Clicked + = Column_Clicked ;
break ;
case "Version" :
column . SortColumnId = 4 ;
column . Clicked + = Column_Clicked ;
break ;
case "Time Played" :
column . SortColumnId = 5 ;
column . Clicked + = Column_Clicked ;
break ;
case "Last Played" :
column . SortColumnId = 6 ;
column . Clicked + = Column_Clicked ;
break ;
case "File Ext" :
column . SortColumnId = 7 ;
column . Clicked + = Column_Clicked ;
break ;
case "File Size" :
column . SortColumnId = 8 ;
column . Clicked + = Column_Clicked ;
break ;
case "Path" :
column . SortColumnId = 9 ;
column . Clicked + = Column_Clicked ;
break ;
}
2019-09-02 12:03:57 -04:00
}
2019-12-21 14:52:31 -05:00
}
2021-01-08 03:14:13 -05:00
private void InitializeSwitchInstance ( )
2019-12-21 14:52:31 -05:00
{
2020-01-21 17:23:11 -05:00
_virtualFileSystem . Reload ( ) ;
2021-01-08 03:14:13 -05:00
IRenderer renderer = new Renderer ( ) ;
IAalOutput audioEngine = new DummyAudioOut ( ) ;
if ( ConfigurationState . Instance . System . AudioBackend . Value = = AudioBackend . SoundIo )
{
if ( SoundIoAudioOut . IsSupported )
{
audioEngine = new SoundIoAudioOut ( ) ;
}
else
{
Logger . Warning ? . Print ( LogClass . Audio , "SoundIO is not supported, falling back to dummy audio out." ) ;
}
}
else if ( ConfigurationState . Instance . System . AudioBackend . Value = = AudioBackend . OpenAl )
{
if ( OpenALAudioOut . IsSupported )
{
audioEngine = new OpenALAudioOut ( ) ;
}
else
{
Logger . Warning ? . Print ( LogClass . Audio , "OpenAL is not supported, trying to fall back to SoundIO." ) ;
if ( SoundIoAudioOut . IsSupported )
{
Logger . Warning ? . Print ( LogClass . Audio , "Found SoundIO, changing configuration." ) ;
ConfigurationState . Instance . System . AudioBackend . Value = AudioBackend . SoundIo ;
SaveConfig ( ) ;
audioEngine = new SoundIoAudioOut ( ) ;
}
else
{
Logger . Warning ? . Print ( LogClass . Audio , "SoundIO is not supported, falling back to dummy audio out." ) ;
}
}
}
_emulationContext = new HLE . Switch ( _virtualFileSystem , _contentManager , _userChannelPersistence , renderer , audioEngine )
2020-08-02 21:30:58 -04:00
{
UiHandler = _uiHandler
} ;
2019-12-21 14:52:31 -05:00
2021-01-08 03:14:13 -05:00
_emulationContext . Initialize ( ) ;
2019-09-02 12:03:57 -04:00
}
2021-01-08 03:14:13 -05:00
public void UpdateGameTable ( )
2019-09-02 12:03:57 -04:00
{
2020-07-03 19:29:36 -04:00
if ( _updatingGameTable | | _gameLoaded )
2019-09-02 12:03:57 -04:00
{
2019-11-28 23:32:51 -05:00
return ;
2019-09-02 12:03:57 -04:00
}
2019-11-28 23:32:51 -05:00
_updatingGameTable = true ;
_tableStore . Clear ( ) ;
2020-01-31 13:21:46 -05:00
Thread applicationLibraryThread = new Thread ( ( ) = >
{
2021-01-08 03:14:13 -05:00
_applicationLibrary . LoadApplications ( ConfigurationState . Instance . Ui . GameDirs , ConfigurationState . Instance . System . Language ) ;
2019-11-28 23:32:51 -05:00
2020-01-31 13:21:46 -05:00
_updatingGameTable = false ;
} ) ;
2021-01-08 03:14:13 -05:00
applicationLibraryThread . Name = "GUI.ApplicationLibraryThread" ;
2020-01-31 13:21:46 -05:00
applicationLibraryThread . IsBackground = true ;
applicationLibraryThread . Start ( ) ;
2019-09-02 12:03:57 -04:00
}
2021-01-08 03:14:13 -05:00
[Conditional("RELEASE")]
public void PerformanceCheck ( )
2019-09-02 12:03:57 -04:00
{
2021-01-08 03:14:13 -05:00
if ( ConfigurationState . Instance . Logger . EnableDebug . Value )
2019-09-02 12:03:57 -04:00
{
2021-01-08 03:14:13 -05:00
MessageDialog debugWarningDialog = new MessageDialog ( this , DialogFlags . Modal , MessageType . Warning , ButtonsType . YesNo , null )
{
Title = "Ryujinx - Warning" ,
Text = "You have debug logging enabled, which is designed to be used by developers only." ,
SecondaryText = "For optimal performance, it's recommended to disable debug logging. Would you like to disable debug logging now?"
} ;
if ( debugWarningDialog . Run ( ) = = ( int ) ResponseType . Yes )
{
ConfigurationState . Instance . Logger . EnableDebug . Value = false ;
SaveConfig ( ) ;
}
debugWarningDialog . Dispose ( ) ;
2019-09-02 12:03:57 -04:00
}
2021-01-08 03:14:13 -05:00
if ( ! string . IsNullOrWhiteSpace ( ConfigurationState . Instance . Graphics . ShadersDumpPath . Value ) )
2019-09-02 12:03:57 -04:00
{
2021-01-08 03:14:13 -05:00
MessageDialog shadersDumpWarningDialog = new MessageDialog ( this , DialogFlags . Modal , MessageType . Warning , ButtonsType . YesNo , null )
2020-03-30 17:39:46 -04:00
{
2021-01-08 03:14:13 -05:00
Title = "Ryujinx - Warning" ,
Text = "You have shader dumping enabled, which is designed to be used by developers only." ,
SecondaryText = "For optimal performance, it's recommended to disable shader dumping. Would you like to disable shader dumping now?"
} ;
2020-03-30 17:39:46 -04:00
2021-01-08 03:14:13 -05:00
if ( shadersDumpWarningDialog . Run ( ) = = ( int ) ResponseType . Yes )
{
ConfigurationState . Instance . Graphics . ShadersDumpPath . Value = "" ;
SaveConfig ( ) ;
2020-03-30 17:39:46 -04:00
}
2021-01-08 03:14:13 -05:00
shadersDumpWarningDialog . Dispose ( ) ;
}
}
2020-03-30 17:39:46 -04:00
2021-01-08 03:14:13 -05:00
public void LoadApplication ( string path )
{
if ( _gameLoaded )
{
GtkDialog . CreateInfoDialog ( "A game has already been loaded" , "Please close it first and try again." ) ;
}
else
{
PerformanceCheck ( ) ;
2020-03-30 17:39:46 -04:00
2019-09-19 19:59:48 -04:00
Logger . RestartTime ( ) ;
2021-01-08 03:14:13 -05:00
InitializeSwitchInstance ( ) ;
2020-01-21 17:23:11 -05:00
2020-07-06 22:41:07 -04:00
UpdateGraphicsConfig ( ) ;
2019-12-21 14:52:31 -05:00
2020-09-01 05:09:42 -04:00
SystemVersion firmwareVersion = _contentManager . GetCurrentFirmwareVersion ( ) ;
bool isDirectory = Directory . Exists ( path ) ;
if ( ! SetupValidator . CanStartApplication ( _contentManager , path , out UserError userError ) )
{
if ( SetupValidator . CanFixStartApplication ( _contentManager , path , userError , out firmwareVersion ) )
{
if ( userError = = UserError . NoFirmware )
{
2021-01-08 03:14:13 -05:00
string message = $"Would you like to install the firmware embedded in this game? (Firmware {firmwareVersion.VersionString})" ;
2020-09-01 05:09:42 -04:00
2021-01-08 03:14:13 -05:00
ResponseType responseDialog = ( ResponseType ) GtkDialog . CreateConfirmationDialog ( "No Firmware Installed" , message ) . Run ( ) ;
2020-09-01 05:09:42 -04:00
2021-01-08 03:14:13 -05:00
if ( responseDialog ! = ResponseType . Yes )
{
2020-09-01 05:09:42 -04:00
UserErrorDialog . CreateUserErrorDialog ( userError ) ;
2021-01-08 03:14:13 -05:00
_emulationContext . Dispose ( ) ;
2020-09-01 05:09:42 -04:00
return ;
}
}
if ( ! SetupValidator . TryFixStartApplication ( _contentManager , path , userError , out _ ) )
{
UserErrorDialog . CreateUserErrorDialog ( userError ) ;
2021-01-08 03:14:13 -05:00
_emulationContext . Dispose ( ) ;
2020-09-01 05:09:42 -04:00
return ;
}
// Tell the user that we installed a firmware for them.
if ( userError = = UserError . NoFirmware )
{
firmwareVersion = _contentManager . GetCurrentFirmwareVersion ( ) ;
RefreshFirmwareLabel ( ) ;
2021-01-08 03:14:13 -05:00
string message = $"No installed firmware was found but Ryujinx was able to install firmware {firmwareVersion.VersionString} from the provided game.\nThe emulator will now start." ;
GtkDialog . CreateInfoDialog ( $"Firmware {firmwareVersion.VersionString} was installed" , message ) ;
2020-09-01 05:09:42 -04:00
}
}
else
{
UserErrorDialog . CreateUserErrorDialog ( userError ) ;
2021-01-08 03:14:13 -05:00
_emulationContext . Dispose ( ) ;
2020-09-01 05:09:42 -04:00
return ;
}
}
Logger . Notice . Print ( LogClass . Application , $"Using Firmware Version: {firmwareVersion?.VersionString}" ) ;
2020-05-05 07:51:04 -04:00
2019-09-02 12:03:57 -04:00
if ( Directory . Exists ( path ) )
{
string [ ] romFsFiles = Directory . GetFiles ( path , "*.istorage" ) ;
if ( romFsFiles . Length = = 0 )
{
romFsFiles = Directory . GetFiles ( path , "*.romfs" ) ;
}
if ( romFsFiles . Length > 0 )
{
2020-08-03 19:32:53 -04:00
Logger . Info ? . Print ( LogClass . Application , "Loading as cart with RomFS." ) ;
2021-01-08 03:14:13 -05:00
_emulationContext . LoadCart ( path , romFsFiles [ 0 ] ) ;
2019-09-02 12:03:57 -04:00
}
else
{
2020-08-03 19:32:53 -04:00
Logger . Info ? . Print ( LogClass . Application , "Loading as cart WITHOUT RomFS." ) ;
2021-01-08 03:14:13 -05:00
_emulationContext . LoadCart ( path ) ;
2019-09-02 12:03:57 -04:00
}
}
else if ( File . Exists ( path ) )
{
switch ( System . IO . Path . GetExtension ( path ) . ToLowerInvariant ( ) )
{
case ".xci" :
2020-08-03 19:32:53 -04:00
Logger . Info ? . Print ( LogClass . Application , "Loading as XCI." ) ;
2021-01-08 03:14:13 -05:00
_emulationContext . LoadXci ( path ) ;
2019-09-02 12:03:57 -04:00
break ;
case ".nca" :
2020-08-03 19:32:53 -04:00
Logger . Info ? . Print ( LogClass . Application , "Loading as NCA." ) ;
2021-01-08 03:14:13 -05:00
_emulationContext . LoadNca ( path ) ;
2019-09-02 12:03:57 -04:00
break ;
case ".nsp" :
case ".pfs0" :
2020-08-03 19:32:53 -04:00
Logger . Info ? . Print ( LogClass . Application , "Loading as NSP." ) ;
2021-01-08 03:14:13 -05:00
_emulationContext . LoadNsp ( path ) ;
2019-09-02 12:03:57 -04:00
break ;
default :
2020-08-03 19:32:53 -04:00
Logger . Info ? . Print ( LogClass . Application , "Loading as homebrew." ) ;
2019-09-02 12:03:57 -04:00
try
{
2021-01-08 03:14:13 -05:00
_emulationContext . LoadProgram ( path ) ;
2019-09-02 12:03:57 -04:00
}
catch ( ArgumentOutOfRangeException )
{
2020-08-03 19:32:53 -04:00
Logger . Error ? . Print ( LogClass . Application , "The file which you have specified is unsupported by Ryujinx." ) ;
2019-09-02 12:03:57 -04:00
}
break ;
}
}
else
{
2020-08-03 19:32:53 -04:00
Logger . Warning ? . Print ( LogClass . Application , "Please specify a valid XCI/NCA/NSP/PFS0/NRO file." ) ;
2021-01-08 03:14:13 -05:00
_emulationContext . Dispose ( ) ;
2020-03-28 23:25:54 -04:00
return ;
2019-09-02 12:03:57 -04:00
}
2021-01-08 03:14:13 -05:00
_currentEmulatedGamePath = path ;
2020-01-21 17:23:11 -05:00
2020-02-13 12:43:29 -05:00
_deviceExitStatus . Reset ( ) ;
2020-02-06 06:38:24 -05:00
2020-11-17 16:40:19 -05:00
Translator . IsReadyForTranslation . Reset ( ) ;
#if MACOS_BUILD
2021-01-08 03:14:13 -05:00
CreateGameWindow ( ) ;
2020-11-17 16:40:19 -05:00
#else
Thread windowThread = new Thread ( ( ) = >
{
2021-01-08 03:14:13 -05:00
CreateGameWindow ( ) ;
2020-11-17 16:40:19 -05:00
} )
{
Name = "GUI.WindowThread"
} ;
windowThread . Start ( ) ;
#endif
2021-01-11 10:03:37 -05:00
_gameLoaded = true ;
_stopEmulation . Sensitive = true ;
_simulateWakeUpMessage . Sensitive = true ;
2019-09-02 12:03:57 -04:00
2020-01-11 21:10:55 -05:00
_firmwareInstallFile . Sensitive = false ;
_firmwareInstallDirectory . Sensitive = false ;
2021-01-08 03:14:13 -05:00
DiscordIntegrationModule . SwitchToPlayingState ( _emulationContext . Application . TitleIdText , _emulationContext . Application . TitleName ) ;
2019-09-02 12:03:57 -04:00
2021-01-08 03:14:13 -05:00
_applicationLibrary . LoadAndSaveMetaData ( _emulationContext . Application . TitleIdText , appMetadata = >
2019-09-02 12:03:57 -04:00
{
2020-01-11 22:01:04 -05:00
appMetadata . LastPlayed = DateTime . UtcNow . ToString ( ) ;
} ) ;
2019-09-02 12:03:57 -04:00
}
}
2021-01-08 03:14:13 -05:00
private void CreateGameWindow ( )
2019-09-02 12:03:57 -04:00
{
2021-01-08 03:14:13 -05:00
if ( RuntimeInformation . IsOSPlatform ( OSPlatform . Windows ) )
2020-08-17 21:49:37 -04:00
{
_windowsMultimediaTimerResolution = new WindowsMultimediaTimerResolution ( 1 ) ;
}
2021-01-08 03:14:13 -05:00
GlRendererWidget = new GlRenderer ( _emulationContext , ConfigurationState . Instance . Logger . GraphicsDebugLevel ) ;
2020-02-11 19:56:19 -05:00
Application . Invoke ( delegate
2019-09-02 12:03:57 -04:00
{
2020-02-11 19:56:19 -05:00
_viewBox . Remove ( _gameTableWindow ) ;
2021-01-08 03:14:13 -05:00
GlRendererWidget . Expand = true ;
_viewBox . Child = GlRendererWidget ;
2020-02-11 19:56:19 -05:00
2021-01-08 03:14:13 -05:00
GlRendererWidget . ShowAll ( ) ;
EditFooterForGameRenderer ( ) ;
2020-07-23 09:12:19 -04:00
2021-01-08 03:14:13 -05:00
if ( Window . State . HasFlag ( Gdk . WindowState . Fullscreen ) )
2020-07-23 09:12:19 -04:00
{
ToggleExtraWidgets ( false ) ;
}
2020-12-01 17:02:27 -05:00
else if ( ConfigurationState . Instance . Ui . StartFullscreen . Value )
{
FullScreen_Toggled ( null , null ) ;
}
2020-02-11 19:56:19 -05:00
} ) ;
2021-01-08 03:14:13 -05:00
GlRendererWidget . WaitEvent . WaitOne ( ) ;
2020-02-11 19:56:19 -05:00
2021-01-08 03:14:13 -05:00
GlRendererWidget . Start ( ) ;
2020-02-11 19:56:19 -05:00
2020-06-16 14:28:02 -04:00
Ptc . Close ( ) ;
PtcProfiler . Stop ( ) ;
2021-01-08 03:14:13 -05:00
_emulationContext . Dispose ( ) ;
2020-02-13 12:43:29 -05:00
_deviceExitStatus . Set ( ) ;
// NOTE: Everything that is here will not be executed when you close the UI.
2020-02-11 19:56:19 -05:00
Application . Invoke ( delegate
{
2021-01-08 03:14:13 -05:00
if ( Window . State . HasFlag ( Gdk . WindowState . Fullscreen ) )
2020-07-23 09:12:19 -04:00
{
ToggleExtraWidgets ( true ) ;
}
2021-01-08 03:14:13 -05:00
_viewBox . Remove ( GlRendererWidget ) ;
GlRendererWidget . Exit ( ) ;
2020-02-11 19:56:19 -05:00
2021-01-08 03:14:13 -05:00
if ( GlRendererWidget . Window ! = Window & & GlRendererWidget . Window ! = null )
2020-02-11 19:56:19 -05:00
{
2021-01-08 03:14:13 -05:00
GlRendererWidget . Window . Dispose ( ) ;
2020-02-11 19:56:19 -05:00
}
2021-01-08 03:14:13 -05:00
GlRendererWidget . Dispose ( ) ;
2020-08-17 21:49:37 -04:00
_windowsMultimediaTimerResolution ? . Dispose ( ) ;
_windowsMultimediaTimerResolution = null ;
2020-02-13 12:43:29 -05:00
2020-02-11 19:56:19 -05:00
_viewBox . Add ( _gameTableWindow ) ;
_gameTableWindow . Expand = true ;
2021-01-08 03:14:13 -05:00
Window . Title = $"Ryujinx {Program.Version}" ;
2020-02-11 19:56:19 -05:00
2020-02-13 12:43:29 -05:00
_emulationContext = null ;
_gameLoaded = false ;
2021-01-08 03:14:13 -05:00
GlRendererWidget = null ;
2020-02-13 12:43:29 -05:00
DiscordIntegrationModule . SwitchToMainMenu ( ) ;
RecreateFooterForMenu ( ) ;
2020-02-11 19:56:19 -05:00
UpdateColumns ( ) ;
UpdateGameTable ( ) ;
Task . Run ( RefreshFirmwareLabel ) ;
2020-09-20 23:45:30 -04:00
Task . Run ( HandleRelaunch ) ;
2020-01-21 17:23:11 -05:00
_stopEmulation . Sensitive = false ;
2021-01-11 10:03:37 -05:00
_simulateWakeUpMessage . Sensitive = false ;
2020-01-21 17:23:11 -05:00
_firmwareInstallFile . Sensitive = true ;
_firmwareInstallDirectory . Sensitive = true ;
} ) ;
2020-02-13 12:43:29 -05:00
}
private void RecreateFooterForMenu ( )
{
2020-03-06 21:40:06 -05:00
_listStatusBox . Show ( ) ;
_statusBar . Hide ( ) ;
2020-02-13 12:43:29 -05:00
}
2020-02-11 19:56:19 -05:00
2021-01-08 03:14:13 -05:00
private void EditFooterForGameRenderer ( )
2020-02-13 12:43:29 -05:00
{
2020-03-06 21:40:06 -05:00
_listStatusBox . Hide ( ) ;
_statusBar . Show ( ) ;
2020-02-11 19:56:19 -05:00
}
public void ToggleExtraWidgets ( bool show )
{
2021-01-08 03:14:13 -05:00
if ( GlRendererWidget ! = null )
2020-02-11 19:56:19 -05:00
{
if ( show )
{
_menuBar . ShowAll ( ) ;
2020-03-06 21:40:06 -05:00
_footerBox . Show ( ) ;
_statusBar . Show ( ) ;
2020-02-11 19:56:19 -05:00
}
else
{
_menuBar . Hide ( ) ;
_footerBox . Hide ( ) ;
}
}
2020-01-21 17:23:11 -05:00
}
2021-01-08 03:14:13 -05:00
private void UpdateGameMetadata ( string titleId )
2020-01-21 17:23:11 -05:00
{
if ( _gameLoaded )
{
2021-01-08 03:14:13 -05:00
_applicationLibrary . LoadAndSaveMetaData ( titleId , appMetadata = >
2020-01-21 17:23:11 -05:00
{
DateTime lastPlayedDateTime = DateTime . Parse ( appMetadata . LastPlayed ) ;
double sessionTimePlayed = DateTime . UtcNow . Subtract ( lastPlayedDateTime ) . TotalSeconds ;
2019-09-02 12:03:57 -04:00
2020-01-21 17:23:11 -05:00
appMetadata . TimePlayed + = Math . Round ( sessionTimePlayed , MidpointRounding . AwayFromZero ) ;
} ) ;
2019-09-02 12:03:57 -04:00
}
}
2021-01-08 03:14:13 -05:00
public void UpdateGraphicsConfig ( )
2020-07-06 22:41:07 -04:00
{
2020-12-15 21:19:07 -05:00
int resScale = ConfigurationState . Instance . Graphics . ResScale ;
2020-07-06 22:41:07 -04:00
float resScaleCustom = ConfigurationState . Instance . Graphics . ResScaleCustom ;
2020-12-15 21:19:07 -05:00
Graphics . Gpu . GraphicsConfig . ResScale = ( resScale = = - 1 ) ? resScaleCustom : resScale ;
Graphics . Gpu . GraphicsConfig . MaxAnisotropy = ConfigurationState . Instance . Graphics . MaxAnisotropy ;
Graphics . Gpu . GraphicsConfig . ShadersDumpPath = ConfigurationState . Instance . Graphics . ShadersDumpPath ;
2020-11-12 18:15:34 -05:00
Graphics . Gpu . GraphicsConfig . EnableShaderCache = ConfigurationState . Instance . Graphics . EnableShaderCache ;
2020-07-06 22:41:07 -04:00
}
2021-01-08 03:14:13 -05:00
public void SaveConfig ( )
2020-05-02 22:00:53 -04:00
{
2020-05-03 06:08:21 -04:00
ConfigurationState . Instance . ToFileFormat ( ) . SaveConfig ( Program . ConfigurationPath ) ;
2020-05-02 22:00:53 -04:00
}
2021-01-08 03:14:13 -05:00
private void End ( )
2019-09-02 12:03:57 -04:00
{
2019-11-28 23:32:51 -05:00
if ( _ending )
{
return ;
}
_ending = true ;
2021-01-08 03:14:13 -05:00
if ( _emulationContext ! = null )
2019-09-02 12:03:57 -04:00
{
2021-01-08 03:14:13 -05:00
UpdateGameMetadata ( _emulationContext . Application . TitleIdText ) ;
2020-02-06 06:38:24 -05:00
2021-01-08 03:14:13 -05:00
if ( GlRendererWidget ! = null )
2020-02-06 06:38:24 -05:00
{
2021-01-08 03:14:13 -05:00
// We tell the widget that we are exiting.
GlRendererWidget . Exit ( ) ;
2020-02-13 12:43:29 -05:00
// Wait for the other thread to dispose the HLE context before exiting.
_deviceExitStatus . WaitOne ( ) ;
2020-02-06 06:38:24 -05:00
}
2019-09-02 12:03:57 -04:00
}
2020-01-21 17:23:11 -05:00
Dispose ( ) ;
2021-01-08 03:14:13 -05:00
Program . Exit ( ) ;
2020-01-21 17:23:11 -05:00
Application . Quit ( ) ;
}
2021-01-08 03:14:13 -05:00
//
// Events
//
2019-12-21 21:49:51 -05:00
private void Application_Added ( object sender , ApplicationAddedEventArgs args )
2019-11-28 23:32:51 -05:00
{
Application . Invoke ( delegate
{
_tableStore . AppendValues (
2019-12-21 21:49:51 -05:00
args . AppData . Favorite ,
new Gdk . Pixbuf ( args . AppData . Icon , 75 , 75 ) ,
$"{args.AppData.TitleName}\n{args.AppData.TitleId.ToUpper()}" ,
args . AppData . Developer ,
args . AppData . Version ,
args . AppData . TimePlayed ,
args . AppData . LastPlayed ,
args . AppData . FileExtension ,
args . AppData . FileSize ,
2020-03-25 13:09:38 -04:00
args . AppData . Path ,
args . AppData . ControlHolder ) ;
2020-01-31 13:21:46 -05:00
} ) ;
}
2019-12-21 21:49:51 -05:00
2020-01-31 13:21:46 -05:00
private void ApplicationCount_Updated ( object sender , ApplicationCountUpdatedEventArgs args )
{
Application . Invoke ( delegate
{
2019-12-21 21:49:51 -05:00
_progressLabel . Text = $"{args.NumAppsLoaded}/{args.NumAppsFound} Games Loaded" ;
2020-01-31 13:21:46 -05:00
float barValue = 0 ;
if ( args . NumAppsFound ! = 0 )
{
barValue = ( float ) args . NumAppsLoaded / args . NumAppsFound ;
}
_progressBar . Value = barValue ;
2020-06-26 06:30:16 -04:00
2021-01-08 03:14:13 -05:00
// Reset the vertical scrollbar to the top when titles finish loading
if ( args . NumAppsLoaded = = args . NumAppsFound )
2020-06-26 06:30:16 -04:00
{
_gameTableWindow . Vadjustment . Value = 0 ;
}
2019-11-28 23:32:51 -05:00
} ) ;
}
2020-03-06 21:40:06 -05:00
private void Update_StatusBar ( object sender , StatusUpdatedEventArgs args )
{
Application . Invoke ( delegate
{
2020-12-15 21:19:07 -05:00
_gameStatus . Text = args . GameStatus ;
_fifoStatus . Text = args . FifoStatus ;
_gpuName . Text = args . GpuName ;
_dockedMode . Text = args . DockedMode ;
_aspectRatio . Text = args . AspectRatio ;
2020-03-06 21:40:06 -05:00
if ( args . VSyncEnabled )
{
_vSyncStatus . Attributes = new Pango . AttrList ( ) ;
_vSyncStatus . Attributes . Insert ( new Pango . AttrForeground ( 11822 , 60138 , 51657 ) ) ;
}
else
{
_vSyncStatus . Attributes = new Pango . AttrList ( ) ;
_vSyncStatus . Attributes . Insert ( new Pango . AttrForeground ( ushort . MaxValue , 17733 , 21588 ) ) ;
}
} ) ;
}
2019-11-28 23:32:51 -05:00
private void FavToggle_Toggled ( object sender , ToggledArgs args )
{
_tableStore . GetIter ( out TreeIter treeIter , new TreePath ( args . Path ) ) ;
2021-01-08 03:14:13 -05:00
string titleId = _tableStore . GetValue ( treeIter , 2 ) . ToString ( ) . Split ( "\n" ) [ 1 ] . ToLower ( ) ;
bool newToggleValue = ! ( bool ) _tableStore . GetValue ( treeIter , 0 ) ;
2019-10-13 02:02:07 -04:00
2020-01-11 22:01:04 -05:00
_tableStore . SetValue ( treeIter , 0 , newToggleValue ) ;
2019-11-28 23:32:51 -05:00
2021-01-08 03:14:13 -05:00
_applicationLibrary . LoadAndSaveMetaData ( titleId , appMetadata = >
2019-11-28 23:32:51 -05:00
{
2020-01-11 22:01:04 -05:00
appMetadata . Favorite = newToggleValue ;
} ) ;
2019-11-28 23:32:51 -05:00
}
2020-06-26 06:30:16 -04:00
private void Column_Clicked ( object sender , EventArgs args )
{
TreeViewColumn column = ( TreeViewColumn ) sender ;
ConfigurationState . Instance . Ui . ColumnSort . SortColumnId . Value = column . SortColumnId ;
ConfigurationState . Instance . Ui . ColumnSort . SortAscending . Value = column . SortOrder = = SortType . Ascending ;
SaveConfig ( ) ;
}
2019-11-28 23:32:51 -05:00
private void Row_Activated ( object sender , RowActivatedArgs args )
2019-09-02 12:03:57 -04:00
{
2019-12-21 21:49:51 -05:00
_gameTableSelection . GetSelected ( out TreeIter treeIter ) ;
2021-01-08 03:14:13 -05:00
2019-11-28 23:32:51 -05:00
string path = ( string ) _tableStore . GetValue ( treeIter , 9 ) ;
2019-09-02 12:03:57 -04:00
LoadApplication ( path ) ;
}
2020-11-18 19:34:28 -05:00
private void VSyncStatus_Clicked ( object sender , ButtonReleaseEventArgs args )
{
_emulationContext . EnableDeviceVsync = ! _emulationContext . EnableDeviceVsync ;
}
private void DockedMode_Clicked ( object sender , ButtonReleaseEventArgs args )
{
ConfigurationState . Instance . System . EnableDockedMode . Value = ! ConfigurationState . Instance . System . EnableDockedMode . Value ;
}
2020-12-15 21:19:07 -05:00
private void AspectRatio_Clicked ( object sender , ButtonReleaseEventArgs args )
{
AspectRatio aspectRatio = ConfigurationState . Instance . Graphics . AspectRatio . Value ;
ConfigurationState . Instance . Graphics . AspectRatio . Value = ( ( int ) aspectRatio + 1 ) > Enum . GetNames ( typeof ( AspectRatio ) ) . Length - 1 ? AspectRatio . Fixed4x3 : aspectRatio + 1 ;
}
2019-12-21 21:49:51 -05:00
private void Row_Clicked ( object sender , ButtonReleaseEventArgs args )
{
2021-01-08 03:14:13 -05:00
if ( args . Event . Button ! = 3 /* Right Click */ )
{
return ;
}
2019-12-21 21:49:51 -05:00
_gameTableSelection . GetSelected ( out TreeIter treeIter ) ;
2021-01-08 03:14:13 -05:00
if ( treeIter . UserData = = IntPtr . Zero )
{
return ;
}
string titleFilePath = _tableStore . GetValue ( treeIter , 9 ) . ToString ( ) ;
string titleName = _tableStore . GetValue ( treeIter , 2 ) . ToString ( ) . Split ( "\n" ) [ 0 ] ;
string titleId = _tableStore . GetValue ( treeIter , 2 ) . ToString ( ) . Split ( "\n" ) [ 1 ] . ToLower ( ) ;
2019-12-21 21:49:51 -05:00
2020-03-25 13:09:38 -04:00
BlitStruct < ApplicationControlProperty > controlData = ( BlitStruct < ApplicationControlProperty > ) _tableStore . GetValue ( treeIter , 10 ) ;
2021-01-08 03:14:13 -05:00
_ = new GameTableContextMenu ( this , _virtualFileSystem , titleFilePath , titleName , titleId , controlData ) ;
2019-12-21 21:49:51 -05:00
}
2019-11-28 23:32:51 -05:00
private void Load_Application_File ( object sender , EventArgs args )
2019-09-02 12:03:57 -04:00
{
2021-01-08 03:14:13 -05:00
using ( FileChooserDialog fileChooser = new FileChooserDialog ( "Choose the file to open" , this , FileChooserAction . Open , "Cancel" , ResponseType . Cancel , "Open" , ResponseType . Accept ) )
2019-09-02 12:03:57 -04:00
{
2021-01-08 03:14:13 -05:00
fileChooser . Filter = new FileFilter ( ) ;
fileChooser . Filter . AddPattern ( "*.nsp" ) ;
fileChooser . Filter . AddPattern ( "*.pfs0" ) ;
fileChooser . Filter . AddPattern ( "*.xci" ) ;
fileChooser . Filter . AddPattern ( "*.nca" ) ;
fileChooser . Filter . AddPattern ( "*.nro" ) ;
fileChooser . Filter . AddPattern ( "*.nso" ) ;
if ( fileChooser . Run ( ) = = ( int ) ResponseType . Accept )
{
LoadApplication ( fileChooser . Filename ) ;
}
2019-09-02 12:03:57 -04:00
}
}
2019-11-28 23:32:51 -05:00
private void Load_Application_Folder ( object sender , EventArgs args )
2019-09-02 12:03:57 -04:00
{
2021-01-08 03:14:13 -05:00
using ( FileChooserDialog fileChooser = new FileChooserDialog ( "Choose the folder to open" , this , FileChooserAction . SelectFolder , "Cancel" , ResponseType . Cancel , "Open" , ResponseType . Accept ) )
2019-09-02 12:03:57 -04:00
{
2021-01-08 03:14:13 -05:00
if ( fileChooser . Run ( ) = = ( int ) ResponseType . Accept )
{
LoadApplication ( fileChooser . Filename ) ;
}
2019-09-02 12:03:57 -04:00
}
}
2019-11-28 23:32:51 -05:00
private void Open_Ryu_Folder ( object sender , EventArgs args )
2019-09-02 12:03:57 -04:00
{
2021-01-08 03:14:13 -05:00
OpenHelper . OpenFolder ( AppDataManager . BaseDirPath ) ;
2019-09-02 12:03:57 -04:00
}
2020-09-20 00:31:05 -04:00
private void OpenLogsFolder_Pressed ( object sender , EventArgs args )
{
string logPath = System . IO . Path . Combine ( AppDomain . CurrentDomain . BaseDirectory , "Logs" ) ;
2021-01-08 03:14:13 -05:00
new DirectoryInfo ( logPath ) . Create ( ) ;
2020-09-20 00:31:05 -04:00
2021-01-08 03:14:13 -05:00
OpenHelper . OpenFolder ( logPath ) ;
2020-09-20 00:31:05 -04:00
}
2019-11-28 23:32:51 -05:00
private void Exit_Pressed ( object sender , EventArgs args )
2019-09-02 12:03:57 -04:00
{
2021-01-14 17:30:52 -05:00
if ( ! _gameLoaded | | ! ConfigurationState . Instance . ShowConfirmExit | | GtkDialog . CreateExitDialog ( ) )
2020-10-09 19:06:48 -04:00
{
2021-01-08 03:14:13 -05:00
End ( ) ;
2020-10-09 19:06:48 -04:00
}
2019-09-02 12:03:57 -04:00
}
2019-11-28 23:32:51 -05:00
private void Window_Close ( object sender , DeleteEventArgs args )
2019-09-02 12:03:57 -04:00
{
2021-01-14 17:30:52 -05:00
if ( ! _gameLoaded | | ! ConfigurationState . Instance . ShowConfirmExit | | GtkDialog . CreateExitDialog ( ) )
2020-10-09 19:06:48 -04:00
{
2021-01-08 03:14:13 -05:00
End ( ) ;
2020-10-09 19:06:48 -04:00
}
else
{
args . RetVal = true ;
}
2019-09-02 12:03:57 -04:00
}
2019-11-28 23:32:51 -05:00
private void StopEmulation_Pressed ( object sender , EventArgs args )
2019-09-02 12:03:57 -04:00
{
2021-01-08 03:14:13 -05:00
GlRendererWidget ? . Exit ( ) ;
2019-09-02 12:03:57 -04:00
}
2020-01-11 21:10:55 -05:00
private void Installer_File_Pressed ( object o , EventArgs args )
{
2021-01-08 03:14:13 -05:00
FileChooserDialog fileChooser = new FileChooserDialog ( "Choose the firmware file to open" , this , FileChooserAction . Open , "Cancel" , ResponseType . Cancel , "Open" , ResponseType . Accept ) ;
2020-01-11 21:10:55 -05:00
fileChooser . Filter = new FileFilter ( ) ;
fileChooser . Filter . AddPattern ( "*.zip" ) ;
fileChooser . Filter . AddPattern ( "*.xci" ) ;
HandleInstallerDialog ( fileChooser ) ;
}
private void Installer_Directory_Pressed ( object o , EventArgs args )
{
2021-01-08 03:14:13 -05:00
FileChooserDialog directoryChooser = new FileChooserDialog ( "Choose the firmware directory to open" , this , FileChooserAction . SelectFolder , "Cancel" , ResponseType . Cancel , "Open" , ResponseType . Accept ) ;
2020-01-11 21:10:55 -05:00
HandleInstallerDialog ( directoryChooser ) ;
}
private void HandleInstallerDialog ( FileChooserDialog fileChooser )
{
if ( fileChooser . Run ( ) = = ( int ) ResponseType . Accept )
{
try
{
string filename = fileChooser . Filename ;
fileChooser . Dispose ( ) ;
2020-05-02 22:00:53 -04:00
SystemVersion firmwareVersion = _contentManager . VerifyFirmwarePackage ( filename ) ;
2020-01-11 21:10:55 -05:00
2021-01-08 03:14:13 -05:00
string dialogTitle = $"Install Firmware {firmwareVersion.VersionString}" ;
2020-01-11 21:10:55 -05:00
if ( firmwareVersion = = null )
{
2021-01-08 03:14:13 -05:00
GtkDialog . CreateErrorDialog ( $"A valid system firmware was not found in {filename}." ) ;
2020-01-11 21:10:55 -05:00
return ;
}
2020-05-02 22:00:53 -04:00
SystemVersion currentVersion = _contentManager . GetCurrentFirmwareVersion ( ) ;
2020-01-11 21:10:55 -05:00
string dialogMessage = $"System version {firmwareVersion.VersionString} will be installed." ;
if ( currentVersion ! = null )
{
2021-01-08 03:14:13 -05:00
dialogMessage + = $"\n\nThis will replace the current system version {currentVersion.VersionString}. " ;
2020-01-11 21:10:55 -05:00
}
2021-01-08 03:14:13 -05:00
dialogMessage + = "\n\nDo you want to continue?" ;
2020-01-11 21:10:55 -05:00
2021-01-08 03:14:13 -05:00
ResponseType responseInstallDialog = ( ResponseType ) GtkDialog . CreateConfirmationDialog ( dialogTitle , dialogMessage ) . Run ( ) ;
2020-01-11 21:10:55 -05:00
2021-01-08 03:14:13 -05:00
MessageDialog waitingDialog = GtkDialog . CreateWaitingDialog ( dialogTitle , "Installing firmware..." ) ;
2020-01-11 21:10:55 -05:00
2021-01-08 03:14:13 -05:00
if ( responseInstallDialog = = ResponseType . Yes )
2020-01-11 21:10:55 -05:00
{
2020-08-03 19:32:53 -04:00
Logger . Info ? . Print ( LogClass . Application , $"Installing firmware {firmwareVersion.VersionString}" ) ;
2020-01-11 21:10:55 -05:00
Thread thread = new Thread ( ( ) = >
{
2021-01-08 03:14:13 -05:00
Application . Invoke ( delegate
2020-01-11 21:10:55 -05:00
{
2021-01-08 03:14:13 -05:00
waitingDialog . Run ( ) ;
} ) ;
2020-01-11 21:10:55 -05:00
try
{
2020-01-21 17:23:11 -05:00
_contentManager . InstallFirmware ( filename ) ;
2020-01-11 21:10:55 -05:00
2021-01-08 03:14:13 -05:00
Application . Invoke ( delegate
2020-01-11 21:10:55 -05:00
{
2021-01-08 03:14:13 -05:00
waitingDialog . Dispose ( ) ;
2020-01-11 21:10:55 -05:00
2021-01-08 03:14:13 -05:00
string message = $"System version {firmwareVersion.VersionString} successfully installed." ;
2020-01-11 21:10:55 -05:00
2021-01-08 03:14:13 -05:00
GtkDialog . CreateInfoDialog ( dialogTitle , message ) ;
Logger . Info ? . Print ( LogClass . Application , message ) ;
} ) ;
2020-01-11 21:10:55 -05:00
}
catch ( Exception ex )
{
2021-01-08 03:14:13 -05:00
Application . Invoke ( delegate
2020-01-11 21:10:55 -05:00
{
2021-01-08 03:14:13 -05:00
waitingDialog . Dispose ( ) ;
2020-01-11 21:10:55 -05:00
2021-01-08 03:14:13 -05:00
GtkDialog . CreateErrorDialog ( ex . Message ) ;
} ) ;
2020-01-11 21:10:55 -05:00
}
finally
{
RefreshFirmwareLabel ( ) ;
}
} ) ;
2020-01-12 19:21:54 -05:00
thread . Name = "GUI.FirmwareInstallerThread" ;
2020-01-11 21:10:55 -05:00
thread . Start ( ) ;
}
}
catch ( Exception ex )
{
2021-01-08 03:14:13 -05:00
GtkDialog . CreateErrorDialog ( ex . Message ) ;
}
}
else
{
fileChooser . Dispose ( ) ;
}
}
2020-01-11 21:10:55 -05:00
2021-01-08 03:14:13 -05:00
private void RefreshFirmwareLabel ( )
{
SystemVersion currentFirmware = _contentManager . GetCurrentFirmwareVersion ( ) ;
2020-01-11 21:10:55 -05:00
2021-01-08 03:14:13 -05:00
Application . Invoke ( delegate
{
_firmwareVersionLabel . Text = currentFirmware ! = null ? currentFirmware . VersionString : "0.0.0" ;
} ) ;
}
2020-01-11 21:10:55 -05:00
2021-01-08 03:14:13 -05:00
private void HandleRelaunch ( )
{
if ( _userChannelPersistence . PreviousIndex ! = - 1 & & _userChannelPersistence . ShouldRestart )
{
_userChannelPersistence . ShouldRestart = false ;
2020-01-11 21:10:55 -05:00
2021-01-08 03:14:13 -05:00
LoadApplication ( _currentEmulatedGamePath ) ;
2020-01-11 21:10:55 -05:00
}
else
{
2021-01-08 03:14:13 -05:00
// otherwise, clear state.
_userChannelPersistence = new UserChannelPersistence ( ) ;
_currentEmulatedGamePath = null ;
2020-01-11 21:10:55 -05:00
}
}
2020-12-01 17:02:27 -05:00
private void FullScreen_Toggled ( object sender , EventArgs args )
2019-09-02 12:03:57 -04:00
{
2021-01-08 03:14:13 -05:00
if ( ! Window . State . HasFlag ( Gdk . WindowState . Fullscreen ) )
2019-09-02 12:03:57 -04:00
{
Fullscreen ( ) ;
2020-02-11 19:56:19 -05:00
ToggleExtraWidgets ( false ) ;
2019-09-02 12:03:57 -04:00
}
else
{
Unfullscreen ( ) ;
2020-02-11 19:56:19 -05:00
ToggleExtraWidgets ( true ) ;
2019-09-02 12:03:57 -04:00
}
}
2020-12-01 17:02:27 -05:00
private void StartFullScreen_Toggled ( object sender , EventArgs args )
{
ConfigurationState . Instance . Ui . StartFullscreen . Value = _startFullScreen . Active ;
SaveConfig ( ) ;
}
2019-11-28 23:32:51 -05:00
private void Settings_Pressed ( object sender , EventArgs args )
2019-09-02 12:03:57 -04:00
{
2021-01-08 03:14:13 -05:00
new SettingsWindow ( this , _virtualFileSystem , _contentManager ) . Show ( ) ;
2019-09-02 12:03:57 -04:00
}
2020-12-15 19:41:42 -05:00
private void Simulate_WakeUp_Message_Pressed ( object sender , EventArgs args )
{
2021-01-08 03:14:13 -05:00
if ( _emulationContext ! = null )
{
_emulationContext . System . SimulateWakeUpMessage ( ) ;
}
2020-12-15 19:41:42 -05:00
}
2019-11-28 23:32:51 -05:00
private void Update_Pressed ( object sender , EventArgs args )
2019-09-02 12:03:57 -04:00
{
2020-09-29 16:05:25 -04:00
if ( Updater . CanUpdate ( true ) )
2019-09-02 12:03:57 -04:00
{
2020-11-27 12:57:20 -05:00
_ = Updater . BeginParse ( this , true ) ;
2019-09-02 12:03:57 -04:00
}
}
2019-11-28 23:32:51 -05:00
private void About_Pressed ( object sender , EventArgs args )
2019-09-02 12:03:57 -04:00
{
2021-01-08 03:14:13 -05:00
new AboutWindow ( ) . Show ( ) ;
2019-11-28 23:32:51 -05:00
}
private void Fav_Toggled ( object sender , EventArgs args )
{
2019-12-21 14:52:31 -05:00
ConfigurationState . Instance . Ui . GuiColumns . FavColumn . Value = _favToggle . Active ;
2019-11-28 23:32:51 -05:00
2019-12-21 14:52:31 -05:00
SaveConfig ( ) ;
2019-11-28 23:32:51 -05:00
UpdateColumns ( ) ;
2019-09-02 12:03:57 -04:00
}
2019-11-28 23:32:51 -05:00
private void Icon_Toggled ( object sender , EventArgs args )
2019-09-02 12:03:57 -04:00
{
2019-12-21 14:52:31 -05:00
ConfigurationState . Instance . Ui . GuiColumns . IconColumn . Value = _iconToggle . Active ;
2019-11-28 23:32:51 -05:00
2019-12-21 14:52:31 -05:00
SaveConfig ( ) ;
2019-11-28 23:32:51 -05:00
UpdateColumns ( ) ;
2019-09-02 12:03:57 -04:00
}
2019-11-28 23:32:51 -05:00
private void Title_Toggled ( object sender , EventArgs args )
2019-09-02 12:03:57 -04:00
{
2019-12-21 14:52:31 -05:00
ConfigurationState . Instance . Ui . GuiColumns . AppColumn . Value = _appToggle . Active ;
2019-11-28 23:32:51 -05:00
2019-12-21 14:52:31 -05:00
SaveConfig ( ) ;
2019-11-28 23:32:51 -05:00
UpdateColumns ( ) ;
2019-09-02 12:03:57 -04:00
}
2019-11-28 23:32:51 -05:00
private void Developer_Toggled ( object sender , EventArgs args )
2019-09-02 12:03:57 -04:00
{
2019-12-21 14:52:31 -05:00
ConfigurationState . Instance . Ui . GuiColumns . DevColumn . Value = _developerToggle . Active ;
2019-11-28 23:32:51 -05:00
2019-12-21 14:52:31 -05:00
SaveConfig ( ) ;
2019-11-28 23:32:51 -05:00
UpdateColumns ( ) ;
2019-09-02 12:03:57 -04:00
}
2019-11-28 23:32:51 -05:00
private void Version_Toggled ( object sender , EventArgs args )
2019-09-02 12:03:57 -04:00
{
2019-12-21 14:52:31 -05:00
ConfigurationState . Instance . Ui . GuiColumns . VersionColumn . Value = _versionToggle . Active ;
2019-11-28 23:32:51 -05:00
2019-12-21 14:52:31 -05:00
SaveConfig ( ) ;
2019-11-28 23:32:51 -05:00
UpdateColumns ( ) ;
2019-09-02 12:03:57 -04:00
}
2019-11-28 23:32:51 -05:00
private void TimePlayed_Toggled ( object sender , EventArgs args )
2019-09-02 12:03:57 -04:00
{
2019-12-21 14:52:31 -05:00
ConfigurationState . Instance . Ui . GuiColumns . TimePlayedColumn . Value = _timePlayedToggle . Active ;
2019-11-28 23:32:51 -05:00
2019-12-21 14:52:31 -05:00
SaveConfig ( ) ;
2019-11-28 23:32:51 -05:00
UpdateColumns ( ) ;
2019-09-02 12:03:57 -04:00
}
2019-11-28 23:32:51 -05:00
private void LastPlayed_Toggled ( object sender , EventArgs args )
2019-09-02 12:03:57 -04:00
{
2019-12-21 14:52:31 -05:00
ConfigurationState . Instance . Ui . GuiColumns . LastPlayedColumn . Value = _lastPlayedToggle . Active ;
2019-11-28 23:32:51 -05:00
2019-12-21 14:52:31 -05:00
SaveConfig ( ) ;
2019-11-28 23:32:51 -05:00
UpdateColumns ( ) ;
2019-09-02 12:03:57 -04:00
}
2019-11-28 23:32:51 -05:00
private void FileExt_Toggled ( object sender , EventArgs args )
2019-09-02 12:03:57 -04:00
{
2019-12-21 14:52:31 -05:00
ConfigurationState . Instance . Ui . GuiColumns . FileExtColumn . Value = _fileExtToggle . Active ;
2019-11-28 23:32:51 -05:00
2019-12-21 14:52:31 -05:00
SaveConfig ( ) ;
2019-11-28 23:32:51 -05:00
UpdateColumns ( ) ;
2019-09-02 12:03:57 -04:00
}
2019-11-28 23:32:51 -05:00
private void FileSize_Toggled ( object sender , EventArgs args )
2019-09-02 12:03:57 -04:00
{
2019-12-21 14:52:31 -05:00
ConfigurationState . Instance . Ui . GuiColumns . FileSizeColumn . Value = _fileSizeToggle . Active ;
2019-11-28 23:32:51 -05:00
2019-12-21 14:52:31 -05:00
SaveConfig ( ) ;
2019-11-28 23:32:51 -05:00
UpdateColumns ( ) ;
2019-09-02 12:03:57 -04:00
}
2019-11-28 23:32:51 -05:00
private void Path_Toggled ( object sender , EventArgs args )
2019-09-02 12:03:57 -04:00
{
2019-12-21 14:52:31 -05:00
ConfigurationState . Instance . Ui . GuiColumns . PathColumn . Value = _pathToggle . Active ;
2019-11-28 23:32:51 -05:00
2019-12-21 14:52:31 -05:00
SaveConfig ( ) ;
2019-11-28 23:32:51 -05:00
UpdateColumns ( ) ;
}
private void RefreshList_Pressed ( object sender , ButtonReleaseEventArgs args )
{
UpdateGameTable ( ) ;
}
2019-09-02 12:03:57 -04:00
}
2021-01-08 03:14:13 -05:00
}