2020-06-16 20:28:02 +02:00
|
|
|
using ARMeilleure.Translation.PTC;
|
2019-09-02 18:03:57 +02:00
|
|
|
using Gtk;
|
2020-09-01 11:09:42 +02:00
|
|
|
using OpenTK;
|
2020-08-30 18:51:53 +02:00
|
|
|
using Ryujinx.Common.Configuration;
|
2018-10-17 19:15:50 +02:00
|
|
|
using Ryujinx.Common.Logging;
|
2021-01-08 09:14:13 +01:00
|
|
|
using Ryujinx.Common.System;
|
2020-05-04 04:15:27 +02:00
|
|
|
using Ryujinx.Common.SystemInfo;
|
2019-12-21 20:52:31 +01:00
|
|
|
using Ryujinx.Configuration;
|
2021-01-08 09:14:13 +01:00
|
|
|
using Ryujinx.Modules;
|
2019-11-29 05:32:51 +01:00
|
|
|
using Ryujinx.Ui;
|
2021-01-08 09:14:13 +01:00
|
|
|
using Ryujinx.Ui.Widgets;
|
2018-02-05 00:08:20 +01:00
|
|
|
using System;
|
|
|
|
using System.IO;
|
2020-02-12 14:35:39 +01:00
|
|
|
using System.Reflection;
|
2020-09-29 22:05:25 +02:00
|
|
|
using System.Threading.Tasks;
|
2018-02-05 00:08:20 +01:00
|
|
|
|
|
|
|
namespace Ryujinx
|
|
|
|
{
|
|
|
|
class Program
|
|
|
|
{
|
2021-02-20 01:34:41 +01:00
|
|
|
public static double WindowScaleFactor { get; private set; }
|
|
|
|
|
2020-02-12 14:35:39 +01:00
|
|
|
public static string Version { get; private set; }
|
|
|
|
|
2020-02-14 20:19:13 +01:00
|
|
|
public static string ConfigurationPath { get; set; }
|
2020-04-25 15:01:32 +02:00
|
|
|
|
2018-02-05 00:08:20 +01:00
|
|
|
static void Main(string[] args)
|
2021-02-20 01:34:41 +01:00
|
|
|
{
|
2021-01-08 09:14:13 +01:00
|
|
|
// Parse Arguments.
|
|
|
|
string launchPathArg = null;
|
|
|
|
string baseDirPathArg = null;
|
|
|
|
bool startFullscreenArg = false;
|
|
|
|
|
2020-08-30 18:51:53 +02:00
|
|
|
for (int i = 0; i < args.Length; ++i)
|
|
|
|
{
|
|
|
|
string arg = args[i];
|
|
|
|
|
|
|
|
if (arg == "-r" || arg == "--root-data-dir")
|
|
|
|
{
|
|
|
|
if (i + 1 >= args.Length)
|
|
|
|
{
|
|
|
|
Logger.Error?.Print(LogClass.Application, $"Invalid option '{arg}'");
|
2021-01-08 09:14:13 +01:00
|
|
|
|
2020-08-30 18:51:53 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2021-01-08 09:14:13 +01:00
|
|
|
baseDirPathArg = args[++i];
|
2020-08-30 18:51:53 +02:00
|
|
|
}
|
2020-12-01 23:02:27 +01:00
|
|
|
else if (arg == "-f" || arg == "--fullscreen")
|
|
|
|
{
|
2021-01-08 09:14:13 +01:00
|
|
|
startFullscreenArg = true;
|
2020-12-01 23:02:27 +01:00
|
|
|
}
|
2021-01-08 09:14:13 +01:00
|
|
|
else if (launchPathArg == null)
|
2020-08-30 18:51:53 +02:00
|
|
|
{
|
2021-01-08 09:14:13 +01:00
|
|
|
launchPathArg = arg;
|
2020-08-30 18:51:53 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-20 01:34:41 +01:00
|
|
|
// Make process DPI aware for proper window sizing on high-res screens.
|
|
|
|
ForceDpiAware.Windows();
|
|
|
|
WindowScaleFactor = ForceDpiAware.GetWindowScaleFactor();
|
|
|
|
|
2021-01-08 09:14:13 +01:00
|
|
|
// Delete backup files after updating.
|
2020-09-29 22:05:25 +02:00
|
|
|
Task.Run(Updater.CleanupUpdate);
|
|
|
|
|
2020-02-12 01:56:19 +01:00
|
|
|
Toolkit.Init(new ToolkitOptions
|
|
|
|
{
|
2021-01-08 09:14:13 +01:00
|
|
|
Backend = PlatformBackend.PreferNative
|
2020-02-12 01:56:19 +01:00
|
|
|
});
|
|
|
|
|
2020-02-12 14:35:39 +01:00
|
|
|
Version = Assembly.GetEntryAssembly().GetCustomAttribute<AssemblyInformationalVersionAttribute>().InformationalVersion;
|
|
|
|
|
2020-02-14 11:33:22 +01:00
|
|
|
Console.Title = $"Ryujinx Console {Version}";
|
|
|
|
|
2019-09-02 18:03:57 +02:00
|
|
|
string systemPath = Environment.GetEnvironmentVariable("Path", EnvironmentVariableTarget.Machine);
|
|
|
|
Environment.SetEnvironmentVariable("Path", $"{Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "bin")};{systemPath}");
|
2019-04-26 06:53:10 +02:00
|
|
|
|
2021-01-08 09:14:13 +01:00
|
|
|
// Hook unhandled exception and process exit events.
|
|
|
|
GLib.ExceptionManager.UnhandledException += (GLib.UnhandledExceptionArgs e) => ProcessUnhandledException(e.ExceptionObject as Exception, e.IsTerminating);
|
2020-08-04 01:32:53 +02:00
|
|
|
AppDomain.CurrentDomain.UnhandledException += (object sender, UnhandledExceptionEventArgs e) => ProcessUnhandledException(e.ExceptionObject as Exception, e.IsTerminating);
|
2021-01-08 09:14:13 +01:00
|
|
|
AppDomain.CurrentDomain.ProcessExit += (object sender, EventArgs e) => Exit();
|
2019-12-21 20:52:31 +01:00
|
|
|
|
2021-01-08 09:14:13 +01:00
|
|
|
// Setup base data directory.
|
|
|
|
AppDataManager.Initialize(baseDirPathArg);
|
2020-08-30 18:51:53 +02:00
|
|
|
|
2021-01-08 09:14:13 +01:00
|
|
|
// Initialize the configuration.
|
2019-12-21 20:52:31 +01:00
|
|
|
ConfigurationState.Initialize();
|
|
|
|
|
2021-01-08 09:14:13 +01:00
|
|
|
// Initialize the logger system.
|
2019-12-21 20:52:31 +01:00
|
|
|
LoggerModule.Initialize();
|
|
|
|
|
2021-01-08 09:14:13 +01:00
|
|
|
// Initialize Discord integration.
|
2019-12-21 20:52:31 +01:00
|
|
|
DiscordIntegrationModule.Initialize();
|
|
|
|
|
2020-08-30 18:51:53 +02:00
|
|
|
string localConfigurationPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Config.json");
|
2021-01-08 09:14:13 +01:00
|
|
|
string appDataConfigurationPath = Path.Combine(AppDataManager.BaseDirPath, "Config.json");
|
2019-12-21 20:52:31 +01:00
|
|
|
|
2021-02-09 10:24:37 +01:00
|
|
|
// Now load the configuration as the other subsystems are now registered
|
|
|
|
ConfigurationPath = File.Exists(localConfigurationPath)
|
|
|
|
? localConfigurationPath
|
|
|
|
: File.Exists(appDataConfigurationPath)
|
|
|
|
? appDataConfigurationPath
|
|
|
|
: null;
|
|
|
|
|
|
|
|
if (ConfigurationPath == null)
|
2020-02-14 20:19:13 +01:00
|
|
|
{
|
2021-02-09 10:24:37 +01:00
|
|
|
// No configuration, we load the default values and save it to disk
|
2020-08-30 18:51:53 +02:00
|
|
|
ConfigurationPath = appDataConfigurationPath;
|
2020-02-14 20:19:13 +01:00
|
|
|
|
2021-02-09 10:24:37 +01:00
|
|
|
ConfigurationState.Instance.LoadDefault();
|
|
|
|
ConfigurationState.Instance.ToFileFormat().SaveConfig(ConfigurationPath);
|
2019-12-21 20:52:31 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-02-09 10:24:37 +01:00
|
|
|
if (ConfigurationFileFormat.TryLoad(ConfigurationPath, out ConfigurationFileFormat configurationFileFormat))
|
|
|
|
{
|
|
|
|
ConfigurationState.Instance.Load(configurationFileFormat, ConfigurationPath);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ConfigurationState.Instance.LoadDefault();
|
|
|
|
Logger.Warning?.PrintMsg(LogClass.Application, $"Failed to load config! Loading the default config instead.\nFailed config location {ConfigurationPath}");
|
|
|
|
}
|
2019-12-21 20:52:31 +01:00
|
|
|
}
|
|
|
|
|
2021-01-08 09:14:13 +01:00
|
|
|
if (startFullscreenArg)
|
2020-12-01 23:02:27 +01:00
|
|
|
{
|
|
|
|
ConfigurationState.Instance.Ui.StartFullscreen.Value = true;
|
|
|
|
}
|
|
|
|
|
2021-02-09 10:24:37 +01:00
|
|
|
// Logging system information.
|
2020-08-04 01:32:53 +02:00
|
|
|
PrintSystemInfo();
|
2020-05-07 15:24:33 +02:00
|
|
|
|
2021-01-08 09:14:13 +01:00
|
|
|
// Initialize Gtk.
|
2019-09-02 18:03:57 +02:00
|
|
|
Application.Init();
|
2019-04-26 06:53:10 +02:00
|
|
|
|
2021-01-08 09:14:13 +01:00
|
|
|
// Check if keys exists.
|
2020-08-30 18:51:53 +02:00
|
|
|
bool hasGlobalProdKeys = File.Exists(Path.Combine(AppDataManager.KeysDirPath, "prod.keys"));
|
|
|
|
bool hasAltProdKeys = !AppDataManager.IsCustomBasePath && File.Exists(Path.Combine(AppDataManager.KeysDirPathAlt, "prod.keys"));
|
2021-01-08 09:14:13 +01:00
|
|
|
if (!hasGlobalProdKeys && !hasAltProdKeys)
|
2019-11-29 05:32:51 +01:00
|
|
|
{
|
2020-09-01 11:09:42 +02:00
|
|
|
UserErrorDialog.CreateUserErrorDialog(UserError.NoKeys);
|
2019-11-29 05:32:51 +01:00
|
|
|
}
|
2018-02-05 00:08:20 +01:00
|
|
|
|
2021-01-08 09:14:13 +01:00
|
|
|
// Force dedicated GPU if we can.
|
|
|
|
ForceDedicatedGpu.Nvidia();
|
|
|
|
|
|
|
|
// Show the main window UI.
|
2019-11-29 05:32:51 +01:00
|
|
|
MainWindow mainWindow = new MainWindow();
|
2019-09-02 18:03:57 +02:00
|
|
|
mainWindow.Show();
|
2019-05-30 22:27:43 +02:00
|
|
|
|
2021-01-08 09:14:13 +01:00
|
|
|
if (launchPathArg != null)
|
2019-09-08 03:59:41 +02:00
|
|
|
{
|
2021-01-08 09:14:13 +01:00
|
|
|
mainWindow.LoadApplication(launchPathArg);
|
2019-09-08 03:59:41 +02:00
|
|
|
}
|
|
|
|
|
2020-09-29 22:05:25 +02:00
|
|
|
if (ConfigurationState.Instance.CheckUpdatesOnStart.Value && Updater.CanUpdate(false))
|
|
|
|
{
|
2021-02-23 16:19:02 +01:00
|
|
|
Updater.BeginParse(mainWindow, false).ContinueWith(task =>
|
|
|
|
{
|
|
|
|
Logger.Error?.Print(LogClass.Application, $"Updater Error: {task.Exception}");
|
|
|
|
}, TaskContinuationOptions.OnlyOnFaulted);
|
2020-09-29 22:05:25 +02:00
|
|
|
}
|
|
|
|
|
2019-09-02 18:03:57 +02:00
|
|
|
Application.Run();
|
2018-02-05 00:08:20 +01:00
|
|
|
}
|
2018-11-15 03:22:50 +01:00
|
|
|
|
2020-08-04 01:32:53 +02:00
|
|
|
private static void PrintSystemInfo()
|
2019-11-29 05:32:51 +01:00
|
|
|
{
|
2020-08-04 01:32:53 +02:00
|
|
|
Logger.Notice.Print(LogClass.Application, $"Ryujinx Version: {Version}");
|
2021-03-01 05:22:00 +01:00
|
|
|
SystemInfo.Gather().Print();
|
2019-11-29 05:32:51 +01:00
|
|
|
|
2020-08-04 01:32:53 +02:00
|
|
|
var enabledLogs = Logger.GetEnabledLevels();
|
|
|
|
Logger.Notice.Print(LogClass.Application, $"Logs Enabled: {(enabledLogs.Count == 0 ? "<None>" : string.Join(", ", enabledLogs))}");
|
2020-08-30 18:51:53 +02:00
|
|
|
|
|
|
|
if (AppDataManager.IsCustomBasePath)
|
|
|
|
{
|
|
|
|
Logger.Notice.Print(LogClass.Application, $"Custom Data Directory: {AppDataManager.BaseDirPath}");
|
|
|
|
}
|
2020-08-04 01:32:53 +02:00
|
|
|
}
|
2019-11-29 05:32:51 +01:00
|
|
|
|
2021-01-08 09:14:13 +01:00
|
|
|
private static void ProcessUnhandledException(Exception ex, bool isTerminating)
|
2020-08-04 01:32:53 +02:00
|
|
|
{
|
2020-06-16 20:28:02 +02:00
|
|
|
Ptc.Close();
|
|
|
|
PtcProfiler.Stop();
|
|
|
|
|
2021-01-08 09:14:13 +01:00
|
|
|
string message = $"Unhandled exception caught: {ex}";
|
2020-08-04 01:32:53 +02:00
|
|
|
|
|
|
|
Logger.Error?.PrintMsg(LogClass.Application, message);
|
2020-06-16 20:28:02 +02:00
|
|
|
|
2021-01-08 09:14:13 +01:00
|
|
|
if (Logger.Error == null)
|
|
|
|
{
|
|
|
|
Logger.Notice.PrintMsg(LogClass.Application, message);
|
|
|
|
}
|
2020-08-04 01:32:53 +02:00
|
|
|
|
|
|
|
if (isTerminating)
|
|
|
|
{
|
2021-01-08 09:14:13 +01:00
|
|
|
Exit();
|
2019-11-29 05:32:51 +01:00
|
|
|
}
|
|
|
|
}
|
2020-08-04 01:32:53 +02:00
|
|
|
|
2021-01-08 09:14:13 +01:00
|
|
|
public static void Exit()
|
2020-08-04 01:32:53 +02:00
|
|
|
{
|
2021-01-08 09:14:13 +01:00
|
|
|
DiscordIntegrationModule.Exit();
|
|
|
|
|
2020-08-04 01:32:53 +02:00
|
|
|
Ptc.Dispose();
|
|
|
|
PtcProfiler.Dispose();
|
|
|
|
|
|
|
|
Logger.Shutdown();
|
|
|
|
}
|
2018-02-05 00:08:20 +01:00
|
|
|
}
|
2020-09-29 22:05:25 +02:00
|
|
|
}
|