Program.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. else
  67. {
  68. Logger.PrintWarning(LogClass.Application, "Please specify a valid XCI/NCA/NSP/PFS0/NRO file");
  69. }
  70. }
  71. else
  72. {
  73. Logger.PrintWarning(LogClass.Application, "Please specify the folder with the NSOs/IStorage or a NSO/NRO.");
  74. }
  75. using (GlScreen screen = new GlScreen(device, renderer))
  76. {
  77. screen.MainLoop();
  78. device.Dispose();
  79. }
  80. audioOut.Dispose();
  81. Logger.Shutdown();
  82. }
  83. private static void CurrentDomain_ProcessExit(object sender, EventArgs e)
  84. {
  85. Logger.Shutdown();
  86. }
  87. private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
  88. {
  89. var exception = e.ExceptionObject as Exception;
  90. Logger.PrintError(LogClass.Emulation, $"Unhandled exception caught: {exception}");
  91. if (e.IsTerminating)
  92. {
  93. Logger.Shutdown();
  94. }
  95. }
  96. /// <summary>
  97. /// Picks an <see cref="IAalOutput"/> audio output renderer supported on this machine
  98. /// </summary>
  99. /// <returns>An <see cref="IAalOutput"/> supported by this machine</returns>
  100. private static IAalOutput InitializeAudioEngine()
  101. {
  102. if (SoundIoAudioOut.IsSupported)
  103. {
  104. return new SoundIoAudioOut();
  105. }
  106. else if (OpenALAudioOut.IsSupported)
  107. {
  108. return new OpenALAudioOut();
  109. }
  110. else
  111. {
  112. return new DummyAudioOut();
  113. }
  114. }
  115. }
  116. }