SettingsWindow.cs 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571
  1. using Gtk;
  2. using Ryujinx.Audio;
  3. using Ryujinx.Configuration;
  4. using Ryujinx.Common.Configuration;
  5. using Ryujinx.Common.Configuration.Hid;
  6. using Ryujinx.Configuration.System;
  7. using Ryujinx.HLE.HOS.Services.Time.TimeZone;
  8. using Ryujinx.HLE.FileSystem;
  9. using System;
  10. using System.Collections.Generic;
  11. using System.Diagnostics;
  12. using System.IO;
  13. using System.Reflection;
  14. using System.Threading.Tasks;
  15. using GUI = Gtk.Builder.ObjectAttribute;
  16. namespace Ryujinx.Ui
  17. {
  18. public class SettingsWindow : Window
  19. {
  20. private readonly VirtualFileSystem _virtualFileSystem;
  21. private readonly ListStore _gameDirsBoxStore;
  22. private readonly ListStore _audioBackendStore;
  23. private readonly TimeZoneContentManager _timeZoneContentManager;
  24. private readonly HashSet<string> _validTzRegions;
  25. private long _systemTimeOffset;
  26. #pragma warning disable CS0649, IDE0044
  27. [GUI] CheckButton _errorLogToggle;
  28. [GUI] CheckButton _warningLogToggle;
  29. [GUI] CheckButton _infoLogToggle;
  30. [GUI] CheckButton _stubLogToggle;
  31. [GUI] CheckButton _debugLogToggle;
  32. [GUI] CheckButton _fileLogToggle;
  33. [GUI] CheckButton _guestLogToggle;
  34. [GUI] CheckButton _fsAccessLogToggle;
  35. [GUI] Adjustment _fsLogSpinAdjustment;
  36. [GUI] ComboBoxText _graphicsDebugLevel;
  37. [GUI] CheckButton _dockedModeToggle;
  38. [GUI] CheckButton _discordToggle;
  39. [GUI] CheckButton _vSyncToggle;
  40. [GUI] CheckButton _multiSchedToggle;
  41. [GUI] CheckButton _ptcToggle;
  42. [GUI] CheckButton _fsicToggle;
  43. [GUI] CheckButton _ignoreToggle;
  44. [GUI] CheckButton _directKeyboardAccess;
  45. [GUI] ComboBoxText _systemLanguageSelect;
  46. [GUI] ComboBoxText _systemRegionSelect;
  47. [GUI] Entry _systemTimeZoneEntry;
  48. [GUI] EntryCompletion _systemTimeZoneCompletion;
  49. [GUI] Box _audioBackendBox;
  50. [GUI] ComboBox _audioBackendSelect;
  51. [GUI] SpinButton _systemTimeYearSpin;
  52. [GUI] SpinButton _systemTimeMonthSpin;
  53. [GUI] SpinButton _systemTimeDaySpin;
  54. [GUI] SpinButton _systemTimeHourSpin;
  55. [GUI] SpinButton _systemTimeMinuteSpin;
  56. [GUI] Adjustment _systemTimeYearSpinAdjustment;
  57. [GUI] Adjustment _systemTimeMonthSpinAdjustment;
  58. [GUI] Adjustment _systemTimeDaySpinAdjustment;
  59. [GUI] Adjustment _systemTimeHourSpinAdjustment;
  60. [GUI] Adjustment _systemTimeMinuteSpinAdjustment;
  61. [GUI] CheckButton _custThemeToggle;
  62. [GUI] Entry _custThemePath;
  63. [GUI] ToggleButton _browseThemePath;
  64. [GUI] Label _custThemePathLabel;
  65. [GUI] TreeView _gameDirsBox;
  66. [GUI] Entry _addGameDirBox;
  67. [GUI] Entry _graphicsShadersDumpPath;
  68. [GUI] ComboBoxText _anisotropy;
  69. [GUI] ComboBoxText _resScaleCombo;
  70. [GUI] Entry _resScaleText;
  71. [GUI] ToggleButton _configureController1;
  72. [GUI] ToggleButton _configureController2;
  73. [GUI] ToggleButton _configureController3;
  74. [GUI] ToggleButton _configureController4;
  75. [GUI] ToggleButton _configureController5;
  76. [GUI] ToggleButton _configureController6;
  77. [GUI] ToggleButton _configureController7;
  78. [GUI] ToggleButton _configureController8;
  79. [GUI] ToggleButton _configureControllerH;
  80. #pragma warning restore CS0649, IDE0044
  81. public SettingsWindow(VirtualFileSystem virtualFileSystem, HLE.FileSystem.Content.ContentManager contentManager) : this(new Builder("Ryujinx.Ui.SettingsWindow.glade"), virtualFileSystem, contentManager) { }
  82. private SettingsWindow(Builder builder, VirtualFileSystem virtualFileSystem, HLE.FileSystem.Content.ContentManager contentManager) : base(builder.GetObject("_settingsWin").Handle)
  83. {
  84. builder.Autoconnect(this);
  85. this.Icon = new Gdk.Pixbuf(Assembly.GetExecutingAssembly(), "Ryujinx.Ui.assets.Icon.png");
  86. _virtualFileSystem = virtualFileSystem;
  87. _timeZoneContentManager = new TimeZoneContentManager();
  88. _timeZoneContentManager.InitializeInstance(virtualFileSystem, contentManager, LibHac.FsSystem.IntegrityCheckLevel.None);
  89. _validTzRegions = new HashSet<string>(_timeZoneContentManager.LocationNameCache.Length, StringComparer.Ordinal); // Zone regions are identifiers. Must match exactly.
  90. //Bind Events
  91. _configureController1.Pressed += (sender, args) => ConfigureController_Pressed(sender, args, PlayerIndex.Player1);
  92. _configureController2.Pressed += (sender, args) => ConfigureController_Pressed(sender, args, PlayerIndex.Player2);
  93. _configureController3.Pressed += (sender, args) => ConfigureController_Pressed(sender, args, PlayerIndex.Player3);
  94. _configureController4.Pressed += (sender, args) => ConfigureController_Pressed(sender, args, PlayerIndex.Player4);
  95. _configureController5.Pressed += (sender, args) => ConfigureController_Pressed(sender, args, PlayerIndex.Player5);
  96. _configureController6.Pressed += (sender, args) => ConfigureController_Pressed(sender, args, PlayerIndex.Player6);
  97. _configureController7.Pressed += (sender, args) => ConfigureController_Pressed(sender, args, PlayerIndex.Player7);
  98. _configureController8.Pressed += (sender, args) => ConfigureController_Pressed(sender, args, PlayerIndex.Player8);
  99. _configureControllerH.Pressed += (sender, args) => ConfigureController_Pressed(sender, args, PlayerIndex.Handheld);
  100. _systemTimeZoneEntry.FocusOutEvent += TimeZoneEntry_FocusOut;
  101. _resScaleCombo.Changed += (sender, args) => _resScaleText.Visible = _resScaleCombo.ActiveId == "-1";
  102. //Setup Currents
  103. if (ConfigurationState.Instance.Logger.EnableFileLog)
  104. {
  105. _fileLogToggle.Click();
  106. }
  107. if (ConfigurationState.Instance.Logger.EnableError)
  108. {
  109. _errorLogToggle.Click();
  110. }
  111. if (ConfigurationState.Instance.Logger.EnableWarn)
  112. {
  113. _warningLogToggle.Click();
  114. }
  115. if (ConfigurationState.Instance.Logger.EnableInfo)
  116. {
  117. _infoLogToggle.Click();
  118. }
  119. if (ConfigurationState.Instance.Logger.EnableStub)
  120. {
  121. _stubLogToggle.Click();
  122. }
  123. if (ConfigurationState.Instance.Logger.EnableDebug)
  124. {
  125. _debugLogToggle.Click();
  126. }
  127. if (ConfigurationState.Instance.Logger.EnableGuest)
  128. {
  129. _guestLogToggle.Click();
  130. }
  131. if (ConfigurationState.Instance.Logger.EnableFsAccessLog)
  132. {
  133. _fsAccessLogToggle.Click();
  134. }
  135. foreach (GraphicsDebugLevel level in Enum.GetValues(typeof(GraphicsDebugLevel)))
  136. {
  137. _graphicsDebugLevel.Append(level.ToString(), level.ToString());
  138. }
  139. _graphicsDebugLevel.SetActiveId(ConfigurationState.Instance.Logger.GraphicsDebugLevel.Value.ToString());
  140. if (ConfigurationState.Instance.System.EnableDockedMode)
  141. {
  142. _dockedModeToggle.Click();
  143. }
  144. if (ConfigurationState.Instance.EnableDiscordIntegration)
  145. {
  146. _discordToggle.Click();
  147. }
  148. if (ConfigurationState.Instance.Graphics.EnableVsync)
  149. {
  150. _vSyncToggle.Click();
  151. }
  152. if (ConfigurationState.Instance.System.EnableMulticoreScheduling)
  153. {
  154. _multiSchedToggle.Click();
  155. }
  156. if (ConfigurationState.Instance.System.EnablePtc)
  157. {
  158. _ptcToggle.Click();
  159. }
  160. if (ConfigurationState.Instance.System.EnableFsIntegrityChecks)
  161. {
  162. _fsicToggle.Click();
  163. }
  164. if (ConfigurationState.Instance.System.IgnoreMissingServices)
  165. {
  166. _ignoreToggle.Click();
  167. }
  168. if (ConfigurationState.Instance.Hid.EnableKeyboard)
  169. {
  170. _directKeyboardAccess.Click();
  171. }
  172. if (ConfigurationState.Instance.Ui.EnableCustomTheme)
  173. {
  174. _custThemeToggle.Click();
  175. }
  176. // Custom EntryCompletion Columns. If added to glade, need to override more signals
  177. ListStore tzList = new ListStore(typeof(string), typeof(string), typeof(string));
  178. _systemTimeZoneCompletion.Model = tzList;
  179. CellRendererText offsetCol = new CellRendererText();
  180. CellRendererText abbrevCol = new CellRendererText();
  181. _systemTimeZoneCompletion.PackStart(offsetCol, false);
  182. _systemTimeZoneCompletion.AddAttribute(offsetCol, "text", 0);
  183. _systemTimeZoneCompletion.TextColumn = 1; // Regions Column
  184. _systemTimeZoneCompletion.PackStart(abbrevCol, false);
  185. _systemTimeZoneCompletion.AddAttribute(abbrevCol, "text", 2);
  186. int maxLocationLength = 0;
  187. foreach (var (offset, location, abbr) in _timeZoneContentManager.ParseTzOffsets())
  188. {
  189. var hours = Math.DivRem(offset, 3600, out int seconds);
  190. var minutes = Math.Abs(seconds) / 60;
  191. var abbr2 = (abbr.StartsWith('+') || abbr.StartsWith('-')) ? string.Empty : abbr;
  192. tzList.AppendValues($"UTC{hours:+0#;-0#;+00}:{minutes:D2} ", location, abbr2);
  193. _validTzRegions.Add(location);
  194. maxLocationLength = Math.Max(maxLocationLength, location.Length);
  195. }
  196. _systemTimeZoneEntry.WidthChars = Math.Max(20, maxLocationLength + 1); // Ensure minimum Entry width
  197. _systemTimeZoneEntry.Text = _timeZoneContentManager.SanityCheckDeviceLocationName();
  198. _systemTimeZoneCompletion.MatchFunc = TimeZoneMatchFunc;
  199. _systemLanguageSelect.SetActiveId(ConfigurationState.Instance.System.Language.Value.ToString());
  200. _systemRegionSelect.SetActiveId(ConfigurationState.Instance.System.Region.Value.ToString());
  201. _resScaleCombo.SetActiveId(ConfigurationState.Instance.Graphics.ResScale.Value.ToString());
  202. _anisotropy.SetActiveId(ConfigurationState.Instance.Graphics.MaxAnisotropy.Value.ToString());
  203. _custThemePath.Buffer.Text = ConfigurationState.Instance.Ui.CustomThemePath;
  204. _resScaleText.Buffer.Text = ConfigurationState.Instance.Graphics.ResScaleCustom.Value.ToString();
  205. _resScaleText.Visible = _resScaleCombo.ActiveId == "-1";
  206. _graphicsShadersDumpPath.Buffer.Text = ConfigurationState.Instance.Graphics.ShadersDumpPath;
  207. _fsLogSpinAdjustment.Value = ConfigurationState.Instance.System.FsGlobalAccessLogMode;
  208. _systemTimeOffset = ConfigurationState.Instance.System.SystemTimeOffset;
  209. _gameDirsBox.AppendColumn("", new CellRendererText(), "text", 0);
  210. _gameDirsBoxStore = new ListStore(typeof(string));
  211. _gameDirsBox.Model = _gameDirsBoxStore;
  212. foreach (string gameDir in ConfigurationState.Instance.Ui.GameDirs.Value)
  213. {
  214. _gameDirsBoxStore.AppendValues(gameDir);
  215. }
  216. if (_custThemeToggle.Active == false)
  217. {
  218. _custThemePath.Sensitive = false;
  219. _custThemePathLabel.Sensitive = false;
  220. _browseThemePath.Sensitive = false;
  221. }
  222. //Setup system time spinners
  223. UpdateSystemTimeSpinners();
  224. _audioBackendStore = new ListStore(typeof(string), typeof(AudioBackend));
  225. TreeIter openAlIter = _audioBackendStore.AppendValues("OpenAL", AudioBackend.OpenAl);
  226. TreeIter soundIoIter = _audioBackendStore.AppendValues("SoundIO", AudioBackend.SoundIo);
  227. TreeIter dummyIter = _audioBackendStore.AppendValues("Dummy", AudioBackend.Dummy);
  228. _audioBackendSelect = ComboBox.NewWithModelAndEntry(_audioBackendStore);
  229. _audioBackendSelect.EntryTextColumn = 0;
  230. _audioBackendSelect.Entry.IsEditable = false;
  231. switch (ConfigurationState.Instance.System.AudioBackend.Value)
  232. {
  233. case AudioBackend.OpenAl:
  234. _audioBackendSelect.SetActiveIter(openAlIter);
  235. break;
  236. case AudioBackend.SoundIo:
  237. _audioBackendSelect.SetActiveIter(soundIoIter);
  238. break;
  239. case AudioBackend.Dummy:
  240. _audioBackendSelect.SetActiveIter(dummyIter);
  241. break;
  242. default:
  243. throw new ArgumentOutOfRangeException();
  244. }
  245. _audioBackendBox.Add(_audioBackendSelect);
  246. _audioBackendSelect.Show();
  247. bool openAlIsSupported = false;
  248. bool soundIoIsSupported = false;
  249. Task.Run(() =>
  250. {
  251. openAlIsSupported = OpenALAudioOut.IsSupported;
  252. soundIoIsSupported = SoundIoAudioOut.IsSupported;
  253. });
  254. // This function runs whenever the dropdown is opened
  255. _audioBackendSelect.SetCellDataFunc(_audioBackendSelect.Cells[0], (layout, cell, model, iter) =>
  256. {
  257. cell.Sensitive = ((AudioBackend)_audioBackendStore.GetValue(iter, 1)) switch
  258. {
  259. AudioBackend.OpenAl => openAlIsSupported,
  260. AudioBackend.SoundIo => soundIoIsSupported,
  261. AudioBackend.Dummy => true,
  262. _ => throw new ArgumentOutOfRangeException()
  263. };
  264. });
  265. }
  266. private void UpdateSystemTimeSpinners()
  267. {
  268. //Bind system time events
  269. _systemTimeYearSpin.ValueChanged -= SystemTimeSpin_ValueChanged;
  270. _systemTimeMonthSpin.ValueChanged -= SystemTimeSpin_ValueChanged;
  271. _systemTimeDaySpin.ValueChanged -= SystemTimeSpin_ValueChanged;
  272. _systemTimeHourSpin.ValueChanged -= SystemTimeSpin_ValueChanged;
  273. _systemTimeMinuteSpin.ValueChanged -= SystemTimeSpin_ValueChanged;
  274. //Apply actual system time + SystemTimeOffset to system time spin buttons
  275. DateTime systemTime = DateTime.Now.AddSeconds(_systemTimeOffset);
  276. _systemTimeYearSpinAdjustment.Value = systemTime.Year;
  277. _systemTimeMonthSpinAdjustment.Value = systemTime.Month;
  278. _systemTimeDaySpinAdjustment.Value = systemTime.Day;
  279. _systemTimeHourSpinAdjustment.Value = systemTime.Hour;
  280. _systemTimeMinuteSpinAdjustment.Value = systemTime.Minute;
  281. //Format spin buttons text to include leading zeros
  282. _systemTimeYearSpin.Text = systemTime.Year.ToString("0000");
  283. _systemTimeMonthSpin.Text = systemTime.Month.ToString("00");
  284. _systemTimeDaySpin.Text = systemTime.Day.ToString("00");
  285. _systemTimeHourSpin.Text = systemTime.Hour.ToString("00");
  286. _systemTimeMinuteSpin.Text = systemTime.Minute.ToString("00");
  287. //Bind system time events
  288. _systemTimeYearSpin.ValueChanged += SystemTimeSpin_ValueChanged;
  289. _systemTimeMonthSpin.ValueChanged += SystemTimeSpin_ValueChanged;
  290. _systemTimeDaySpin.ValueChanged += SystemTimeSpin_ValueChanged;
  291. _systemTimeHourSpin.ValueChanged += SystemTimeSpin_ValueChanged;
  292. _systemTimeMinuteSpin.ValueChanged += SystemTimeSpin_ValueChanged;
  293. }
  294. //Events
  295. private void TimeZoneEntry_FocusOut(Object sender, FocusOutEventArgs e)
  296. {
  297. if (!_validTzRegions.Contains(_systemTimeZoneEntry.Text))
  298. {
  299. _systemTimeZoneEntry.Text = _timeZoneContentManager.SanityCheckDeviceLocationName();
  300. }
  301. }
  302. private bool TimeZoneMatchFunc(EntryCompletion compl, string key, TreeIter iter)
  303. {
  304. key = key.Trim().Replace(' ', '_');
  305. return ((string)compl.Model.GetValue(iter, 1)).Contains(key, StringComparison.OrdinalIgnoreCase) || // region
  306. ((string)compl.Model.GetValue(iter, 2)).StartsWith(key, StringComparison.OrdinalIgnoreCase) || // abbr
  307. ((string)compl.Model.GetValue(iter, 0)).Substring(3).StartsWith(key); // offset
  308. }
  309. private void SystemTimeSpin_ValueChanged(Object sender, EventArgs e)
  310. {
  311. int year = _systemTimeYearSpin.ValueAsInt;
  312. int month = _systemTimeMonthSpin.ValueAsInt;
  313. int day = _systemTimeDaySpin.ValueAsInt;
  314. int hour = _systemTimeHourSpin.ValueAsInt;
  315. int minute = _systemTimeMinuteSpin.ValueAsInt;
  316. if (!DateTime.TryParse(year + "-" + month + "-" + day + " " + hour + ":" + minute, out DateTime newTime))
  317. {
  318. UpdateSystemTimeSpinners();
  319. return;
  320. }
  321. newTime = newTime.AddSeconds(DateTime.Now.Second).AddMilliseconds(DateTime.Now.Millisecond);
  322. long systemTimeOffset = (long)Math.Ceiling((newTime - DateTime.Now).TotalMinutes) * 60L;
  323. if (_systemTimeOffset != systemTimeOffset)
  324. {
  325. _systemTimeOffset = systemTimeOffset;
  326. UpdateSystemTimeSpinners();
  327. }
  328. }
  329. private void AddDir_Pressed(object sender, EventArgs args)
  330. {
  331. if (Directory.Exists(_addGameDirBox.Buffer.Text))
  332. {
  333. _gameDirsBoxStore.AppendValues(_addGameDirBox.Buffer.Text);
  334. }
  335. else
  336. {
  337. FileChooserDialog fileChooser = new FileChooserDialog("Choose the game directory to add to the list", this, FileChooserAction.SelectFolder, "Cancel", ResponseType.Cancel, "Add", ResponseType.Accept)
  338. {
  339. SelectMultiple = true
  340. };
  341. if (fileChooser.Run() == (int)ResponseType.Accept)
  342. {
  343. foreach (string directory in fileChooser.Filenames)
  344. {
  345. bool directoryAdded = false;
  346. if (_gameDirsBoxStore.GetIterFirst(out TreeIter treeIter))
  347. {
  348. do
  349. {
  350. if (directory.Equals((string)_gameDirsBoxStore.GetValue(treeIter, 0)))
  351. {
  352. directoryAdded = true;
  353. break;
  354. }
  355. } while(_gameDirsBoxStore.IterNext(ref treeIter));
  356. }
  357. if (!directoryAdded)
  358. {
  359. _gameDirsBoxStore.AppendValues(directory);
  360. }
  361. }
  362. }
  363. fileChooser.Dispose();
  364. }
  365. _addGameDirBox.Buffer.Text = "";
  366. ((ToggleButton)sender).SetStateFlags(0, true);
  367. }
  368. private void RemoveDir_Pressed(object sender, EventArgs args)
  369. {
  370. TreeSelection selection = _gameDirsBox.Selection;
  371. if (selection.GetSelected(out TreeIter treeIter))
  372. {
  373. _gameDirsBoxStore.Remove(ref treeIter);
  374. }
  375. ((ToggleButton)sender).SetStateFlags(0, true);
  376. }
  377. private void CustThemeToggle_Activated(object sender, EventArgs args)
  378. {
  379. _custThemePath.Sensitive = _custThemeToggle.Active;
  380. _custThemePathLabel.Sensitive = _custThemeToggle.Active;
  381. _browseThemePath.Sensitive = _custThemeToggle.Active;
  382. }
  383. private void BrowseThemeDir_Pressed(object sender, EventArgs args)
  384. {
  385. FileChooserDialog fileChooser = new FileChooserDialog("Choose the theme to load", this, FileChooserAction.Open, "Cancel", ResponseType.Cancel, "Select", ResponseType.Accept);
  386. fileChooser.Filter = new FileFilter();
  387. fileChooser.Filter.AddPattern("*.css");
  388. if (fileChooser.Run() == (int)ResponseType.Accept)
  389. {
  390. _custThemePath.Buffer.Text = fileChooser.Filename;
  391. }
  392. fileChooser.Dispose();
  393. _browseThemePath.SetStateFlags(0, true);
  394. }
  395. private void OpenLogsFolder_Pressed(object sender, EventArgs args)
  396. {
  397. string logPath = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Logs");
  398. DirectoryInfo directory = new DirectoryInfo(logPath);
  399. directory.Create();
  400. Process.Start(new ProcessStartInfo()
  401. {
  402. FileName = logPath,
  403. UseShellExecute = true,
  404. Verb = "open"
  405. });
  406. }
  407. private void ConfigureController_Pressed(object sender, EventArgs args, PlayerIndex playerIndex)
  408. {
  409. ((ToggleButton)sender).SetStateFlags(0, true);
  410. ControllerWindow controllerWin = new ControllerWindow(playerIndex, _virtualFileSystem);
  411. controllerWin.Show();
  412. }
  413. private void SaveToggle_Activated(object sender, EventArgs args)
  414. {
  415. List<string> gameDirs = new List<string>();
  416. _gameDirsBoxStore.GetIterFirst(out TreeIter treeIter);
  417. for (int i = 0; i < _gameDirsBoxStore.IterNChildren(); i++)
  418. {
  419. gameDirs.Add((string)_gameDirsBoxStore.GetValue(treeIter, 0));
  420. _gameDirsBoxStore.IterNext(ref treeIter);
  421. }
  422. if (!float.TryParse(_resScaleText.Buffer.Text, out float resScaleCustom) || resScaleCustom <= 0.0f)
  423. {
  424. resScaleCustom = 1.0f;
  425. }
  426. if (_validTzRegions.Contains(_systemTimeZoneEntry.Text))
  427. {
  428. ConfigurationState.Instance.System.TimeZone.Value = _systemTimeZoneEntry.Text;
  429. }
  430. ConfigurationState.Instance.Logger.EnableError.Value = _errorLogToggle.Active;
  431. ConfigurationState.Instance.Logger.EnableWarn.Value = _warningLogToggle.Active;
  432. ConfigurationState.Instance.Logger.EnableInfo.Value = _infoLogToggle.Active;
  433. ConfigurationState.Instance.Logger.EnableStub.Value = _stubLogToggle.Active;
  434. ConfigurationState.Instance.Logger.EnableDebug.Value = _debugLogToggle.Active;
  435. ConfigurationState.Instance.Logger.EnableGuest.Value = _guestLogToggle.Active;
  436. ConfigurationState.Instance.Logger.EnableFsAccessLog.Value = _fsAccessLogToggle.Active;
  437. ConfigurationState.Instance.Logger.EnableFileLog.Value = _fileLogToggle.Active;
  438. ConfigurationState.Instance.Logger.GraphicsDebugLevel.Value = Enum.Parse<GraphicsDebugLevel>(_graphicsDebugLevel.ActiveId);
  439. ConfigurationState.Instance.System.EnableDockedMode.Value = _dockedModeToggle.Active;
  440. ConfigurationState.Instance.EnableDiscordIntegration.Value = _discordToggle.Active;
  441. ConfigurationState.Instance.Graphics.EnableVsync.Value = _vSyncToggle.Active;
  442. ConfigurationState.Instance.System.EnableMulticoreScheduling.Value = _multiSchedToggle.Active;
  443. ConfigurationState.Instance.System.EnablePtc.Value = _ptcToggle.Active;
  444. ConfigurationState.Instance.System.EnableFsIntegrityChecks.Value = _fsicToggle.Active;
  445. ConfigurationState.Instance.System.IgnoreMissingServices.Value = _ignoreToggle.Active;
  446. ConfigurationState.Instance.Hid.EnableKeyboard.Value = _directKeyboardAccess.Active;
  447. ConfigurationState.Instance.Ui.EnableCustomTheme.Value = _custThemeToggle.Active;
  448. ConfigurationState.Instance.System.Language.Value = Enum.Parse<Language>(_systemLanguageSelect.ActiveId);
  449. ConfigurationState.Instance.System.Region.Value = Enum.Parse<Configuration.System.Region>(_systemRegionSelect.ActiveId);
  450. ConfigurationState.Instance.System.SystemTimeOffset.Value = _systemTimeOffset;
  451. ConfigurationState.Instance.Ui.CustomThemePath.Value = _custThemePath.Buffer.Text;
  452. ConfigurationState.Instance.Graphics.ShadersDumpPath.Value = _graphicsShadersDumpPath.Buffer.Text;
  453. ConfigurationState.Instance.Ui.GameDirs.Value = gameDirs;
  454. ConfigurationState.Instance.System.FsGlobalAccessLogMode.Value = (int)_fsLogSpinAdjustment.Value;
  455. ConfigurationState.Instance.Graphics.MaxAnisotropy.Value = float.Parse(_anisotropy.ActiveId);
  456. ConfigurationState.Instance.Graphics.ResScale.Value = int.Parse(_resScaleCombo.ActiveId);
  457. ConfigurationState.Instance.Graphics.ResScaleCustom.Value = resScaleCustom;
  458. if (_audioBackendSelect.GetActiveIter(out TreeIter activeIter))
  459. {
  460. ConfigurationState.Instance.System.AudioBackend.Value = (AudioBackend)_audioBackendStore.GetValue(activeIter, 1);
  461. }
  462. MainWindow.SaveConfig();
  463. MainWindow.UpdateGraphicsConfig();
  464. MainWindow.ApplyTheme();
  465. Dispose();
  466. }
  467. private void CloseToggle_Activated(object sender, EventArgs args)
  468. {
  469. Dispose();
  470. }
  471. }
  472. }