Program.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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. Config.Read(device);
  19. Logger.Updated += Log.LogMessage;
  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. Console.WriteLine("Loading as cart with RomFS.");
  34. device.LoadCart(args[0], romFsFiles[0]);
  35. }
  36. else
  37. {
  38. Console.WriteLine("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. Console.WriteLine("Loading as XCI.");
  48. device.LoadXci(args[0]);
  49. break;
  50. case ".nca":
  51. Console.WriteLine("Loading as NCA.");
  52. device.LoadNca(args[0]);
  53. break;
  54. case ".nsp":
  55. case ".pfs0":
  56. Console.WriteLine("Loading as NSP.");
  57. device.LoadNsp(args[0]);
  58. break;
  59. default:
  60. Console.WriteLine("Loading as homebrew.");
  61. device.LoadProgram(args[0]);
  62. break;
  63. }
  64. }
  65. }
  66. else
  67. {
  68. Console.WriteLine("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. }
  77. private static void CurrentDomain_ProcessExit(object sender, EventArgs e)
  78. {
  79. Log.Close();
  80. }
  81. private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
  82. {
  83. var exception = e.ExceptionObject as Exception;
  84. Logger.PrintError(LogClass.Emulation, $"Unhandled exception caught: {exception}");
  85. if (e.IsTerminating)
  86. {
  87. Log.Close();
  88. }
  89. }
  90. /// <summary>
  91. /// Picks an <see cref="IAalOutput"/> audio output renderer supported on this machine
  92. /// </summary>
  93. /// <returns>An <see cref="IAalOutput"/> supported by this machine</returns>
  94. private static IAalOutput InitializeAudioEngine()
  95. {
  96. if (SoundIoAudioOut.IsSupported)
  97. {
  98. return new SoundIoAudioOut();
  99. }
  100. else if (OpenALAudioOut.IsSupported)
  101. {
  102. return new OpenALAudioOut();
  103. }
  104. else
  105. {
  106. return new DummyAudioOut();
  107. }
  108. }
  109. }
  110. }