ProfileDialog.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. using Gtk;
  2. using Ryujinx.UI.Common.Configuration;
  3. using System;
  4. using System.Reflection;
  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 // Field is never assigned to, Add readonly modifier
  12. [GUI] Entry _profileEntry;
  13. [GUI] Label _errorMessage;
  14. #pragma warning restore CS0649, IDE0044
  15. public ProfileDialog() : this(new Builder("Ryujinx.Gtk3.UI.Widgets.ProfileDialog.glade")) { }
  16. private ProfileDialog(Builder builder) : base(builder.GetRawOwnedObject("_profileDialog"))
  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. }