예제 #1
0
        public static int OpenFileWrite(string path, out System.IO.Stream stream)
        {
            if (Settings.IsUnix)
            {
                try
                {
                    stream = new System.IO.FileStream(path, System.IO.FileMode.Create, System.IO.FileAccess.Write);
                    return(0);
                }
                catch (Exception)
                {
                    stream = null;
                    return(Marshal.GetLastWin32Error());
                }
            }


            string         filename = NameFix.AddLongPathPrefix(path);
            SafeFileHandle hFile    = Win32Native.CreateFile(filename,
                                                             GENERIC_WRITE,
                                                             System.IO.FileShare.None,
                                                             IntPtr.Zero,
                                                             System.IO.FileMode.Create,
                                                             FILE_ATTRIBUTE_NORMAL,
                                                             IntPtr.Zero);

            if (hFile.IsInvalid)
            {
                stream = null;
                return(Marshal.GetLastWin32Error());
            }

            stream = new System.IO.FileStream(hFile, System.IO.FileAccess.Write);
            return(0);
        }
예제 #2
0
        // errorMessage = new Win32Exception(errorCode).Message;

        public static int OpenFileRead(string path, out System.IO.Stream stream)
        {
            string         filename = NameFix.AddLongPathPrefix(path);
            SafeFileHandle hFile    = Win32Native.CreateFile(filename,
                                                             GENERIC_READ,
                                                             System.IO.FileShare.Read,
                                                             IntPtr.Zero,
                                                             System.IO.FileMode.Open,
                                                             FILE_ATTRIBUTE_NORMAL,
                                                             IntPtr.Zero);

            if (hFile.IsInvalid)
            {
                stream = null;
                return(Marshal.GetLastWin32Error());
            }
            stream = new System.IO.FileStream(hFile, System.IO.FileAccess.Read);
            return(0);
        }