MainWindow.cs 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797
  1. using Gtk;
  2. using JsonPrettyPrinterPlus;
  3. using Ryujinx.Audio;
  4. using Ryujinx.Common.Logging;
  5. using Ryujinx.Configuration;
  6. using Ryujinx.Graphics.OpenGL;
  7. using Ryujinx.HLE.FileSystem;
  8. using Ryujinx.Profiler;
  9. using System;
  10. using System.Diagnostics;
  11. using System.IO;
  12. using System.Reflection;
  13. using System.Text;
  14. using System.Threading;
  15. using System.Threading.Tasks;
  16. using Utf8Json;
  17. using Utf8Json.Resolvers;
  18. using GUI = Gtk.Builder.ObjectAttribute;
  19. namespace Ryujinx.Ui
  20. {
  21. public class MainWindow : Window
  22. {
  23. private static HLE.Switch _device;
  24. private static Renderer _renderer;
  25. private static IAalOutput _audioOut;
  26. private static GlScreen _screen;
  27. private static ListStore _tableStore;
  28. private static bool _updatingGameTable;
  29. private static bool _gameLoaded;
  30. private static bool _ending;
  31. private static TreeView _treeView;
  32. #pragma warning disable CS0649
  33. #pragma warning disable IDE0044
  34. [GUI] Window _mainWin;
  35. [GUI] CheckMenuItem _fullScreen;
  36. [GUI] MenuItem _stopEmulation;
  37. [GUI] CheckMenuItem _favToggle;
  38. [GUI] CheckMenuItem _iconToggle;
  39. [GUI] CheckMenuItem _appToggle;
  40. [GUI] CheckMenuItem _developerToggle;
  41. [GUI] CheckMenuItem _versionToggle;
  42. [GUI] CheckMenuItem _timePlayedToggle;
  43. [GUI] CheckMenuItem _lastPlayedToggle;
  44. [GUI] CheckMenuItem _fileExtToggle;
  45. [GUI] CheckMenuItem _fileSizeToggle;
  46. [GUI] CheckMenuItem _pathToggle;
  47. [GUI] TreeView _gameTable;
  48. [GUI] TreeSelection _gameTableSelection;
  49. [GUI] Label _progressLabel;
  50. [GUI] LevelBar _progressBar;
  51. #pragma warning restore CS0649
  52. #pragma warning restore IDE0044
  53. public MainWindow() : this(new Builder("Ryujinx.Ui.MainWindow.glade")) { }
  54. private MainWindow(Builder builder) : base(builder.GetObject("_mainWin").Handle)
  55. {
  56. builder.Autoconnect(this);
  57. DeleteEvent += Window_Close;
  58. ApplicationLibrary.ApplicationAdded += Application_Added;
  59. _gameTable.ButtonReleaseEvent += Row_Clicked;
  60. bool continueWithStartup = Migration.PromptIfMigrationNeededForStartup(this, out bool migrationNeeded);
  61. if (!continueWithStartup)
  62. {
  63. End();
  64. }
  65. _renderer = new Renderer();
  66. _audioOut = InitializeAudioEngine();
  67. // TODO: Initialization and dispose of HLE.Switch when starting/stoping emulation.
  68. _device = InitializeSwitchInstance();
  69. if (migrationNeeded)
  70. {
  71. bool migrationSuccessful = Migration.DoMigrationForStartup(this, _device);
  72. if (!migrationSuccessful)
  73. {
  74. End();
  75. }
  76. }
  77. _treeView = _gameTable;
  78. ApplyTheme();
  79. _mainWin.Icon = new Gdk.Pixbuf(Assembly.GetExecutingAssembly(), "Ryujinx.Ui.assets.Icon.png");
  80. _stopEmulation.Sensitive = false;
  81. if (ConfigurationState.Instance.Ui.GuiColumns.FavColumn) _favToggle.Active = true;
  82. if (ConfigurationState.Instance.Ui.GuiColumns.IconColumn) _iconToggle.Active = true;
  83. if (ConfigurationState.Instance.Ui.GuiColumns.AppColumn) _appToggle.Active = true;
  84. if (ConfigurationState.Instance.Ui.GuiColumns.DevColumn) _developerToggle.Active = true;
  85. if (ConfigurationState.Instance.Ui.GuiColumns.VersionColumn) _versionToggle.Active = true;
  86. if (ConfigurationState.Instance.Ui.GuiColumns.TimePlayedColumn) _timePlayedToggle.Active = true;
  87. if (ConfigurationState.Instance.Ui.GuiColumns.LastPlayedColumn) _lastPlayedToggle.Active = true;
  88. if (ConfigurationState.Instance.Ui.GuiColumns.FileExtColumn) _fileExtToggle.Active = true;
  89. if (ConfigurationState.Instance.Ui.GuiColumns.FileSizeColumn) _fileSizeToggle.Active = true;
  90. if (ConfigurationState.Instance.Ui.GuiColumns.PathColumn) _pathToggle.Active = true;
  91. _gameTable.Model = _tableStore = new ListStore(
  92. typeof(bool),
  93. typeof(Gdk.Pixbuf),
  94. typeof(string),
  95. typeof(string),
  96. typeof(string),
  97. typeof(string),
  98. typeof(string),
  99. typeof(string),
  100. typeof(string),
  101. typeof(string));
  102. _tableStore.SetSortFunc(5, TimePlayedSort);
  103. _tableStore.SetSortFunc(6, LastPlayedSort);
  104. _tableStore.SetSortFunc(8, FileSizeSort);
  105. _tableStore.SetSortColumnId(0, SortType.Descending);
  106. UpdateColumns();
  107. #pragma warning disable CS4014
  108. UpdateGameTable();
  109. #pragma warning restore CS4014
  110. }
  111. internal static void ApplyTheme()
  112. {
  113. if (!ConfigurationState.Instance.Ui.EnableCustomTheme)
  114. {
  115. return;
  116. }
  117. if (File.Exists(ConfigurationState.Instance.Ui.CustomThemePath) && (System.IO.Path.GetExtension(ConfigurationState.Instance.Ui.CustomThemePath) == ".css"))
  118. {
  119. CssProvider cssProvider = new CssProvider();
  120. cssProvider.LoadFromPath(ConfigurationState.Instance.Ui.CustomThemePath);
  121. StyleContext.AddProviderForScreen(Gdk.Screen.Default, cssProvider, 800);
  122. }
  123. else
  124. {
  125. Logger.PrintWarning(LogClass.Application, $"The \"custom_theme_path\" section in \"Config.json\" contains an invalid path: \"{ConfigurationState.Instance.Ui.CustomThemePath}\".");
  126. }
  127. }
  128. private void UpdateColumns()
  129. {
  130. foreach (TreeViewColumn column in _gameTable.Columns)
  131. {
  132. _gameTable.RemoveColumn(column);
  133. }
  134. CellRendererToggle favToggle = new CellRendererToggle();
  135. favToggle.Toggled += FavToggle_Toggled;
  136. if (ConfigurationState.Instance.Ui.GuiColumns.FavColumn) _gameTable.AppendColumn("Fav", favToggle, "active", 0);
  137. if (ConfigurationState.Instance.Ui.GuiColumns.IconColumn) _gameTable.AppendColumn("Icon", new CellRendererPixbuf(), "pixbuf", 1);
  138. if (ConfigurationState.Instance.Ui.GuiColumns.AppColumn) _gameTable.AppendColumn("Application", new CellRendererText(), "text", 2);
  139. if (ConfigurationState.Instance.Ui.GuiColumns.DevColumn) _gameTable.AppendColumn("Developer", new CellRendererText(), "text", 3);
  140. if (ConfigurationState.Instance.Ui.GuiColumns.VersionColumn) _gameTable.AppendColumn("Version", new CellRendererText(), "text", 4);
  141. if (ConfigurationState.Instance.Ui.GuiColumns.TimePlayedColumn) _gameTable.AppendColumn("Time Played", new CellRendererText(), "text", 5);
  142. if (ConfigurationState.Instance.Ui.GuiColumns.LastPlayedColumn) _gameTable.AppendColumn("Last Played", new CellRendererText(), "text", 6);
  143. if (ConfigurationState.Instance.Ui.GuiColumns.FileExtColumn) _gameTable.AppendColumn("File Ext", new CellRendererText(), "text", 7);
  144. if (ConfigurationState.Instance.Ui.GuiColumns.FileSizeColumn) _gameTable.AppendColumn("File Size", new CellRendererText(), "text", 8);
  145. if (ConfigurationState.Instance.Ui.GuiColumns.PathColumn) _gameTable.AppendColumn("Path", new CellRendererText(), "text", 9);
  146. foreach (TreeViewColumn column in _gameTable.Columns)
  147. {
  148. if (column.Title == "Fav" && ConfigurationState.Instance.Ui.GuiColumns.FavColumn) column.SortColumnId = 0;
  149. else if (column.Title == "Application" && ConfigurationState.Instance.Ui.GuiColumns.AppColumn) column.SortColumnId = 2;
  150. else if (column.Title == "Developer" && ConfigurationState.Instance.Ui.GuiColumns.DevColumn) column.SortColumnId = 3;
  151. else if (column.Title == "Version" && ConfigurationState.Instance.Ui.GuiColumns.VersionColumn) column.SortColumnId = 4;
  152. else if (column.Title == "Time Played" && ConfigurationState.Instance.Ui.GuiColumns.TimePlayedColumn) column.SortColumnId = 5;
  153. else if (column.Title == "Last Played" && ConfigurationState.Instance.Ui.GuiColumns.LastPlayedColumn) column.SortColumnId = 6;
  154. else if (column.Title == "File Ext" && ConfigurationState.Instance.Ui.GuiColumns.FileExtColumn) column.SortColumnId = 7;
  155. else if (column.Title == "File Size" && ConfigurationState.Instance.Ui.GuiColumns.FileSizeColumn) column.SortColumnId = 8;
  156. else if (column.Title == "Path" && ConfigurationState.Instance.Ui.GuiColumns.PathColumn) column.SortColumnId = 9;
  157. }
  158. }
  159. private HLE.Switch InitializeSwitchInstance()
  160. {
  161. HLE.Switch instance = new HLE.Switch(_renderer, _audioOut);
  162. instance.Initialize();
  163. return instance;
  164. }
  165. internal static async Task UpdateGameTable()
  166. {
  167. if (_updatingGameTable)
  168. {
  169. return;
  170. }
  171. _updatingGameTable = true;
  172. _tableStore.Clear();
  173. await Task.Run(() => ApplicationLibrary.LoadApplications(ConfigurationState.Instance.Ui.GameDirs,
  174. _device.System.KeySet, _device.System.State.DesiredTitleLanguage, _device.System.FsClient,
  175. _device.FileSystem));
  176. _updatingGameTable = false;
  177. }
  178. internal void LoadApplication(string path)
  179. {
  180. if (_gameLoaded)
  181. {
  182. GtkDialog.CreateErrorDialog("A game has already been loaded. Please close the emulator and try again");
  183. }
  184. else
  185. {
  186. Logger.RestartTime();
  187. // TODO: Move this somewhere else + reloadable?
  188. Ryujinx.Graphics.Gpu.GraphicsConfig.ShadersDumpPath = ConfigurationState.Instance.Graphics.ShadersDumpPath;
  189. if (Directory.Exists(path))
  190. {
  191. string[] romFsFiles = Directory.GetFiles(path, "*.istorage");
  192. if (romFsFiles.Length == 0)
  193. {
  194. romFsFiles = Directory.GetFiles(path, "*.romfs");
  195. }
  196. if (romFsFiles.Length > 0)
  197. {
  198. Logger.PrintInfo(LogClass.Application, "Loading as cart with RomFS.");
  199. _device.LoadCart(path, romFsFiles[0]);
  200. }
  201. else
  202. {
  203. Logger.PrintInfo(LogClass.Application, "Loading as cart WITHOUT RomFS.");
  204. _device.LoadCart(path);
  205. }
  206. }
  207. else if (File.Exists(path))
  208. {
  209. switch (System.IO.Path.GetExtension(path).ToLowerInvariant())
  210. {
  211. case ".xci":
  212. Logger.PrintInfo(LogClass.Application, "Loading as XCI.");
  213. _device.LoadXci(path);
  214. break;
  215. case ".nca":
  216. Logger.PrintInfo(LogClass.Application, "Loading as NCA.");
  217. _device.LoadNca(path);
  218. break;
  219. case ".nsp":
  220. case ".pfs0":
  221. Logger.PrintInfo(LogClass.Application, "Loading as NSP.");
  222. _device.LoadNsp(path);
  223. break;
  224. default:
  225. Logger.PrintInfo(LogClass.Application, "Loading as homebrew.");
  226. try
  227. {
  228. _device.LoadProgram(path);
  229. }
  230. catch (ArgumentOutOfRangeException)
  231. {
  232. Logger.PrintError(LogClass.Application, "The file which you have specified is unsupported by Ryujinx.");
  233. }
  234. break;
  235. }
  236. }
  237. else
  238. {
  239. Logger.PrintWarning(LogClass.Application, "Please specify a valid XCI/NCA/NSP/PFS0/NRO file.");
  240. End();
  241. }
  242. #if MACOS_BUILD
  243. CreateGameWindow();
  244. #else
  245. new Thread(CreateGameWindow).Start();
  246. #endif
  247. _gameLoaded = true;
  248. _stopEmulation.Sensitive = true;
  249. DiscordIntegrationModule.SwitchToPlayingState(_device.System.TitleId, _device.System.TitleName);
  250. string metadataFolder = System.IO.Path.Combine(new VirtualFileSystem().GetBasePath(), "games", _device.System.TitleId, "gui");
  251. string metadataFile = System.IO.Path.Combine(metadataFolder, "metadata.json");
  252. IJsonFormatterResolver resolver = CompositeResolver.Create(new[] { StandardResolver.AllowPrivateSnakeCase });
  253. ApplicationMetadata appMetadata;
  254. if (!File.Exists(metadataFile))
  255. {
  256. Directory.CreateDirectory(metadataFolder);
  257. appMetadata = new ApplicationMetadata
  258. {
  259. Favorite = false,
  260. TimePlayed = 0,
  261. LastPlayed = "Never"
  262. };
  263. byte[] data = JsonSerializer.Serialize(appMetadata, resolver);
  264. File.WriteAllText(metadataFile, Encoding.UTF8.GetString(data, 0, data.Length).PrettyPrintJson());
  265. }
  266. using (Stream stream = File.OpenRead(metadataFile))
  267. {
  268. appMetadata = JsonSerializer.Deserialize<ApplicationMetadata>(stream, resolver);
  269. }
  270. appMetadata.LastPlayed = DateTime.UtcNow.ToString();
  271. byte[] saveData = JsonSerializer.Serialize(appMetadata, resolver);
  272. File.WriteAllText(metadataFile, Encoding.UTF8.GetString(saveData, 0, saveData.Length).PrettyPrintJson());
  273. }
  274. }
  275. private static void CreateGameWindow()
  276. {
  277. _device.Hid.InitializePrimaryController(ConfigurationState.Instance.Hid.ControllerType);
  278. using (_screen = new GlScreen(_device, _renderer))
  279. {
  280. _screen.MainLoop();
  281. End();
  282. }
  283. }
  284. private static void End()
  285. {
  286. if (_ending)
  287. {
  288. return;
  289. }
  290. _ending = true;
  291. if (_gameLoaded)
  292. {
  293. string metadataFolder = System.IO.Path.Combine(new VirtualFileSystem().GetBasePath(), "games", _device.System.TitleId, "gui");
  294. string metadataFile = System.IO.Path.Combine(metadataFolder, "metadata.json");
  295. IJsonFormatterResolver resolver = CompositeResolver.Create(new[] { StandardResolver.AllowPrivateSnakeCase });
  296. ApplicationMetadata appMetadata;
  297. if (!File.Exists(metadataFile))
  298. {
  299. Directory.CreateDirectory(metadataFolder);
  300. appMetadata = new ApplicationMetadata
  301. {
  302. Favorite = false,
  303. TimePlayed = 0,
  304. LastPlayed = "Never"
  305. };
  306. byte[] data = JsonSerializer.Serialize(appMetadata, resolver);
  307. File.WriteAllText(metadataFile, Encoding.UTF8.GetString(data, 0, data.Length).PrettyPrintJson());
  308. }
  309. using (Stream stream = File.OpenRead(metadataFile))
  310. {
  311. appMetadata = JsonSerializer.Deserialize<ApplicationMetadata>(stream, resolver);
  312. }
  313. DateTime lastPlayedDateTime = DateTime.Parse(appMetadata.LastPlayed);
  314. double sessionTimePlayed = DateTime.UtcNow.Subtract(lastPlayedDateTime).TotalSeconds;
  315. appMetadata.TimePlayed += Math.Round(sessionTimePlayed, MidpointRounding.AwayFromZero);
  316. byte[] saveData = JsonSerializer.Serialize(appMetadata, resolver);
  317. File.WriteAllText(metadataFile, Encoding.UTF8.GetString(saveData, 0, saveData.Length).PrettyPrintJson());
  318. }
  319. Profile.FinishProfiling();
  320. _device?.Dispose();
  321. _audioOut?.Dispose();
  322. Logger.Shutdown();
  323. Environment.Exit(0);
  324. }
  325. /// <summary>
  326. /// Picks an <see cref="IAalOutput"/> audio output renderer supported on this machine
  327. /// </summary>
  328. /// <returns>An <see cref="IAalOutput"/> supported by this machine</returns>
  329. private static IAalOutput InitializeAudioEngine()
  330. {
  331. /*if (SoundIoAudioOut.IsSupported)
  332. {
  333. return new SoundIoAudioOut();
  334. }
  335. else*/ if (OpenALAudioOut.IsSupported)
  336. {
  337. return new OpenALAudioOut();
  338. }
  339. else
  340. {
  341. return new DummyAudioOut();
  342. }
  343. }
  344. //Events
  345. private void Application_Added(object sender, ApplicationAddedEventArgs args)
  346. {
  347. Application.Invoke(delegate
  348. {
  349. _tableStore.AppendValues(
  350. args.AppData.Favorite,
  351. new Gdk.Pixbuf(args.AppData.Icon, 75, 75),
  352. $"{args.AppData.TitleName}\n{args.AppData.TitleId.ToUpper()}",
  353. args.AppData.Developer,
  354. args.AppData.Version,
  355. args.AppData.TimePlayed,
  356. args.AppData.LastPlayed,
  357. args.AppData.FileExtension,
  358. args.AppData.FileSize,
  359. args.AppData.Path);
  360. _progressLabel.Text = $"{args.NumAppsLoaded}/{args.NumAppsFound} Games Loaded";
  361. _progressBar.Value = (float)args.NumAppsLoaded / args.NumAppsFound;
  362. });
  363. }
  364. private void FavToggle_Toggled(object sender, ToggledArgs args)
  365. {
  366. _tableStore.GetIter(out TreeIter treeIter, new TreePath(args.Path));
  367. string titleId = _tableStore.GetValue(treeIter, 2).ToString().Split("\n")[1].ToLower();
  368. string metadataPath = System.IO.Path.Combine(new VirtualFileSystem().GetBasePath(), "games", titleId, "gui", "metadata.json");
  369. IJsonFormatterResolver resolver = CompositeResolver.Create(new[] { StandardResolver.AllowPrivateSnakeCase });
  370. ApplicationMetadata appMetadata;
  371. using (Stream stream = File.OpenRead(metadataPath))
  372. {
  373. appMetadata = JsonSerializer.Deserialize<ApplicationMetadata>(stream, resolver);
  374. }
  375. if ((bool)_tableStore.GetValue(treeIter, 0))
  376. {
  377. _tableStore.SetValue(treeIter, 0, false);
  378. appMetadata.Favorite = false;
  379. }
  380. else
  381. {
  382. _tableStore.SetValue(treeIter, 0, true);
  383. appMetadata.Favorite = true;
  384. }
  385. byte[] saveData = JsonSerializer.Serialize(appMetadata, resolver);
  386. File.WriteAllText(metadataPath, Encoding.UTF8.GetString(saveData, 0, saveData.Length).PrettyPrintJson());
  387. }
  388. private void Row_Activated(object sender, RowActivatedArgs args)
  389. {
  390. _gameTableSelection.GetSelected(out TreeIter treeIter);
  391. string path = (string)_tableStore.GetValue(treeIter, 9);
  392. LoadApplication(path);
  393. }
  394. private void Row_Clicked(object sender, ButtonReleaseEventArgs args)
  395. {
  396. if (args.Event.Button != 3) return;
  397. _gameTableSelection.GetSelected(out TreeIter treeIter);
  398. if (treeIter.UserData == IntPtr.Zero) return;
  399. GameTableContextMenu contextMenu = new GameTableContextMenu(_tableStore, treeIter, _device.System.FsClient);
  400. contextMenu.ShowAll();
  401. contextMenu.PopupAtPointer(null);
  402. }
  403. private void Load_Application_File(object sender, EventArgs args)
  404. {
  405. FileChooserDialog fileChooser = new FileChooserDialog("Choose the file to open", this, FileChooserAction.Open, "Cancel", ResponseType.Cancel, "Open", ResponseType.Accept);
  406. fileChooser.Filter = new FileFilter();
  407. fileChooser.Filter.AddPattern("*.nsp" );
  408. fileChooser.Filter.AddPattern("*.pfs0");
  409. fileChooser.Filter.AddPattern("*.xci" );
  410. fileChooser.Filter.AddPattern("*.nca" );
  411. fileChooser.Filter.AddPattern("*.nro" );
  412. fileChooser.Filter.AddPattern("*.nso" );
  413. if (fileChooser.Run() == (int)ResponseType.Accept)
  414. {
  415. LoadApplication(fileChooser.Filename);
  416. }
  417. fileChooser.Dispose();
  418. }
  419. private void Load_Application_Folder(object sender, EventArgs args)
  420. {
  421. FileChooserDialog fileChooser = new FileChooserDialog("Choose the folder to open", this, FileChooserAction.SelectFolder, "Cancel", ResponseType.Cancel, "Open", ResponseType.Accept);
  422. if (fileChooser.Run() == (int)ResponseType.Accept)
  423. {
  424. LoadApplication(fileChooser.Filename);
  425. }
  426. fileChooser.Dispose();
  427. }
  428. private void Open_Ryu_Folder(object sender, EventArgs args)
  429. {
  430. Process.Start(new ProcessStartInfo()
  431. {
  432. FileName = new VirtualFileSystem().GetBasePath(),
  433. UseShellExecute = true,
  434. Verb = "open"
  435. });
  436. }
  437. private void Exit_Pressed(object sender, EventArgs args)
  438. {
  439. _screen?.Exit();
  440. End();
  441. }
  442. private void Window_Close(object sender, DeleteEventArgs args)
  443. {
  444. _screen?.Exit();
  445. End();
  446. }
  447. private void StopEmulation_Pressed(object sender, EventArgs args)
  448. {
  449. // TODO: Write logic to kill running game
  450. _gameLoaded = false;
  451. }
  452. private void FullScreen_Toggled(object sender, EventArgs args)
  453. {
  454. if (_fullScreen.Active)
  455. {
  456. Fullscreen();
  457. }
  458. else
  459. {
  460. Unfullscreen();
  461. }
  462. }
  463. private void Settings_Pressed(object sender, EventArgs args)
  464. {
  465. SwitchSettings settingsWin = new SwitchSettings();
  466. settingsWin.Show();
  467. }
  468. private void Update_Pressed(object sender, EventArgs args)
  469. {
  470. string ryuUpdater = System.IO.Path.Combine(new VirtualFileSystem().GetBasePath(), "RyuUpdater.exe");
  471. try
  472. {
  473. Process.Start(new ProcessStartInfo(ryuUpdater, "/U") { UseShellExecute = true });
  474. }
  475. catch(System.ComponentModel.Win32Exception)
  476. {
  477. GtkDialog.CreateErrorDialog("Update canceled by user or updater was not found");
  478. }
  479. }
  480. private void About_Pressed(object sender, EventArgs args)
  481. {
  482. AboutWindow aboutWin = new AboutWindow();
  483. aboutWin.Show();
  484. }
  485. private void Fav_Toggled(object sender, EventArgs args)
  486. {
  487. ConfigurationState.Instance.Ui.GuiColumns.FavColumn.Value = _favToggle.Active;
  488. SaveConfig();
  489. UpdateColumns();
  490. }
  491. private void Icon_Toggled(object sender, EventArgs args)
  492. {
  493. ConfigurationState.Instance.Ui.GuiColumns.IconColumn.Value = _iconToggle.Active;
  494. SaveConfig();
  495. UpdateColumns();
  496. }
  497. private void Title_Toggled(object sender, EventArgs args)
  498. {
  499. ConfigurationState.Instance.Ui.GuiColumns.AppColumn.Value = _appToggle.Active;
  500. SaveConfig();
  501. UpdateColumns();
  502. }
  503. private void Developer_Toggled(object sender, EventArgs args)
  504. {
  505. ConfigurationState.Instance.Ui.GuiColumns.DevColumn.Value = _developerToggle.Active;
  506. SaveConfig();
  507. UpdateColumns();
  508. }
  509. private void Version_Toggled(object sender, EventArgs args)
  510. {
  511. ConfigurationState.Instance.Ui.GuiColumns.VersionColumn.Value = _versionToggle.Active;
  512. SaveConfig();
  513. UpdateColumns();
  514. }
  515. private void TimePlayed_Toggled(object sender, EventArgs args)
  516. {
  517. ConfigurationState.Instance.Ui.GuiColumns.TimePlayedColumn.Value = _timePlayedToggle.Active;
  518. SaveConfig();
  519. UpdateColumns();
  520. }
  521. private void LastPlayed_Toggled(object sender, EventArgs args)
  522. {
  523. ConfigurationState.Instance.Ui.GuiColumns.LastPlayedColumn.Value = _lastPlayedToggle.Active;
  524. SaveConfig();
  525. UpdateColumns();
  526. }
  527. private void FileExt_Toggled(object sender, EventArgs args)
  528. {
  529. ConfigurationState.Instance.Ui.GuiColumns.FileExtColumn.Value = _fileExtToggle.Active;
  530. SaveConfig();
  531. UpdateColumns();
  532. }
  533. private void FileSize_Toggled(object sender, EventArgs args)
  534. {
  535. ConfigurationState.Instance.Ui.GuiColumns.FileSizeColumn.Value = _fileSizeToggle.Active;
  536. SaveConfig();
  537. UpdateColumns();
  538. }
  539. private void Path_Toggled(object sender, EventArgs args)
  540. {
  541. ConfigurationState.Instance.Ui.GuiColumns.PathColumn.Value = _pathToggle.Active;
  542. SaveConfig();
  543. UpdateColumns();
  544. }
  545. private void RefreshList_Pressed(object sender, ButtonReleaseEventArgs args)
  546. {
  547. #pragma warning disable CS4014
  548. UpdateGameTable();
  549. #pragma warning restore CS4014
  550. }
  551. private static int TimePlayedSort(ITreeModel model, TreeIter a, TreeIter b)
  552. {
  553. string aValue = model.GetValue(a, 5).ToString();
  554. string bValue = model.GetValue(b, 5).ToString();
  555. if (aValue.Length > 4 && aValue.Substring(aValue.Length - 4) == "mins")
  556. {
  557. aValue = (float.Parse(aValue.Substring(0, aValue.Length - 5)) * 60).ToString();
  558. }
  559. else if (aValue.Length > 3 && aValue.Substring(aValue.Length - 3) == "hrs")
  560. {
  561. aValue = (float.Parse(aValue.Substring(0, aValue.Length - 4)) * 3600).ToString();
  562. }
  563. else if (aValue.Length > 4 && aValue.Substring(aValue.Length - 4) == "days")
  564. {
  565. aValue = (float.Parse(aValue.Substring(0, aValue.Length - 5)) * 86400).ToString();
  566. }
  567. else
  568. {
  569. aValue = aValue.Substring(0, aValue.Length - 1);
  570. }
  571. if (bValue.Length > 4 && bValue.Substring(bValue.Length - 4) == "mins")
  572. {
  573. bValue = (float.Parse(bValue.Substring(0, bValue.Length - 5)) * 60).ToString();
  574. }
  575. else if (bValue.Length > 3 && bValue.Substring(bValue.Length - 3) == "hrs")
  576. {
  577. bValue = (float.Parse(bValue.Substring(0, bValue.Length - 4)) * 3600).ToString();
  578. }
  579. else if (bValue.Length > 4 && bValue.Substring(bValue.Length - 4) == "days")
  580. {
  581. bValue = (float.Parse(bValue.Substring(0, bValue.Length - 5)) * 86400).ToString();
  582. }
  583. else
  584. {
  585. bValue = bValue.Substring(0, bValue.Length - 1);
  586. }
  587. if (float.Parse(aValue) > float.Parse(bValue))
  588. {
  589. return -1;
  590. }
  591. else if (float.Parse(bValue) > float.Parse(aValue))
  592. {
  593. return 1;
  594. }
  595. else
  596. {
  597. return 0;
  598. }
  599. }
  600. private static int LastPlayedSort(ITreeModel model, TreeIter a, TreeIter b)
  601. {
  602. string aValue = model.GetValue(a, 6).ToString();
  603. string bValue = model.GetValue(b, 6).ToString();
  604. if (aValue == "Never")
  605. {
  606. aValue = DateTime.UnixEpoch.ToString();
  607. }
  608. if (bValue == "Never")
  609. {
  610. bValue = DateTime.UnixEpoch.ToString();
  611. }
  612. return DateTime.Compare(DateTime.Parse(bValue), DateTime.Parse(aValue));
  613. }
  614. private static int FileSizeSort(ITreeModel model, TreeIter a, TreeIter b)
  615. {
  616. string aValue = model.GetValue(a, 8).ToString();
  617. string bValue = model.GetValue(b, 8).ToString();
  618. if (aValue.Substring(aValue.Length - 2) == "GB")
  619. {
  620. aValue = (float.Parse(aValue[0..^2]) * 1024).ToString();
  621. }
  622. else
  623. {
  624. aValue = aValue[0..^2];
  625. }
  626. if (bValue.Substring(bValue.Length - 2) == "GB")
  627. {
  628. bValue = (float.Parse(bValue[0..^2]) * 1024).ToString();
  629. }
  630. else
  631. {
  632. bValue = bValue[0..^2];
  633. }
  634. if (float.Parse(aValue) > float.Parse(bValue))
  635. {
  636. return -1;
  637. }
  638. else if (float.Parse(bValue) > float.Parse(aValue))
  639. {
  640. return 1;
  641. }
  642. else
  643. {
  644. return 0;
  645. }
  646. }
  647. public static void SaveConfig()
  648. {
  649. ConfigurationState.Instance.ToFileFormat().SaveConfig(System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Config.json"));
  650. }
  651. }
  652. }