MiniblinkNet/MemoryFileSystem.cs

(开头部分) 5KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using System.IO;

namespace Kyozy.MiniblinkNet
{
    /// <summary>
    /// 内存文件系统,订阅 OnDataLoaded 事件,并在事件参数中设置内存数据
    /// </summary>
    public class MemoryFileSystem : FileSystem
    {
        //private Dictionary<GCHandle, MemoryStream> m_strems;
        /// <summary>
        /// 数据载入事件
        /// </summary>
        public event EventHandler<DataLoadedEventArgs> OnDataLoaded;

        public override IntPtr FileOpen(IntPtr Path)
        {
            string fileName = Help.PtrToStringUTF8(Path);
            if (OnDataLoaded != null)
            {
                DataLoadedEventArgs e = new DataLoadedEventArgs(fileName);
                OnDataLoaded(this, e);
                if (e.Data == null)
                {
                    e.Data = File.ReadAllBytes(fileName);
                    if (e.Data == null)
                    {
                        return IntPtr.Zero;
                    }
                }
                MemoryStream ms = new MemoryStream(e.Data);
                GCHandle handle = GCHandle.Alloc(ms);
                return GCHandle.ToIntPtr(handle);

            }
            return IntPtr.Zero;
        }

        public override void FileClose(IntPtr handle)
        {
            try
            {
                if (handle != IntPtr.Zero)
                {
                    GCHandle gch = GCHandle.FromIntPtr(handle);
                    MemoryStream ms = (MemoryStream)gch.Target;
                    ms.Dispose();
                    gch.Free();
                }
            }
            catch (InvalidOperationException e)
            {
                System.Windows.Forms.MessageBox.Show(e.Message);
            }

后面还有 135 行代码,解锁后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明

AI 解读 AI

登录后可用,每次 10 算力,解读结果公开显示在下面。

还没有人解读过这个文件。