MainWindow.cs 29 KB

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