コード例 #1
0
ファイル: Kernel32.cs プロジェクト: ccl13/BlinkStickDotNet
 public static extern SafeFileHandle CreateFile(string fileName,
                                                [MarshalAs(UnmanagedType.U4)] NativeFileAccess fileAccess,
                                                [MarshalAs(UnmanagedType.U4)] NativeFileShare fileShare,
                                                IntPtr securityAttributes,
                                                [MarshalAs(UnmanagedType.U4)] NativeFileMode creationDisposition,
                                                NativeFileFlag flags,
                                                IntPtr template);
コード例 #2
0
 internal static extern IntPtr Create(
     string fileName,
     NativeFileAccess desiredAccess,
     NativeFileShare shareMode,
     IntPtr securityAttributes,
     NativeFileMode mode,
     NativeFileOptions flagsAndOptions,
     IntPtr templateFile);
コード例 #3
0
 internal static extern SafeFileHandle CreateFile(
     [In] string lpFileName,
     [In] NativeFileAccess dwDesiredAccess,
     [In] NativeFileShare dwShareMode,
     [In, Optional] IntPtr lpSecurityAttributes,
     [In] NativeFileMode dwCreationDisposition,
     [In] NativeFileOptions dwFlagsAndAttributes,
     [In, Optional] IntPtr hTemplateFile);
コード例 #4
0
ファイル: Win32Native.cs プロジェクト: alexey-bez/SharpDX
 internal static extern IntPtr Create(
     string fileName,
     NativeFileAccess desiredAccess,
     NativeFileShare shareMode,
     IntPtr securityAttributes,
     NativeFileMode mode,
     NativeFileOptions flagsAndOptions,
     IntPtr templateFile);
コード例 #5
0
ファイル: NativeFileStream.cs プロジェクト: Nezz/SharpDX
        /// <summary>
        /// Initializes a new instance of the <see cref="NativeFileStream"/> class.
        /// </summary>
        /// <param name="fileName">Name of the file.</param>
        /// <param name="fileMode">The file mode.</param>
        /// <param name="access">The access mode.</param>
        /// <param name="share">The share mode.</param>
        public unsafe NativeFileStream(string fileName, NativeFileMode fileMode, NativeFileAccess access, NativeFileShare share = NativeFileShare.Read)
        {
#if W8CORE
            //uint newAccess = 0;
            //const int FILE_ATTRIBUTE_NORMAL = 0x00000080;
            //const int FILE_FLAG_RANDOM_ACCESS = 0x10000000;
            //const int FILE_FLAG_SEQUENTIAL_SCAN = 0x08000000;

            //var extendedParams = default(NativeFile.CREATEFILE2_EXTENDED_PARAMETERS);
            //extendedParams.dwSize = (uint)Utilities.SizeOf<NativeFile.CREATEFILE2_EXTENDED_PARAMETERS>();
            //extendedParams.dwFileAttributes = FILE_ATTRIBUTE_NORMAL;
            //extendedParams.dwFileFlags = FILE_FLAG_RANDOM_ACCESS;
            //extendedParams.dwSecurityQosFlags = 0;
            //extendedParams.lpSecurityAttributes = IntPtr.Zero;
            //extendedParams.hTemplateFile = IntPtr.Zero;

            //if ((access & NativeFileAccess.Read) != 0)
            //{
            //    // Sets GENERIC_READ
            //    newAccess |= 0x00120089;
            //}

            //if ((access & NativeFileAccess.Write) != 0)
            //{
            //    newAccess |= 0x00120116;
            //}

            //if ((access & NativeFileAccess.Execute) != 0)
            //{
            //    newAccess |= 0x001200a0;
            //}
            //handle = NativeFile.Create(fileName, (NativeFileAccess)newAccess, share, fileMode, new IntPtr(&extendedParams));
            handle = NativeFile.Create(fileName, access, share, fileMode, IntPtr.Zero);
#else
            handle = NativeFile.Create(fileName, access, share, IntPtr.Zero, fileMode, NativeFileOptions.None, IntPtr.Zero);
#endif
            if (handle == new IntPtr(-1))
            {
                var lastWin32Error = MarshalGetLastWin32Error();
                if (lastWin32Error == 2)
                {
                    throw new FileNotFoundException("Unable to find file", fileName);
                }

                var lastError = Result.GetResultFromWin32Error(lastWin32Error);
                throw new IOException(string.Format(CultureInfo.InvariantCulture, "Unable to open file {0}", fileName), lastError.Code);
            }
            canRead = 0 != (access & NativeFileAccess.Read);
            canWrite = 0 != (access & NativeFileAccess.Write);

            // TODO how setup correctly canSeek flags? 
            // Kernel32.GetFileType(SafeFileHandle handle); is not available on W8CORE
            canSeek = true;

        }
