Ejemplo n.º 1
0
        public static unsafe bool WriteToDisk(FixedString128 gameSaveFilePath, MemoryBinaryWriter writer)
        {
            Baselib_ErrorState errorState = new Baselib_ErrorState();

            Baselib_FileIO_SyncFile gameSaveFileHandle = Baselib_FileIO_SyncOpen(gameSaveFilePath.GetUnsafePtr(), Baselib_FileIO_OpenFlags.CreateAlways | Baselib_FileIO_OpenFlags.Write, &errorState);

            if (errorState.code != Baselib_ErrorCode.Success)
            {
                return(false);
            }

            Baselib_FileIO_SyncWrite(gameSaveFileHandle, 0, (IntPtr)writer.Data, (uint)writer.Length, &errorState);
            if (errorState.code != Baselib_ErrorCode.Success)
            {
                return(false);
            }

            Baselib_FileIO_SyncFlush(gameSaveFileHandle, &errorState);
            if (errorState.code != Baselib_ErrorCode.Success)
            {
                return(false);
            }

            // If we get this far, we'll consider the write a success because it should have been completed.
            Baselib_FileIO_SyncClose(gameSaveFileHandle, &errorState);
            return(true);
        }
Ejemplo n.º 2
0
        public static unsafe bool ReadFromDisk(FixedString128 gameSaveFilePath)
        {
            Baselib_ErrorState      errorState = new Baselib_ErrorState();
            Baselib_FileIO_SyncFile fileHandle = Baselib_FileIO_SyncOpen(gameSaveFilePath.GetUnsafePtr(), Baselib_FileIO_OpenFlags.Read, &errorState);

            if (errorState.code != Baselib_ErrorCode.Success)
            {
                return(false);
            }

            GameSaveFile gameSaveFile;

            gameSaveFile.filePath   = gameSaveFilePath;
            gameSaveFile.fileHandle = fileHandle;
            gameSaveReadFiles.Add(gameSaveFile);
            return(true);
        }
Ejemplo n.º 3
0
        public unsafe void LoadSoundClipFromDisk(EntityManager mgr, Entity e, string filePath)
        {
            DynamicBuffer <AudioClipCompressed> audioClipCompressed = mgr.GetBuffer <AudioClipCompressed>(e);

            if (audioClipCompressed.Length > 0)
            {
                return;
            }

#if UNITY_ANDROID
            var op = IOService.RequestAsyncRead(filePath);
            while (op.GetStatus() <= AsyncOp.Status.InProgress)
            {
                ;
            }

            op.GetData(out byte *data, out int sizeInBytes);
            audioClipCompressed.ResizeUninitialized(sizeInBytes);
            byte *audioClipCompressedBytes = (byte *)audioClipCompressed.GetUnsafePtr();
            for (int i = 0; i < sizeInBytes; i++)
            {
                audioClipCompressedBytes[i] = data[i];
            }

            op.Dispose();
#else
            FixedString512          filePathFixedString = new FixedString512(filePath);
            Baselib_ErrorState      errorState          = new Baselib_ErrorState();
            Baselib_FileIO_SyncFile fileHandle          = Baselib_FileIO_SyncOpen(filePathFixedString.GetUnsafePtr(), Baselib_FileIO_OpenFlags.Read, &errorState);
            if (errorState.code != Baselib_ErrorCode.Success)
            {
                return;
            }

            UInt64 fileSize = Baselib_FileIO_SyncGetFileSize(fileHandle, &errorState);
            if (fileSize > Int32.MaxValue)
            {
                Baselib_FileIO_SyncClose(fileHandle, &errorState);
                return;
            }

            audioClipCompressed.ResizeUninitialized((int)fileSize);
            UInt64 bytesRead = Baselib_FileIO_SyncRead(fileHandle, 0, (IntPtr)audioClipCompressed.GetUnsafePtr(), (ulong)audioClipCompressed.Length, &errorState);
            Baselib_FileIO_SyncClose(fileHandle, &errorState);
#endif
        }
 public static extern void Baselib_FileIO_SyncClose(Baselib_FileIO_SyncFile file, Baselib_ErrorState *errorState);
 public static extern UInt64 Baselib_FileIO_SyncGetFileSize(Baselib_FileIO_SyncFile file, Baselib_ErrorState *errorState);
 public static extern void Baselib_FileIO_SyncSetFileSize(Baselib_FileIO_SyncFile file, UInt64 size, Baselib_ErrorState *errorState);
 public static extern UInt64 Baselib_FileIO_SyncWrite(Baselib_FileIO_SyncFile file, UInt64 offset, IntPtr buffer, UInt64 size, Baselib_ErrorState *errorState);