From 61a3254dec1e5f094c5d737a47e1b0f9381cedba Mon Sep 17 00:00:00 2001 From: Gatongone Date: Wed, 2 Dec 2026 12:04:28 +0800 Subject: [PATCH] Add managed virtual filesystem injection Add SQLiteVfs.Register/Unregister, ISQLiteVirtualFileSystem/ISQLiteVirtualFile and a System.IO-backed SQLiteFileSystem default. The managed sqlite3_vfs bridge handles the database, journal and temporary files, rejects a second open of the same database path with SQLITE_BUSY, reports callback errors through SQLiteVfs.LastError/xGetLastError, and reuses page buffers. Includes changeset documentation updates and 58 EditMode tests. --- CHANGELOG.md | 2 + README.md | 29 + Runtime/sqlite-net/SQLiteVirtualFileSystem.cs | 1087 +++++++++++++++++ .../SQLiteVirtualFileSystem.cs.meta | 11 + Tests/Editor/TestVirtualFileSystem.cs | 290 +++++ Tests/Editor/TestVirtualFileSystem.cs.meta | 11 + 6 files changed, 1430 insertions(+) create mode 100644 Runtime/sqlite-net/SQLiteVirtualFileSystem.cs create mode 100644 Runtime/sqlite-net/SQLiteVirtualFileSystem.cs.meta create mode 100644 Tests/Editor/TestVirtualFileSystem.cs create mode 100644 Tests/Editor/TestVirtualFileSystem.cs.meta diff --git a/CHANGELOG.md b/CHANGELOG.md index 366c781..489ea7b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ - SQLite session extension support: capture net row changes with `BeginChangeSet`/`CaptureChangeSet`, apply them with `ApplyTo`, invert them with `Invert`, diff attached databases and inspect `Changes` - Table filters for both capture and apply, plus conflict handling through `SQLiteChangeSetConflict` +- Managed virtual filesystem injection: `SQLiteVfs.Register`/`Unregister`, `ISQLiteVirtualFileSystem` + and `ISQLiteVirtualFile`, with a default `SQLiteFileSystem` implementation - Native SQLCipher builds now enable `SQLITE_ENABLE_SESSION` and `SQLITE_ENABLE_PREUPDATE_HOOK` on Windows, Linux, Android, iOS, tvOS, macOS and WebGL diff --git a/README.md b/README.md index ba338f6..38ce2a6 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,7 @@ This package provides the excelent [SQLite-net](https://github.com/praeclarum/sq + `SQLiteConnection.Deserialize` extension method for deserializing memory (`byte[]`, `NativeArray` or `ReadOnlySpan`) into an open database (reference: [SQLite Deserialization](https://www.sqlite.org/c3ref/deserialize.html)). + `SQLiteConnection.ImportCsvToTable` extension method for importing a CSV text stream as a new table inside the database. + Row-level changesets via the SQLite session extension: `BeginChangeSet`/`CaptureChangeSet`, `ApplyTo`, `Invert`, `Diff`, table filters and conflict handling. + + Managed virtual filesystem injection through `SQLiteVfs.Register` and `ISQLiteVirtualFileSystem`, for platforms whose file APIs are not normal paths (for example WeChat's `FileSystemManager`). - [SQLite3 Multiple Ciphers 2.1.3](https://github.com/utelle/SQLite3MultipleCiphers/releases/tag/v2.1.3) (based on [SQLite 3.50.1](https://sqlite.org/releaselog/3_50_1.html)) + Supports encrypted databases + Enabled modules: [R\*Tree](https://sqlite.org/rtree.html), [Geopoly](https://sqlite.org/geopoly.html), [FTS5](https://sqlite.org/fts5.html), [Built-In Math Functions](https://www.sqlite.org/lang_mathfunc.html) @@ -103,6 +104,34 @@ public class TestSQLite : MonoBehaviour ``` +## Virtual filesystems +When a platform cannot open a database through a normal path (for example WeChat Mini Game's +`FileSystemManager`), register an `ISQLiteVirtualFileSystem` and open the connection with its +VFS name: +```cs +SQLiteVfs.Register("game", new MyVirtualFileSystem()); + +using var db = new SQLiteConnection(new SQLiteConnectionString( + "game.sqlite", + SQLiteOpenFlags.Create | SQLiteOpenFlags.ReadWrite, + storeDateTimeAsTicks: true, + vfsName: "game")); + +db.CreateTable(); +db.Insert(new Player { Name = "gilzoide" }); +``` +`ISQLiteVirtualFile` is random-access and synchronous: `Read`, `Write`, `Truncate`, `Sync` and +`Length`. SQLite also routes the database journal and temporary files through it. + +Limitations: +- One connection per database file; a second open returns `SQLITE_BUSY`. +- WAL is not supported. Use `journal_mode=DELETE` (the default). +- Call `SQLiteVfs.Unregister` only after all connections using it are closed. + +`SQLiteFileSystem` is the default `System.IO` implementation. WebGL builds can use the Emscripten +filesystem; WeChat needs an implementation backed by `FileSystemManager`'s synchronous +`openSync`/`readSync`/`writeSync`/`closeSync` APIs. + ## License SQLite-net for Unity first-party code is licensed under the [MIT license](LICENSE.txt). diff --git a/Runtime/sqlite-net/SQLiteVirtualFileSystem.cs b/Runtime/sqlite-net/SQLiteVirtualFileSystem.cs new file mode 100644 index 0000000..f163354 --- /dev/null +++ b/Runtime/sqlite-net/SQLiteVirtualFileSystem.cs @@ -0,0 +1,1087 @@ +/* + * Copyright (c) PeroPeroGames Co., Ltd. + * + * Managed SQLite virtual filesystem (VFS) injection. + * + * Usage: + * + * SQLiteVfs.Register("game", new MyVirtualFileSystem()); + * var db = new SQLiteConnection(new SQLiteConnectionString( + * "game.sqlite", vfsName: "game")); + * + * The native VFS bridge keeps the SQLite file semantics in C#; a custom + * ISQLiteVirtualFileSystem only has to provide random-access byte streams. + * It is intended for single-connection databases with journal_mode=DELETE + * (WAL needs shared-memory support and is not implemented). + */ +#if !USE_CSHARP_SQLITE && !USE_WP8_NATIVE_SQLITE && !USE_SQLITEPCL_RAW && !UNITY_VISIONOS +// ReSharper disable InconsistentNaming + +using System; +using System.Collections.Generic; +using System.IO; +using System.Runtime.InteropServices; +using System.Text; +using System.Threading; + +// ReSharper disable once CheckNamespace +namespace SQLite +{ + [Flags] + public enum SQLiteVirtualFileOpenFlags + { + ReadOnly = 1, + ReadWrite = 2, + Create = 4, + DeleteOnClose = 8, + Exclusive = 16, + } + + /// + /// A single file opened by an . + /// Implementations must be random-access and synchronous. + /// + public interface ISQLiteVirtualFile : IDisposable + { + long Length { get; } + + /// Reads up to bytes; returns the number read. + int Read(byte[] buffer, int offset, int count, long fileOffset); + + /// Writes bytes; returns the number written. + int Write(byte[] buffer, int offset, int count, long fileOffset); + + void Truncate(long length); + void Sync(); + } + + /// + /// Optional extension for files that can preallocate storage. SQLite sends + /// this hint before large writes; without it the backend only sees many + /// small writes. + /// + public interface ISQLiteVirtualFileWithSizeHint : ISQLiteVirtualFile + { + void SetSizeHint(long size); + } + + /// + /// Storage backend injected into SQLite through . + /// Paths are whatever SQLite passes to the VFS: the database file, its + /// journal, and temporary files all flow through this interface. + /// + public interface ISQLiteVirtualFileSystem + { + bool Exists(string path); + ISQLiteVirtualFile Open(string path, SQLiteVirtualFileOpenFlags flags); + void Delete(string path); + string GetFullPath(string path); + } + + /// + /// Registers managed virtual filesystems with SQLite. Open a connection + /// with after registering. + /// + /// The VFS is single-connection per database file: a second open of the + /// same path returns SQLITE_BUSY, locking is a no-op, and WAL is not + /// supported. Use journal_mode=DELETE (the default) and close every + /// connection before unregistering. + /// + public static class SQLiteVfs + { + private const int SQLITE_OK = 0; + private const int SQLITE_BUSY = 5; + private const int SQLITE_IOERR = 10; + private const int SQLITE_NOTFOUND = 12; + private const int SQLITE_CANTOPEN = 14; + private const int SQLITE_IOERR_SHORT_READ = 522; + private const int SQLITE_OPEN_READONLY = 0x00000001; + private const int SQLITE_OPEN_READWRITE = 0x00000002; + private const int SQLITE_OPEN_CREATE = 0x00000004; + private const int SQLITE_OPEN_DELETEONCLOSE = 0x00000008; + private const int SQLITE_OPEN_EXCLUSIVE = 0x00000010; + + private static string _lastError; + private static readonly object Gate = new object(); + private static readonly Dictionary Registrations = + new Dictionary(StringComparer.Ordinal); + + private static readonly OpenCallback OpenDelegate = OnOpen; + private static readonly DeleteCallback DeleteDelegate = OnDelete; + private static readonly AccessCallback AccessDelegate = OnAccess; + private static readonly FullPathnameCallback FullPathnameDelegate = OnFullPathname; + private static readonly RandomnessCallback RandomnessDelegate = OnRandomness; + private static readonly SleepCallback SleepDelegate = OnSleep; + private static readonly CurrentTimeCallback CurrentTimeDelegate = OnCurrentTime; + private static readonly GetLastErrorCallback GetLastErrorDelegate = OnGetLastError; + private static readonly CloseCallback CloseDelegate = OnClose; + private static readonly ReadCallback ReadDelegate = OnRead; + private static readonly WriteCallback WriteDelegate = OnWrite; + private static readonly TruncateCallback TruncateDelegate = OnTruncate; + private static readonly SyncCallback SyncDelegate = OnSync; + private static readonly FileSizeCallback FileSizeDelegate = OnFileSize; + private static readonly LockCallback LockDelegate = OnLock; + private static readonly UnlockCallback UnlockDelegate = OnUnlock; + private static readonly CheckReservedLockCallback CheckReservedLockDelegate = OnCheckReservedLock; + private static readonly FileControlCallback FileControlDelegate = OnFileControl; + private static readonly SectorSizeCallback SectorSizeDelegate = OnSectorSize; + private static readonly DeviceCharacteristicsCallback DeviceCharacteristicsDelegate = OnDeviceCharacteristics; + + private static readonly IntPtr OpenPtr; + private static readonly IntPtr DeletePtr; + private static readonly IntPtr AccessPtr; + private static readonly IntPtr FullPathnamePtr; + private static readonly IntPtr RandomnessPtr; + private static readonly IntPtr SleepPtr; + private static readonly IntPtr CurrentTimePtr; + private static readonly IntPtr GetLastErrorPtr; + private static readonly IntPtr ClosePtr; + private static readonly IntPtr ReadPtr; + private static readonly IntPtr WritePtr; + private static readonly IntPtr TruncatePtr; + private static readonly IntPtr SyncPtr; + private static readonly IntPtr FileSizePtr; + private static readonly IntPtr LockPtr; + private static readonly IntPtr UnlockPtr; + private static readonly IntPtr CheckReservedLockPtr; + private static readonly IntPtr FileControlPtr; + private static readonly IntPtr SectorSizePtr; + private static readonly IntPtr DeviceCharacteristicsPtr; + private static readonly IntPtr IoMethodsPtr; + + static SQLiteVfs() + { + OpenPtr = Marshal.GetFunctionPointerForDelegate(OpenDelegate); + DeletePtr = Marshal.GetFunctionPointerForDelegate(DeleteDelegate); + AccessPtr = Marshal.GetFunctionPointerForDelegate(AccessDelegate); + FullPathnamePtr = Marshal.GetFunctionPointerForDelegate(FullPathnameDelegate); + RandomnessPtr = Marshal.GetFunctionPointerForDelegate(RandomnessDelegate); + SleepPtr = Marshal.GetFunctionPointerForDelegate(SleepDelegate); + CurrentTimePtr = Marshal.GetFunctionPointerForDelegate(CurrentTimeDelegate); + GetLastErrorPtr = Marshal.GetFunctionPointerForDelegate(GetLastErrorDelegate); + ClosePtr = Marshal.GetFunctionPointerForDelegate(CloseDelegate); + ReadPtr = Marshal.GetFunctionPointerForDelegate(ReadDelegate); + WritePtr = Marshal.GetFunctionPointerForDelegate(WriteDelegate); + TruncatePtr = Marshal.GetFunctionPointerForDelegate(TruncateDelegate); + SyncPtr = Marshal.GetFunctionPointerForDelegate(SyncDelegate); + FileSizePtr = Marshal.GetFunctionPointerForDelegate(FileSizeDelegate); + LockPtr = Marshal.GetFunctionPointerForDelegate(LockDelegate); + UnlockPtr = Marshal.GetFunctionPointerForDelegate(UnlockDelegate); + CheckReservedLockPtr = Marshal.GetFunctionPointerForDelegate(CheckReservedLockDelegate); + FileControlPtr = Marshal.GetFunctionPointerForDelegate(FileControlDelegate); + SectorSizePtr = Marshal.GetFunctionPointerForDelegate(SectorSizeDelegate); + DeviceCharacteristicsPtr = Marshal.GetFunctionPointerForDelegate(DeviceCharacteristicsDelegate); + + IoMethodsPtr = CreateIoMethods(); + } + + /// + /// Last exception caught by a VFS callback. SQLite's own + /// open-failure message is generic, so this is the place to see the + /// backend error (for example a WeChat FileSystemManager failure). + /// + public static string LastError + { + get { return _lastError; } + } + + public static void Register(string name, ISQLiteVirtualFileSystem fileSystem) + { + if (string.IsNullOrEmpty(name)) + throw new ArgumentException("A VFS name is required.", nameof(name)); + if (fileSystem == null) + throw new ArgumentNullException(nameof(fileSystem)); + + lock (Gate) + { + if (Registrations.ContainsKey(name)) + throw new InvalidOperationException("A VFS named '" + name + "' is already registered."); + + var registration = Registration.Create(name, fileSystem); + var rc = VfsRegister(registration.VfsPointer, 0); + if (rc != SQLITE_OK) + { + registration.Free(); + throw new InvalidOperationException( + "sqlite3_vfs_register('" + name + "') failed with code " + rc + "."); + } + + Registrations.Add(name, registration); + } + } + + public static void Unregister(string name) + { + if (string.IsNullOrEmpty(name)) + throw new ArgumentException("A VFS name is required.", nameof(name)); + + Registration registration; + lock (Gate) + { + if (!Registrations.TryGetValue(name, out registration)) + throw new InvalidOperationException("No VFS named '" + name + "' is registered."); + if (registration.HasActiveFiles) + throw new InvalidOperationException( + "Cannot unregister VFS '" + name + "' while connections are open."); + } + + var rc = VfsUnregister(registration.VfsPointer); + if (rc != SQLITE_OK) + throw new InvalidOperationException( + "sqlite3_vfs_unregister('" + name + "') failed with code " + rc + "."); + + lock (Gate) + { + Registrations.Remove(name); + } + registration.Free(); + } + + private static IntPtr CreateIoMethods() + { + var methods = new IoMethods + { + iVersion = 1, + xClose = ClosePtr, + xRead = ReadPtr, + xWrite = WritePtr, + xTruncate = TruncatePtr, + xSync = SyncPtr, + xFileSize = FileSizePtr, + xLock = LockPtr, + xUnlock = UnlockPtr, + xCheckReservedLock = CheckReservedLockPtr, + xFileControl = FileControlPtr, + xSectorSize = SectorSizePtr, + xDeviceCharacteristics = DeviceCharacteristicsPtr, + }; + var pointer = Marshal.AllocHGlobal(Marshal.SizeOf()); + Marshal.StructureToPtr(methods, pointer, false); + return pointer; + } + + private static int Fail(Exception exception, int result) + { + _lastError = exception.ToString(); + return result; + } + + private static Registration GetRegistration(IntPtr pVfs) + { + if (pVfs == IntPtr.Zero) + return null; + var vfs = Marshal.PtrToStructure(pVfs); + if (vfs.pAppData == IntPtr.Zero) + return null; + try + { + return GCHandle.FromIntPtr(vfs.pAppData).Target as Registration; + } + catch + { + return null; + } + } + + private static VfsFile GetFile(IntPtr pFile) + { + if (pFile == IntPtr.Zero) + return null; + var header = Marshal.PtrToStructure(pFile); + if (header.Handle == IntPtr.Zero) + return null; + try + { + return GCHandle.FromIntPtr(header.Handle).Target as VfsFile; + } + catch + { + return null; + } + } + + private static SQLiteVirtualFileOpenFlags MapFlags(int flags) + { + var result = (SQLiteVirtualFileOpenFlags)0; + if ((flags & SQLITE_OPEN_READONLY) != 0) + result |= SQLiteVirtualFileOpenFlags.ReadOnly; + if ((flags & SQLITE_OPEN_READWRITE) != 0) + result |= SQLiteVirtualFileOpenFlags.ReadWrite; + if ((flags & SQLITE_OPEN_CREATE) != 0) + result |= SQLiteVirtualFileOpenFlags.Create; + if ((flags & SQLITE_OPEN_DELETEONCLOSE) != 0) + result |= SQLiteVirtualFileOpenFlags.DeleteOnClose; + if ((flags & SQLITE_OPEN_EXCLUSIVE) != 0) + result |= SQLiteVirtualFileOpenFlags.Exclusive; + return result; + } + + private static string ReadUtf8(IntPtr pointer) + { + if (pointer == IntPtr.Zero) + return null; + var length = 0; + while (Marshal.ReadByte(pointer, length) != 0) + length++; + if (length == 0) + return string.Empty; + var bytes = new byte[length]; + Marshal.Copy(pointer, bytes, 0, length); + return Encoding.UTF8.GetString(bytes); + } + + private static IntPtr AllocUtf8(string value) + { + var bytes = Encoding.UTF8.GetBytes(value); + var pointer = Marshal.AllocHGlobal(bytes.Length + 1); + Marshal.Copy(bytes, 0, pointer, bytes.Length); + Marshal.WriteByte(pointer, bytes.Length, 0); + return pointer; + } + + private static void WriteUtf8(IntPtr destination, int capacity, string value) + { + var bytes = Encoding.UTF8.GetBytes(value); + var count = Math.Min(bytes.Length, capacity - 1); + if (count > 0) + Marshal.Copy(bytes, 0, destination, count); + Marshal.WriteByte(destination, count, 0); + } + +#if UNITY_2018_1_OR_NEWER + [AOT.MonoPInvokeCallback(typeof(OpenCallback))] +#endif + private static int OnOpen(IntPtr pVfs, IntPtr zName, IntPtr pFile, int flags, IntPtr pOutFlags) + { + Registration registration = null; + string path = null; + ISQLiteVirtualFile file = null; + try + { + registration = GetRegistration(pVfs); + if (registration == null) + return SQLITE_CANTOPEN; + + path = ReadUtf8(zName); + if (!registration.TryAcquireMainPath(path)) + return SQLITE_BUSY; + + file = registration.FileSystem.Open(path, MapFlags(flags)); + if (file == null) + { + registration.ReleaseMainPath(path); + return SQLITE_CANTOPEN; + } + + var vfsFile = new VfsFile + { + Registration = registration, + File = file, + Path = path, + DeleteOnClose = (flags & SQLITE_OPEN_DELETEONCLOSE) != 0, + }; + vfsFile.Handle = GCHandle.Alloc(vfsFile, GCHandleType.Normal); + + var header = new FileHeader + { + pMethods = IoMethodsPtr, + Handle = GCHandle.ToIntPtr(vfsFile.Handle), + }; + Marshal.StructureToPtr(header, pFile, false); + + if (pOutFlags != IntPtr.Zero) + Marshal.WriteInt32(pOutFlags, flags); + registration.AddActiveFile(); + return SQLITE_OK; + } + catch (Exception ex) + { + if (file != null) + { + try { file.Dispose(); } + catch (Exception disposeException) + { + System.Diagnostics.Debug.WriteLine(disposeException); + } + } + if (registration != null) + registration.ReleaseMainPath(path); + return Fail(ex, SQLITE_CANTOPEN); + } + } + +#if UNITY_2018_1_OR_NEWER + [AOT.MonoPInvokeCallback(typeof(DeleteCallback))] +#endif + private static int OnDelete(IntPtr pVfs, IntPtr zName, int _syncDir) + { + try + { + var registration = GetRegistration(pVfs); + if (registration == null) + return SQLITE_IOERR; + registration.FileSystem.Delete(ReadUtf8(zName)); + return SQLITE_OK; + } + catch (Exception ex) { return Fail(ex, SQLITE_IOERR); } + } + +#if UNITY_2018_1_OR_NEWER + [AOT.MonoPInvokeCallback(typeof(AccessCallback))] +#endif + private static int OnAccess(IntPtr pVfs, IntPtr zName, int _flags, IntPtr pResOut) + { + try + { + var registration = GetRegistration(pVfs); + var exists = registration != null && registration.FileSystem.Exists(ReadUtf8(zName)); + if (pResOut != IntPtr.Zero) + Marshal.WriteInt32(pResOut, exists ? 1 : 0); + return SQLITE_OK; + } + catch (Exception ex) { return Fail(ex, SQLITE_IOERR); } + } + +#if UNITY_2018_1_OR_NEWER + [AOT.MonoPInvokeCallback(typeof(FullPathnameCallback))] +#endif + private static int OnFullPathname(IntPtr pVfs, IntPtr zName, int nOut, IntPtr zOut) + { + try + { + var registration = GetRegistration(pVfs); + var path = ReadUtf8(zName); + var fullPath = registration != null + ? registration.FileSystem.GetFullPath(path) + : path; + if (fullPath == null || nOut <= 0) + return SQLITE_CANTOPEN; + + var bytes = Encoding.UTF8.GetBytes(fullPath); + if (bytes.Length >= nOut) + return SQLITE_CANTOPEN; + + WriteUtf8(zOut, nOut, fullPath); + return SQLITE_OK; + } + catch (Exception ex) { return Fail(ex, SQLITE_IOERR); } + } + +#if UNITY_2018_1_OR_NEWER + [AOT.MonoPInvokeCallback(typeof(RandomnessCallback))] +#endif + private static int OnRandomness(IntPtr _pVfs, int nByte, IntPtr zOut) + { + try + { + var remaining = nByte; + var offset = 0; + while (remaining > 0) + { + var bytes = Guid.NewGuid().ToByteArray(); + var count = Math.Min(remaining, bytes.Length); + Marshal.Copy(bytes, 0, IntPtr.Add(zOut, offset), count); + offset += count; + remaining -= count; + } + return SQLITE_OK; + } + catch (Exception ex) { return Fail(ex, SQLITE_IOERR); } + } + +#if UNITY_2018_1_OR_NEWER + [AOT.MonoPInvokeCallback(typeof(SleepCallback))] +#endif + private static int OnSleep(IntPtr _pVfs, int microseconds) + { + try + { + if (microseconds > 0) + Thread.Sleep(Math.Max(1, microseconds / 1000)); + return SQLITE_OK; + } + catch (Exception ex) { return Fail(ex, SQLITE_IOERR); } + } + +#if UNITY_2018_1_OR_NEWER + [AOT.MonoPInvokeCallback(typeof(CurrentTimeCallback))] +#endif + private static int OnCurrentTime(IntPtr _pVfs, IntPtr pTime) + { + try + { + var julianDay = DateTime.UtcNow.ToOADate() + 2415018.5; + Marshal.WriteInt64(pTime, BitConverter.DoubleToInt64Bits(julianDay)); + return SQLITE_OK; + } + catch (Exception ex) { return Fail(ex, SQLITE_IOERR); } + } + +#if UNITY_2018_1_OR_NEWER + [AOT.MonoPInvokeCallback(typeof(GetLastErrorCallback))] +#endif + private static int OnGetLastError(IntPtr _pVfs, int nByte, IntPtr zErrMsg) + { + var message = _lastError; + if (!string.IsNullOrEmpty(message) && nByte > 0 && zErrMsg != IntPtr.Zero) + WriteUtf8(zErrMsg, nByte, message); + return 0; + } + +#if UNITY_2018_1_OR_NEWER + [AOT.MonoPInvokeCallback(typeof(CloseCallback))] +#endif + private static int OnClose(IntPtr pFile) + { + try + { + var vfsFile = GetFile(pFile); + if (vfsFile == null) + return SQLITE_OK; + + var deleteOnClose = vfsFile.DeleteOnClose; + var registration = vfsFile.Registration; + var path = vfsFile.Path; + + try + { + vfsFile.File.Dispose(); + } + catch (Exception ex) { return Fail(ex, SQLITE_IOERR); } + finally + { + if (vfsFile.Handle.IsAllocated) + vfsFile.Handle.Free(); + Marshal.WriteIntPtr(pFile, IntPtr.Zero); + Marshal.WriteIntPtr(pFile, IntPtr.Size, IntPtr.Zero); + if (registration != null) + { + registration.ReleaseMainPath(path); + registration.RemoveActiveFile(); + } + } + + if (deleteOnClose && registration != null) + registration.FileSystem.Delete(path); + return SQLITE_OK; + } + catch (Exception ex) { return Fail(ex, SQLITE_IOERR); } + } + +#if UNITY_2018_1_OR_NEWER + [AOT.MonoPInvokeCallback(typeof(ReadCallback))] +#endif + private static int OnRead(IntPtr pFile, IntPtr buffer, int count, long fileOffset) + { + try + { + if (count <= 0) + return SQLITE_OK; + + var vfsFile = GetFile(pFile); + if (vfsFile == null) + return SQLITE_IOERR; + + var data = vfsFile.Buffer; + if (data == null || data.Length < count) + { + data = new byte[Math.Max(count, 4096)]; + vfsFile.Buffer = data; + } + + var read = vfsFile.File.Read(data, 0, count, fileOffset); + if (read < 0) + return SQLITE_IOERR; + if (read < count) + Array.Clear(data, read, count - read); + Marshal.Copy(data, 0, buffer, count); + return read < count ? SQLITE_IOERR_SHORT_READ : SQLITE_OK; + } + catch (Exception ex) { return Fail(ex, SQLITE_IOERR); } + } + +#if UNITY_2018_1_OR_NEWER + [AOT.MonoPInvokeCallback(typeof(WriteCallback))] +#endif + private static int OnWrite(IntPtr pFile, IntPtr buffer, int count, long fileOffset) + { + try + { + if (count <= 0) + return SQLITE_OK; + + var vfsFile = GetFile(pFile); + if (vfsFile == null) + return SQLITE_IOERR; + + var data = vfsFile.Buffer; + if (data == null || data.Length < count) + { + data = new byte[Math.Max(count, 4096)]; + vfsFile.Buffer = data; + } + + Marshal.Copy(buffer, data, 0, count); + return vfsFile.File.Write(data, 0, count, fileOffset) == count + ? SQLITE_OK + : SQLITE_IOERR; + } + catch (Exception ex) { return Fail(ex, SQLITE_IOERR); } + } + +#if UNITY_2018_1_OR_NEWER + [AOT.MonoPInvokeCallback(typeof(TruncateCallback))] +#endif + private static int OnTruncate(IntPtr pFile, long size) + { + try + { + var vfsFile = GetFile(pFile); + if (vfsFile == null) + return SQLITE_IOERR; + vfsFile.File.Truncate(size); + return SQLITE_OK; + } + catch (Exception ex) { return Fail(ex, SQLITE_IOERR); } + } + +#if UNITY_2018_1_OR_NEWER + [AOT.MonoPInvokeCallback(typeof(SyncCallback))] +#endif + private static int OnSync(IntPtr pFile, int flags) + { + try + { + var vfsFile = GetFile(pFile); + if (vfsFile == null) + return SQLITE_IOERR; + vfsFile.File.Sync(); + return SQLITE_OK; + } + catch (Exception ex) { return Fail(ex, SQLITE_IOERR); } + } + +#if UNITY_2018_1_OR_NEWER + [AOT.MonoPInvokeCallback(typeof(FileSizeCallback))] +#endif + private static int OnFileSize(IntPtr pFile, IntPtr pSize) + { + try + { + var vfsFile = GetFile(pFile); + if (vfsFile == null) + return SQLITE_IOERR; + Marshal.WriteInt64(pSize, vfsFile.File.Length); + return SQLITE_OK; + } + catch (Exception ex) { return Fail(ex, SQLITE_IOERR); } + } + +#if UNITY_2018_1_OR_NEWER + [AOT.MonoPInvokeCallback(typeof(LockCallback))] +#endif + private static int OnLock(IntPtr _pFile, int _lockType) + { + return SQLITE_OK; + } + +#if UNITY_2018_1_OR_NEWER + [AOT.MonoPInvokeCallback(typeof(UnlockCallback))] +#endif + private static int OnUnlock(IntPtr _pFile, int _lockType) + { + return SQLITE_OK; + } + +#if UNITY_2018_1_OR_NEWER + [AOT.MonoPInvokeCallback(typeof(CheckReservedLockCallback))] +#endif + private static int OnCheckReservedLock(IntPtr pFile, IntPtr pResOut) + { + if (pResOut != IntPtr.Zero) + Marshal.WriteInt32(pResOut, 0); + return SQLITE_OK; + } + +#if UNITY_2018_1_OR_NEWER + [AOT.MonoPInvokeCallback(typeof(FileControlCallback))] +#endif + private static int OnFileControl(IntPtr pFile, int op, IntPtr pArg) + { + // SQLITE_FCNTL_SIZE_HINT: give the backend a chance to preallocate. + if (op == 5 && pArg != IntPtr.Zero) + { + var vfsFile = GetFile(pFile); + var sizeHint = vfsFile != null + ? vfsFile.File as ISQLiteVirtualFileWithSizeHint + : null; + if (sizeHint != null) + { + sizeHint.SetSizeHint(Marshal.ReadInt64(pArg)); + return SQLITE_OK; + } + } + return SQLITE_NOTFOUND; + } + +#if UNITY_2018_1_OR_NEWER + [AOT.MonoPInvokeCallback(typeof(SectorSizeCallback))] +#endif + private static int OnSectorSize(IntPtr _pFile) + { + return 4096; + } + +#if UNITY_2018_1_OR_NEWER + [AOT.MonoPInvokeCallback(typeof(DeviceCharacteristicsCallback))] +#endif + private static int OnDeviceCharacteristics(IntPtr _pFile) + { + return 0; + } + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + private delegate int OpenCallback(IntPtr pVfs, IntPtr zName, IntPtr pFile, int flags, IntPtr pOutFlags); + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + private delegate int DeleteCallback(IntPtr pVfs, IntPtr zName, int syncDir); + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + private delegate int AccessCallback(IntPtr pVfs, IntPtr zName, int flags, IntPtr pResOut); + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + private delegate int FullPathnameCallback(IntPtr pVfs, IntPtr zName, int nOut, IntPtr zOut); + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + private delegate int RandomnessCallback(IntPtr pVfs, int nByte, IntPtr zOut); + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + private delegate int SleepCallback(IntPtr pVfs, int microseconds); + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + private delegate int CurrentTimeCallback(IntPtr pVfs, IntPtr pTime); + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + private delegate int GetLastErrorCallback(IntPtr pVfs, int nByte, IntPtr zErrMsg); + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + private delegate int CloseCallback(IntPtr pFile); + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + private delegate int ReadCallback(IntPtr pFile, IntPtr buffer, int count, long fileOffset); + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + private delegate int WriteCallback(IntPtr pFile, IntPtr buffer, int count, long fileOffset); + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + private delegate int TruncateCallback(IntPtr pFile, long size); + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + private delegate int SyncCallback(IntPtr pFile, int flags); + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + private delegate int FileSizeCallback(IntPtr pFile, IntPtr pSize); + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + private delegate int LockCallback(IntPtr pFile, int lockType); + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + private delegate int UnlockCallback(IntPtr pFile, int lockType); + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + private delegate int CheckReservedLockCallback(IntPtr pFile, IntPtr pResOut); + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + private delegate int FileControlCallback(IntPtr pFile, int op, IntPtr pArg); + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + private delegate int SectorSizeCallback(IntPtr pFile); + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + private delegate int DeviceCharacteristicsCallback(IntPtr pFile); + + [StructLayout(LayoutKind.Sequential)] + private struct Vfs + { + public int iVersion; + public int szOsFile; + public int mxPathname; + public IntPtr pNext; + public IntPtr zName; + public IntPtr pAppData; + public IntPtr xOpen; + public IntPtr xDelete; + public IntPtr xAccess; + public IntPtr xFullPathname; + public IntPtr xDlOpen; + public IntPtr xDlError; + public IntPtr xDlSym; + public IntPtr xDlClose; + public IntPtr xRandomness; + public IntPtr xSleep; + public IntPtr xCurrentTime; + public IntPtr xGetLastError; + public IntPtr xCurrentTimeInt64; + public IntPtr xSetSystemCall; + public IntPtr xGetSystemCall; + public IntPtr xNextSystemCall; + } + + [StructLayout(LayoutKind.Sequential)] + private struct IoMethods + { + public int iVersion; + public IntPtr xClose; + public IntPtr xRead; + public IntPtr xWrite; + public IntPtr xTruncate; + public IntPtr xSync; + public IntPtr xFileSize; + public IntPtr xLock; + public IntPtr xUnlock; + public IntPtr xCheckReservedLock; + public IntPtr xFileControl; + public IntPtr xSectorSize; + public IntPtr xDeviceCharacteristics; + } + + [StructLayout(LayoutKind.Sequential)] + private struct FileHeader + { + public IntPtr pMethods; + public IntPtr Handle; + } + + private sealed class VfsFile + { + public Registration Registration; + public ISQLiteVirtualFile File; + public string Path; + public bool DeleteOnClose; + public GCHandle Handle; + public byte[] Buffer; + } + + private sealed class Registration + { + public ISQLiteVirtualFileSystem FileSystem; + public IntPtr VfsPointer; + public IntPtr NamePtr; + public GCHandle Self; + + private readonly object _pathsGate = new object(); + private readonly HashSet _openMainPaths = + new HashSet(StringComparer.Ordinal); + private int _activeFiles; + + public bool HasActiveFiles + { + get + { + lock (_pathsGate) + { + return _activeFiles > 0; + } + } + } + + public void AddActiveFile() + { + lock (_pathsGate) + { + _activeFiles++; + } + } + + public void RemoveActiveFile() + { + lock (_pathsGate) + { + if (_activeFiles > 0) + _activeFiles--; + } + } + + public bool TryAcquireMainPath(string path) + { + if (string.IsNullOrEmpty(path) || IsAuxiliaryPath(path)) + return true; + lock (_pathsGate) + { + return _openMainPaths.Add(path); + } + } + + public void ReleaseMainPath(string path) + { + if (string.IsNullOrEmpty(path) || IsAuxiliaryPath(path)) + return; + lock (_pathsGate) + { + _openMainPaths.Remove(path); + } + } + + private static bool IsAuxiliaryPath(string path) + { + return path.EndsWith("-journal", StringComparison.Ordinal) + || path.EndsWith("-wal", StringComparison.Ordinal) + || path.EndsWith("-shm", StringComparison.Ordinal); + } + + public static Registration Create(string name, ISQLiteVirtualFileSystem fileSystem) + { + var registration = new Registration + { + FileSystem = fileSystem, + NamePtr = AllocUtf8(name), + }; + registration.Self = GCHandle.Alloc(registration); + registration.VfsPointer = Marshal.AllocHGlobal(Marshal.SizeOf()); + var vfs = new Vfs + { + iVersion = 1, + szOsFile = Marshal.SizeOf(), + mxPathname = 1024, + pNext = IntPtr.Zero, + zName = registration.NamePtr, + pAppData = GCHandle.ToIntPtr(registration.Self), + xOpen = OpenPtr, + xDelete = DeletePtr, + xAccess = AccessPtr, + xFullPathname = FullPathnamePtr, + xDlOpen = IntPtr.Zero, + xDlError = IntPtr.Zero, + xDlSym = IntPtr.Zero, + xDlClose = IntPtr.Zero, + xRandomness = RandomnessPtr, + xSleep = SleepPtr, + xCurrentTime = CurrentTimePtr, + xGetLastError = GetLastErrorPtr, + xCurrentTimeInt64 = IntPtr.Zero, + xSetSystemCall = IntPtr.Zero, + xGetSystemCall = IntPtr.Zero, + xNextSystemCall = IntPtr.Zero, + }; + Marshal.StructureToPtr(vfs, registration.VfsPointer, false); + return registration; + } + + public void Free() + { + if (Self.IsAllocated) + Self.Free(); + if (NamePtr != IntPtr.Zero) + Marshal.FreeHGlobal(NamePtr); + if (VfsPointer != IntPtr.Zero) + Marshal.FreeHGlobal(VfsPointer); + Self = default(GCHandle); + NamePtr = IntPtr.Zero; + VfsPointer = IntPtr.Zero; + } + } + + [DllImport(SQLite3.LibraryPath, EntryPoint = "sqlite3_vfs_register", CallingConvention = CallingConvention.Cdecl)] + private static extern int VfsRegister(IntPtr vfs, int makeDflt); + + [DllImport(SQLite3.LibraryPath, EntryPoint = "sqlite3_vfs_unregister", CallingConvention = CallingConvention.Cdecl)] + private static extern int VfsUnregister(IntPtr vfs); + } + + /// + /// Default backed by System.IO. + /// On WebGL this uses Emscripten's filesystem; WeChat needs its own + /// FileSystemManager implementation. + /// + public sealed class SQLiteFileSystem : ISQLiteVirtualFileSystem + { + public bool Exists(string path) + { + return File.Exists(path); + } + + public ISQLiteVirtualFile Open(string path, SQLiteVirtualFileOpenFlags flags) + { + var access = (flags & SQLiteVirtualFileOpenFlags.ReadOnly) != 0 + ? FileAccess.Read + : FileAccess.ReadWrite; + var mode = (flags & SQLiteVirtualFileOpenFlags.Create) != 0 + ? FileMode.OpenOrCreate + : FileMode.Open; + var stream = new FileStream( + path, + mode, + access, + FileShare.ReadWrite | FileShare.Delete, + 4096, + FileOptions.RandomAccess); + return new SQLiteFile(stream, path, + (flags & SQLiteVirtualFileOpenFlags.DeleteOnClose) != 0); + } + + public void Delete(string path) + { + if (File.Exists(path)) + File.Delete(path); + } + + public string GetFullPath(string path) + { + return Path.GetFullPath(path); + } + + private sealed class SQLiteFile : ISQLiteVirtualFileWithSizeHint + { + private readonly FileStream _stream; + private readonly string _path; + private readonly bool _deleteOnClose; + + public SQLiteFile(FileStream stream, string path, bool deleteOnClose) + { + _stream = stream; + _path = path; + _deleteOnClose = deleteOnClose; + } + + public long Length + { + get { return _stream.Length; } + } + + public int Read(byte[] buffer, int offset, int count, long fileOffset) + { + _stream.Position = fileOffset; + var total = 0; + while (total < count) + { + var read = _stream.Read(buffer, offset + total, count - total); + if (read == 0) + break; + total += read; + } + return total; + } + + public int Write(byte[] buffer, int offset, int count, long fileOffset) + { + _stream.Position = fileOffset; + _stream.Write(buffer, offset, count); + return count; + } + + public void Truncate(long length) + { + _stream.SetLength(length); + } + + public void Sync() + { + try + { + _stream.Flush(true); + } + catch (NotSupportedException) + { + _stream.Flush(); + } + } + + public void SetSizeHint(long size) + { + // FileStream has no portable preallocation; the hint is advisory. + } + + public void Dispose() + { + _stream.Dispose(); + if (_deleteOnClose && File.Exists(_path)) + File.Delete(_path); + } + } + } +} +#endif + + + diff --git a/Runtime/sqlite-net/SQLiteVirtualFileSystem.cs.meta b/Runtime/sqlite-net/SQLiteVirtualFileSystem.cs.meta new file mode 100644 index 0000000..d0e9da0 --- /dev/null +++ b/Runtime/sqlite-net/SQLiteVirtualFileSystem.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: d2e2de229c0346048fb7d952f56c0daa +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Tests/Editor/TestVirtualFileSystem.cs b/Tests/Editor/TestVirtualFileSystem.cs new file mode 100644 index 0000000..caf6182 --- /dev/null +++ b/Tests/Editor/TestVirtualFileSystem.cs @@ -0,0 +1,290 @@ +#if !USE_CSHARP_SQLITE && !USE_WP8_NATIVE_SQLITE && !USE_SQLITEPCL_RAW && !UNITY_VISIONOS +using System; +using System.Collections.Generic; +using System.Linq; +using NUnit.Framework; +using SQLite; + +// ReSharper disable once CheckNamespace +namespace Gilzoide.SqliteNet.Tests.Editor +{ + public class TestVirtualFileSystem + { + [Test] + public void VirtualFileSystemRoundTripsDatabase() + { + var fileSystem = new MemoryVirtualFileSystem(); + var vfsName = "test-vfs-" + Guid.NewGuid().ToString("N"); + SQLiteVfs.Register(vfsName, fileSystem); + try + { + using (var db = Open(vfsName, "game.sqlite")) + { + db.CreateTable(); + db.Insert(new VfsRow { Id = 1, Name = "hello" }); + } + + Assert.IsTrue(fileSystem.Exists("game.sqlite")); + + using (var db = Open(vfsName, "game.sqlite")) + { + var row = db.Find(1); + Assert.IsNotNull(row); + Assert.AreEqual("hello", row.Name); + } + } + finally + { + SQLiteVfs.Unregister(vfsName); + } + } + + [Test] + public void VirtualFileSystemCanBeUnregistered() + { + var vfsName = "test-vfs-" + Guid.NewGuid().ToString("N"); + SQLiteVfs.Register(vfsName, new MemoryVirtualFileSystem()); + SQLiteVfs.Unregister(vfsName); + + Assert.Throws(() => SQLiteVfs.Unregister(vfsName)); + } + + [Test] + public void VirtualFileSystemUsesJournal() + { + var fileSystem = new MemoryVirtualFileSystem(); + var vfsName = "test-vfs-" + Guid.NewGuid().ToString("N"); + SQLiteVfs.Register(vfsName, fileSystem); + try + { + using (var db = Open(vfsName, "journal.sqlite")) + { + db.CreateTable(); + db.Insert(new VfsRow { Id = 1, Name = "journal" }); + } + + Assert.IsTrue(fileSystem.OpenedPaths.Any(path => path.EndsWith("-journal"))); + } + finally + { + SQLiteVfs.Unregister(vfsName); + } + } + + [Test] + public void SecondConnectionIsRejected() + { + var fileSystem = new MemoryVirtualFileSystem(); + var vfsName = "test-vfs-" + Guid.NewGuid().ToString("N"); + SQLiteVfs.Register(vfsName, fileSystem); + try + { + using (var first = Open(vfsName, "locked.sqlite")) + { + first.CreateTable(); + Assert.Throws(() => + { + using var second = Open(vfsName, "locked.sqlite"); + }); + } + + using (var reopened = Open(vfsName, "locked.sqlite")) + { + Assert.AreEqual(0, reopened.Table().Count()); + } + } + finally + { + SQLiteVfs.Unregister(vfsName); + } + } + + [Test] + public void OpenFailureRecordsBackendError() + { + var vfsName = "test-vfs-" + Guid.NewGuid().ToString("N"); + SQLiteVfs.Register(vfsName, new ThrowingFileSystem()); + try + { + var exception = Assert.Throws( + () => Open(vfsName, "missing.sqlite")); + StringAssert.Contains("missing.sqlite", exception.Message); + StringAssert.Contains("boom", SQLiteVfs.LastError); + } + finally + { + SQLiteVfs.Unregister(vfsName); + } + } + + [Test] + public void DefaultFileSystemRoundTripsDatabase() + { + var vfsName = "test-fs-" + Guid.NewGuid().ToString("N"); + var path = System.IO.Path.Combine( + System.IO.Path.GetTempPath(), + "sqlite-vfs-" + Guid.NewGuid().ToString("N") + ".sqlite"); + SQLiteVfs.Register(vfsName, new SQLiteFileSystem()); + try + { + using (var db = Open(vfsName, path)) + { + db.CreateTable(); + db.Insert(new VfsRow { Id = 1, Name = "default" }); + } + + using (var db = Open(vfsName, path)) + { + Assert.AreEqual("default", db.Find(1).Name); + } + } + finally + { + SQLiteVfs.Unregister(vfsName); + if (System.IO.File.Exists(path)) + System.IO.File.Delete(path); + } + } + + private static SQLiteConnection Open(string vfsName, string path) + { + return new SQLiteConnection(new SQLiteConnectionString( + path, + SQLiteOpenFlags.Create | SQLiteOpenFlags.ReadWrite, + storeDateTimeAsTicks: true, + vfsName: vfsName)); + } + + public sealed class VfsRow + { + [PrimaryKey] + public int Id { get; set; } + + public string Name { get; set; } + } + + private sealed class ThrowingFileSystem : ISQLiteVirtualFileSystem + { + public bool Exists(string path) + { + return false; + } + + public ISQLiteVirtualFile Open(string path, SQLiteVirtualFileOpenFlags flags) + { + throw new System.IO.IOException("boom"); + } + + public void Delete(string path) + { + } + + public string GetFullPath(string path) + { + return path; + } + } + + private sealed class MemoryVirtualFileSystem : ISQLiteVirtualFileSystem + { + private readonly Dictionary _files = + new Dictionary(StringComparer.Ordinal); + + public readonly HashSet OpenedPaths = + new HashSet(StringComparer.Ordinal); + + public bool Exists(string path) + { + return _files.ContainsKey(path); + } + + public ISQLiteVirtualFile Open(string path, SQLiteVirtualFileOpenFlags flags) + { + OpenedPaths.Add(path); + byte[] data; + if (!_files.TryGetValue(path, out data)) + { + if ((flags & SQLiteVirtualFileOpenFlags.Create) == 0) + return null; + data = Array.Empty(); + _files[path] = data; + } + return new MemoryVirtualFile(this, path, data); + } + + public void Delete(string path) + { + _files.Remove(path); + } + + public string GetFullPath(string path) + { + return path; + } + + internal void Set(string path, byte[] data) + { + _files[path] = data; + } + + private sealed class MemoryVirtualFile : ISQLiteVirtualFile + { + private readonly MemoryVirtualFileSystem _fileSystem; + private readonly string _path; + private byte[] _data; + + public MemoryVirtualFile( + MemoryVirtualFileSystem fileSystem, + string path, + byte[] data) + { + _fileSystem = fileSystem; + _path = path; + _data = data; + } + + public long Length + { + get { return _data.Length; } + } + + public int Read(byte[] buffer, int offset, int count, long fileOffset) + { + if (fileOffset >= _data.Length) + return 0; + var available = (int)Math.Min(count, _data.Length - fileOffset); + Array.Copy(_data, (int)fileOffset, buffer, offset, available); + return available; + } + + public int Write(byte[] buffer, int offset, int count, long fileOffset) + { + var required = (int)(fileOffset + count); + if (_data.Length < required) + Array.Resize(ref _data, required); + Array.Copy(buffer, offset, _data, (int)fileOffset, count); + _fileSystem.Set(_path, _data); + return count; + } + + public void Truncate(long length) + { + Array.Resize(ref _data, (int)length); + _fileSystem.Set(_path, _data); + } + + public void Sync() + { + } + + public void Dispose() + { + _fileSystem.Set(_path, _data); + } + } + } + } +} +#endif + + diff --git a/Tests/Editor/TestVirtualFileSystem.cs.meta b/Tests/Editor/TestVirtualFileSystem.cs.meta new file mode 100644 index 0000000..518d2bc --- /dev/null +++ b/Tests/Editor/TestVirtualFileSystem.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 40c3f5e6e39f4653a639f2acc828cbdd +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: