Program.cs 4.6 KB

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