Program.cs 4.5 KB

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