renaming + optimizations

pull/2/head
Evan Hemsley 2020-01-17 19:16:09 -08:00
parent 4f0e9ec566
commit c3bcdeced6
8 changed files with 37 additions and 32 deletions

View File

@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16 # Visual Studio Version 16
VisualStudioVersion = 16.0.29709.97 VisualStudioVersion = 16.0.29709.97
MinimumVisualStudioVersion = 10.0.40219.1 MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SharpPhysFS", "SharpPhysFS\SharpPhysFS.csproj", "{AD6AA182-8C7F-4F3A-AAEF-7BD993D1D262}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NETPhysFS", "SharpPhysFS\NETPhysFS.csproj", "{AD6AA182-8C7F-4F3A-AAEF-7BD993D1D262}"
EndProject EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{250EE88E-18B5-4433-ACF0-24A1D81429CF}" Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{250EE88E-18B5-4433-ACF0-24A1D81429CF}"
ProjectSection(SolutionItems) = preProject ProjectSection(SolutionItems) = preProject

View File

@ -1,8 +1,7 @@
using System; using System;
using System.Linq;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
namespace SharpPhysFS namespace MoonTools.NETPhysFS
{ {
[UnmanagedFunctionPointer(CallingConvention.Cdecl, CharSet = CharSet.Ansi)] [UnmanagedFunctionPointer(CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
public delegate int InitDelegate(); public delegate int InitDelegate();

View File

@ -3,10 +3,10 @@
<Version>1.0.0</Version> <Version>1.0.0</Version>
<TargetFramework>netstandard2.0</TargetFramework> <TargetFramework>netstandard2.0</TargetFramework>
<Description>.NET wrapper for PhysFS</Description> <Description>.NET wrapper for PhysFS</Description>
<PackageId>SharpPhysFS</PackageId> <PackageId>MoonTools.NETPhysFS</PackageId>
<RootNamespace>SharpPhysFS</RootNamespace> <RootNamespace>MoonTools.NETPhysFS</RootNamespace>
<Product>SharpPhysFS</Product> <Product>MoonTools.NETPhysFS</Product>
<AssemblyName>SharpPhysFS</AssemblyName> <AssemblyName>MoonTools.NETPhysFS</AssemblyName>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild> <GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup> </PropertyGroup>

View File

@ -1,7 +1,7 @@
using System; using System;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
namespace SharpPhysFS namespace MoonTools.NETPhysFS
{ {
public sealed partial class PhysFS public sealed partial class PhysFS
{ {

View File

@ -2,7 +2,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
namespace SharpPhysFS namespace MoonTools.NETPhysFS
{ {
public class PhysFSLibNotFound : Exception public class PhysFSLibNotFound : Exception
{ {
@ -253,11 +253,16 @@ namespace SharpPhysFS
/// This call may block while drives spin up. Be forewarned. /// This call may block while drives spin up. Be forewarned.
/// </remarks> /// </remarks>
/// <returns>An enumeration of paths to available CD-ROM drives.</returns> /// <returns>An enumeration of paths to available CD-ROM drives.</returns>
public string[] GetCdRomDirs() public IEnumerable<string> GetCdRomDirs()
{ {
var list = new List<string>(); IntPtr files = Interop.PHYSFS_getCdRomDirs();
GetCdRomDirsCallback((s) => list.Add(s)); for (IntPtr ptr = files; Marshal.ReadIntPtr(ptr) != IntPtr.Zero; ptr = IntPtr.Add(ptr, IntPtr.Size))
return list.ToArray(); {
var strPtr = (IntPtr)Marshal.PtrToStructure(ptr, typeof(IntPtr));
var str = Marshal.PtrToStringAnsi(strPtr);
if (!IsDirectory(str)) { yield return str; } // the dll seems to be returning directories. boo!
}
Interop.PHYSFS_freeList(files);
} }
/// <summary> /// <summary>
@ -340,11 +345,16 @@ namespace SharpPhysFS
/// <summary> /// <summary>
/// Get the current search path. /// Get the current search path.
/// </summary> /// </summary>
public string[] GetSearchPath() public IEnumerable<string> GetSearchPath()
{ {
var list = new List<string>(); IntPtr files = Interop.PHYSFS_getSearchPath();
GetSearchPathCallback((s) => list.Add(s)); for (IntPtr ptr = files; Marshal.ReadIntPtr(ptr) != IntPtr.Zero; ptr = IntPtr.Add(ptr, IntPtr.Size))
return list.ToArray(); {
var strPtr = (IntPtr)Marshal.PtrToStructure(ptr, typeof(IntPtr));
var str = Marshal.PtrToStringAnsi(strPtr);
if (!IsDirectory(str)) { yield return str; } // the dll seems to be returning directories. boo!
}
Interop.PHYSFS_freeList(files);
} }
/// <summary> /// <summary>

View File

@ -1,7 +1,7 @@
using System; using System;
using System.IO; using System.IO;
namespace SharpPhysFS namespace MoonTools.NETPhysFS
{ {
public class PhysFSStream : Stream public class PhysFSStream : Stream
{ {
@ -89,19 +89,19 @@ namespace SharpPhysFS
return pos + offset; return pos + offset;
} }
public long Write(byte[] buffer, uint offset, uint count) public long Write(byte[] buffer, uint count)
{ {
return PhysFS.LowLevel.Write(handle, buffer, 1, count); return PhysFS.LowLevel.Write(handle, buffer, 1, count);
} }
public override void Write(byte[] buffer, int offset, int count) public override void Write(byte[] buffer, int offset, int count)
{ {
Write(buffer, (uint)offset, (uint)count); Write(buffer, (uint)count);
} }
public override void SetLength(long value) public override void SetLength(long value)
{ {
throw new NotImplementedException(); throw new NotSupportedException();
} }
protected override void Dispose(bool disposing) protected override void Dispose(bool disposing)

View File

@ -3,7 +3,7 @@ using System.IO;
using System.Linq; using System.Linq;
using FluentAssertions; using FluentAssertions;
using NUnit.Framework; using NUnit.Framework;
using SharpPhysFS; using MoonTools.NETPhysFS;
namespace UnitTests namespace UnitTests
{ {
@ -21,7 +21,7 @@ namespace UnitTests
public void VersionCheck(byte major, byte minor, byte patch) public void VersionCheck(byte major, byte minor, byte patch)
{ {
using var pfs = new PhysFS(""); using var pfs = new PhysFS("");
new SharpPhysFS.Version() { major = major, minor = minor, patch = patch }.Should().BeEquivalentTo(pfs.GetLinkedVersion()); new MoonTools.NETPhysFS.Version() { major = major, minor = minor, patch = patch }.Should().BeEquivalentTo(pfs.GetLinkedVersion());
} }
[Test] [Test]
@ -89,13 +89,10 @@ namespace UnitTests
var effectiveCdDrives = DriveInfo.GetDrives() var effectiveCdDrives = DriveInfo.GetDrives()
.Where(x => x.DriveType == DriveType.CDRom) .Where(x => x.DriveType == DriveType.CDRom)
.Select(x => x.RootDirectory.FullName) .Select(x => x.RootDirectory.FullName)
.OrderBy(s => s)
.ToArray(); .ToArray();
var enumeratedCdDrives = pfs.GetCdRomDirs(); var enumeratedCdDrives = pfs.GetCdRomDirs().OrderBy(s => s);
Array.Sort(effectiveCdDrives);
Array.Sort(enumeratedCdDrives);
enumeratedCdDrives.Should().BeEquivalentTo(effectiveCdDrives); enumeratedCdDrives.Should().BeEquivalentTo(effectiveCdDrives);
} }

View File

@ -3,10 +3,6 @@
<TargetFramework>netcoreapp3.0</TargetFramework> <TargetFramework>netcoreapp3.0</TargetFramework>
<IsPackable>false</IsPackable> <IsPackable>false</IsPackable>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\SharpPhysFS\SharpPhysFS.csproj" />
</ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="FluentAssertions" Version="5.10.0" /> <PackageReference Include="FluentAssertions" Version="5.10.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.4.0" /> <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.4.0" />
@ -16,4 +12,7 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference> </PackageReference>
</ItemGroup> </ItemGroup>
<ItemGroup>
<ProjectReference Include="..\SharpPhysFS\NETPhysFS.csproj" />
</ItemGroup>
</Project> </Project>