コード例 #6
0
 private static extern SafeFileHandle CreateFileTransactedW(
     [In, MarshalAs(UnmanagedType.LPWStr)] string lpFileName,
     [In] NativeFileAccess dwDesiredAccess,
     [In] NativeFileShare dwShareMode,
     [In] IntPtr lpSecurityAttributes,
     [In] NativeFileMode dwCreationDisposition,
     [In] uint dwFlagsAndAttributes,
     [In] IntPtr hTemplateFile,
     [In] SafeTxHandle hTransaction,
     [In] IntPtr pusMiniVersion,
     [In] IntPtr pExtendedParameter);
コード例 #7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="NativeFileStream"/> class.
        /// </summary>
        /// <param name="fileName">Name of the file.</param>
        /// <param name="fileMode">The file mode.</param>
        /// <param name="access">The access mode.</param>
        /// <param name="share">The share mode.</param>
        public unsafe NativeFileStream(string fileName, NativeFileMode fileMode, NativeFileAccess access, NativeFileShare share = NativeFileShare.Read)
        {
#if W8CORE
            //uint newAccess = 0;
            //const int FILE_ATTRIBUTE_NORMAL = 0x00000080;
            //const int FILE_FLAG_RANDOM_ACCESS = 0x10000000;
            //const int FILE_FLAG_SEQUENTIAL_SCAN = 0x08000000;

            //var extendedParams = default(NativeFile.CREATEFILE2_EXTENDED_PARAMETERS);
            //extendedParams.dwSize = (uint)Utilities.SizeOf<NativeFile.CREATEFILE2_EXTENDED_PARAMETERS>();
            //extendedParams.dwFileAttributes = FILE_ATTRIBUTE_NORMAL;
            //extendedParams.dwFileFlags = FILE_FLAG_RANDOM_ACCESS;
            //extendedParams.dwSecurityQosFlags = 0;
            //extendedParams.lpSecurityAttributes = IntPtr.Zero;
            //extendedParams.hTemplateFile = IntPtr.Zero;

            //if ((access & NativeFileAccess.Read) != 0)
            //{
            //    // Sets GENERIC_READ
            //    newAccess |= 0x00120089;
            //}

            //if ((access & NativeFileAccess.Write) != 0)
            //{
            //    newAccess |= 0x00120116;
            //}

            //if ((access & NativeFileAccess.Execute) != 0)
            //{
            //    newAccess |= 0x001200a0;
            //}
            //handle = NativeFile.Create(fileName, (NativeFileAccess)newAccess, share, fileMode, new IntPtr(&extendedParams));
            handle = NativeFile.Create(fileName, access, share, fileMode, IntPtr.Zero);
#else
            handle = NativeFile.Create(fileName, access, share, IntPtr.Zero, fileMode, NativeFileOptions.None, IntPtr.Zero);
#endif
            if (handle == new IntPtr(-1))
            {
                var lastWin32Error = MarshalGetLastWin32Error();
                if (lastWin32Error == 2)
                {
                    throw new FileNotFoundException("Unable to find file", fileName);
                }

                var lastError = Result.GetResultFromWin32Error(lastWin32Error);
                throw new IOException(string.Format(CultureInfo.InvariantCulture, "Unable to open file {0}", fileName), lastError.Code);
            }
            canRead  = 0 != (access & NativeFileAccess.Read);
            canWrite = 0 != (access & NativeFileAccess.Write);

            // TODO how setup correctly canSeek flags?
            // Kernel32.GetFileType(SafeFileHandle handle); is not available on W8CORE
            canSeek = true;
        }
