Extract helper method `HawkFile.PathContainsPipe`

This commit is contained in:
YoshiRulz 2024-07-03 20:37:33 +10:00
parent 43d16473d8
commit 0067dd4b0a
No known key found for this signature in database
GPG Key ID: C4DE31C245353FB7
6 changed files with 12 additions and 10 deletions

View File

@ -3,7 +3,6 @@ using System.IO;
using System.Security.Principal;
using BizHawk.Common;
using BizHawk.Common.StringExtensions;
namespace BizHawk.Client.EmuHawk
{
@ -16,7 +15,7 @@ namespace BizHawk.Client.EmuHawk
/// <remarks>http://stackoverflow.com/questions/139010/how-to-resolve-a-lnk-in-c-sharp</remarks>
public static string ResolveShortcut(string filename)
{
if (OSTailoredCode.IsUnixHost || filename.ContainsOrdinal('|')
if (OSTailoredCode.IsUnixHost || HawkFile.PathContainsPipe(filename)
|| !".lnk".Equals(Path.GetExtension(filename), StringComparison.OrdinalIgnoreCase))
{
return filename; // archive internal files are never shortcuts (and choke when analyzing any further)

View File

@ -8,7 +8,6 @@ using System.Windows.Forms;
using BizHawk.Client.Common;
using BizHawk.Common;
using BizHawk.Common.PathExtensions;
using BizHawk.Common.StringExtensions;
using BizHawk.Emulation.Common;
using BizHawk.Emulation.Cores.Arcades.MAME;
using BizHawk.Emulation.DiscSystem;
@ -311,7 +310,7 @@ namespace BizHawk.Client.EmuHawk
{
static string ResolvePath(string path)
{
if (!path.ContainsOrdinal('|') && Disc.IsValidExtension(Path.GetExtension(path)))
if (!HawkFile.PathContainsPipe(path) && Disc.IsValidExtension(Path.GetExtension(path)))
{
return path; // nothing to do in this case
}
@ -343,7 +342,7 @@ namespace BizHawk.Client.EmuHawk
static ConsoleID IdentifyConsole(string path)
{
if (!path.ContainsOrdinal('|') && Disc.IsValidExtension(Path.GetExtension(path)))
if (!HawkFile.PathContainsPipe(path) && Disc.IsValidExtension(Path.GetExtension(path)))
{
using var disc = DiscExtensions.CreateAnyType(path, Console.WriteLine);
if (disc is null)

View File

@ -61,7 +61,7 @@ namespace BizHawk.Client.EmuHawk
if (!Game.IsNullInstance())
{
if (MainForm.CurrentlyOpenRom.ContainsOrdinal('|'))
if (HawkFile.PathContainsPipe(MainForm.CurrentlyOpenRom))
{
var pieces = MainForm.CurrentlyOpenRom.Split('|');

View File

@ -2,8 +2,10 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using BizHawk.Common.CollectionExtensions;
using BizHawk.Common.StringExtensions;
namespace BizHawk.Common
{
@ -21,6 +23,10 @@ namespace BizHawk.Common
/// </remarks>
public sealed class HawkFile : IDisposable
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool PathContainsPipe(string s)
=> s.ContainsOrdinal('|');
private readonly List<HawkArchiveFileItem>? _archiveItems;
private Stream? _boundStream;

View File

@ -5,7 +5,6 @@ using System.IO;
using System.Threading;
using BizHawk.Common;
using BizHawk.Common.StringExtensions;
namespace BizHawk.Emulation.Cores.Arcades.MAME
{
@ -54,7 +53,7 @@ namespace BizHawk.Emulation.Cores.Arcades.MAME
public static bool IsMAMEMachine(string path)
{
if (_acquire == null) throw new InvalidOperationException("MAME Machine DB not initialized. It's a client responsibility because only a client knows where the database is located.");
if (path.ContainsOrdinal('|')) return false; // binded archive, can't be a mame zip (note | is not a legal filesystem char, at least on windows)
if (HawkFile.PathContainsPipe(path)) return false; // binded archive, can't be a mame zip (note | is not a legal filesystem char, at least on windows)
if (Path.GetExtension(path).ToLowerInvariant() is not ".zip" and not ".7z") return false;
_acquire.WaitOne();
return Instance.MachineDB.Contains(Path.GetFileNameWithoutExtension(path).ToLowerInvariant());

View File

@ -7,7 +7,6 @@ using System.Text;
using BizHawk.BizInvoke;
using BizHawk.Common;
using BizHawk.Common.StringExtensions;
using BizHawk.Emulation.Common;
namespace BizHawk.Emulation.Cores.Consoles.Nintendo.N3DS
@ -47,7 +46,7 @@ namespace BizHawk.Emulation.Cores.Consoles.Nintendo.N3DS
[CoreConstructor(VSystemID.Raw.N3DS)]
public Encore(CoreLoadParameters<EncoreSettings, EncoreSyncSettings> lp)
{
if (lp.Roms.Exists(static r => r.RomPath.ContainsOrdinal('|')))
if (lp.Roms.Exists(static r => HawkFile.PathContainsPipe(r.RomPath)))
{
throw new InvalidOperationException("3DS does not support compressed ROMs");
}