Program.cs 4.7 KB

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