Program.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. using Gtk;
  2. using Ryujinx.Common;
  3. using Ryujinx.Common.Logging;
  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. Logger.PrintInfo(LogClass.Application, $"Ryujinx Version: {Version}");
  36. Logger.PrintInfo(LogClass.Application, $"Operating System: {SystemInfo.OsDescription}");
  37. Logger.PrintInfo(LogClass.Application, $"CPU: {SystemInfo.CpuName}");
  38. Logger.PrintInfo(LogClass.Application, $"Total RAM: {SystemInfo.RamSize}");
  39. string localConfigurationPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Config.json");
  40. string globalBasePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Ryujinx");
  41. string globalConfigurationPath = Path.Combine(globalBasePath, "Config.json");
  42. // Now load the configuration as the other subsystems are now registered
  43. if (File.Exists(localConfigurationPath))
  44. {
  45. ConfigurationPath = localConfigurationPath;
  46. ConfigurationFileFormat configurationFileFormat = ConfigurationFileFormat.Load(localConfigurationPath);
  47. ConfigurationState.Instance.Load(configurationFileFormat, ConfigurationPath);
  48. }
  49. else if (File.Exists(globalConfigurationPath))
  50. {
  51. ConfigurationPath = globalConfigurationPath;
  52. ConfigurationFileFormat configurationFileFormat = ConfigurationFileFormat.Load(globalConfigurationPath);
  53. ConfigurationState.Instance.Load(configurationFileFormat, ConfigurationPath);
  54. }
  55. else
  56. {
  57. // No configuration, we load the default values and save it on disk
  58. ConfigurationPath = globalConfigurationPath;
  59. // Make sure to create the Ryujinx directory if needed.
  60. Directory.CreateDirectory(globalBasePath);
  61. ConfigurationState.Instance.LoadDefault();
  62. ConfigurationState.Instance.ToFileFormat().SaveConfig(globalConfigurationPath);
  63. }
  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. }