MainWindow.cs 48 KB

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