Ejemplo n.º 1
0
        public Result OpenCustomStorageFileSystem(out IFileSystem fileSystem, CustomStorageId storageId)
        {
            fileSystem = default;

            switch (storageId)
            {
            case CustomStorageId.SdCard:
            {
                Result rc = FsCreators.SdFileSystemCreator.Create(out IFileSystem sdFs);
                if (rc.IsFailure())
                {
                    return(rc);
                }

                string customStorageDir = CustomStorage.GetCustomStorageDirectoryName(CustomStorageId.SdCard);
                string subDirName       = $"/{NintendoDirectoryName}/{customStorageDir}";

                rc = Util.CreateSubFileSystem(out IFileSystem subFs, sdFs, subDirName, true);
                if (rc.IsFailure())
                {
                    return(rc);
                }

                rc = FsCreators.EncryptedFileSystemCreator.Create(out IFileSystem encryptedFs, subFs,
                                                                  EncryptedFsKeyId.CustomStorage, SdEncryptionSeed);
                if (rc.IsFailure())
                {
                    return(rc);
                }

                fileSystem = encryptedFs;
                return(Result.Success);
            }

            case CustomStorageId.System:
            {
                Result rc = FsCreators.BuiltInStorageFileSystemCreator.Create(out IFileSystem userFs, string.Empty,
                                                                              BisPartitionId.User);
                if (rc.IsFailure())
                {
                    return(rc);
                }

                string customStorageDir = CustomStorage.GetCustomStorageDirectoryName(CustomStorageId.System);
                string subDirName       = $"/{customStorageDir}";

                rc = Util.CreateSubFileSystem(out IFileSystem subFs, userFs, subDirName, true);
                if (rc.IsFailure())
                {
                    return(rc);
                }

                fileSystem = subFs;
                return(Result.Success);
            }

            default:
                return(ResultFs.InvalidArgument.Log());
            }
        }
Ejemplo n.º 2
0
        public static string GetCustomStorageDirectoryName(CustomStorageId storageId)
        {
            switch (storageId)
            {
            case CustomStorageId.System:
            case CustomStorageId.SdCard:
                return("CustomStorage0");

            default:
                throw new ArgumentOutOfRangeException(nameof(storageId), storageId, null);
            }
        }
Ejemplo n.º 3
0
        public static U8Span GetCustomStorageDirectoryName(CustomStorageId storageId)
        {
            switch (storageId)
            {
            case CustomStorageId.System:
            case CustomStorageId.SdCard:
                return(new U8Span(CustomStorageDirectoryName));

            default:
                Abort.UnexpectedDefault();
                return(default);
            }
        }
Ejemplo n.º 4
0
        public static Result MountCustomStorage(this FileSystemClient fs, U8Span mountName, CustomStorageId storageId)
        {
            Result rc = MountHelpers.CheckMountName(mountName);

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

            IFileSystemProxy fsProxy = fs.GetFileSystemProxyServiceObject();

            rc = fsProxy.OpenCustomStorageFileSystem(out IFileSystem customFs, storageId);
            if (rc.IsFailure())
            {
                return(rc);
            }

            return(fs.Register(mountName, customFs));
        }
Ejemplo n.º 5
0
        public Result OpenCustomStorageFileSystem(out ReferenceCountedDisposable <IFileSystem> fileSystem,
                                                  CustomStorageId storageId)
        {
            UnsafeHelpers.SkipParamInit(out fileSystem);

            ReferenceCountedDisposable <IFileSystem> tempFs      = null;
            ReferenceCountedDisposable <IFileSystem> encryptedFs = null;

            try
            {
                Span <byte> path = stackalloc byte[0x40];

                switch (storageId)
                {
                case CustomStorageId.SdCard:
                {
                    Result rc = BaseFileSystemService.OpenSdCardProxyFileSystem(out tempFs);
                    if (rc.IsFailure())
                    {
                        return(rc);
                    }

                    U8Span customStorageDir = CustomStorage.GetCustomStorageDirectoryName(CustomStorageId.SdCard);
                    var    sb = new U8StringBuilder(path);
                    sb.Append((byte)'/')
                    .Append(CommonPaths.SdCardNintendoRootDirectoryName)
                    .Append((byte)'/')
                    .Append(customStorageDir);

                    rc = Utility.WrapSubDirectory(out tempFs, ref tempFs, new U8Span(path), true);
                    if (rc.IsFailure())
                    {
                        return(rc);
                    }

                    rc = FsCreators.EncryptedFileSystemCreator.Create(out encryptedFs, tempFs,
                                                                      EncryptedFsKeyId.CustomStorage, SdEncryptionSeed);
                    if (rc.IsFailure())
                    {
                        return(rc);
                    }

                    return(Result.Success);
                }

                case CustomStorageId.System:
                {
                    Result rc = BaseFileSystemService.OpenBisFileSystem(out tempFs, U8Span.Empty,
                                                                        BisPartitionId.User);
                    if (rc.IsFailure())
                    {
                        return(rc);
                    }

                    U8Span customStorageDir = CustomStorage.GetCustomStorageDirectoryName(CustomStorageId.System);
                    var    sb = new U8StringBuilder(path);
                    sb.Append((byte)'/')
                    .Append(customStorageDir);

                    rc = Utility.WrapSubDirectory(out tempFs, ref tempFs, new U8Span(path), true);
                    if (rc.IsFailure())
                    {
                        return(rc);
                    }

                    fileSystem = Shared.Move(ref tempFs);
                    return(Result.Success);
                }

                default:
                    return(ResultFs.InvalidArgument.Log());
                }
            }
            finally
            {
                tempFs?.Dispose();
                encryptedFs?.Dispose();
            }
        }
Ejemplo n.º 6
0
        public static Result MountCustomStorage(this FileSystemClient fs, U8Span mountName, CustomStorageId storageId)
        {
            Result rc = fs.Impl.CheckMountName(mountName);

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

            ReferenceCountedDisposable <IFileSystemSf> fileSystem = null;

            try
            {
                using ReferenceCountedDisposable <IFileSystemProxy> fsProxy = fs.Impl.GetFileSystemProxyServiceObject();

                rc = fsProxy.Target.OpenCustomStorageFileSystem(out fileSystem, storageId);
                if (rc.IsFailure())
                {
                    return(rc);
                }

                var fileSystemAdapter = new FileSystemServiceObjectAdapter(fileSystem);
                return(fs.Register(mountName, fileSystemAdapter));
            }
            finally
            {
                fileSystem?.Dispose();
            }
        }