Program.cs 4.2 KB

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