Esempio 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());
            }
        }
Esempio n. 2
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();
            }
        }