mirror of
https://github.com/StarBeat/UnityDependencyAnalyzer.git
synced 2026-03-08 05:35:27 +08:00
46 lines
1.2 KiB
C#
46 lines
1.2 KiB
C#
|
|
using System;
|
|||
|
|
namespace UnityFileApi
|
|||
|
|
{
|
|||
|
|
// Use this class to read data from a Unity file.
|
|||
|
|
public class UnityFile : IDisposable
|
|||
|
|
{
|
|||
|
|
internal UnityFile()
|
|||
|
|
{
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
internal UnityFileHandle m_Handle;
|
|||
|
|
|
|||
|
|
public long Read(long size, byte[] buffer)
|
|||
|
|
{
|
|||
|
|
var r = DllWrapper.ReadFile(m_Handle, size, buffer, out var actualSize);
|
|||
|
|
UnityFileSystem.HandleErrors(r);
|
|||
|
|
|
|||
|
|
return actualSize;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public long Seek(long offset, SeekOrigin origin = SeekOrigin.Begin)
|
|||
|
|
{
|
|||
|
|
var r = DllWrapper.SeekFile(m_Handle, offset, origin, out var newPosition);
|
|||
|
|
UnityFileSystem.HandleErrors(r);
|
|||
|
|
|
|||
|
|
return newPosition;
|
|||
|
|
}
|
|||
|
|
public long GetSize()
|
|||
|
|
{
|
|||
|
|
// This could be a property but as it may throw an exception, it's probably better as a method.
|
|||
|
|
|
|||
|
|
var r = DllWrapper.GetFileSize(m_Handle, out var size);
|
|||
|
|
UnityFileSystem.HandleErrors(r);
|
|||
|
|
|
|||
|
|
return size;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public void Dispose()
|
|||
|
|
{
|
|||
|
|
if (m_Handle != null && !m_Handle.IsInvalid)
|
|||
|
|
{
|
|||
|
|
m_Handle.Dispose();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|