コード例 #1
0
        public static bool Exists(string path)
        {
            if (string.IsNullOrEmpty(path))
            {
                return(false);
            }
            int error;

            return(FileInternal.ExistsFile(path, out error));
        }
コード例 #2
0
ファイル: Directory.cs プロジェクト: ebekker/Blazor-Legacy
        public static string GetCurrentDirectory()
        {
            int    error;
            string dir = FileInternal.GetCurrentDirectory(out error);

            if (error != 0)
            {
                throw FileInternal.GetException(error, string.Empty);
            }
            return(dir);
        }
コード例 #3
0
ファイル: FileStream.cs プロジェクト: ncave/dna-redux
 protected override void Dispose(bool disposing)
 {
     if (this.handle != IntPtr.Zero)
     {
         int error;
         FileInternal.Close(this.handle, out error);
         if (disposing && error != 0)
         {
             // Throw exception on error, but not if this is being called from destructor
             throw FileInternal.GetException(error, this.filename);
         }
         this.handle = IntPtr.Zero;
         // TODO: GC.UnregisterForFinalize(this);
     }
 }
コード例 #4
0
        public FileStream(string filename, FileMode mode, FileAccess access, FileShare share)
        {
            int    error;
            IntPtr handle = FileInternal.Open(filename, mode, access, share, out error);

            if (error != 0)
            {
                throw FileInternal.GetException(error, filename);
            }
            this.handle   = handle;
            this.filename = filename;

            this.canRead  = true;
            this.canWrite = true;
            this.canSeek  = true;
        }
コード例 #5
0
ファイル: FileStream.cs プロジェクト: ncave/dna-redux
        public override int Read(byte[] buffer, int offset, int count)
        {
            if (this.handle == IntPtr.Zero)
            {
                throw new ObjectDisposedException("Stream has been closed");
            }
            if (offset < 0 || count < 0 || offset + count > buffer.Length)
            {
                throw new ArgumentOutOfRangeException();
            }

            int error;
            int ret = FileInternal.Read(this.handle, buffer, offset, count, out error);

            if (error != 0)
            {
                throw FileInternal.GetException(error, this.filename);
            }
            return(ret);
        }
コード例 #6
0
        public override void Write(byte[] buffer, int offset, int count)
        {
            if (this.handle == IntPtr.Zero)
            {
                throw new ObjectDisposedException("Stream has been closed");
            }
            if (offset < 0 || count < 0 || offset + count > buffer.Length)
            {
                throw new ArgumentOutOfRangeException();
            }

            int error;
            int ret = FileInternal.Write(this.handle, buffer, offset, count, out error);

            if (error != 0)
            {
                throw FileInternal.GetException(error, this.filename);
            }
            if (ret != count)
            {
                throw new IOException("Not all data written :/");
            }
        }
コード例 #7
0
ファイル: Directory.cs プロジェクト: ebekker/Blazor-Legacy
        private static string[] GetFileSystemEntries(string path, string pattern, FileAttributes mask, FileAttributes attrs)
        {
            if (path == null || pattern == null)
            {
                throw new ArgumentNullException();
            }

            if (pattern == String.Empty)
            {
                return new string[] { }
            }
            ;

            if (path.Trim() == "")
            {
                throw new ArgumentException("The Path does not have a valid format");
            }

            string wild     = Path.Combine(path, pattern);
            string wildpath = Path.GetDirectoryName(wild);

            if (wildpath.IndexOfAny(Path.InvalidPathChars) != -1)
            {
                throw new ArgumentException("Path contains invalid characters");
            }

            if (wildpath.IndexOfAny(Path.InvalidPathChars) != -1)
            {
                if (path.IndexOfAny(SearchPattern.InvalidChars) == -1)
                {
                    throw new ArgumentException("Path contains invalid characters", "path");
                }

                throw new ArgumentException("Pattern contains invalid characters", "pattern");
            }

            int error;

            if (!FileInternal.ExistsDirectory(wildpath, out error))
            {
                if (error == FileInternal.Error_OK)
                {
                    int file_error;
                    if (FileInternal.ExistsFile(wildpath, out file_error))
                    {
                        return(new string[] { wildpath });
                    }
                }

                if (error != FileInternal.ERROR_PATH_NOT_FOUND)
                {
                    throw FileInternal.GetException(error, wildpath);
                }

                if (wildpath.IndexOfAny(SearchPattern.WildcardChars) == -1)
                {
                    throw new DirectoryNotFoundException("Directory '" + wildpath + "' not found.");
                }

                if (path.IndexOfAny(SearchPattern.WildcardChars) == -1)
                {
                    throw new ArgumentException("Pattern is invalid", "pattern");
                }

                throw new ArgumentException("Path is invalid", "path");
            }

            string path_with_pattern = Path.Combine(wildpath, pattern);

            string[] result = FileInternal.GetFileSystemEntries(path, path_with_pattern, attrs, mask, out error);
            if (error != 0)
            {
                throw FileInternal.GetException(error, wildpath);
            }

            return(result);
        }
    }