ProfileDialog.cs 1.6 KB

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