2020-06-16 14:28:02 -04:00
|
|
|
using ARMeilleure.Translation.PTC;
|
2019-09-02 12:03:57 -04:00
|
|
|
using Gtk;
|
2020-08-30 12:51:53 -04:00
|
|
|
using Ryujinx.Common.Configuration;
|
2018-10-17 13:15:50 -04:00
|
|
|
using Ryujinx.Common.Logging;
|
2020-05-03 22:15:27 -04:00
|
|
|
using Ryujinx.Common.SystemInfo;
|
2019-12-21 14:52:31 -05:00
|
|
|
using Ryujinx.Configuration;
|
2019-11-28 23:32:51 -05:00
|
|
|
using Ryujinx.Ui;
|
2020-02-11 19:56:19 -05:00
|
|
|
using OpenTK;
|
2018-02-04 18:08:20 -05:00
|
|
|
using System;
|
|
|
|
using System.IO;
|
2020-02-12 08:35:39 -05:00
|
|
|
using System.Reflection;
|
2018-02-04 18:08:20 -05:00
|
|
|
|
|
|
|
namespace Ryujinx
|
|
|
|
{
|
|
|
|
class Program
|
|
|
|
{
|
2020-02-12 08:35:39 -05:00
|
|
|
public static string Version { get; private set; }
|
|
|
|
|
2020-02-14 14:19:13 -05:00
|
|
|
public static string ConfigurationPath { get; set; }
|
2020-04-25 09:01:32 -04:00
|
|
|
|
2018-02-04 18:08:20 -05:00
|
|
|
static void Main(string[] args)
|
|
|
|
{
|
2020-08-30 12:51:53 -04:00
|
|
|
// Parse Arguments
|
|
|
|
string launchPath = null;
|
|
|
|
string baseDirPath = null;
|
|
|
|
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}'");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
baseDirPath = args[++i];
|
|
|
|
}
|
|
|
|
else if (launchPath == null)
|
|
|
|
{
|
|
|
|
launchPath = arg;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-11 19:56:19 -05:00
|
|
|
Toolkit.Init(new ToolkitOptions
|
|
|
|
{
|
|
|
|
Backend = PlatformBackend.PreferNative,
|
|
|
|
EnableHighResolution = true
|
|
|
|
});
|
|
|
|
|
2020-02-12 08:35:39 -05:00
|
|
|
Version = Assembly.GetEntryAssembly().GetCustomAttribute<AssemblyInformationalVersionAttribute>().InformationalVersion;
|
|
|
|
|
2020-02-14 05:33:22 -05:00
|
|
|
Console.Title = $"Ryujinx Console {Version}";
|
|
|
|
|
2019-09-02 12:03:57 -04:00
|
|
|
string systemPath = Environment.GetEnvironmentVariable("Path", EnvironmentVariableTarget.Machine);
|
|
|
|
Environment.SetEnvironmentVariable("Path", $"{Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "bin")};{systemPath}");
|
2019-04-26 00:53:10 -04:00
|
|
|
|
2020-08-03 19:32:53 -04:00
|
|
|
// Hook unhandled exception and process exit events
|
|
|
|
GLib.ExceptionManager.UnhandledException += (GLib.UnhandledExceptionArgs e) => ProcessUnhandledException(e.ExceptionObject as Exception, e.IsTerminating);
|
|
|
|
AppDomain.CurrentDomain.UnhandledException += (object sender, UnhandledExceptionEventArgs e) => ProcessUnhandledException(e.ExceptionObject as Exception, e.IsTerminating);
|
|
|
|
AppDomain.CurrentDomain.ProcessExit += (object sender, EventArgs e) => ProgramExit();
|
2019-12-21 14:52:31 -05:00
|
|
|
|
2020-08-30 12:51:53 -04:00
|
|
|
// Setup base data directory
|
|
|
|
AppDataManager.Initialize(baseDirPath);
|
|
|
|
|
2019-12-21 14:52:31 -05:00
|
|
|
// Initialize the configuration
|
|
|
|
ConfigurationState.Initialize();
|
|
|
|
|
|
|
|
// Initialize the logger system
|
|
|
|
LoggerModule.Initialize();
|
|
|
|
|
|
|
|
// Initialize Discord integration
|
|
|
|
DiscordIntegrationModule.Initialize();
|
|
|
|
|
2020-08-30 12:51:53 -04:00
|
|
|
string localConfigurationPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Config.json");
|
|
|
|
string appDataConfigurationPath = Path.Combine(AppDataManager.BaseDirPath, "Config.json");
|
2019-12-21 14:52:31 -05:00
|
|
|
|
|
|
|
// Now load the configuration as the other subsystems are now registered
|
2020-02-14 14:19:13 -05:00
|
|
|
if (File.Exists(localConfigurationPath))
|
2019-12-21 14:52:31 -05:00
|
|
|
{
|
2020-02-14 14:19:13 -05:00
|
|
|
ConfigurationPath = localConfigurationPath;
|
|
|
|
|
|
|
|
ConfigurationFileFormat configurationFileFormat = ConfigurationFileFormat.Load(localConfigurationPath);
|
|
|
|
|
2020-03-19 18:37:55 -04:00
|
|
|
ConfigurationState.Instance.Load(configurationFileFormat, ConfigurationPath);
|
2020-02-14 14:19:13 -05:00
|
|
|
}
|
2020-08-30 12:51:53 -04:00
|
|
|
else if (File.Exists(appDataConfigurationPath))
|
2020-02-14 14:19:13 -05:00
|
|
|
{
|
2020-08-30 12:51:53 -04:00
|
|
|
ConfigurationPath = appDataConfigurationPath;
|
2020-02-14 14:19:13 -05:00
|
|
|
|
2020-08-30 12:51:53 -04:00
|
|
|
ConfigurationFileFormat configurationFileFormat = ConfigurationFileFormat.Load(appDataConfigurationPath);
|
2020-02-14 14:19:13 -05:00
|
|
|
|
2020-03-19 18:37:55 -04:00
|
|
|
ConfigurationState.Instance.Load(configurationFileFormat, ConfigurationPath);
|
2019-12-21 14:52:31 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// No configuration, we load the default values and save it on disk
|
2020-08-30 12:51:53 -04:00
|
|
|
ConfigurationPath = appDataConfigurationPath;
|
2020-02-14 17:07:22 -05:00
|
|
|
|
2019-12-21 14:52:31 -05:00
|
|
|
ConfigurationState.Instance.LoadDefault();
|
2020-08-30 12:51:53 -04:00
|
|
|
ConfigurationState.Instance.ToFileFormat().SaveConfig(appDataConfigurationPath);
|
2019-12-21 14:52:31 -05:00
|
|
|
}
|
|
|
|
|
2020-08-03 19:32:53 -04:00
|
|
|
PrintSystemInfo();
|
2020-05-07 09:24:33 -04:00
|
|
|
|
2019-09-02 12:03:57 -04:00
|
|
|
Application.Init();
|
2019-04-26 00:53:10 -04:00
|
|
|
|
2020-08-30 12:51:53 -04:00
|
|
|
bool hasGlobalProdKeys = File.Exists(Path.Combine(AppDataManager.KeysDirPath, "prod.keys"));
|
|
|
|
bool hasAltProdKeys = !AppDataManager.IsCustomBasePath && File.Exists(Path.Combine(AppDataManager.KeysDirPathAlt, "prod.keys"));
|
|
|
|
if (!hasGlobalProdKeys && !hasAltProdKeys && !Migration.IsMigrationNeeded())
|
2019-11-28 23:32:51 -05:00
|
|
|
{
|
2020-02-06 06:38:24 -05:00
|
|
|
GtkDialog.CreateWarningDialog("Key file was not found", "Please refer to `KEYS.md` for more info");
|
2019-11-28 23:32:51 -05:00
|
|
|
}
|
2018-02-04 18:08:20 -05:00
|
|
|
|
2019-11-28 23:32:51 -05:00
|
|
|
MainWindow mainWindow = new MainWindow();
|
2019-09-02 12:03:57 -04:00
|
|
|
mainWindow.Show();
|
2019-05-30 16:27:43 -04:00
|
|
|
|
2020-08-30 12:51:53 -04:00
|
|
|
if (launchPath != null)
|
2019-09-07 21:59:41 -04:00
|
|
|
{
|
2020-08-30 12:51:53 -04:00
|
|
|
mainWindow.LoadApplication(launchPath);
|
2019-09-07 21:59:41 -04:00
|
|
|
}
|
|
|
|
|
2019-09-02 12:03:57 -04:00
|
|
|
Application.Run();
|
2018-02-04 18:08:20 -05:00
|
|
|
}
|
2018-11-14 21:22:50 -05:00
|
|
|
|
2020-08-03 19:32:53 -04:00
|
|
|
private static void PrintSystemInfo()
|
2019-11-28 23:32:51 -05:00
|
|
|
{
|
2020-08-03 19:32:53 -04:00
|
|
|
Logger.Notice.Print(LogClass.Application, $"Ryujinx Version: {Version}");
|
|
|
|
|
|
|
|
Logger.Notice.Print(LogClass.Application, $"Operating System: {SystemInfo.Instance.OsDescription}");
|
|
|
|
Logger.Notice.Print(LogClass.Application, $"CPU: {SystemInfo.Instance.CpuName}");
|
|
|
|
Logger.Notice.Print(LogClass.Application, $"Total RAM: {SystemInfo.Instance.RamSizeInMB}");
|
2019-11-28 23:32:51 -05:00
|
|
|
|
2020-08-03 19:32:53 -04:00
|
|
|
var enabledLogs = Logger.GetEnabledLevels();
|
|
|
|
Logger.Notice.Print(LogClass.Application, $"Logs Enabled: {(enabledLogs.Count == 0 ? "<None>" : string.Join(", ", enabledLogs))}");
|
2020-08-30 12:51:53 -04:00
|
|
|
|
|
|
|
if (AppDataManager.IsCustomBasePath)
|
|
|
|
{
|
|
|
|
Logger.Notice.Print(LogClass.Application, $"Custom Data Directory: {AppDataManager.BaseDirPath}");
|
|
|
|
}
|
2020-08-03 19:32:53 -04:00
|
|
|
}
|
2019-11-28 23:32:51 -05:00
|
|
|
|
2020-08-03 19:32:53 -04:00
|
|
|
private static void ProcessUnhandledException(Exception e, bool isTerminating)
|
|
|
|
{
|
2020-06-16 14:28:02 -04:00
|
|
|
Ptc.Close();
|
|
|
|
PtcProfiler.Stop();
|
|
|
|
|
2020-08-03 19:32:53 -04:00
|
|
|
string message = $"Unhandled exception caught: {e}";
|
|
|
|
|
|
|
|
Logger.Error?.PrintMsg(LogClass.Application, message);
|
2020-06-16 14:28:02 -04:00
|
|
|
|
2020-08-03 19:32:53 -04:00
|
|
|
if (Logger.Error == null) Logger.Notice.PrintMsg(LogClass.Application, message);
|
|
|
|
|
|
|
|
if (isTerminating)
|
|
|
|
{
|
|
|
|
ProgramExit();
|
2019-11-28 23:32:51 -05:00
|
|
|
}
|
|
|
|
}
|
2020-08-03 19:32:53 -04:00
|
|
|
|
|
|
|
private static void ProgramExit()
|
|
|
|
{
|
|
|
|
Ptc.Dispose();
|
|
|
|
PtcProfiler.Dispose();
|
|
|
|
|
|
|
|
Logger.Shutdown();
|
|
|
|
}
|
2018-02-04 18:08:20 -05:00
|
|
|
}
|
2020-06-16 14:28:02 -04:00
|
|
|
}
|