Program.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. using Gtk;
  2. using Ryujinx.Common.Logging;
  3. using Ryujinx.Configuration;
  4. using Ryujinx.Debugger.Profiler;
  5. using Ryujinx.Ui;
  6. using OpenTK;
  7. using System;
  8. using System.IO;
  9. using System.Reflection;
  10. namespace Ryujinx
  11. {
  12. class Program
  13. {
  14. public static string Version { get; private set; }
  15. public static string ConfigurationPath { get; set; }
  16. static void Main(string[] args)
  17. {
  18. Toolkit.Init(new ToolkitOptions
  19. {
  20. Backend = PlatformBackend.PreferNative,
  21. EnableHighResolution = true
  22. });
  23. Version = Assembly.GetEntryAssembly().GetCustomAttribute<AssemblyInformationalVersionAttribute>().InformationalVersion;
  24. Console.Title = $"Ryujinx Console {Version}";
  25. string systemPath = Environment.GetEnvironmentVariable("Path", EnvironmentVariableTarget.Machine);
  26. Environment.SetEnvironmentVariable("Path", $"{Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "bin")};{systemPath}");
  27. GLib.ExceptionManager.UnhandledException += Glib_UnhandledException;
  28. // Initialize the configuration
  29. ConfigurationState.Initialize();
  30. // Initialize the logger system
  31. LoggerModule.Initialize();
  32. // Initialize Discord integration
  33. DiscordIntegrationModule.Initialize();
  34. string localConfigurationPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Config.json");
  35. string globalBasePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Ryujinx");
  36. string globalConfigurationPath = Path.Combine(globalBasePath, "Config.json");
  37. // Now load the configuration as the other subsystems are now registered
  38. if (File.Exists(localConfigurationPath))
  39. {
  40. ConfigurationPath = localConfigurationPath;
  41. ConfigurationFileFormat configurationFileFormat = ConfigurationFileFormat.Load(localConfigurationPath);
  42. ConfigurationState.Instance.Load(configurationFileFormat, ConfigurationPath);
  43. }
  44. else if (File.Exists(globalConfigurationPath))
  45. {
  46. ConfigurationPath = globalConfigurationPath;
  47. ConfigurationFileFormat configurationFileFormat = ConfigurationFileFormat.Load(globalConfigurationPath);
  48. ConfigurationState.Instance.Load(configurationFileFormat, ConfigurationPath);
  49. }
  50. else
  51. {
  52. // No configuration, we load the default values and save it on disk
  53. ConfigurationPath = globalConfigurationPath;
  54. // Make sure to create the Ryujinx directory if needed.
  55. Directory.CreateDirectory(globalBasePath);
  56. ConfigurationState.Instance.LoadDefault();
  57. ConfigurationState.Instance.ToFileFormat().SaveConfig(globalConfigurationPath);
  58. }
  59. Profile.Initialize();
  60. Application.Init();
  61. string globalProdKeysPath = Path.Combine(globalBasePath, "system", "prod.keys");
  62. string userProfilePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".switch", "prod.keys");
  63. if (!File.Exists(globalProdKeysPath) && !File.Exists(userProfilePath) && !Migration.IsMigrationNeeded())
  64. {
  65. GtkDialog.CreateWarningDialog("Key file was not found", "Please refer to `KEYS.md` for more info");
  66. }
  67. MainWindow mainWindow = new MainWindow();
  68. mainWindow.Show();
  69. if (args.Length == 1)
  70. {
  71. mainWindow.LoadApplication(args[0]);
  72. }
  73. Application.Run();
  74. }
  75. private static void Glib_UnhandledException(GLib.UnhandledExceptionArgs e)
  76. {
  77. Exception exception = e.ExceptionObject as Exception;
  78. Logger.PrintError(LogClass.Application, $"Unhandled exception caught: {exception}");
  79. if (e.IsTerminating)
  80. {
  81. Logger.Shutdown();
  82. }
  83. }
  84. }
  85. }