Ejemplo n.º 1
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);
            SetConcatenationFileAttribute(path);

            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;
            }
        }
Ejemplo n.º 2
0
        protected override Result DoCreateFile(U8Span path, long size, CreateFileOptions options)
        {
            CreateFileOptions newOptions = options & ~CreateFileOptions.CreateConcatenationFile;

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

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

            if (IsConcatenationFile(new U8Span(parentDir)))
            {
                // Cannot create a file inside of a concatenation file
                return(ResultFs.PathNotFound.Log());
            }

            Result rc = BaseFileSystem.CreateDirectory(path, NxFileAttributes.Archive);

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

            long remaining = size;

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

                FsPath fileName;
                unsafe { _ = &fileName; } // workaround for CS0165

                rc = GetSubFilePath(fileName.Str, path, i);
                if (rc.IsFailure())
                {
                    return(rc);
                }

                Result createSubFileResult = BaseFileSystem.CreateFile(fileName, fileSize, CreateFileOptions.None);

                if (createSubFileResult.IsFailure())
                {
                    BaseFileSystem.DeleteDirectoryRecursively(path);
                    return(createSubFileResult);
                }

                remaining -= fileSize;
            }

            return(Result.Success);
        }
Ejemplo n.º 3
0
        protected override Result CreateFileImpl(string path, long size, CreateFileOptions options)
        {
            path = PathTools.Normalize(path);

            CreateFileOptions newOptions = options & ~CreateFileOptions.CreateConcatenationFile;

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

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

            if (IsConcatenationFile(parentDir))
            {
                // Cannot create a file inside of a concatenation file
                return(ResultFs.PathNotFound.Log());
            }

            Result rc = BaseFileSystem.CreateDirectory(path, NxFileAttributes.Archive);

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

            long remaining = size;

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

                Result createSubFileResult = BaseFileSystem.CreateFile(fileName, fileSize, CreateFileOptions.None);

                if (createSubFileResult.IsFailure())
                {
                    BaseFileSystem.DeleteDirectoryRecursively(path);
                    return(createSubFileResult);
                }

                remaining -= fileSize;
            }

            return(Result.Success);
        }