Skip to content

Commit

Permalink
Allow setting download location from command line arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
EliteAsian123 committed Aug 24, 2024
1 parent f33c616 commit 99580a6
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 22 deletions.
6 changes: 6 additions & 0 deletions Assets/Script/Helpers/PathHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ private static void Init()
LauncherPath = Path.Join(localAppdata, "YARC", "Launcher");

// Get official setlist path
// (this is replaced by the launch argument if it is set)
SetlistPath = FindSetlistPath();
}

Expand Down Expand Up @@ -140,6 +141,11 @@ private static string FindSetlistPath()
}
}

public static void SetSetlistPathFromDownloadLocation(string downloadLocation)
{
SetlistPath = Path.Join(downloadLocation, "Setlists");
}

/// <summary>
/// Safely enumerates a directory for files using the given processing delegate.
/// </summary>
Expand Down
62 changes: 62 additions & 0 deletions Assets/Script/Persistent/CommandLineArgs.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
namespace YARG
{
public struct CommandLineArgs
{
// Yes, the arguments should probably be prefixed with "--", however, this is based upon
// Unity's existing command line arguments to make them consistent in style.

/// <summary>
/// Whether or not the game should be launched in offline mode. Offline mode disables
/// offline features such as fetching the OpenSource icons.
/// </summary>
private const string OFFLINE_ARG = "-offline";

/// <summary>
/// Used to select the language the game will be launcher in. The argument after should be
/// the language code.
/// </summary>
private const string LANGUAGE_ARG = "-lang";

/// <summary>
/// Used to reference the download location of YARG and all of its setlists (by the launcher).
/// The argument after should be the download location path.
/// </summary>
private const string DOWNLOAD_LOCATION_ARG = "-download-location";

public bool Offline { get; private set; }
public string Language { get; private set; }
public string DownloadLocation { get; private set; }

public static CommandLineArgs Parse(string[] args)
{
var output = new CommandLineArgs();

// Remember, the first argument is always the application itself
for (int i = 1; i < args.Length; i++)
{
switch (args[i])
{
case OFFLINE_ARG:
output.Offline = true;
break;
case LANGUAGE_ARG:
i++;
if (i < args.Length)
{
output.Language = args[i];
}
break;
case DOWNLOAD_LOCATION_ARG:
i++;
if (i < args.Length)
{
output.DownloadLocation = args[i];
}
break;
}
}

return output;
}
}
}
3 changes: 3 additions & 0 deletions Assets/Script/Persistent/CommandLineArgs.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 8 additions & 22 deletions Assets/Script/Persistent/GlobalVariables.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using YARG.Core.Logging;
using YARG.Core.Audio;
using YARG.Core.Song;
using YARG.Helpers;
using YARG.Input;
using YARG.Integration;
using YARG.Localization;
Expand All @@ -36,11 +37,6 @@ public enum SceneIndex
[DefaultExecutionOrder(-5000)]
public class GlobalVariables : MonoSingleton<GlobalVariables>
{
// Yes, these should probably be prefixed with "--", however, this is based upon
// Unity's existing command line arguments to make them consistent in style.
private const string OFFLINE_ARG = "-offline";
private const string LANGUAGE_ARG = "-lang";

public List<YargPlayer> Players { get; private set; }

public static bool OfflineMode { get; private set; }
Expand All @@ -56,35 +52,25 @@ protected override void SingletonAwake()
CurrentVersion = LoadVersion();
YargLogger.LogFormatInfo("YARG {0}", CurrentVersion);

// Get command line args
var argsArray = Environment.GetCommandLineArgs();
var args = new List<string>();
if (argsArray.Length >= 1)
{
args = argsArray[1..].ToList();
}
// Command line arguments

// Get the language specified in the launch options, otherwise, use default
string cultureCode = null;
var languageArgIndex = args.IndexOf(LANGUAGE_ARG);
if (languageArgIndex != -1 && languageArgIndex + 1 < args.Count)
{
cultureCode = args[languageArgIndex + 1];
}
var args = CommandLineArgs.Parse(Environment.GetCommandLineArgs());

// Check for offline mode
OfflineMode = args.Contains(OFFLINE_ARG);
OfflineMode = args.Offline;
if (OfflineMode)
{
YargLogger.LogInfo("Playing in offline mode");
}

PathHelper.SetSetlistPathFromDownloadLocation(args.DownloadLocation);

// Initialize important classes

ReplayContainer.Init();
ScoreContainer.Init();
PlaylistContainer.Initialize();
CustomContentManager.Initialize();
LocalizationManager.Initialize(cultureCode);
LocalizationManager.Initialize(args.Language);

int profileCount = PlayerContainer.LoadProfiles();
YargLogger.LogFormatInfo("Loaded {0} profiles", profileCount);
Expand Down

0 comments on commit 99580a6

Please sign in to comment.