MainWindow.cs 52 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412
  1. using ARMeilleure.Translation.PTC;
  2. using Gtk;
  3. using LibHac.Common;
  4. using LibHac.Ns;
  5. using Ryujinx.Audio;
  6. using Ryujinx.Common.Configuration;
  7. using Ryujinx.Common.Logging;
  8. using Ryujinx.Common.System;
  9. using Ryujinx.Configuration;
  10. using Ryujinx.Graphics.GAL;
  11. using Ryujinx.Graphics.OpenGL;
  12. using Ryujinx.HLE.FileSystem;
  13. using Ryujinx.HLE.FileSystem.Content;
  14. using Ryujinx.HLE.HOS;
  15. using Ryujinx.Ui.Diagnostic;
  16. using System;
  17. using System.Diagnostics;
  18. using System.IO;
  19. using System.Reflection;
  20. using System.Threading;
  21. using System.Threading.Tasks;
  22. using GUI = Gtk.Builder.ObjectAttribute;
  23. namespace Ryujinx.Ui
  24. {
  25. public class MainWindow : Window
  26. {
  27. private static VirtualFileSystem _virtualFileSystem;
  28. private static ContentManager _contentManager;
  29. private static UserChannelPersistence _userChannelPersistence;
  30. private static WindowsMultimediaTimerResolution _windowsMultimediaTimerResolution;
  31. private static HLE.Switch _emulationContext;
  32. private static GlRenderer _glWidget;
  33. private static GtkHostUiHandler _uiHandler;
  34. public static GlRenderer GlWidget => _glWidget;
  35. private static AutoResetEvent _deviceExitStatus = new AutoResetEvent(false);
  36. private static AutoResetEvent _widgetInitEvent = new AutoResetEvent(false);
  37. private static ListStore _tableStore;
  38. private static bool _updatingGameTable;
  39. private static bool _gameLoaded;
  40. private static string _gamePath;
  41. private static bool _ending;
  42. #pragma warning disable CS0169, CS0649, IDE0044
  43. [GUI] public MenuItem ExitMenuItem;
  44. [GUI] public MenuItem UpdateMenuItem;
  45. [GUI] MenuBar _menuBar;
  46. [GUI] Box _footerBox;
  47. [GUI] Box _statusBar;
  48. [GUI] MenuItem _stopEmulation;
  49. [GUI] MenuItem _fullScreen;
  50. [GUI] CheckMenuItem _favToggle;
  51. [GUI] MenuItem _firmwareInstallDirectory;
  52. [GUI] MenuItem _firmwareInstallFile;
  53. [GUI] Label _fifoStatus;
  54. [GUI] CheckMenuItem _iconToggle;
  55. [GUI] CheckMenuItem _developerToggle;
  56. [GUI] CheckMenuItem _appToggle;
  57. [GUI] CheckMenuItem _timePlayedToggle;
  58. [GUI] CheckMenuItem _versionToggle;
  59. [GUI] CheckMenuItem _lastPlayedToggle;
  60. [GUI] CheckMenuItem _fileExtToggle;
  61. [GUI] CheckMenuItem _pathToggle;
  62. [GUI] CheckMenuItem _fileSizeToggle;
  63. [GUI] Label _dockedMode;
  64. [GUI] Label _gameStatus;
  65. [GUI] TreeView _gameTable;
  66. [GUI] TreeSelection _gameTableSelection;
  67. [GUI] ScrolledWindow _gameTableWindow;
  68. [GUI] Label _gpuName;
  69. [GUI] Label _progressLabel;
  70. [GUI] Label _firmwareVersionLabel;
  71. [GUI] LevelBar _progressBar;
  72. [GUI] Box _viewBox;
  73. [GUI] Label _vSyncStatus;
  74. [GUI] Box _listStatusBox;
  75. #pragma warning restore CS0649, IDE0044, CS0169
  76. public MainWindow() : this(new Builder("Ryujinx.Ui.MainWindow.glade")) { }
  77. private MainWindow(Builder builder) : base(builder.GetObject("_mainWin").Handle)
  78. {
  79. builder.Autoconnect(this);
  80. int monitorWidth = Display.PrimaryMonitor.Geometry.Width * Display.PrimaryMonitor.ScaleFactor;
  81. int monitorHeight = Display.PrimaryMonitor.Geometry.Height * Display.PrimaryMonitor.ScaleFactor;
  82. this.DefaultWidth = monitorWidth < 1280 ? monitorWidth : 1280;
  83. this.DefaultHeight = monitorHeight < 760 ? monitorHeight : 760;
  84. this.WindowStateEvent += MainWindow_WindowStateEvent;
  85. this.DeleteEvent += Window_Close;
  86. _fullScreen.Activated += FullScreen_Toggled;
  87. this.Icon = new Gdk.Pixbuf(Assembly.GetExecutingAssembly(), "Ryujinx.Ui.assets.Icon.png");
  88. this.Title = $"Ryujinx {Program.Version}";
  89. ApplicationLibrary.ApplicationAdded += Application_Added;
  90. ApplicationLibrary.ApplicationCountUpdated += ApplicationCount_Updated;
  91. GlRenderer.StatusUpdatedEvent += Update_StatusBar;
  92. _gameTable.ButtonReleaseEvent += Row_Clicked;
  93. // First we check that a migration isn't needed. (because VirtualFileSystem will create the new directory otherwise)
  94. bool continueWithStartup = Migration.PromptIfMigrationNeededForStartup(this, out bool migrationNeeded);
  95. if (!continueWithStartup)
  96. {
  97. End(null);
  98. }
  99. _virtualFileSystem = VirtualFileSystem.CreateInstance();
  100. _userChannelPersistence = new UserChannelPersistence();
  101. _contentManager = new ContentManager(_virtualFileSystem);
  102. if (migrationNeeded)
  103. {
  104. bool migrationSuccessful = Migration.DoMigrationForStartup(this, _virtualFileSystem);
  105. if (!migrationSuccessful)
  106. {
  107. End(null);
  108. }
  109. }
  110. // Make sure that everything is loaded.
  111. _virtualFileSystem.Reload();
  112. ApplyTheme();
  113. _stopEmulation.Sensitive = false;
  114. if (ConfigurationState.Instance.Ui.GuiColumns.FavColumn) _favToggle.Active = true;
  115. if (ConfigurationState.Instance.Ui.GuiColumns.IconColumn) _iconToggle.Active = true;
  116. if (ConfigurationState.Instance.Ui.GuiColumns.AppColumn) _appToggle.Active = true;
  117. if (ConfigurationState.Instance.Ui.GuiColumns.DevColumn) _developerToggle.Active = true;
  118. if (ConfigurationState.Instance.Ui.GuiColumns.VersionColumn) _versionToggle.Active = true;
  119. if (ConfigurationState.Instance.Ui.GuiColumns.TimePlayedColumn) _timePlayedToggle.Active = true;
  120. if (ConfigurationState.Instance.Ui.GuiColumns.LastPlayedColumn) _lastPlayedToggle.Active = true;
  121. if (ConfigurationState.Instance.Ui.GuiColumns.FileExtColumn) _fileExtToggle.Active = true;
  122. if (ConfigurationState.Instance.Ui.GuiColumns.FileSizeColumn) _fileSizeToggle.Active = true;
  123. if (ConfigurationState.Instance.Ui.GuiColumns.PathColumn) _pathToggle.Active = true;
  124. _gameTable.Model = _tableStore = new ListStore(
  125. typeof(bool),
  126. typeof(Gdk.Pixbuf),
  127. typeof(string),
  128. typeof(string),
  129. typeof(string),
  130. typeof(string),
  131. typeof(string),
  132. typeof(string),
  133. typeof(string),
  134. typeof(string),
  135. typeof(BlitStruct<ApplicationControlProperty>));
  136. _tableStore.SetSortFunc(5, TimePlayedSort);
  137. _tableStore.SetSortFunc(6, LastPlayedSort);
  138. _tableStore.SetSortFunc(8, FileSizeSort);
  139. int columnId = ConfigurationState.Instance.Ui.ColumnSort.SortColumnId;
  140. bool ascending = ConfigurationState.Instance.Ui.ColumnSort.SortAscending;
  141. _tableStore.SetSortColumnId(columnId, ascending ? SortType.Ascending : SortType.Descending);
  142. _gameTable.EnableSearch = true;
  143. _gameTable.SearchColumn = 2;
  144. UpdateColumns();
  145. UpdateGameTable();
  146. ConfigurationState.Instance.Ui.GameDirs.Event += (sender, args) =>
  147. {
  148. if (args.OldValue != args.NewValue)
  149. {
  150. UpdateGameTable();
  151. }
  152. };
  153. Task.Run(RefreshFirmwareLabel);
  154. _statusBar.Hide();
  155. _uiHandler = new GtkHostUiHandler(this);
  156. _gamePath = null;
  157. }
  158. private void MainWindow_WindowStateEvent(object o, WindowStateEventArgs args)
  159. {
  160. _fullScreen.Label = args.Event.NewWindowState.HasFlag(Gdk.WindowState.Fullscreen) ? "Exit Fullscreen" : "Enter Fullscreen";
  161. }
  162. internal static void ApplyTheme()
  163. {
  164. if (!ConfigurationState.Instance.Ui.EnableCustomTheme)
  165. {
  166. return;
  167. }
  168. if (File.Exists(ConfigurationState.Instance.Ui.CustomThemePath) && (System.IO.Path.GetExtension(ConfigurationState.Instance.Ui.CustomThemePath) == ".css"))
  169. {
  170. CssProvider cssProvider = new CssProvider();
  171. cssProvider.LoadFromPath(ConfigurationState.Instance.Ui.CustomThemePath);
  172. StyleContext.AddProviderForScreen(Gdk.Screen.Default, cssProvider, 800);
  173. }
  174. else
  175. {
  176. Logger.Warning?.Print(LogClass.Application, $"The \"custom_theme_path\" section in \"Config.json\" contains an invalid path: \"{ConfigurationState.Instance.Ui.CustomThemePath}\".");
  177. }
  178. }
  179. private void UpdateColumns()
  180. {
  181. foreach (TreeViewColumn column in _gameTable.Columns)
  182. {
  183. _gameTable.RemoveColumn(column);
  184. }
  185. CellRendererToggle favToggle = new CellRendererToggle();
  186. favToggle.Toggled += FavToggle_Toggled;
  187. if (ConfigurationState.Instance.Ui.GuiColumns.FavColumn) _gameTable.AppendColumn("Fav", favToggle, "active", 0);
  188. if (ConfigurationState.Instance.Ui.GuiColumns.IconColumn) _gameTable.AppendColumn("Icon", new CellRendererPixbuf(), "pixbuf", 1);
  189. if (ConfigurationState.Instance.Ui.GuiColumns.AppColumn) _gameTable.AppendColumn("Application", new CellRendererText(), "text", 2);
  190. if (ConfigurationState.Instance.Ui.GuiColumns.DevColumn) _gameTable.AppendColumn("Developer", new CellRendererText(), "text", 3);
  191. if (ConfigurationState.Instance.Ui.GuiColumns.VersionColumn) _gameTable.AppendColumn("Version", new CellRendererText(), "text", 4);
  192. if (ConfigurationState.Instance.Ui.GuiColumns.TimePlayedColumn) _gameTable.AppendColumn("Time Played", new CellRendererText(), "text", 5);
  193. if (ConfigurationState.Instance.Ui.GuiColumns.LastPlayedColumn) _gameTable.AppendColumn("Last Played", new CellRendererText(), "text", 6);
  194. if (ConfigurationState.Instance.Ui.GuiColumns.FileExtColumn) _gameTable.AppendColumn("File Ext", new CellRendererText(), "text", 7);
  195. if (ConfigurationState.Instance.Ui.GuiColumns.FileSizeColumn) _gameTable.AppendColumn("File Size", new CellRendererText(), "text", 8);
  196. if (ConfigurationState.Instance.Ui.GuiColumns.PathColumn) _gameTable.AppendColumn("Path", new CellRendererText(), "text", 9);
  197. foreach (TreeViewColumn column in _gameTable.Columns)
  198. {
  199. switch (column.Title)
  200. {
  201. case "Fav":
  202. column.SortColumnId = 0;
  203. column.Clicked += Column_Clicked;
  204. break;
  205. case "Application":
  206. column.SortColumnId = 2;
  207. column.Clicked += Column_Clicked;
  208. break;
  209. case "Developer":
  210. column.SortColumnId = 3;
  211. column.Clicked += Column_Clicked;
  212. break;
  213. case "Version":
  214. column.SortColumnId = 4;
  215. column.Clicked += Column_Clicked;
  216. break;
  217. case "Time Played":
  218. column.SortColumnId = 5;
  219. column.Clicked += Column_Clicked;
  220. break;
  221. case "Last Played":
  222. column.SortColumnId = 6;
  223. column.Clicked += Column_Clicked;
  224. break;
  225. case "File Ext":
  226. column.SortColumnId = 7;
  227. column.Clicked += Column_Clicked;
  228. break;
  229. case "File Size":
  230. column.SortColumnId = 8;
  231. column.Clicked += Column_Clicked;
  232. break;
  233. case "Path":
  234. column.SortColumnId = 9;
  235. column.Clicked += Column_Clicked;
  236. break;
  237. }
  238. }
  239. }
  240. private HLE.Switch InitializeSwitchInstance()
  241. {
  242. _virtualFileSystem.Reload();
  243. HLE.Switch instance = new HLE.Switch(_virtualFileSystem, _contentManager, _userChannelPersistence, InitializeRenderer(), InitializeAudioEngine())
  244. {
  245. UiHandler = _uiHandler
  246. };
  247. instance.Initialize();
  248. return instance;
  249. }
  250. internal static void UpdateGameTable()
  251. {
  252. if (_updatingGameTable || _gameLoaded)
  253. {
  254. return;
  255. }
  256. _updatingGameTable = true;
  257. _tableStore.Clear();
  258. Thread applicationLibraryThread = new Thread(() =>
  259. {
  260. ApplicationLibrary.LoadApplications(ConfigurationState.Instance.Ui.GameDirs,
  261. _virtualFileSystem, ConfigurationState.Instance.System.Language);
  262. _updatingGameTable = false;
  263. });
  264. applicationLibraryThread.Name = "GUI.ApplicationLibraryThread";
  265. applicationLibraryThread.IsBackground = true;
  266. applicationLibraryThread.Start();
  267. }
  268. internal void LoadApplication(string path)
  269. {
  270. if (_gameLoaded)
  271. {
  272. GtkDialog.CreateInfoDialog("Ryujinx", "A game has already been loaded", "Please close it first and try again.");
  273. }
  274. else
  275. {
  276. #if !DEBUG
  277. if (ConfigurationState.Instance.Logger.EnableDebug.Value)
  278. {
  279. MessageDialog debugWarningDialog = new MessageDialog(this, DialogFlags.Modal, MessageType.Warning, ButtonsType.YesNo, null)
  280. {
  281. Title = "Ryujinx - Warning",
  282. Text = "You have debug logging enabled, which is designed to be used by developers only.",
  283. SecondaryText = "For optimal performance, it's recommended to disable debug logging. Would you like to disable debug logging now?"
  284. };
  285. if (debugWarningDialog.Run() == (int)ResponseType.Yes)
  286. {
  287. ConfigurationState.Instance.Logger.EnableDebug.Value = false;
  288. SaveConfig();
  289. }
  290. debugWarningDialog.Dispose();
  291. }
  292. if (!string.IsNullOrWhiteSpace(ConfigurationState.Instance.Graphics.ShadersDumpPath.Value))
  293. {
  294. MessageDialog shadersDumpWarningDialog = new MessageDialog(this, DialogFlags.Modal, MessageType.Warning, ButtonsType.YesNo, null)
  295. {
  296. Title = "Ryujinx - Warning",
  297. Text = "You have shader dumping enabled, which is designed to be used by developers only.",
  298. SecondaryText = "For optimal performance, it's recommended to disable shader dumping. Would you like to disable shader dumping now?"
  299. };
  300. if (shadersDumpWarningDialog.Run() == (int)ResponseType.Yes)
  301. {
  302. ConfigurationState.Instance.Graphics.ShadersDumpPath.Value = "";
  303. SaveConfig();
  304. }
  305. shadersDumpWarningDialog.Dispose();
  306. }
  307. #endif
  308. Logger.RestartTime();
  309. HLE.Switch device = InitializeSwitchInstance();
  310. UpdateGraphicsConfig();
  311. SystemVersion firmwareVersion = _contentManager.GetCurrentFirmwareVersion();
  312. bool isDirectory = Directory.Exists(path);
  313. if (!SetupValidator.CanStartApplication(_contentManager, path, out UserError userError))
  314. {
  315. if (SetupValidator.CanFixStartApplication(_contentManager, path, userError, out firmwareVersion))
  316. {
  317. if (userError == UserError.NoFirmware)
  318. {
  319. MessageDialog shouldInstallFirmwareDialog = new MessageDialog(this, DialogFlags.Modal, MessageType.Info, ButtonsType.YesNo, null)
  320. {
  321. Title = "Ryujinx - Info",
  322. Text = "No Firmware Installed",
  323. SecondaryText = $"Would you like to install the firmware embedded in this game? (Firmware {firmwareVersion.VersionString})"
  324. };
  325. if (shouldInstallFirmwareDialog.Run() != (int)ResponseType.Yes)
  326. {
  327. shouldInstallFirmwareDialog.Dispose();
  328. UserErrorDialog.CreateUserErrorDialog(userError);
  329. device.Dispose();
  330. return;
  331. }
  332. else
  333. {
  334. shouldInstallFirmwareDialog.Dispose();
  335. }
  336. }
  337. if (!SetupValidator.TryFixStartApplication(_contentManager, path, userError, out _))
  338. {
  339. UserErrorDialog.CreateUserErrorDialog(userError);
  340. device.Dispose();
  341. return;
  342. }
  343. // Tell the user that we installed a firmware for them.
  344. if (userError == UserError.NoFirmware)
  345. {
  346. firmwareVersion = _contentManager.GetCurrentFirmwareVersion();
  347. RefreshFirmwareLabel();
  348. GtkDialog.CreateInfoDialog("Ryujinx - Info", $"Firmware {firmwareVersion.VersionString} was installed",
  349. $"No installed firmware was found but Ryujinx was able to install firmware {firmwareVersion.VersionString} from the provided game.\nThe emulator will now start.");
  350. }
  351. }
  352. else
  353. {
  354. UserErrorDialog.CreateUserErrorDialog(userError);
  355. device.Dispose();
  356. return;
  357. }
  358. }
  359. _widgetInitEvent.Reset();
  360. #if MACOS_BUILD
  361. CreateGameWindow(device);
  362. #else
  363. Thread windowThread = new Thread(() =>
  364. {
  365. CreateGameWindow(device);
  366. })
  367. {
  368. Name = "GUI.WindowThread"
  369. };
  370. windowThread.Start();
  371. #endif
  372. _widgetInitEvent.WaitOne();
  373. // Make sure the widget get initialized by forcing an update of GTK
  374. while (Application.EventsPending())
  375. {
  376. Application.RunIteration();
  377. }
  378. Logger.Notice.Print(LogClass.Application, $"Using Firmware Version: {firmwareVersion?.VersionString}");
  379. if (Directory.Exists(path))
  380. {
  381. string[] romFsFiles = Directory.GetFiles(path, "*.istorage");
  382. if (romFsFiles.Length == 0)
  383. {
  384. romFsFiles = Directory.GetFiles(path, "*.romfs");
  385. }
  386. if (romFsFiles.Length > 0)
  387. {
  388. Logger.Info?.Print(LogClass.Application, "Loading as cart with RomFS.");
  389. device.LoadCart(path, romFsFiles[0]);
  390. }
  391. else
  392. {
  393. Logger.Info?.Print(LogClass.Application, "Loading as cart WITHOUT RomFS.");
  394. device.LoadCart(path);
  395. }
  396. }
  397. else if (File.Exists(path))
  398. {
  399. switch (System.IO.Path.GetExtension(path).ToLowerInvariant())
  400. {
  401. case ".xci":
  402. Logger.Info?.Print(LogClass.Application, "Loading as XCI.");
  403. device.LoadXci(path);
  404. break;
  405. case ".nca":
  406. Logger.Info?.Print(LogClass.Application, "Loading as NCA.");
  407. device.LoadNca(path);
  408. break;
  409. case ".nsp":
  410. case ".pfs0":
  411. Logger.Info?.Print(LogClass.Application, "Loading as NSP.");
  412. device.LoadNsp(path);
  413. break;
  414. default:
  415. Logger.Info?.Print(LogClass.Application, "Loading as homebrew.");
  416. try
  417. {
  418. device.LoadProgram(path);
  419. }
  420. catch (ArgumentOutOfRangeException)
  421. {
  422. Logger.Error?.Print(LogClass.Application, "The file which you have specified is unsupported by Ryujinx.");
  423. }
  424. break;
  425. }
  426. }
  427. else
  428. {
  429. Logger.Warning?.Print(LogClass.Application, "Please specify a valid XCI/NCA/NSP/PFS0/NRO file.");
  430. device.Dispose();
  431. return;
  432. }
  433. string titleNameSection = string.IsNullOrWhiteSpace(device.Application.TitleName) ? string.Empty
  434. : $" - {device.Application.TitleName}";
  435. string titleVersionSection = string.IsNullOrWhiteSpace(device.Application.DisplayVersion) ? string.Empty
  436. : $" v{device.Application.DisplayVersion}";
  437. string titleIdSection = string.IsNullOrWhiteSpace(device.Application.TitleIdText) ? string.Empty
  438. : $" ({device.Application.TitleIdText.ToUpper()})";
  439. string titleArchSection = device.Application.TitleIs64Bit ? " (64-bit)" : " (32-bit)";
  440. Title = $"Ryujinx {Program.Version}{titleNameSection}{titleVersionSection}{titleIdSection}{titleArchSection}";
  441. _emulationContext = device;
  442. _gamePath = path;
  443. _deviceExitStatus.Reset();
  444. _gameLoaded = true;
  445. _stopEmulation.Sensitive = true;
  446. _firmwareInstallFile.Sensitive = false;
  447. _firmwareInstallDirectory.Sensitive = false;
  448. DiscordIntegrationModule.SwitchToPlayingState(device.Application.TitleIdText, device.Application.TitleName);
  449. ApplicationLibrary.LoadAndSaveMetaData(device.Application.TitleIdText, appMetadata =>
  450. {
  451. appMetadata.LastPlayed = DateTime.UtcNow.ToString();
  452. });
  453. }
  454. }
  455. private void CreateGameWindow(HLE.Switch device)
  456. {
  457. if (Environment.OSVersion.Platform == PlatformID.Win32NT)
  458. {
  459. _windowsMultimediaTimerResolution = new WindowsMultimediaTimerResolution(1);
  460. }
  461. _glWidget = new GlRenderer(device, ConfigurationState.Instance.Logger.GraphicsDebugLevel);
  462. Application.Invoke(delegate
  463. {
  464. _viewBox.Remove(_gameTableWindow);
  465. _glWidget.Expand = true;
  466. _viewBox.Child = _glWidget;
  467. _glWidget.ShowAll();
  468. EditFooterForGameRender();
  469. if (this.Window.State.HasFlag(Gdk.WindowState.Fullscreen))
  470. {
  471. ToggleExtraWidgets(false);
  472. }
  473. });
  474. _widgetInitEvent.Set();
  475. _glWidget.WaitEvent.WaitOne();
  476. _glWidget.Start();
  477. Ptc.Close();
  478. PtcProfiler.Stop();
  479. device.Dispose();
  480. _deviceExitStatus.Set();
  481. // NOTE: Everything that is here will not be executed when you close the UI.
  482. Application.Invoke(delegate
  483. {
  484. if (this.Window.State.HasFlag(Gdk.WindowState.Fullscreen))
  485. {
  486. ToggleExtraWidgets(true);
  487. }
  488. _viewBox.Remove(_glWidget);
  489. _glWidget.Exit();
  490. if(_glWidget.Window != this.Window && _glWidget.Window != null)
  491. {
  492. _glWidget.Window.Dispose();
  493. }
  494. _glWidget.Dispose();
  495. _windowsMultimediaTimerResolution?.Dispose();
  496. _windowsMultimediaTimerResolution = null;
  497. _viewBox.Add(_gameTableWindow);
  498. _gameTableWindow.Expand = true;
  499. this.Window.Title = $"Ryujinx {Program.Version}";
  500. _emulationContext = null;
  501. _gameLoaded = false;
  502. _glWidget = null;
  503. DiscordIntegrationModule.SwitchToMainMenu();
  504. RecreateFooterForMenu();
  505. UpdateColumns();
  506. UpdateGameTable();
  507. Task.Run(RefreshFirmwareLabel);
  508. Task.Run(HandleRelaunch);
  509. _stopEmulation.Sensitive = false;
  510. _firmwareInstallFile.Sensitive = true;
  511. _firmwareInstallDirectory.Sensitive = true;
  512. });
  513. }
  514. private void RecreateFooterForMenu()
  515. {
  516. _listStatusBox.Show();
  517. _statusBar.Hide();
  518. }
  519. private void EditFooterForGameRender()
  520. {
  521. _listStatusBox.Hide();
  522. _statusBar.Show();
  523. }
  524. public void ToggleExtraWidgets(bool show)
  525. {
  526. if (_glWidget != null)
  527. {
  528. if (show)
  529. {
  530. _menuBar.ShowAll();
  531. _footerBox.Show();
  532. _statusBar.Show();
  533. }
  534. else
  535. {
  536. _menuBar.Hide();
  537. _footerBox.Hide();
  538. }
  539. }
  540. }
  541. private static void UpdateGameMetadata(string titleId)
  542. {
  543. if (_gameLoaded)
  544. {
  545. ApplicationLibrary.LoadAndSaveMetaData(titleId, appMetadata =>
  546. {
  547. DateTime lastPlayedDateTime = DateTime.Parse(appMetadata.LastPlayed);
  548. double sessionTimePlayed = DateTime.UtcNow.Subtract(lastPlayedDateTime).TotalSeconds;
  549. appMetadata.TimePlayed += Math.Round(sessionTimePlayed, MidpointRounding.AwayFromZero);
  550. });
  551. }
  552. }
  553. public static void UpdateGraphicsConfig()
  554. {
  555. int resScale = ConfigurationState.Instance.Graphics.ResScale;
  556. float resScaleCustom = ConfigurationState.Instance.Graphics.ResScaleCustom;
  557. Graphics.Gpu.GraphicsConfig.ResScale = (resScale == -1) ? resScaleCustom : resScale;
  558. Graphics.Gpu.GraphicsConfig.MaxAnisotropy = ConfigurationState.Instance.Graphics.MaxAnisotropy;
  559. Graphics.Gpu.GraphicsConfig.ShadersDumpPath = ConfigurationState.Instance.Graphics.ShadersDumpPath;
  560. Graphics.Gpu.GraphicsConfig.EnableShaderCache = ConfigurationState.Instance.Graphics.EnableShaderCache;
  561. }
  562. public static void SaveConfig()
  563. {
  564. ConfigurationState.Instance.ToFileFormat().SaveConfig(Program.ConfigurationPath);
  565. }
  566. private void End(HLE.Switch device)
  567. {
  568. if (_ending)
  569. {
  570. return;
  571. }
  572. _ending = true;
  573. if (device != null)
  574. {
  575. UpdateGameMetadata(device.Application.TitleIdText);
  576. if (_glWidget != null)
  577. {
  578. // We tell the widget that we are exiting
  579. _glWidget.Exit();
  580. // Wait for the other thread to dispose the HLE context before exiting.
  581. _deviceExitStatus.WaitOne();
  582. }
  583. }
  584. Dispose();
  585. DiscordIntegrationModule.Exit();
  586. Ptc.Dispose();
  587. PtcProfiler.Dispose();
  588. Logger.Shutdown();
  589. Application.Quit();
  590. }
  591. private static IRenderer InitializeRenderer()
  592. {
  593. return new Renderer();
  594. }
  595. private static IAalOutput InitializeAudioEngine()
  596. {
  597. if (ConfigurationState.Instance.System.AudioBackend.Value == AudioBackend.SoundIo)
  598. {
  599. if (SoundIoAudioOut.IsSupported)
  600. {
  601. return new SoundIoAudioOut();
  602. }
  603. else
  604. {
  605. Logger.Warning?.Print(LogClass.Audio, "SoundIO is not supported, falling back to dummy audio out.");
  606. }
  607. }
  608. else if (ConfigurationState.Instance.System.AudioBackend.Value == AudioBackend.OpenAl)
  609. {
  610. if (OpenALAudioOut.IsSupported)
  611. {
  612. return new OpenALAudioOut();
  613. }
  614. else
  615. {
  616. Logger.Warning?.Print(LogClass.Audio, "OpenAL is not supported, trying to fall back to SoundIO.");
  617. if (SoundIoAudioOut.IsSupported)
  618. {
  619. Logger.Warning?.Print(LogClass.Audio, "Found SoundIO, changing configuration.");
  620. ConfigurationState.Instance.System.AudioBackend.Value = AudioBackend.SoundIo;
  621. SaveConfig();
  622. return new SoundIoAudioOut();
  623. }
  624. else
  625. {
  626. Logger.Warning?.Print(LogClass.Audio, "SoundIO is not supported, falling back to dummy audio out.");
  627. }
  628. }
  629. }
  630. return new DummyAudioOut();
  631. }
  632. //Events
  633. private void Application_Added(object sender, ApplicationAddedEventArgs args)
  634. {
  635. Application.Invoke(delegate
  636. {
  637. _tableStore.AppendValues(
  638. args.AppData.Favorite,
  639. new Gdk.Pixbuf(args.AppData.Icon, 75, 75),
  640. $"{args.AppData.TitleName}\n{args.AppData.TitleId.ToUpper()}",
  641. args.AppData.Developer,
  642. args.AppData.Version,
  643. args.AppData.TimePlayed,
  644. args.AppData.LastPlayed,
  645. args.AppData.FileExtension,
  646. args.AppData.FileSize,
  647. args.AppData.Path,
  648. args.AppData.ControlHolder);
  649. });
  650. }
  651. private void ApplicationCount_Updated(object sender, ApplicationCountUpdatedEventArgs args)
  652. {
  653. Application.Invoke(delegate
  654. {
  655. _progressLabel.Text = $"{args.NumAppsLoaded}/{args.NumAppsFound} Games Loaded";
  656. float barValue = 0;
  657. if (args.NumAppsFound != 0)
  658. {
  659. barValue = (float)args.NumAppsLoaded / args.NumAppsFound;
  660. }
  661. _progressBar.Value = barValue;
  662. if (args.NumAppsLoaded == args.NumAppsFound) // Reset the vertical scrollbar to the top when titles finish loading
  663. {
  664. _gameTableWindow.Vadjustment.Value = 0;
  665. }
  666. });
  667. }
  668. private void Update_StatusBar(object sender, StatusUpdatedEventArgs args)
  669. {
  670. Application.Invoke(delegate
  671. {
  672. _gameStatus.Text = args.GameStatus;
  673. _fifoStatus.Text = args.FifoStatus;
  674. _gpuName.Text = args.GpuName;
  675. _dockedMode.Text = args.DockedMode;
  676. if (args.VSyncEnabled)
  677. {
  678. _vSyncStatus.Attributes = new Pango.AttrList();
  679. _vSyncStatus.Attributes.Insert(new Pango.AttrForeground(11822, 60138, 51657));
  680. }
  681. else
  682. {
  683. _vSyncStatus.Attributes = new Pango.AttrList();
  684. _vSyncStatus.Attributes.Insert(new Pango.AttrForeground(ushort.MaxValue, 17733, 21588));
  685. }
  686. });
  687. }
  688. private void FavToggle_Toggled(object sender, ToggledArgs args)
  689. {
  690. _tableStore.GetIter(out TreeIter treeIter, new TreePath(args.Path));
  691. string titleId = _tableStore.GetValue(treeIter, 2).ToString().Split("\n")[1].ToLower();
  692. bool newToggleValue = !(bool)_tableStore.GetValue(treeIter, 0);
  693. _tableStore.SetValue(treeIter, 0, newToggleValue);
  694. ApplicationLibrary.LoadAndSaveMetaData(titleId, appMetadata =>
  695. {
  696. appMetadata.Favorite = newToggleValue;
  697. });
  698. }
  699. private void Column_Clicked(object sender, EventArgs args)
  700. {
  701. TreeViewColumn column = (TreeViewColumn)sender;
  702. ConfigurationState.Instance.Ui.ColumnSort.SortColumnId.Value = column.SortColumnId;
  703. ConfigurationState.Instance.Ui.ColumnSort.SortAscending.Value = column.SortOrder == SortType.Ascending;
  704. SaveConfig();
  705. }
  706. private void Row_Activated(object sender, RowActivatedArgs args)
  707. {
  708. _gameTableSelection.GetSelected(out TreeIter treeIter);
  709. string path = (string)_tableStore.GetValue(treeIter, 9);
  710. LoadApplication(path);
  711. }
  712. private void Row_Clicked(object sender, ButtonReleaseEventArgs args)
  713. {
  714. if (args.Event.Button != 3) return;
  715. _gameTableSelection.GetSelected(out TreeIter treeIter);
  716. if (treeIter.UserData == IntPtr.Zero) return;
  717. BlitStruct<ApplicationControlProperty> controlData = (BlitStruct<ApplicationControlProperty>)_tableStore.GetValue(treeIter, 10);
  718. GameTableContextMenu contextMenu = new GameTableContextMenu(_tableStore, controlData, treeIter, _virtualFileSystem);
  719. contextMenu.ShowAll();
  720. contextMenu.PopupAtPointer(null);
  721. }
  722. private void Load_Application_File(object sender, EventArgs args)
  723. {
  724. FileChooserDialog fileChooser = new FileChooserDialog("Choose the file to open", this, FileChooserAction.Open, "Cancel", ResponseType.Cancel, "Open", ResponseType.Accept);
  725. fileChooser.Filter = new FileFilter();
  726. fileChooser.Filter.AddPattern("*.nsp" );
  727. fileChooser.Filter.AddPattern("*.pfs0");
  728. fileChooser.Filter.AddPattern("*.xci" );
  729. fileChooser.Filter.AddPattern("*.nca" );
  730. fileChooser.Filter.AddPattern("*.nro" );
  731. fileChooser.Filter.AddPattern("*.nso" );
  732. if (fileChooser.Run() == (int)ResponseType.Accept)
  733. {
  734. LoadApplication(fileChooser.Filename);
  735. }
  736. fileChooser.Dispose();
  737. }
  738. private void Load_Application_Folder(object sender, EventArgs args)
  739. {
  740. FileChooserDialog fileChooser = new FileChooserDialog("Choose the folder to open", this, FileChooserAction.SelectFolder, "Cancel", ResponseType.Cancel, "Open", ResponseType.Accept);
  741. if (fileChooser.Run() == (int)ResponseType.Accept)
  742. {
  743. LoadApplication(fileChooser.Filename);
  744. }
  745. fileChooser.Dispose();
  746. }
  747. private void Open_Ryu_Folder(object sender, EventArgs args)
  748. {
  749. Process.Start(new ProcessStartInfo
  750. {
  751. FileName = AppDataManager.BaseDirPath,
  752. UseShellExecute = true,
  753. Verb = "open"
  754. });
  755. }
  756. private void OpenLogsFolder_Pressed(object sender, EventArgs args)
  757. {
  758. string logPath = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Logs");
  759. DirectoryInfo directory = new DirectoryInfo(logPath);
  760. directory.Create();
  761. Process.Start(new ProcessStartInfo
  762. {
  763. FileName = logPath,
  764. UseShellExecute = true,
  765. Verb = "open"
  766. });
  767. }
  768. private void Exit_Pressed(object sender, EventArgs args)
  769. {
  770. if (!_gameLoaded || GtkDialog.CreateExitDialog())
  771. {
  772. End(_emulationContext);
  773. }
  774. }
  775. private void Window_Close(object sender, DeleteEventArgs args)
  776. {
  777. if (!_gameLoaded || GtkDialog.CreateExitDialog())
  778. {
  779. End(_emulationContext);
  780. }
  781. else
  782. {
  783. args.RetVal = true;
  784. }
  785. }
  786. private void StopEmulation_Pressed(object sender, EventArgs args)
  787. {
  788. _glWidget?.Exit();
  789. }
  790. private void Installer_File_Pressed(object o, EventArgs args)
  791. {
  792. FileChooserDialog fileChooser = new FileChooserDialog("Choose the firmware file to open",
  793. this,
  794. FileChooserAction.Open,
  795. "Cancel",
  796. ResponseType.Cancel,
  797. "Open",
  798. ResponseType.Accept);
  799. fileChooser.Filter = new FileFilter();
  800. fileChooser.Filter.AddPattern("*.zip");
  801. fileChooser.Filter.AddPattern("*.xci");
  802. HandleInstallerDialog(fileChooser);
  803. }
  804. private void Installer_Directory_Pressed(object o, EventArgs args)
  805. {
  806. FileChooserDialog directoryChooser = new FileChooserDialog("Choose the firmware directory to open",
  807. this,
  808. FileChooserAction.SelectFolder,
  809. "Cancel",
  810. ResponseType.Cancel,
  811. "Open",
  812. ResponseType.Accept);
  813. HandleInstallerDialog(directoryChooser);
  814. }
  815. private void RefreshFirmwareLabel()
  816. {
  817. SystemVersion currentFirmware = _contentManager.GetCurrentFirmwareVersion();
  818. GLib.Idle.Add(new GLib.IdleHandler(() =>
  819. {
  820. _firmwareVersionLabel.Text = currentFirmware != null ? currentFirmware.VersionString : "0.0.0";
  821. return false;
  822. }));
  823. }
  824. private void HandleRelaunch()
  825. {
  826. if (_userChannelPersistence.PreviousIndex != -1 && _userChannelPersistence.ShouldRestart)
  827. {
  828. _userChannelPersistence.ShouldRestart = false;
  829. LoadApplication(_gamePath);
  830. }
  831. else
  832. {
  833. // otherwise, clear state.
  834. _userChannelPersistence = new UserChannelPersistence();
  835. _gamePath = null;
  836. }
  837. }
  838. private void HandleInstallerDialog(FileChooserDialog fileChooser)
  839. {
  840. if (fileChooser.Run() == (int)ResponseType.Accept)
  841. {
  842. MessageDialog dialog = null;
  843. try
  844. {
  845. string filename = fileChooser.Filename;
  846. fileChooser.Dispose();
  847. SystemVersion firmwareVersion = _contentManager.VerifyFirmwarePackage(filename);
  848. if (firmwareVersion == null)
  849. {
  850. dialog = new MessageDialog(this, DialogFlags.Modal, MessageType.Info, ButtonsType.Ok, false, "");
  851. dialog.Text = "Firmware not found.";
  852. dialog.SecondaryText = $"A valid system firmware was not found in {filename}.";
  853. Logger.Error?.Print(LogClass.Application, $"A valid system firmware was not found in {filename}.");
  854. dialog.Run();
  855. dialog.Hide();
  856. dialog.Dispose();
  857. return;
  858. }
  859. SystemVersion currentVersion = _contentManager.GetCurrentFirmwareVersion();
  860. string dialogMessage = $"System version {firmwareVersion.VersionString} will be installed.";
  861. if (currentVersion != null)
  862. {
  863. dialogMessage += $"This will replace the current system version {currentVersion.VersionString}. ";
  864. }
  865. dialogMessage += "Do you want to continue?";
  866. dialog = new MessageDialog(this, DialogFlags.Modal, MessageType.Question, ButtonsType.YesNo, false, "");
  867. dialog.Text = $"Install Firmware {firmwareVersion.VersionString}";
  868. dialog.SecondaryText = dialogMessage;
  869. int response = dialog.Run();
  870. dialog.Dispose();
  871. dialog = new MessageDialog(this, DialogFlags.Modal, MessageType.Info, ButtonsType.None, false, "");
  872. dialog.Text = $"Install Firmware {firmwareVersion.VersionString}";
  873. dialog.SecondaryText = "Installing firmware...";
  874. if (response == (int)ResponseType.Yes)
  875. {
  876. Logger.Info?.Print(LogClass.Application, $"Installing firmware {firmwareVersion.VersionString}");
  877. Thread thread = new Thread(() =>
  878. {
  879. GLib.Idle.Add(new GLib.IdleHandler(() =>
  880. {
  881. dialog.Run();
  882. return false;
  883. }));
  884. try
  885. {
  886. _contentManager.InstallFirmware(filename);
  887. GLib.Idle.Add(new GLib.IdleHandler(() =>
  888. {
  889. dialog.Dispose();
  890. dialog = new MessageDialog(this, DialogFlags.Modal, MessageType.Info, ButtonsType.Ok, false, "");
  891. dialog.Text = $"Install Firmware {firmwareVersion.VersionString}";
  892. dialog.SecondaryText = $"System version {firmwareVersion.VersionString} successfully installed.";
  893. Logger.Info?.Print(LogClass.Application, $"System version {firmwareVersion.VersionString} successfully installed.");
  894. dialog.Run();
  895. dialog.Dispose();
  896. return false;
  897. }));
  898. }
  899. catch (Exception ex)
  900. {
  901. GLib.Idle.Add(new GLib.IdleHandler(() =>
  902. {
  903. dialog.Dispose();
  904. dialog = new MessageDialog(this, DialogFlags.Modal, MessageType.Info, ButtonsType.Ok, false, "");
  905. dialog.Text = $"Install Firmware {firmwareVersion.VersionString} Failed.";
  906. dialog.SecondaryText = $"An error occured while installing system version {firmwareVersion.VersionString}." +
  907. " Please check logs for more info.";
  908. Logger.Error?.Print(LogClass.Application, ex.Message);
  909. dialog.Run();
  910. dialog.Dispose();
  911. return false;
  912. }));
  913. }
  914. finally
  915. {
  916. RefreshFirmwareLabel();
  917. }
  918. });
  919. thread.Name = "GUI.FirmwareInstallerThread";
  920. thread.Start();
  921. }
  922. else
  923. {
  924. dialog.Dispose();
  925. }
  926. }
  927. catch (Exception ex)
  928. {
  929. if (dialog != null)
  930. {
  931. dialog.Dispose();
  932. }
  933. dialog = new MessageDialog(this, DialogFlags.Modal, MessageType.Info, ButtonsType.Ok, false, "");
  934. dialog.Text = "Parsing Firmware Failed.";
  935. dialog.SecondaryText = "An error occured while parsing firmware. Please check the logs for more info.";
  936. Logger.Error?.Print(LogClass.Application, ex.Message);
  937. dialog.Run();
  938. dialog.Dispose();
  939. }
  940. }
  941. else
  942. {
  943. fileChooser.Dispose();
  944. }
  945. }
  946. private void FullScreen_Toggled(object o, EventArgs args)
  947. {
  948. bool fullScreenToggled = this.Window.State.HasFlag(Gdk.WindowState.Fullscreen);
  949. if (!fullScreenToggled)
  950. {
  951. Fullscreen();
  952. ToggleExtraWidgets(false);
  953. }
  954. else
  955. {
  956. Unfullscreen();
  957. ToggleExtraWidgets(true);
  958. }
  959. }
  960. private void Settings_Pressed(object sender, EventArgs args)
  961. {
  962. SettingsWindow settingsWin = new SettingsWindow(_virtualFileSystem, _contentManager);
  963. settingsWin.Show();
  964. }
  965. private void Update_Pressed(object sender, EventArgs args)
  966. {
  967. if (Updater.CanUpdate(true))
  968. {
  969. Updater.BeginParse(this, true);
  970. }
  971. }
  972. private void About_Pressed(object sender, EventArgs args)
  973. {
  974. AboutWindow aboutWin = new AboutWindow();
  975. aboutWin.Show();
  976. }
  977. private void Fav_Toggled(object sender, EventArgs args)
  978. {
  979. ConfigurationState.Instance.Ui.GuiColumns.FavColumn.Value = _favToggle.Active;
  980. SaveConfig();
  981. UpdateColumns();
  982. }
  983. private void Icon_Toggled(object sender, EventArgs args)
  984. {
  985. ConfigurationState.Instance.Ui.GuiColumns.IconColumn.Value = _iconToggle.Active;
  986. SaveConfig();
  987. UpdateColumns();
  988. }
  989. private void Title_Toggled(object sender, EventArgs args)
  990. {
  991. ConfigurationState.Instance.Ui.GuiColumns.AppColumn.Value = _appToggle.Active;
  992. SaveConfig();
  993. UpdateColumns();
  994. }
  995. private void Developer_Toggled(object sender, EventArgs args)
  996. {
  997. ConfigurationState.Instance.Ui.GuiColumns.DevColumn.Value = _developerToggle.Active;
  998. SaveConfig();
  999. UpdateColumns();
  1000. }
  1001. private void Version_Toggled(object sender, EventArgs args)
  1002. {
  1003. ConfigurationState.Instance.Ui.GuiColumns.VersionColumn.Value = _versionToggle.Active;
  1004. SaveConfig();
  1005. UpdateColumns();
  1006. }
  1007. private void TimePlayed_Toggled(object sender, EventArgs args)
  1008. {
  1009. ConfigurationState.Instance.Ui.GuiColumns.TimePlayedColumn.Value = _timePlayedToggle.Active;
  1010. SaveConfig();
  1011. UpdateColumns();
  1012. }
  1013. private void LastPlayed_Toggled(object sender, EventArgs args)
  1014. {
  1015. ConfigurationState.Instance.Ui.GuiColumns.LastPlayedColumn.Value = _lastPlayedToggle.Active;
  1016. SaveConfig();
  1017. UpdateColumns();
  1018. }
  1019. private void FileExt_Toggled(object sender, EventArgs args)
  1020. {
  1021. ConfigurationState.Instance.Ui.GuiColumns.FileExtColumn.Value = _fileExtToggle.Active;
  1022. SaveConfig();
  1023. UpdateColumns();
  1024. }
  1025. private void FileSize_Toggled(object sender, EventArgs args)
  1026. {
  1027. ConfigurationState.Instance.Ui.GuiColumns.FileSizeColumn.Value = _fileSizeToggle.Active;
  1028. SaveConfig();
  1029. UpdateColumns();
  1030. }
  1031. private void Path_Toggled(object sender, EventArgs args)
  1032. {
  1033. ConfigurationState.Instance.Ui.GuiColumns.PathColumn.Value = _pathToggle.Active;
  1034. SaveConfig();
  1035. UpdateColumns();
  1036. }
  1037. private void RefreshList_Pressed(object sender, ButtonReleaseEventArgs args)
  1038. {
  1039. UpdateGameTable();
  1040. }
  1041. private static int TimePlayedSort(ITreeModel model, TreeIter a, TreeIter b)
  1042. {
  1043. string aValue = model.GetValue(a, 5).ToString();
  1044. string bValue = model.GetValue(b, 5).ToString();
  1045. if (aValue.Length > 4 && aValue.Substring(aValue.Length - 4) == "mins")
  1046. {
  1047. aValue = (float.Parse(aValue.Substring(0, aValue.Length - 5)) * 60).ToString();
  1048. }
  1049. else if (aValue.Length > 3 && aValue.Substring(aValue.Length - 3) == "hrs")
  1050. {
  1051. aValue = (float.Parse(aValue.Substring(0, aValue.Length - 4)) * 3600).ToString();
  1052. }
  1053. else if (aValue.Length > 4 && aValue.Substring(aValue.Length - 4) == "days")
  1054. {
  1055. aValue = (float.Parse(aValue.Substring(0, aValue.Length - 5)) * 86400).ToString();
  1056. }
  1057. else
  1058. {
  1059. aValue = aValue.Substring(0, aValue.Length - 1);
  1060. }
  1061. if (bValue.Length > 4 && bValue.Substring(bValue.Length - 4) == "mins")
  1062. {
  1063. bValue = (float.Parse(bValue.Substring(0, bValue.Length - 5)) * 60).ToString();
  1064. }
  1065. else if (bValue.Length > 3 && bValue.Substring(bValue.Length - 3) == "hrs")
  1066. {
  1067. bValue = (float.Parse(bValue.Substring(0, bValue.Length - 4)) * 3600).ToString();
  1068. }
  1069. else if (bValue.Length > 4 && bValue.Substring(bValue.Length - 4) == "days")
  1070. {
  1071. bValue = (float.Parse(bValue.Substring(0, bValue.Length - 5)) * 86400).ToString();
  1072. }
  1073. else
  1074. {
  1075. bValue = bValue.Substring(0, bValue.Length - 1);
  1076. }
  1077. if (float.Parse(aValue) > float.Parse(bValue))
  1078. {
  1079. return -1;
  1080. }
  1081. else if (float.Parse(bValue) > float.Parse(aValue))
  1082. {
  1083. return 1;
  1084. }
  1085. else
  1086. {
  1087. return 0;
  1088. }
  1089. }
  1090. private static int LastPlayedSort(ITreeModel model, TreeIter a, TreeIter b)
  1091. {
  1092. string aValue = model.GetValue(a, 6).ToString();
  1093. string bValue = model.GetValue(b, 6).ToString();
  1094. if (aValue == "Never")
  1095. {
  1096. aValue = DateTime.UnixEpoch.ToString();
  1097. }
  1098. if (bValue == "Never")
  1099. {
  1100. bValue = DateTime.UnixEpoch.ToString();
  1101. }
  1102. return DateTime.Compare(DateTime.Parse(bValue), DateTime.Parse(aValue));
  1103. }
  1104. private static int FileSizeSort(ITreeModel model, TreeIter a, TreeIter b)
  1105. {
  1106. string aValue = model.GetValue(a, 8).ToString();
  1107. string bValue = model.GetValue(b, 8).ToString();
  1108. if (aValue.Substring(aValue.Length - 2) == "GB")
  1109. {
  1110. aValue = (float.Parse(aValue[0..^2]) * 1024).ToString();
  1111. }
  1112. else
  1113. {
  1114. aValue = aValue[0..^2];
  1115. }
  1116. if (bValue.Substring(bValue.Length - 2) == "GB")
  1117. {
  1118. bValue = (float.Parse(bValue[0..^2]) * 1024).ToString();
  1119. }
  1120. else
  1121. {
  1122. bValue = bValue[0..^2];
  1123. }
  1124. if (float.Parse(aValue) > float.Parse(bValue))
  1125. {
  1126. return -1;
  1127. }
  1128. else if (float.Parse(bValue) > float.Parse(aValue))
  1129. {
  1130. return 1;
  1131. }
  1132. else
  1133. {
  1134. return 0;
  1135. }
  1136. }
  1137. }
  1138. }