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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ Built with Unity 6.5

### Added

- Plugin helpers resolve table-local media directories by controller namespace and game ID, with case-insensitive matching for VPX folder layouts.

- Windows Open Pinball Device support for Pinscape Pico with named nudge axes, firmware scale presets and preassigned cabinet buttons. The updated NativeInput library is required for OPD discovery.

- Shared Pinscape joystick nudge setup and sampled rest calibration in the editor and Player, with explicit velocity presets, device-axis selection, editable SI scales, and sensor state reset on disconnect.
Expand Down
65 changes: 65 additions & 0 deletions VisualPinball.Plugins.Test/TableMediaPathsTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// Visual Pinball Engine
// Copyright (C) 2026 freezy and VPE Team
// SPDX-License-Identifier: MIT

using System;
using System.IO;
using System.Linq;
using NUnit.Framework;

namespace VisualPinball.Plugins.Test
{
public sealed class TableMediaPathsTests
{
private string _root = null!;

[SetUp]
public void SetUp() => _root = Directory.CreateDirectory(Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString("N"))).FullName;

[TearDown]
public void TearDown() => Directory.Delete(_root, recursive: true);

[Test]
public void LooksUpEachComponentAndRetainsItsSpelling()
{
string mediaRoot = Directory.CreateDirectory(Path.Combine(_root, "Sérum")).FullName;
string local = Directory.CreateDirectory(Path.Combine(mediaRoot, "PINMAME", "ROM")).FullName;
string fallback = Directory.CreateDirectory(Path.Combine(mediaRoot, "Rom")).FullName;
string file = Path.Combine(local, "ROM.cRZ");
File.WriteAllText(file, "");

var media = TableMediaPaths.FindDirectory(_root, "sérum");
Assert.That(TableMediaPaths.GameDirectories(media, new GameIdentity("pinmame", "rom")).ToArray(),
Is.EqualTo(new[] { local, fallback }));
Assert.That(TableMediaPaths.FindFile(local, "rom.crz"), Is.EqualTo(file));
}

[Test]
public void RejectsCaseCollisionsEvenWithAnExactMatch()
{
Directory.CreateDirectory(Path.Combine(_root, "rom"));
Directory.CreateDirectory(Path.Combine(_root, "ROM"));
if (Directory.GetDirectories(_root).Length != 2) {
Assert.Ignore("Requires a case-sensitive filesystem.");
}
File.WriteAllText(Path.Combine(_root, "rom.crz"), "");
File.WriteAllText(Path.Combine(_root, "ROM.CRZ"), "");

Assert.Multiple(() => {
Assert.That(TableMediaPaths.FindDirectory(_root, "rom"), Is.Null);
Assert.That(TableMediaPaths.GameDirectories(_root, new GameIdentity("pinmame", "rom")), Is.Empty);
Assert.That(TableMediaPaths.FindFile(_root, "rom.crz"), Is.Null);
});
}

[TestCase("..")]
[TestCase("../outside")]
[TestCase("pinmame\\rom")]
[TestCase("C:outside")]
public void RejectsPathsAsGameKeys(string key)
{
Assert.That(TableMediaPaths.GameDirectories(_root, new GameIdentity("pinmame", key)), Is.Empty);
Assert.That(TableMediaPaths.FindDirectory(_root, key), Is.Null);
}
}
}
2 changes: 2 additions & 0 deletions VisualPinball.Plugins.Test/TableMediaPathsTests.cs.meta

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

64 changes: 64 additions & 0 deletions VisualPinball.Plugins/Api/TableMediaPaths.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// Visual Pinball Engine
// Copyright (C) 2026 freezy and VPE Team
// SPDX-License-Identifier: MIT

#nullable enable

using System;
using System.Collections.Generic;
using System.IO;

namespace VisualPinball.Plugins
{
/// <summary>Locates VPX-compatible media paths, skipping ambiguous case-insensitive matches.</summary>
public static class TableMediaPaths
{
private static readonly char[] InvalidNameCharacters = { '/', '\\', ':', '\0' };

/// <summary>Existing game directories, with the controller namespace taking precedence over a bare game key.</summary>
public static IEnumerable<string> GameDirectories(string? root, GameIdentity game)
{
if (!IsName(game.Provider) || !IsName(game.Key)) yield break;
var scoped = FindDirectory(root, game.Provider, game.Key);
if (scoped != null) yield return scoped;
var unscoped = FindDirectory(root, game.Key);
if (unscoped != null) yield return unscoped;
}

/// <summary>Finds an existing child directory by matching each component separately.</summary>
public static string? FindDirectory(string? root, params string[] names)
{
if (string.IsNullOrWhiteSpace(root) || names.Length == 0) return null;
foreach (string name in names) {
root = FindChild(root, name, directoryOnly: true);
if (root == null) return null;
}
return root;
}

/// <summary>Finds a file directly in the given directory.</summary>
public static string? FindFile(string? directory, string name) => FindChild(directory, name, directoryOnly: false);

private static bool IsName(string? name) => !string.IsNullOrWhiteSpace(name) && name != "." && name != ".."
&& name.IndexOfAny(InvalidNameCharacters) < 0;

private static string? FindChild(string? directory, string name, bool directoryOnly)
{
if (string.IsNullOrWhiteSpace(directory) || !IsName(name)) return null;
try {
string? match = null;
var entries = directoryOnly ? Directory.EnumerateDirectories(directory) : Directory.EnumerateFiles(directory);
foreach (string path in entries) {
string actual = Path.GetFileName(path);
if (!string.Equals(actual, name, StringComparison.OrdinalIgnoreCase)) continue;
if (match != null) return null;
match = path;
}
return match;
} catch (Exception error) when (error is IOException || error is UnauthorizedAccessException
|| error is ArgumentException || error is NotSupportedException) {
return null;
}
}
}
}
2 changes: 2 additions & 0 deletions VisualPinball.Plugins/Api/TableMediaPaths.cs.meta

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

Loading