public unsafe static LzHandle LzOpenFile( string path, OpenFileStyle openStyle = OpenFileStyle.Read | OpenFileStyle.ShareCompat) { OFSTRUCT ofs = new OFSTRUCT(); return(new LzHandle(ValidateLzResult(Imports.LZOpenFileW(path, ref ofs, openStyle), path))); }
public unsafe static LzHandle LzOpenFile( string path, out string uncompressedName, OpenFileStyle openStyle = OpenFileStyle.Read | OpenFileStyle.ShareCompat) { OFSTRUCT ofs = new OFSTRUCT(); int result = ValidateLzResult(Imports.LZOpenFileW(path, ref ofs, openStyle), path); uncompressedName = BufferHelper.GetNullTerminatedAsciiString(ofs.szPathName); return(new LzHandle(result)); }
/// <summary> /// /// </summary> /// <param name="FileName"></param> /// <param name="protection"></param> /// <param name="name"></param> /// <param name="access"></param> /// <returns></returns> public bool OpenEx(string FileName, MapProtection protection, string name, MapAccess access) { bool RV = false; m_hMap = Win32MapApis.OpenFileMapping((int)access, false, name); if (m_hMap == NULL_HANDLE) { if (System.IO.File.Exists(GetMMFDir() + FileName)) { long maxSize; System.IO.FileStream stream = System.IO.File.Open(GetMMFDir() + FileName, System.IO.FileMode.Open); maxSize = stream.Length; stream.Close(); IntPtr hFile = INVALID_HANDLE_VALUE; OFSTRUCT ipStruct = new OFSTRUCT(); string MMFName = GetMMFDir() + FileName; hFile = Win32MapApis.OpenFile(MMFName, ipStruct , 2); // determine file access needed // we'll always need generic read access int desiredAccess = GENERIC_READ; if ((protection == MapProtection.PageReadWrite) || (protection == MapProtection.PageWriteCopy)) { desiredAccess |= GENERIC_WRITE; } // open or create the file // if it doesn't exist, it gets created m_hMap = Win32MapApis.CreateFileMapping( hFile, IntPtr.Zero, (int)protection, (int)((maxSize >> 32) & 0xFFFFFFFF), (int)(maxSize & 0xFFFFFFFF), name ); // close file handle, we don't need it if (!(hFile == NULL_HANDLE)) { Win32MapApis.CloseHandle(hFile); } RV = true; } } else { RV = true; } return(RV); }
public static extern CustomFileSafeHandle OpenFile2([MarshalAs(UnmanagedType.LPStr)] string lpFileName, out OFSTRUCT lpReOpenBuff, long uStyle);
public static extern IntPtr OpenFile([MarshalAs(UnmanagedType.LPStr)] string lpFileName, out OFSTRUCT lpReOpenBuff, long uStyle);
public static extern int LZOpenFileA([MarshalAs(UnmanagedType.LPStr)] System.Text.StringBuilder param0, ref OFSTRUCT param1, ushort param2);
public static extern int OpenFile([System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPStr)] string lpFileName, out OFSTRUCT lpReOpenBuff, OpenFileStyle uStyle);
public static extern IntPtr OpenFile(String lpFileName, [Out, MarshalAs(UnmanagedType.LPStruct)] OFSTRUCT lpReOpenBuff, int uStyle);
private void InnerOpen() { if (string.IsNullOrEmpty(_fileName)) { throw new Exception("必须设置磁盘文件名称。"); } if (string.IsNullOrEmpty(_mappingName)) { throw new Exception("必须设置内存映射文件名称。"); } InnerClose(); if (_openMode == FileMappingOpenMode.Open) { mappingHandle = OpenFileMapping(FILE_MAP_ALL_ACCESS, 0, _mappingName); } else { if (_initialLength == 0) { throw new Exception("内存映射文件长度必须大于0。"); } fileHandle = CreateFile(_fileName, GENERIC_READ | GENERIC_WRITE, FileShare.Read | FileShare.Write, IntPtr.Zero, FileMode.OpenOrCreate, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, IntPtr.Zero); if ((int)fileHandle != INVALID_HANDLE_VALUE) { mappingHandle = CreateFileMapping(fileHandle, IntPtr.Zero, PAGE_READWRITE, 0, _initialLength, _mappingName); } } if (mappingHandle != IntPtr.Zero) { headHandle = MapViewOfFile(mappingHandle, FILE_MAP_COPY | FILE_MAP_READ | FILE_MAP_WRITE, 0, 0, IntPtr.Zero); if (headHandle != IntPtr.Zero) { if (_openMode == FileMappingOpenMode.Open) { OFSTRUCT fileStruct = new OFSTRUCT(); IntPtr handle = OpenFile(_fileName, ref fileStruct, OF_READ); if ((int)handle != INVALID_HANDLE_VALUE) { _length = GetFileSize(handle, IntPtr.Zero); CloseHandle(handle); } } else { _length = GetFileSize(fileHandle, IntPtr.Zero); } _opened = _length > 0; } } if (!_opened) { InnerClose(); if (_openMode == FileMappingOpenMode.Open) { throw new Exception("无法打开内存映射文件。"); } else { throw new Exception("无法创建内存映射文件。"); } } }
public static extern IntPtr OpenFile(string lpFileName, ref OFSTRUCT lpReOpenBuff, int wStyle);
public extern static IntPtr OpenFile([System.Runtime.InteropServices.In][System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPStr)] System.Text.StringBuilder lpFileName, ref OFSTRUCT lpReOpenBuff, Style uStyle);
public static extern int LZOpenFileW( string lpFileName, ref OFSTRUCT lpReOpenBuf, OpenFileStyle wStyle);
public static extern int OpenFile([In][MarshalAs(UnmanagedType.LPStr)] string lpFileName, ref OFSTRUCT lpReOpenBuff, uint uStyle);