Esempio n. 1
0
        private void SetConcatenationFileAttribute(string path)
        {
            NxFileAttributes attributes = BaseFileSystem.GetFileAttributes(path);

            attributes |= NxFileAttributes.Archive;
            BaseFileSystem.SetFileAttributes(path, attributes);
        }
Esempio n. 2
0
        protected override Result DoGetFileAttributes(out NxFileAttributes attributes, U8Span path)
        {
            UnsafeHelpers.SkipParamInit(out attributes);

            Result rc = ResolveFullPath(out string fullPath, path, true);

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

            rc = GetFileInfo(out FileInfo info, fullPath);
            if (rc.IsFailure())
            {
                return(rc);
            }

            if (info.Attributes == (FileAttributes)(-1))
            {
                return(ResultFs.PathNotFound.Log());
            }

            attributes = info.Attributes.ToNxAttributes();
            return(Result.Success);
        }
Esempio n. 3
0
        protected override Result DoGetFileAttributes(out NxFileAttributes attributes, U8Span path)
        {
            UnsafeHelpers.SkipParamInit(out attributes);

            Unsafe.SkipInit(out FsPath normalizedPath);
            Result rc = PathNormalizer.Normalize(normalizedPath.Str, out _, path, false, false);

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

            if (FsTable.GetFile(normalizedPath, out FileNode file).IsSuccess())
            {
                attributes = file.Attributes;
                return(Result.Success);
            }

            if (FsTable.GetDirectory(normalizedPath, out DirectoryNode dir).IsSuccess())
            {
                attributes = dir.Attributes;
                return(Result.Success);
            }

            return(ResultFs.PathNotFound.Log());
        }
Esempio n. 4
0
        protected override Result DoCreateDirectory(U8Span path, NxFileAttributes archiveAttribute)
        {
            Result rc = ResolveFullPath(out string fullPath, path, false);

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

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

            if (dir.Exists)
            {
                return(ResultFs.PathAlreadyExists.Log());
            }

            if (dir.Parent?.Exists != true)
            {
                return(ResultFs.PathNotFound.Log());
            }

            return(CreateDirInternal(dir, archiveAttribute));
        }
Esempio n. 5
0
        protected override Result DoCreateDirectory(U8Span path, NxFileAttributes archiveAttribute)
        {
            Unsafe.SkipInit(out FsPath normalizedPath);
            Result rc = PathNormalizer.Normalize(normalizedPath.Str, out _, path, false, false);

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

            rc = FsTable.AddDirectory(normalizedPath);
            if (rc.IsFailure())
            {
                return(rc);
            }

            rc = FsTable.GetDirectory(normalizedPath, out DirectoryNode dir);
            if (rc.IsFailure())
            {
                return(rc);
            }

            dir.Attributes = archiveAttribute;
            return(Result.Success);
        }
Esempio n. 6
0
        protected override Result SetFileAttributesImpl(string path, NxFileAttributes attributes)
        {
            string localPath = ResolveLocalPath(PathTools.Normalize(path));

            Result rc = GetFileInfo(out FileInfo info, localPath);

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

            if (info.Attributes == (FileAttributes)(-1))
            {
                return(ResultFs.PathNotFound.Log());
            }

            FileAttributes attributesOld = info.Attributes;
            FileAttributes attributesNew = attributesOld.ApplyNxAttributes(attributes);

            try
            {
                info.Attributes = attributesNew;
            }
            catch (IOException)
            {
                return(ResultFs.PathNotFound.Log());
            }

            return(Result.Success);
        }
Esempio n. 7
0
        protected override Result DoSetFileAttributes(U8Span path, NxFileAttributes attributes)
        {
            Result rc = ResolveFullPath(out string fullPath, path, true);

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

            rc = GetFileInfo(out FileInfo info, fullPath);
            if (rc.IsFailure())
            {
                return(rc);
            }

            if (info.Attributes == (FileAttributes)(-1))
            {
                return(ResultFs.PathNotFound.Log());
            }

            FileAttributes attributesOld = info.Attributes;
            FileAttributes attributesNew = attributesOld.ApplyNxAttributes(attributes);

            try
            {
                info.Attributes = attributesNew;
            }
            catch (IOException)
            {
                return(ResultFs.PathNotFound.Log());
            }

            return(Result.Success);
        }
Esempio n. 8
0
        protected override Result GetFileAttributesImpl(out NxFileAttributes attributes, U8Span path)
        {
            attributes = default;

            Result rc = ResolveFullPath(out string fullPath, path);

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

            rc = GetFileInfo(out FileInfo info, fullPath);
            if (rc.IsFailure())
            {
                return(rc);
            }

            if (info.Attributes == (FileAttributes)(-1))
            {
                attributes = default;
                return(ResultFs.PathNotFound.Log());
            }

            attributes = info.Attributes.ToNxAttributes();
            return(Result.Success);
        }
        public Result CreateDirectory(string path, NxFileAttributes archiveAttribute)
        {
            if (IsDisposed)
            {
                return(ResultFs.PreconditionViolation.Log());
            }

            return(CreateDirectoryImpl(path, archiveAttribute));
        }
Esempio n. 10
0
        public Result SetFileAttributes(string path, NxFileAttributes attributes)
        {
            if (IsDisposed)
            {
                return(ResultFs.PreconditionViolation.Log());
            }

            return(SetFileAttributesImpl(path, attributes));
        }
Esempio n. 11
0
        public void SetFileAttributes(string path, NxFileAttributes attributes)
        {
            path = ToDiscUtilsPath(PathTools.Normalize(path));

            FileAttributes attributesOld = File.GetAttributes(path);
            FileAttributes attributesNew = attributesOld.ApplyNxAttributes(attributes);

            Fs.SetAttributes(path, attributesNew);
        }
Esempio n. 12
0
        public Result SetFileAttributes(U8Span path, NxFileAttributes attributes)
        {
            if (path.IsNull())
            {
                return(ResultFs.NullptrArgument.Log());
            }

            return(DoSetFileAttributes(path, attributes));
        }
Esempio n. 13
0
        public Result CreateDirectory(U8Span path, NxFileAttributes archiveAttribute)
        {
            if (path.IsNull())
            {
                return(ResultFs.NullptrArgument.Log());
            }

            return(DoCreateDirectory(path, archiveAttribute));
        }
Esempio n. 14
0
        public Result SetFileAttributes(U8Span spanpath, NxFileAttributes attributes)
        {
            string path = PathTools.Normalize(spanpath.ToString());
            Tuple <string, IAttributeFileSystem> t = FileDict[path];

            t.Item2.SetFileAttributes(t.Item1.ToU8Span(), attributes);

            return(Result.Success);
        }
Esempio n. 15
0
        public Result GetFileAttributes(string path, out NxFileAttributes attributes)
        {
            if (IsDisposed)
            {
                attributes = default;
                return(ResultFs.PreconditionViolation.Log());
            }

            return(GetFileAttributesImpl(path, out attributes));
        }
        public Result GetFileAttributes(out NxFileAttributes attributes, U8Span path)
        {
            if (IsDisposed)
            {
                attributes = default;
                return(ResultFs.PreconditionViolation.Log());
            }

            return(GetFileAttributesImpl(out attributes, path));
        }
Esempio n. 17
0
        public Result GetFileAttributes(out NxFileAttributes attributes, U8Span path)
        {
            if (path.IsNull())
            {
                attributes = default;
                return(ResultFs.NullptrArgument.Log());
            }

            return(DoGetFileAttributes(out attributes, path));
        }
Esempio n. 18
0
        public void SetFileAttributes(string path, NxFileAttributes attributes)
        {
            path = PathTools.Normalize(path);
            string localPath = ResolveLocalPath(path);

            FileAttributes attributesOld = File.GetAttributes(localPath);
            FileAttributes attributesNew = attributesOld.ApplyNxAttributes(attributes);

            File.SetAttributes(localPath, attributesNew);
        }
Esempio n. 19
0
        public Result GetFileAttributes(out NxFileAttributes attributes, U8Span path)
        {
            UnsafeHelpers.SkipParamInit(out attributes);

            if (path.IsNull())
            {
                return(ResultFs.NullptrArgument.Log());
            }

            return(DoGetFileAttributes(out attributes, path));
        }
Esempio n. 20
0
        protected override Result DoSetFileAttributes(U8Span path, NxFileAttributes attributes)
        {
            if (FsTable.GetFile(path, out FileNode file).IsSuccess())
            {
                file.Attributes = attributes;
                return(Result.Success);
            }

            if (FsTable.GetDirectory(path, out DirectoryNode dir).IsSuccess())
            {
                dir.Attributes = attributes;
                return(Result.Success);
            }

            return(ResultFs.PathNotFound.Log());
        }
Esempio n. 21
0
        protected override Result DoGetFileAttributes(out NxFileAttributes attributes, U8Span path)
        {
            if (FsTable.GetFile(path, out FileNode file).IsSuccess())
            {
                attributes = file.Attributes;
                return(Result.Success);
            }

            if (FsTable.GetDirectory(path, out DirectoryNode dir).IsSuccess())
            {
                attributes = dir.Attributes;
                return(Result.Success);
            }

            attributes = default;
            return(ResultFs.PathNotFound.Log());
        }
Esempio n. 22
0
        protected override Result DoCreateDirectory(U8Span path, NxFileAttributes archiveAttribute)
        {
            Result rc = FsTable.AddDirectory(path);

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

            rc = FsTable.GetDirectory(path, out DirectoryNode dir);
            if (rc.IsFailure())
            {
                return(rc);
            }

            dir.Attributes = archiveAttribute;
            return(Result.Success);
        }
        protected override Result DoGetFileAttributes(out NxFileAttributes attributes, U8Span path)
        {
            UnsafeHelpers.SkipParamInit(out attributes);

            if (FsTable.GetFile(path, out FileNode file).IsSuccess())
            {
                attributes = file.Attributes;
                return(Result.Success);
            }

            if (FsTable.GetDirectory(path, out DirectoryNode dir).IsSuccess())
            {
                attributes = dir.Attributes;
                return(Result.Success);
            }

            return(ResultFs.PathNotFound.Log());
        }
Esempio n. 24
0
        private static Result CreateDirInternal(DirectoryInfo dir, NxFileAttributes attributes)
        {
            try
            {
                dir.Create();
                dir.Refresh();

                if (attributes.HasFlag(NxFileAttributes.Archive))
                {
                    dir.Attributes |= FileAttributes.Archive;
                }
            }
            catch (Exception ex) when(ex.HResult < 0)
            {
                return(HResult.HResultToHorizonResult(ex.HResult).Log());
            }

            return(Result.Success);
        }
Esempio n. 25
0
        protected override Result GetFileAttributesImpl(string path, out NxFileAttributes attributes)
        {
            attributes = default;

            string localPath = ResolveLocalPath(PathTools.Normalize(path));

            Result rc = GetFileInfo(out FileInfo info, localPath);

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

            if (info.Attributes == (FileAttributes)(-1))
            {
                attributes = default;
                return(ResultFs.PathNotFound.Log());
            }

            attributes = info.Attributes.ToNxAttributes();
            return(Result.Success);
        }
Esempio n. 26
0
        protected override Result CreateDirectoryImpl(string path, NxFileAttributes archiveAttribute)
        {
            string localPath = ResolveLocalPath(PathTools.Normalize(path));

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

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

            if (dir.Exists)
            {
                return(ResultFs.PathAlreadyExists.Log());
            }

            if (dir.Parent?.Exists != true)
            {
                return(ResultFs.PathNotFound.Log());
            }

            return(CreateDirInternal(dir, archiveAttribute));
        }
Esempio n. 27
0
        public void CreateFile(string path, long size, CreateFileOptions options)
        {
            path = PathTools.Normalize(path);

            CreateFileOptions newOptions = options & ~CreateFileOptions.CreateConcatenationFile;

            if (!options.HasFlag(CreateFileOptions.CreateConcatenationFile))
            {
                BaseFileSystem.CreateFile(path, size, newOptions);
                return;
            }

            // A concatenation file directory can't contain normal files
            string parentDir = PathTools.GetParentDirectory(path);

            if (IsConcatenationFile(parentDir))
            {
                throw new IOException("Cannot create files inside of a concatenation file");
            }

            BaseFileSystem.CreateDirectory(path);
            NxFileAttributes attributes = BaseFileSystem.GetFileAttributes(path) | NxFileAttributes.Archive;

            BaseFileSystem.SetFileAttributes(path, attributes);

            long remaining = size;

            for (int i = 0; remaining > 0; i++)
            {
                long   fileSize = Math.Min(SubFileSize, remaining);
                string fileName = GetSubFilePath(path, i);

                BaseFileSystem.CreateFile(fileName, fileSize, CreateFileOptions.None);

                remaining -= fileSize;
            }
        }
Esempio n. 28
0
 internal static bool HasConcatenationFileAttribute(NxFileAttributes attributes)
 {
     return((attributes & NxFileAttributes.Directory) != 0 && (attributes & NxFileAttributes.Archive) != 0);
 }
Esempio n. 29
0
        public static FileAttributes ApplyNxAttributes(this FileAttributes attributes, NxFileAttributes nxAttributes)
        {
            // The only 2 bits from FileAttributes that are used in NxFileAttributes
            const int mask = 3 << 4;

            FileAttributes oldAttributes = attributes & (FileAttributes)mask;

            return(oldAttributes | nxAttributes.ToFatAttributes());
        }
Esempio n. 30
0
 public static FileAttributes ToFatAttributes(this NxFileAttributes attributes)
 {
     return((FileAttributes)(((int)attributes & 3) << 4));
 }