예제 #1
0
        internal static SafeFileHandle GetFileHandle(string filename)
        {
            if (IsLongPath(filename))
            {
                filename = GetWin32LongPath(filename);
            }
            SafeFileHandle hfile = Win32FileSystem.CreateFile(filename, (int)Win32FileSystem.FILE_GENERIC_READ, Win32FileSystem.FILE_SHARE_READ, IntPtr.Zero, Win32FileSystem.OPEN_EXISTING, 0, IntPtr.Zero);

            if (hfile.IsInvalid)
            {
                ThrowWin32Exception();
            }
            return(hfile);
        }
예제 #2
0
        private static SafeFileHandle CreateFileForWrite(string filename)
        {
            if (IsLongPath(filename))
            {
                filename = GetWin32LongPath(filename);
            }
            SafeFileHandle hfile = Win32FileSystem.CreateFile(filename, (int)Win32FileSystem.FILE_GENERIC_WRITE, Win32FileSystem.FILE_SHARE_NONE, IntPtr.Zero, Win32FileSystem.CREATE_ALWAYS, 0, IntPtr.Zero);

            if (hfile.IsInvalid)
            {
                ThrowWin32Exception();
            }
            return(hfile);
        }
예제 #3
0
        internal static SafeFileHandle GetFileHandleWithWrite(string filename)
        {
            if (IsLongPath(filename))
            {
                filename = GetWin32LongPath(filename);
            }
//            SafeFileHandle hfile = Win32FileSystem.CreateFile(filename, (int)(Win32FileSystem.FILE_GENERIC_READ | Win32FileSystem.FILE_GENERIC_WRITE | Win32FileSystem.FILE_WRITE_ATTRIBUTES), Win32FileSystem.FILE_SHARE_NONE, IntPtr.Zero, Win32FileSystem.OPEN_EXISTING, 0, IntPtr.Zero);
            SafeFileHandle hfile = Win32FileSystem.CreateFile(filename, (int)(Win32FileSystem.FILE_GENERIC_READ), Win32FileSystem.FILE_SHARE_READ, IntPtr.Zero, Win32FileSystem.OPEN_EXISTING, 0, IntPtr.Zero);

            if (hfile.IsInvalid)
            {
                ThrowWin32Exception();
            }
            return(hfile);
        }
예제 #4
0
        public static System.IO.FileStream GetFileStream(string filename, System.IO.FileAccess access = System.IO.FileAccess.Read)
        {
            var            longFilename = GetWin32LongPath(filename);
            SafeFileHandle hfile;

            if (access == System.IO.FileAccess.Write)
            {
                hfile = Win32FileSystem.CreateFile(longFilename, (int)(Win32FileSystem.FILE_GENERIC_READ | Win32FileSystem.FILE_GENERIC_WRITE | Win32FileSystem.FILE_WRITE_ATTRIBUTES), Win32FileSystem.FILE_SHARE_NONE, IntPtr.Zero, Win32FileSystem.OPEN_EXISTING, 0, IntPtr.Zero);
            }
            else
            {
                hfile = Win32FileSystem.CreateFile(longFilename, (int)Win32FileSystem.FILE_GENERIC_READ, Win32FileSystem.FILE_SHARE_READ, IntPtr.Zero, Win32FileSystem.OPEN_EXISTING, 0, IntPtr.Zero);
            }

            if (hfile.IsInvalid)
            {
                ThrowWin32Exception();
            }

            return(new System.IO.FileStream(hfile, access));
        }