Program.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. using Ryujinx.Audio;
  2. using Ryujinx.Common.Logging;
  3. using Ryujinx.Graphics.Gal;
  4. using Ryujinx.Graphics.Gal.OpenGL;
  5. using Ryujinx.HLE;
  6. using System;
  7. using System.IO;
  8. namespace Ryujinx
  9. {
  10. class Program
  11. {
  12. public static string ApplicationDirectory => AppDomain.CurrentDomain.BaseDirectory;
  13. static void Main(string[] args)
  14. {
  15. Console.Title = "Ryujinx Console";
  16. IGalRenderer renderer = new OGLRenderer();
  17. IAalOutput audioOut = InitializeAudioEngine();
  18. Switch device = new Switch(renderer, audioOut);
  19. Configuration.Load(Path.Combine(ApplicationDirectory, "Config.jsonc"));
  20. Configuration.Configure(device);
  21. AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
  22. AppDomain.CurrentDomain.ProcessExit += CurrentDomain_ProcessExit;
  23. if (args.Length == 1)
  24. {
  25. if (Directory.Exists(args[0]))
  26. {
  27. string[] romFsFiles = Directory.GetFiles(args[0], "*.istorage");
  28. if (romFsFiles.Length == 0)
  29. {
  30. romFsFiles = Directory.GetFiles(args[0], "*.romfs");
  31. }
  32. if (romFsFiles.Length > 0)
  33. {
  34. Logger.PrintInfo(LogClass.Application, "Loading as cart with RomFS.");
  35. device.LoadCart(args[0], romFsFiles[0]);
  36. }
  37. else
  38. {
  39. Logger.PrintInfo(LogClass.Application, "Loading as cart WITHOUT RomFS.");
  40. device.LoadCart(args[0]);
  41. }
  42. }
  43. else if (File.Exists(args[0]))
  44. {
  45. switch (Path.GetExtension(args[0]).ToLowerInvariant())
  46. {
  47. case ".xci":
  48. Logger.PrintInfo(LogClass.Application, "Loading as XCI.");
  49. device.LoadXci(args[0]);
  50. break;
  51. case ".nca":
  52. Logger.PrintInfo(LogClass.Application, "Loading as NCA.");
  53. device.LoadNca(args[0]);
  54. break;
  55. case ".nsp":
  56. case ".pfs0":
  57. Logger.PrintInfo(LogClass.Application, "Loading as NSP.");
  58. device.LoadNsp(args[0]);
  59. break;
  60. default:
  61. Logger.PrintInfo(LogClass.Application, "Loading as homebrew.");
  62. device.LoadProgram(args[0]);
  63. break;
  64. }
  65. }
  66. }
  67. else
  68. {
  69. Logger.PrintInfo(LogClass.Application, "Please specify the folder with the NSOs/IStorage or a NSO/NRO.");
  70. }
  71. using (GlScreen screen = new GlScreen(device, renderer))
  72. {
  73. screen.MainLoop();
  74. device.Dispose();
  75. }
  76. audioOut.Dispose();
  77. Logger.Shutdown();
  78. }
  79. private static void CurrentDomain_ProcessExit(object sender, EventArgs e)
  80. {
  81. Logger.Shutdown();
  82. }
  83. private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
  84. {
  85. var exception = e.ExceptionObject as Exception;
  86. Logger.PrintError(LogClass.Emulation, $"Unhandled exception caught: {exception}");
  87. if (e.IsTerminating)
  88. {
  89. Logger.Shutdown();
  90. }
  91. }
  92. /// <summary>
  93. /// Picks an <see cref="IAalOutput"/> audio output renderer supported on this machine
  94. /// </summary>
  95. /// <returns>An <see cref="IAalOutput"/> supported by this machine</returns>
  96. private static IAalOutput InitializeAudioEngine()
  97. {
  98. if (SoundIoAudioOut.IsSupported)
  99. {
  100. return new SoundIoAudioOut();
  101. }
  102. else if (OpenALAudioOut.IsSupported)
  103. {
  104. return new OpenALAudioOut();
  105. }
  106. else
  107. {
  108. return new DummyAudioOut();
  109. }
  110. }
  111. }
  112. }