📄 osfile.cs
字号:
namespace Perst.Impl
{
using System;
using System.IO;
using System.Runtime.InteropServices;
using Perst;
public class OSFile : IFile
{
[DllImport("kernel32.dll", SetLastError=true)]
static extern int FlushFileBuffers(int hFile);
public virtual void Write(long pos, byte[] buf)
{
file.Seek(pos, SeekOrigin.Begin);
file.Write(buf, 0, buf.Length);
}
public virtual int Read(long pos, byte[] buf)
{
file.Seek(pos, SeekOrigin.Begin);
return file.Read(buf, 0, buf.Length);
}
public virtual void Sync()
{
file.Flush();
#if !COMPACT_NET_FRAMEWORK
if (!noFlush) {
#if NET_FRAMEWORK_20
FlushFileBuffers(file.SafeFileHandle.DangerousGetHandle().ToInt32());
#else
FlushFileBuffers(file.Handle.ToInt32());
#endif
}
#endif
}
public bool NoFlush
{
get { return this.noFlush; }
set { this.noFlush = value; }
}
public virtual void Close()
{
file.Close();
}
public virtual void Lock()
{
#if !COMPACT_NET_FRAMEWORK
file.Lock(0, long.MaxValue);
#endif
}
public long Length
{
get { return file.Length; }
}
internal OSFile(String filePath, bool readOnly, bool noFlush)
{
this.noFlush = noFlush;
file = new FileStream(filePath, FileMode.OpenOrCreate,
readOnly ? FileAccess.Read : FileAccess.ReadWrite);
}
protected FileStream file;
protected bool noFlush;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -