Skip to content

Commit

Permalink
Added a command line option (-c, --config) to load a configuration fi…
Browse files Browse the repository at this point in the history
…le through the command line parameters (#59)
  • Loading branch information
ivanmestre authored Oct 22, 2024
1 parent 68092bf commit 49574a9
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Ryujinx.Gtk3/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,11 @@ static void Main(string[] args)
? appDataConfigurationPath
: null;

if (!string.IsNullOrEmpty(CommandLineState.OverrideConfigFile) && File.Exists(CommandLineState.OverrideConfigFile))
{
ConfigurationPath = CommandLineState.OverrideConfigFile;
}

if (ConfigurationPath == null)
{
// No configuration, we load the default values and save it to disk
Expand Down
25 changes: 25 additions & 0 deletions src/Ryujinx.UI.Common/Helper/CommandLineState.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Ryujinx.Common.Logging;
using System.Collections.Generic;
using System.IO;

namespace Ryujinx.UI.Common.Helper
{
Expand All @@ -16,6 +17,7 @@ public static class CommandLineState
public static string LaunchPathArg { get; private set; }
public static string LaunchApplicationId { get; private set; }
public static bool StartFullscreenArg { get; private set; }
public static string OverrideConfigFile { get; private set; }

public static void ParseArguments(string[] args)
{
Expand Down Expand Up @@ -96,6 +98,29 @@ public static void ParseArguments(string[] args)
case "--software-gui":
OverrideHardwareAcceleration = false;
break;
case "-c":
case "--config":
if (i + 1 >= args.Length)
{
Logger.Error?.Print(LogClass.Application, $"Invalid option '{arg}'");

continue;
}

string configFile = args[++i];

if (Path.GetExtension(configFile).ToLower() != ".json")
{
Logger.Error?.Print(LogClass.Application, $"Invalid option '{arg}'");

continue;
}

OverrideConfigFile = configFile;

arguments.Add(arg);
arguments.Add(args[i]);
break;
default:
LaunchPathArg = arg;
break;
Expand Down
5 changes: 5 additions & 0 deletions src/Ryujinx/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,11 @@ public static void ReloadConfig()
ConfigurationPath = appDataConfigurationPath;
}

if (!string.IsNullOrEmpty(CommandLineState.OverrideConfigFile) && File.Exists(CommandLineState.OverrideConfigFile))
{
ConfigurationPath = CommandLineState.OverrideConfigFile;
}

if (ConfigurationPath == null)
{
// No configuration, we load the default values and save it to disk
Expand Down

0 comments on commit 49574a9

Please sign in to comment.