コード例 #8
0
 internal static extern SafeFileHandle CreateFileTransactedW(
     [In] string lpFileName,
     [In] NativeFileAccess dwDesiredAccess,
     [In] NativeFileShare dwShareMode,
     [In, Optional] IntPtr lpSecurityAttributes,
     [In] NativeFileMode dwCreationDisposition,
     [In] NativeFileOptions dwFlagsAndAttributes,
     [In, Optional] IntPtr hTemplateFile,
     [In] SafeKernelTransactionHandle hTransaction,
     [In, Optional] IntPtr pusMiniVersion,
     IntPtr pExtendedParameter);
コード例 #9
0
ファイル: TestNativeFileStream.cs プロジェクト: pH200/SharpDX
 /// <summary>
 /// Creates a file stream.
 /// </summary>
 /// <param name="filename">The filename.</param>
 /// <param name="mode">The mode.</param>
 /// <param name="acccess">The access.</param>
 /// <returns></returns>
 private Stream CreateFileStream(string filename, NativeFileMode mode, NativeFileAccess acccess)
 {
     FileAccess defaultAccess = FileAccess.Read;
     if ((acccess & NativeFileAccess.Read) != 0 )
         defaultAccess = FileAccess.Read;
     if ((acccess & NativeFileAccess.Write) != 0 )
         defaultAccess = FileAccess.Write;
     if ((acccess & NativeFileAccess.ReadWrite) != 0 )
         defaultAccess = FileAccess.ReadWrite;
     return (isTestingNativeFileStream)
                ? (Stream)new NativeFileStream(Name, mode, acccess)
                : new FileStream(filename, (FileMode)mode, defaultAccess);
 }
コード例 #10
0
ファイル: TestNativeFileStream.cs プロジェクト: oeoen/SharpDX
        /// <summary>
        /// Creates a file stream.
        /// </summary>
        /// <param name="filename">The filename.</param>
        /// <param name="mode">The mode.</param>
        /// <param name="acccess">The access.</param>
        /// <returns></returns>
        private Stream CreateFileStream(string filename, NativeFileMode mode, NativeFileAccess acccess)
        {
            FileAccess defaultAccess = FileAccess.Read;

            if ((acccess & NativeFileAccess.Read) != 0)
            {
                defaultAccess = FileAccess.Read;
            }
            if ((acccess & NativeFileAccess.Write) != 0)
            {
                defaultAccess = FileAccess.Write;
            }
            if ((acccess & NativeFileAccess.ReadWrite) != 0)
            {
                defaultAccess = FileAccess.ReadWrite;
            }
            return((isTestingNativeFileStream)
                       ? (Stream) new NativeFileStream(Name, mode, acccess)
                       : new FileStream(filename, (FileMode)mode, defaultAccess));
        }
コード例 #11
0
        /// <summary>
        /// Initializes a new instance of the <see cref="NativeFileStream"/> class.
        /// </summary>
        /// <param name="fileName">Name of the file.</param>
        /// <param name="fileMode">The file mode.</param>
        /// <param name="access">The access mode.</param>
        /// <param name="share">The share mode.</param>
        public unsafe NativeFileStream(string fileName, NativeFileMode fileMode, NativeFileAccess access, NativeFileShare share = NativeFileShare.Read)
        {
            handle = NativeFile.Create(fileName, access, share, IntPtr.Zero, fileMode, NativeFileOptions.None, IntPtr.Zero);
            if (handle == new IntPtr(-1))
            {
                var lastWin32Error = MarshalGetLastWin32Error();
                if (lastWin32Error == 2)
                {
                    throw new FileNotFoundException("Unable to find file", fileName);
                }

                var lastError = Result.GetResultFromWin32Error(lastWin32Error);
                throw new IOException(string.Format(CultureInfo.InvariantCulture, "Unable to open file {0}", fileName), lastError.Code);
            }
            canRead  = 0 != (access & NativeFileAccess.Read);
            canWrite = 0 != (access & NativeFileAccess.Write);

            // TODO how setup correctly canSeek flags?
            // Kernel32.GetFileType(SafeFileHandle handle); is not available on W8CORE
            canSeek = true;
        }
