MainWindow.cs 48 KB

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