?? osfile.cs
字號(hào):
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;
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -