Example #1
0
        protected override Result OpenDirectoryImpl(out IDirectory directory, string path, OpenDirectoryMode mode)
        {
            directory = default;
            string localPath = ResolveLocalPath(PathTools.Normalize(path));

            Result rc = GetDirInfo(out DirectoryInfo dirInfo, localPath);

            if (rc.IsFailure())
            {
                return(rc);
            }

            if (!dirInfo.Attributes.HasFlag(FileAttributes.Directory))
            {
                return(ResultFs.PathNotFound.Log());
            }

            try
            {
                IEnumerator <FileSystemInfo> entryEnumerator = dirInfo.EnumerateFileSystemInfos().GetEnumerator();

                directory = new LocalDirectory(entryEnumerator, dirInfo, mode);
                return(Result.Success);
            }
            catch (Exception ex) when(ex.HResult < 0)
            {
                return(HResult.HResultToHorizonResult(ex.HResult).Log());
            }
        }
Example #2
0
        protected override Result DoOpenDirectory(out IDirectory directory, U8Span path, OpenDirectoryMode mode)
        {
            UnsafeHelpers.SkipParamInit(out directory);
            Result rc = ResolveFullPath(out string fullPath, path);

            if (rc.IsFailure())
            {
                return(rc);
            }

            rc = GetDirInfo(out DirectoryInfo dirInfo, fullPath);
            if (rc.IsFailure())
            {
                return(rc);
            }

            if (!dirInfo.Attributes.HasFlag(FileAttributes.Directory))
            {
                return(ResultFs.PathNotFound.Log());
            }

            try
            {
                IEnumerator <FileSystemInfo> entryEnumerator = dirInfo.EnumerateFileSystemInfos().GetEnumerator();

                directory = new LocalDirectory(entryEnumerator, dirInfo, mode);
                return(Result.Success);
            }
            catch (Exception ex) when(ex.HResult < 0)
            {
                return(HResult.HResultToHorizonResult(ex.HResult).Log());
            }
        }
Example #3
0
        private static Result OpenDirectoryInternal(out IDirectory directory, OpenDirectoryMode mode,
                                                    DirectoryInfo dirInfo)
        {
            try
            {
                IEnumerator <FileSystemInfo> entryEnumerator = dirInfo.EnumerateFileSystemInfos().GetEnumerator();

                directory = new LocalDirectory(entryEnumerator, dirInfo, mode);
                return(Result.Success);
            }
            catch (Exception ex) when(ex.HResult < 0)
            {
                UnsafeHelpers.SkipParamInit(out directory);
                return(HResult.HResultToHorizonResult(ex.HResult).Log());
            }
        }