SettingsWindow.cs 21 KB

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