コード例 #12
0
ファイル: NativeFileStream.cs プロジェクト: tanis2000/FEZ
 public NativeFileStream(string fileName, NativeFileMode fileMode, NativeFileAccess access, NativeFileShare share = NativeFileShare.Read)
 {
     this.handle = NativeFile.Create(fileName, access, share, IntPtr.Zero, fileMode, NativeFileOptions.None, IntPtr.Zero);
       if (this.handle == new IntPtr(-1))
       {
     int lastWin32Error = NativeFileStream.MarshalGetLastWin32Error();
     if (lastWin32Error == 2)
       throw new FileNotFoundException("Unable to find file", fileName);
     Result resultFromWin32Error = Result.GetResultFromWin32Error(lastWin32Error);
     throw new IOException(string.Format((IFormatProvider) CultureInfo.InvariantCulture, "Unable to open file {0}", new object[1]
     {
       (object) fileName
     }), resultFromWin32Error.Code);
       }
       else
       {
     this.canRead = (NativeFileAccess) 0 != (access & NativeFileAccess.Read);
     this.canWrite = (NativeFileAccess) 0 != (access & NativeFileAccess.Write);
     this.canSeek = true;
       }
 }
コード例 #13
0
ファイル: NativeFileStream.cs プロジェクト: conankzhang/fez
 public NativeFileStream(string fileName, NativeFileMode fileMode, NativeFileAccess access, NativeFileShare share = NativeFileShare.Read)
 {
     this.handle = NativeFile.Create(fileName, access, share, IntPtr.Zero, fileMode, NativeFileOptions.None, IntPtr.Zero);
     if (this.handle == new IntPtr(-1))
     {
         int lastWin32Error = NativeFileStream.MarshalGetLastWin32Error();
         if (lastWin32Error == 2)
         {
             throw new FileNotFoundException("Unable to find file", fileName);
         }
         Result resultFromWin32Error = Result.GetResultFromWin32Error(lastWin32Error);
         throw new IOException(string.Format((IFormatProvider)CultureInfo.InvariantCulture, "Unable to open file {0}", new object[1]
         {
             (object)fileName
         }), resultFromWin32Error.Code);
     }
     else
     {
         this.canRead  = (NativeFileAccess)0 != (access & NativeFileAccess.Read);
         this.canWrite = (NativeFileAccess)0 != (access & NativeFileAccess.Write);
         this.canSeek  = true;
     }
 }
コード例 #14
0
 internal static extern IntPtr Create(
     string fileName,
     NativeFileAccess desiredAccess,
     NativeFileShare shareMode,
     NativeFileMode mode,
     IntPtr extendedParameters);
コード例 #15
0
ファイル: Win32Kernel.cs プロジェクト: UCIS/UCIS.Core
 internal static extern SafeFileHandle CreateFile(string fileName, NativeFileAccess fileAccess, NativeFileShare fileShare, IntPtr securityAttributes, NativeFileMode creationDisposition, NativeFileFlag flags, IntPtr template);
コード例 #16
0
 internal static extern IntPtr Create(
     string fileName,
     NativeFileAccess desiredAccess,
     NativeFileShare shareMode,
     NativeFileMode mode,
     IntPtr extendedParameters);
コード例 #17
0
 public static extern int chmod(string path, NativeFileMode mode);