Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
using NUnit.Framework;
using UnityEngine;
using UnityEngine.TestTools;
using VisualPinball.Unity.Simulation;

namespace VisualPinball.Unity.Test
{
Expand Down Expand Up @@ -153,6 +154,8 @@ public void ShouldThrottleOncePerKeyBeyondTheKeyLimit()
}

[TestCase(new[] { "-vpe-log-level=debug" }, "Debug")]
[TestCase(new[] { "--vpe-log-level=debug" }, "Debug")]
[TestCase(new[] { "player.exe", "--vpe-log-level", "warn" }, "Warn")]
[TestCase(new[] { "player.exe", "-vpe-log-level", "trace" }, "Trace")]
[TestCase(new[] { "-VPE-LOG-LEVEL=Warning" }, "Warn")]
[TestCase(new[] { "-vpe-log-level" }, null)]
Expand All @@ -164,6 +167,19 @@ public void ShouldParseTheLevelFromTheCommandLine(string[] args, string expected
(VpeLog.ParseCommandLineLevel(args)?.Name).Should().Be(expected);
}

[TestCase(new[] { "player.exe", "--simulation-trace" }, true)]
[TestCase(new[] { "player.exe", "-simulation-trace" }, true)]
[TestCase(new[] { "--no-simulation-trace" }, false)]
[TestCase(new[] { "-NO-SIMULATION-TRACE" }, false)]
[TestCase(new[] { "--simulation-trace", "--no-simulation-trace" }, false)]
[TestCase(new[] { "-no-simulation-trace", "-simulation-trace" }, true)]
[TestCase(new[] { "player.exe", "--simulation-tracex", "---simulation-trace" }, null)]
[TestCase(new string[0], null)]
public void ShouldParseTheSimulationTraceSwitch(string[] args, bool? expected)
{
SimulationTrace.ParseCommandLineOverride(args).Should().Be(expected);
}

[Test]
public void ShouldKeepTheNewestLinesWithinTheBudget()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ internal static string CommandLine(IReadOnlyList<string> args, bool editor)
for (var i = 0; i < args.Count; i++) {
var arg = args[i];
var isOption = arg.StartsWith("-");
if (editor && !(isOption && arg.StartsWith("-vpe", StringComparison.OrdinalIgnoreCase))) {
if (editor && !(isOption && arg.TrimStart('-').StartsWith("vpe", StringComparison.OrdinalIgnoreCase))) {
continue;
}
var equals = arg.IndexOf('=');
Expand Down
8 changes: 6 additions & 2 deletions VisualPinball.Unity/VisualPinball.Unity/Diagnostics/VpeLog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ private static void PublishSessionDiagnostics()
/// <param name="logDirectory">Folder for session log files. Logging to a file
/// starts with this call; lines logged before it are copied from the tail. An
/// empty string stops logging to a file.</param>
/// <param name="level">Lowest level to log. The <c>-vpe-log-level</c> command
/// <param name="level">Lowest level to log. The <c>--vpe-log-level</c> command
/// line argument overrides it.</param>
public static void Configure(string logDirectory = null, LogLevel level = null)
{
Expand Down Expand Up @@ -489,7 +489,7 @@ public static LogLevel ParseLevel(string name)
}

/// <summary>
/// Reads <c>-vpe-log-level=debug</c> or <c>-vpe-log-level debug</c>.
/// Reads <c>--vpe-log-level=debug</c> or <c>--vpe-log-level debug</c> (one dash works too).
/// </summary>
public static LogLevel ParseCommandLineLevel(IReadOnlyList<string> args)
{
Expand All @@ -498,6 +498,10 @@ public static LogLevel ParseCommandLineLevel(IReadOnlyList<string> args)
}
for (var i = 0; i < args.Count; i++) {
var arg = args[i];
// --name is the documented form, -name still works
if (arg != null && arg.StartsWith("--", StringComparison.Ordinal)) {
arg = arg.Substring(1);
}
if (arg == null || !arg.StartsWith(LevelArgument, StringComparison.OrdinalIgnoreCase)) {
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,23 @@ public static string RomFolderOverride
private static string _hostRomFolder;
private static string _romFolderOverride;

/// <summary>
/// A gamelogic engine couldn't find the ROM the table needs. Raised on the main thread with
/// the ROM's name and the folder(s) that were searched, so the host can ask for the ROM
/// folder.
/// </summary>
public static event Action<string, string> RomMissing;

/// <summary>
/// Called by a gamelogic engine on the main thread when the table's ROM isn't there.
/// </summary>
/// <param name="rom">Name of the ROM, e.g. <c>t2_l8</c></param>
/// <param name="searchedFolders">The ';'-separated folders it looked in, or null</param>
public static void ReportRomMissing(string rom, string searchedFolders)
{
RomMissing?.Invoke(rom, searchedFolders);
}

/// <summary>
/// The root of VPE's own data on this machine (<c>%LOCALAPPDATA%\Visual Pinball Engine</c>
/// on Windows), shared by all VPE apps. Gamelogic engines keep their data in a sub folder.
Expand Down Expand Up @@ -90,6 +107,7 @@ public static string NormalizeFolderList(string folders)
private static void ResetPlaySession()
{
_romFolderOverride = null;
RomMissing = null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
// SPDX-License-Identifier: GPL-3.0-or-later

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
Expand Down Expand Up @@ -215,13 +216,23 @@ public void Dispose()
private static long _beginUsec;

/// <summary>
/// Command-line override for player builds: <c>-simulation-trace</c> records,
/// <c>-no-simulation-trace</c> does not. Null when neither is given.
/// Command-line override for player builds: <c>--simulation-trace</c> records,
/// <c>--no-simulation-trace</c> does not (one dash works too). Null when neither is given.
/// </summary>
public static bool? CommandLineOverride()
public static bool? CommandLineOverride() => ParseCommandLineOverride(Environment.GetCommandLineArgs());

/// <summary>
/// <see cref="CommandLineOverride"/> for given arguments. The last switch wins.
/// </summary>
public static bool? ParseCommandLineOverride(IReadOnlyList<string> args)
{
var result = (bool?)null;
foreach (var arg in Environment.GetCommandLineArgs()) {
if (args == null) {
return null;
}
foreach (var raw in args) {
// --name is the documented form, -name still works
var arg = raw.StartsWith("--", StringComparison.Ordinal) ? raw.Substring(1) : raw;
if (string.Equals(arg, "-simulation-trace", StringComparison.OrdinalIgnoreCase)) {
result = true;
} else if (string.Equals(arg, "-no-simulation-trace", StringComparison.OrdinalIgnoreCase)) {
Expand Down
Loading