ProfileDialog.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. using Gtk;
  2. using System;
  3. using System.Reflection;
  4. using Ryujinx.Ui.Common.Configuration;
  5. using GUI = Gtk.Builder.ObjectAttribute;
  6. namespace Ryujinx.Ui.Widgets
  7. {
  8. public class ProfileDialog : Dialog
  9. {
  10. public string FileName { get; private set; }
  11. #pragma warning disable CS0649, IDE0044
  12. [GUI] Entry _profileEntry;
  13. [GUI] Label _errorMessage;
  14. #pragma warning restore CS0649, IDE0044
  15. public ProfileDialog() : this(new Builder("Ryujinx.Ui.Widgets.ProfileDialog.glade")) { }
  16. private ProfileDialog(Builder builder) : base(builder.GetObject("_profileDialog").Handle)
  17. {
  18. builder.Autoconnect(this);
  19. Icon = new Gdk.Pixbuf(Assembly.GetAssembly(typeof(ConfigurationState)), "Ryujinx.Ui.Common.Resources.Logo_Ryujinx.png");
  20. }
  21. private void OkToggle_Activated(object sender, EventArgs args)
  22. {
  23. ((ToggleButton)sender).SetStateFlags(StateFlags.Normal, true);
  24. bool validFileName = true;
  25. foreach (char invalidChar in System.IO.Path.GetInvalidFileNameChars())
  26. {
  27. if (_profileEntry.Text.Contains(invalidChar))
  28. {
  29. validFileName = false;
  30. }
  31. }
  32. if (validFileName && !string.IsNullOrEmpty(_profileEntry.Text))
  33. {
  34. FileName = $"{_profileEntry.Text}.json";
  35. Respond(ResponseType.Ok);
  36. }
  37. else
  38. {
  39. _errorMessage.Text = "The file name contains invalid characters. Please try again.";
  40. }
  41. }
  42. private void CancelToggle_Activated(object sender, EventArgs args)
  43. {
  44. Respond(ResponseType.Cancel);
  45. }
  46. }
  47. }