SettingsWindow.cs 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465
  1. using Gtk;
  2. using Ryujinx.Audio;
  3. using Ryujinx.Configuration;
  4. using Ryujinx.Common.Configuration.Hid;
  5. using Ryujinx.Configuration.System;
  6. using Ryujinx.HLE.HOS.Services.Time.TimeZone;
  7. using Ryujinx.HLE.FileSystem;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Diagnostics;
  11. using System.IO;
  12. using System.Linq;
  13. using System.Reflection;
  14. using GUI = Gtk.Builder.ObjectAttribute;
  15. namespace Ryujinx.Ui
  16. {
  17. public class SettingsWindow : Window
  18. {
  19. private static ListStore _gameDirsBoxStore;
  20. private static VirtualFileSystem _virtualFileSystem;
  21. private long _systemTimeOffset;
  22. #pragma warning disable CS0649, IDE0044
  23. [GUI] CheckButton _errorLogToggle;
  24. [GUI] CheckButton _warningLogToggle;
  25. [GUI] CheckButton _infoLogToggle;
  26. [GUI] CheckButton _stubLogToggle;
  27. [GUI] CheckButton _debugLogToggle;
  28. [GUI] CheckButton _fileLogToggle;
  29. [GUI] CheckButton _guestLogToggle;
  30. [GUI] CheckButton _fsAccessLogToggle;
  31. [GUI] Adjustment _fsLogSpinAdjustment;
  32. [GUI] CheckButton _dockedModeToggle;
  33. [GUI] CheckButton _discordToggle;
  34. [GUI] CheckButton _vSyncToggle;
  35. [GUI] CheckButton _multiSchedToggle;
  36. [GUI] CheckButton _ptcToggle;
  37. [GUI] CheckButton _fsicToggle;
  38. [GUI] CheckButton _ignoreToggle;
  39. [GUI] CheckButton _directKeyboardAccess;
  40. [GUI] ComboBoxText _systemLanguageSelect;
  41. [GUI] ComboBoxText _systemRegionSelect;
  42. [GUI] ComboBoxText _systemTimeZoneSelect;
  43. [GUI] ComboBoxText _audioBackendSelect;
  44. [GUI] SpinButton _systemTimeYearSpin;
  45. [GUI] SpinButton _systemTimeMonthSpin;
  46. [GUI] SpinButton _systemTimeDaySpin;
  47. [GUI] SpinButton _systemTimeHourSpin;
  48. [GUI] SpinButton _systemTimeMinuteSpin;
  49. [GUI] Adjustment _systemTimeYearSpinAdjustment;
  50. [GUI] Adjustment _systemTimeMonthSpinAdjustment;
  51. [GUI] Adjustment _systemTimeDaySpinAdjustment;
  52. [GUI] Adjustment _systemTimeHourSpinAdjustment;
  53. [GUI] Adjustment _systemTimeMinuteSpinAdjustment;
  54. [GUI] CheckButton _custThemeToggle;
  55. [GUI] Entry _custThemePath;
  56. [GUI] ToggleButton _browseThemePath;
  57. [GUI] Label _custThemePathLabel;
  58. [GUI] TreeView _gameDirsBox;
  59. [GUI] Entry _addGameDirBox;
  60. [GUI] Entry _graphicsShadersDumpPath;
  61. [GUI] ComboBoxText _anisotropy;
  62. [GUI] ComboBoxText _resScaleCombo;
  63. [GUI] Entry _resScaleText;
  64. [GUI] ToggleButton _configureController1;
  65. [GUI] ToggleButton _configureController2;
  66. [GUI] ToggleButton _configureController3;
  67. [GUI] ToggleButton _configureController4;
  68. [GUI] ToggleButton _configureController5;
  69. [GUI] ToggleButton _configureController6;
  70. [GUI] ToggleButton _configureController7;
  71. [GUI] ToggleButton _configureController8;
  72. [GUI] ToggleButton _configureControllerH;
  73. #pragma warning restore CS0649, IDE0044
  74. public SettingsWindow(VirtualFileSystem virtualFileSystem, HLE.FileSystem.Content.ContentManager contentManager) : this(new Builder("Ryujinx.Ui.SettingsWindow.glade"), virtualFileSystem, contentManager) { }
  75. private SettingsWindow(Builder builder, VirtualFileSystem virtualFileSystem, HLE.FileSystem.Content.ContentManager contentManager) : base(builder.GetObject("_settingsWin").Handle)
  76. {
  77. builder.Autoconnect(this);
  78. this.Icon = new Gdk.Pixbuf(Assembly.GetExecutingAssembly(), "Ryujinx.Ui.assets.Icon.png");
  79. _virtualFileSystem = virtualFileSystem;
  80. //Bind Events
  81. _configureController1.Pressed += (sender, args) => ConfigureController_Pressed(sender, args, PlayerIndex.Player1);
  82. _configureController2.Pressed += (sender, args) => ConfigureController_Pressed(sender, args, PlayerIndex.Player2);
  83. _configureController3.Pressed += (sender, args) => ConfigureController_Pressed(sender, args, PlayerIndex.Player3);
  84. _configureController4.Pressed += (sender, args) => ConfigureController_Pressed(sender, args, PlayerIndex.Player4);
  85. _configureController5.Pressed += (sender, args) => ConfigureController_Pressed(sender, args, PlayerIndex.Player5);
  86. _configureController6.Pressed += (sender, args) => ConfigureController_Pressed(sender, args, PlayerIndex.Player6);
  87. _configureController7.Pressed += (sender, args) => ConfigureController_Pressed(sender, args, PlayerIndex.Player7);
  88. _configureController8.Pressed += (sender, args) => ConfigureController_Pressed(sender, args, PlayerIndex.Player8);
  89. _configureControllerH.Pressed += (sender, args) => ConfigureController_Pressed(sender, args, PlayerIndex.Handheld);
  90. _resScaleCombo.Changed += (sender, args) => _resScaleText.Visible = _resScaleCombo.ActiveId == "-1";
  91. //Setup Currents
  92. if (ConfigurationState.Instance.Logger.EnableFileLog)
  93. {
  94. _fileLogToggle.Click();
  95. }
  96. if (ConfigurationState.Instance.Logger.EnableError)
  97. {
  98. _errorLogToggle.Click();
  99. }
  100. if (ConfigurationState.Instance.Logger.EnableWarn)
  101. {
  102. _warningLogToggle.Click();
  103. }
  104. if (ConfigurationState.Instance.Logger.EnableInfo)
  105. {
  106. _infoLogToggle.Click();
  107. }
  108. if (ConfigurationState.Instance.Logger.EnableStub)
  109. {
  110. _stubLogToggle.Click();
  111. }
  112. if (ConfigurationState.Instance.Logger.EnableDebug)
  113. {
  114. _debugLogToggle.Click();
  115. }
  116. if (ConfigurationState.Instance.Logger.EnableGuest)
  117. {
  118. _guestLogToggle.Click();
  119. }
  120. if (ConfigurationState.Instance.Logger.EnableFsAccessLog)
  121. {
  122. _fsAccessLogToggle.Click();
  123. }
  124. if (ConfigurationState.Instance.System.EnableDockedMode)
  125. {
  126. _dockedModeToggle.Click();
  127. }
  128. if (ConfigurationState.Instance.EnableDiscordIntegration)
  129. {
  130. _discordToggle.Click();
  131. }
  132. if (ConfigurationState.Instance.Graphics.EnableVsync)
  133. {
  134. _vSyncToggle.Click();
  135. }
  136. if (ConfigurationState.Instance.System.EnableMulticoreScheduling)
  137. {
  138. _multiSchedToggle.Click();
  139. }
  140. if (ConfigurationState.Instance.System.EnablePtc)
  141. {
  142. _ptcToggle.Click();
  143. }
  144. if (ConfigurationState.Instance.System.EnableFsIntegrityChecks)
  145. {
  146. _fsicToggle.Click();
  147. }
  148. if (ConfigurationState.Instance.System.IgnoreMissingServices)
  149. {
  150. _ignoreToggle.Click();
  151. }
  152. if (ConfigurationState.Instance.Hid.EnableKeyboard)
  153. {
  154. _directKeyboardAccess.Click();
  155. }
  156. if (ConfigurationState.Instance.Ui.EnableCustomTheme)
  157. {
  158. _custThemeToggle.Click();
  159. }
  160. TimeZoneContentManager timeZoneContentManager = new TimeZoneContentManager();
  161. timeZoneContentManager.InitializeInstance(virtualFileSystem, contentManager, LibHac.FsSystem.IntegrityCheckLevel.None);
  162. List<string> locationNames = timeZoneContentManager.LocationNameCache.ToList();
  163. locationNames.Sort();
  164. foreach (string locationName in locationNames)
  165. {
  166. _systemTimeZoneSelect.Append(locationName, locationName);
  167. }
  168. _audioBackendSelect.Append(AudioBackend.Dummy.ToString(), AudioBackend.Dummy.ToString());
  169. if (SoundIoAudioOut.IsSupported)
  170. _audioBackendSelect.Append(AudioBackend.SoundIo.ToString(), "SoundIO");
  171. if (OpenALAudioOut.IsSupported)
  172. _audioBackendSelect.Append(AudioBackend.OpenAl.ToString(), "OpenAL");
  173. _systemLanguageSelect.SetActiveId(ConfigurationState.Instance.System.Language.Value.ToString());
  174. _systemRegionSelect.SetActiveId(ConfigurationState.Instance.System.Region.Value.ToString());
  175. _audioBackendSelect.SetActiveId(ConfigurationState.Instance.System.AudioBackend.Value.ToString());
  176. _systemTimeZoneSelect.SetActiveId(timeZoneContentManager.SanityCheckDeviceLocationName());
  177. _resScaleCombo.SetActiveId(ConfigurationState.Instance.Graphics.ResScale.Value.ToString());
  178. _anisotropy.SetActiveId(ConfigurationState.Instance.Graphics.MaxAnisotropy.Value.ToString());
  179. _custThemePath.Buffer.Text = ConfigurationState.Instance.Ui.CustomThemePath;
  180. _resScaleText.Buffer.Text = ConfigurationState.Instance.Graphics.ResScaleCustom.Value.ToString();
  181. _resScaleText.Visible = _resScaleCombo.ActiveId == "-1";
  182. _graphicsShadersDumpPath.Buffer.Text = ConfigurationState.Instance.Graphics.ShadersDumpPath;
  183. _fsLogSpinAdjustment.Value = ConfigurationState.Instance.System.FsGlobalAccessLogMode;
  184. _systemTimeOffset = ConfigurationState.Instance.System.SystemTimeOffset;
  185. _gameDirsBox.AppendColumn("", new CellRendererText(), "text", 0);
  186. _gameDirsBoxStore = new ListStore(typeof(string));
  187. _gameDirsBox.Model = _gameDirsBoxStore;
  188. foreach (string gameDir in ConfigurationState.Instance.Ui.GameDirs.Value)
  189. {
  190. _gameDirsBoxStore.AppendValues(gameDir);
  191. }
  192. if (_custThemeToggle.Active == false)
  193. {
  194. _custThemePath.Sensitive = false;
  195. _custThemePathLabel.Sensitive = false;
  196. _browseThemePath.Sensitive = false;
  197. }
  198. //Setup system time spinners
  199. UpdateSystemTimeSpinners();
  200. }
  201. private void UpdateSystemTimeSpinners()
  202. {
  203. //Bind system time events
  204. _systemTimeYearSpin.ValueChanged -= SystemTimeSpin_ValueChanged;
  205. _systemTimeMonthSpin.ValueChanged -= SystemTimeSpin_ValueChanged;
  206. _systemTimeDaySpin.ValueChanged -= SystemTimeSpin_ValueChanged;
  207. _systemTimeHourSpin.ValueChanged -= SystemTimeSpin_ValueChanged;
  208. _systemTimeMinuteSpin.ValueChanged -= SystemTimeSpin_ValueChanged;
  209. //Apply actual system time + SystemTimeOffset to system time spin buttons
  210. DateTime systemTime = DateTime.Now.AddSeconds(_systemTimeOffset);
  211. _systemTimeYearSpinAdjustment.Value = systemTime.Year;
  212. _systemTimeMonthSpinAdjustment.Value = systemTime.Month;
  213. _systemTimeDaySpinAdjustment.Value = systemTime.Day;
  214. _systemTimeHourSpinAdjustment.Value = systemTime.Hour;
  215. _systemTimeMinuteSpinAdjustment.Value = systemTime.Minute;
  216. //Format spin buttons text to include leading zeros
  217. _systemTimeYearSpin.Text = systemTime.Year.ToString("0000");
  218. _systemTimeMonthSpin.Text = systemTime.Month.ToString("00");
  219. _systemTimeDaySpin.Text = systemTime.Day.ToString("00");
  220. _systemTimeHourSpin.Text = systemTime.Hour.ToString("00");
  221. _systemTimeMinuteSpin.Text = systemTime.Minute.ToString("00");
  222. //Bind system time events
  223. _systemTimeYearSpin.ValueChanged += SystemTimeSpin_ValueChanged;
  224. _systemTimeMonthSpin.ValueChanged += SystemTimeSpin_ValueChanged;
  225. _systemTimeDaySpin.ValueChanged += SystemTimeSpin_ValueChanged;
  226. _systemTimeHourSpin.ValueChanged += SystemTimeSpin_ValueChanged;
  227. _systemTimeMinuteSpin.ValueChanged += SystemTimeSpin_ValueChanged;
  228. }
  229. //Events
  230. private void SystemTimeSpin_ValueChanged(Object sender, EventArgs e)
  231. {
  232. int year = _systemTimeYearSpin.ValueAsInt;
  233. int month = _systemTimeMonthSpin.ValueAsInt;
  234. int day = _systemTimeDaySpin.ValueAsInt;
  235. int hour = _systemTimeHourSpin.ValueAsInt;
  236. int minute = _systemTimeMinuteSpin.ValueAsInt;
  237. if (!DateTime.TryParse(year + "-" + month + "-" + day + " " + hour + ":" + minute, out DateTime newTime))
  238. {
  239. UpdateSystemTimeSpinners();
  240. return;
  241. }
  242. newTime = newTime.AddSeconds(DateTime.Now.Second).AddMilliseconds(DateTime.Now.Millisecond);
  243. long systemTimeOffset = (long)Math.Ceiling((newTime - DateTime.Now).TotalMinutes) * 60L;
  244. if (_systemTimeOffset != systemTimeOffset)
  245. {
  246. _systemTimeOffset = systemTimeOffset;
  247. UpdateSystemTimeSpinners();
  248. }
  249. }
  250. private void AddDir_Pressed(object sender, EventArgs args)
  251. {
  252. if (Directory.Exists(_addGameDirBox.Buffer.Text))
  253. {
  254. _gameDirsBoxStore.AppendValues(_addGameDirBox.Buffer.Text);
  255. }
  256. else
  257. {
  258. FileChooserDialog fileChooser = new FileChooserDialog("Choose the game directory to add to the list", this, FileChooserAction.SelectFolder, "Cancel", ResponseType.Cancel, "Add", ResponseType.Accept)
  259. {
  260. SelectMultiple = true
  261. };
  262. if (fileChooser.Run() == (int)ResponseType.Accept)
  263. {
  264. foreach (string directory in fileChooser.Filenames)
  265. {
  266. bool directoryAdded = false;
  267. if (_gameDirsBoxStore.GetIterFirst(out TreeIter treeIter))
  268. {
  269. do
  270. {
  271. if (directory.Equals((string)_gameDirsBoxStore.GetValue(treeIter, 0)))
  272. {
  273. directoryAdded = true;
  274. break;
  275. }
  276. } while(_gameDirsBoxStore.IterNext(ref treeIter));
  277. }
  278. if (!directoryAdded)
  279. {
  280. _gameDirsBoxStore.AppendValues(directory);
  281. }
  282. }
  283. }
  284. fileChooser.Dispose();
  285. }
  286. _addGameDirBox.Buffer.Text = "";
  287. ((ToggleButton)sender).SetStateFlags(0, true);
  288. }
  289. private void RemoveDir_Pressed(object sender, EventArgs args)
  290. {
  291. TreeSelection selection = _gameDirsBox.Selection;
  292. if (selection.GetSelected(out TreeIter treeIter))
  293. {
  294. _gameDirsBoxStore.Remove(ref treeIter);
  295. }
  296. ((ToggleButton)sender).SetStateFlags(0, true);
  297. }
  298. private void CustThemeToggle_Activated(object sender, EventArgs args)
  299. {
  300. _custThemePath.Sensitive = _custThemeToggle.Active;
  301. _custThemePathLabel.Sensitive = _custThemeToggle.Active;
  302. _browseThemePath.Sensitive = _custThemeToggle.Active;
  303. }
  304. private void BrowseThemeDir_Pressed(object sender, EventArgs args)
  305. {
  306. FileChooserDialog fileChooser = new FileChooserDialog("Choose the theme to load", this, FileChooserAction.Open, "Cancel", ResponseType.Cancel, "Select", ResponseType.Accept);
  307. fileChooser.Filter = new FileFilter();
  308. fileChooser.Filter.AddPattern("*.css");
  309. if (fileChooser.Run() == (int)ResponseType.Accept)
  310. {
  311. _custThemePath.Buffer.Text = fileChooser.Filename;
  312. }
  313. fileChooser.Dispose();
  314. _browseThemePath.SetStateFlags(0, true);
  315. }
  316. private void OpenLogsFolder_Pressed(object sender, EventArgs args)
  317. {
  318. string logPath = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Logs");
  319. DirectoryInfo directory = new DirectoryInfo(logPath);
  320. directory.Create();
  321. Process.Start(new ProcessStartInfo()
  322. {
  323. FileName = logPath,
  324. UseShellExecute = true,
  325. Verb = "open"
  326. });
  327. }
  328. private void ConfigureController_Pressed(object sender, EventArgs args, PlayerIndex playerIndex)
  329. {
  330. ((ToggleButton)sender).SetStateFlags(0, true);
  331. ControllerWindow controllerWin = new ControllerWindow(playerIndex, _virtualFileSystem);
  332. controllerWin.Show();
  333. }
  334. private void SaveToggle_Activated(object sender, EventArgs args)
  335. {
  336. List<string> gameDirs = new List<string>();
  337. _gameDirsBoxStore.GetIterFirst(out TreeIter treeIter);
  338. for (int i = 0; i < _gameDirsBoxStore.IterNChildren(); i++)
  339. {
  340. gameDirs.Add((string)_gameDirsBoxStore.GetValue(treeIter, 0));
  341. _gameDirsBoxStore.IterNext(ref treeIter);
  342. }
  343. float resScaleCustom;
  344. if (!float.TryParse(_resScaleText.Buffer.Text, out resScaleCustom) || resScaleCustom <= 0.0f)
  345. {
  346. resScaleCustom = 1.0f;
  347. }
  348. ConfigurationState.Instance.Logger.EnableError.Value = _errorLogToggle.Active;
  349. ConfigurationState.Instance.Logger.EnableWarn.Value = _warningLogToggle.Active;
  350. ConfigurationState.Instance.Logger.EnableInfo.Value = _infoLogToggle.Active;
  351. ConfigurationState.Instance.Logger.EnableStub.Value = _stubLogToggle.Active;
  352. ConfigurationState.Instance.Logger.EnableDebug.Value = _debugLogToggle.Active;
  353. ConfigurationState.Instance.Logger.EnableGuest.Value = _guestLogToggle.Active;
  354. ConfigurationState.Instance.Logger.EnableFsAccessLog.Value = _fsAccessLogToggle.Active;
  355. ConfigurationState.Instance.Logger.EnableFileLog.Value = _fileLogToggle.Active;
  356. ConfigurationState.Instance.System.EnableDockedMode.Value = _dockedModeToggle.Active;
  357. ConfigurationState.Instance.EnableDiscordIntegration.Value = _discordToggle.Active;
  358. ConfigurationState.Instance.Graphics.EnableVsync.Value = _vSyncToggle.Active;
  359. ConfigurationState.Instance.System.EnableMulticoreScheduling.Value = _multiSchedToggle.Active;
  360. ConfigurationState.Instance.System.EnablePtc.Value = _ptcToggle.Active;
  361. ConfigurationState.Instance.System.EnableFsIntegrityChecks.Value = _fsicToggle.Active;
  362. ConfigurationState.Instance.System.IgnoreMissingServices.Value = _ignoreToggle.Active;
  363. ConfigurationState.Instance.Hid.EnableKeyboard.Value = _directKeyboardAccess.Active;
  364. ConfigurationState.Instance.Ui.EnableCustomTheme.Value = _custThemeToggle.Active;
  365. ConfigurationState.Instance.System.Language.Value = Enum.Parse<Language>(_systemLanguageSelect.ActiveId);
  366. ConfigurationState.Instance.System.Region.Value = Enum.Parse<Configuration.System.Region>(_systemRegionSelect.ActiveId);
  367. ConfigurationState.Instance.System.AudioBackend.Value = Enum.Parse<AudioBackend>(_audioBackendSelect.ActiveId);
  368. ConfigurationState.Instance.System.TimeZone.Value = _systemTimeZoneSelect.ActiveId;
  369. ConfigurationState.Instance.System.SystemTimeOffset.Value = _systemTimeOffset;
  370. ConfigurationState.Instance.Ui.CustomThemePath.Value = _custThemePath.Buffer.Text;
  371. ConfigurationState.Instance.Graphics.ShadersDumpPath.Value = _graphicsShadersDumpPath.Buffer.Text;
  372. ConfigurationState.Instance.Ui.GameDirs.Value = gameDirs;
  373. ConfigurationState.Instance.System.FsGlobalAccessLogMode.Value = (int)_fsLogSpinAdjustment.Value;
  374. ConfigurationState.Instance.Graphics.MaxAnisotropy.Value = float.Parse(_anisotropy.ActiveId);
  375. ConfigurationState.Instance.Graphics.ResScale.Value = int.Parse(_resScaleCombo.ActiveId);
  376. ConfigurationState.Instance.Graphics.ResScaleCustom.Value = resScaleCustom;
  377. MainWindow.SaveConfig();
  378. MainWindow.UpdateGraphicsConfig();
  379. MainWindow.ApplyTheme();
  380. Dispose();
  381. }
  382. private void CloseToggle_Activated(object sender, EventArgs args)
  383. {
  384. Dispose();
  385. }
  386. }
  387. }