예제 #1
0
        public void SetFileAttributes_PathDoesNotExist_ReturnsPathNotFound()
        {
            IAttributeFileSystem fs = CreateAttributeFileSystem();

            Result rc = fs.SetFileAttributes("/path".ToU8Span(), NxFileAttributes.None);

            Assert.Equal(ResultFs.PathNotFound.Value, rc);
        }
예제 #2
0
        public static SwitchFs OpenNandPartition(Keyset keyset, IAttributeFileSystem fileSystem)
        {
            var concatFs     = new ConcatenationFileSystem(fileSystem);
            var saveDirFs    = new SubdirectoryFileSystem(concatFs, "/save");
            var contentDirFs = new SubdirectoryFileSystem(concatFs, "/Contents");

            return(new SwitchFs(keyset, contentDirFs, saveDirFs));
        }
예제 #3
0
        public void GetFileSize_PathDoesNotExist_ReturnsPathNotFound()
        {
            IAttributeFileSystem fs = CreateAttributeFileSystem();

            Result rc = fs.GetFileSize(out _, "/path".ToU8Span());

            Assert.Equal(ResultFs.PathNotFound.Value, rc);
        }
예제 #4
0
        public void GetFileSize_ReadNewFileSize()
        {
            IAttributeFileSystem fs = CreateAttributeFileSystem();

            fs.CreateFile("/file".ToU8Span(), 845, CreateFileOptions.None);

            Assert.True(fs.GetFileSize(out long fileSize, "/file".ToU8Span()).IsSuccess());
            Assert.Equal(845, fileSize);
        }
예제 #5
0
        public void CreateDirectory_WithArchiveAttribute_ArchiveFlagIsSet()
        {
            IAttributeFileSystem fs = CreateAttributeFileSystem();

            Assert.True(fs.CreateDirectory("/dir".ToU8Span(), NxFileAttributes.Archive).IsSuccess());

            Assert.True(fs.GetFileAttributes(out NxFileAttributes attributes, "/dir".ToU8Span()).IsSuccess());
            Assert.Equal(NxFileAttributes.Directory | NxFileAttributes.Archive, attributes);
        }
예제 #6
0
        public void GetFileAttributes_AttributesOnNewDirHaveOnlyDirFlagSet()
        {
            IAttributeFileSystem fs = CreateAttributeFileSystem();

            fs.CreateDirectory("/dir".ToU8Span());

            Assert.Success(fs.GetFileAttributes(out NxFileAttributes attributes, "/dir".ToU8Span()));
            Assert.Equal(NxFileAttributes.Directory, attributes);
        }
예제 #7
0
        public void GetFileAttributes_AttributesOnNewFileAreEmpty()
        {
            IAttributeFileSystem fs = CreateAttributeFileSystem();

            fs.CreateFile("/file".ToU8Span(), 0, CreateFileOptions.None);

            Assert.Success(fs.GetFileAttributes(out NxFileAttributes attributes, "/file".ToU8Span()));
            Assert.Equal(NxFileAttributes.None, attributes);
        }
예제 #8
0
        public void CreateDirectory_WithoutArchiveAttribute_ArchiveFlagIsNotSet()
        {
            IAttributeFileSystem fs = CreateAttributeFileSystem();

            Assert.Success(fs.CreateDirectory("/dir".ToU8Span(), NxFileAttributes.None));

            Assert.Success(fs.GetFileAttributes(out NxFileAttributes attributes, "/dir".ToU8Span()));
            Assert.Equal(NxFileAttributes.Directory, attributes);
        }
예제 #9
0
        public void GetFileSize_PathIsDirectory_ReturnsPathNotFound()
        {
            IAttributeFileSystem fs = CreateAttributeFileSystem();

            fs.CreateDirectory("/dir".ToU8Span());

            Result rc = fs.GetFileSize(out _, "/dir".ToU8Span());

            Assert.Equal(ResultFs.PathNotFound.Value, rc);
        }
예제 #10
0
        public static SwitchFs OpenSdCard(Keyset keyset, IAttributeFileSystem fileSystem)
        {
            var concatFs     = new ConcatenationFileSystem(fileSystem);
            var saveDirFs    = new SubdirectoryFileSystem(concatFs, "/Nintendo/save");
            var contentDirFs = new SubdirectoryFileSystem(concatFs, "/Nintendo/Contents");

            var encSaveFs    = new AesXtsFileSystem(saveDirFs, keyset.SdCardKeys[0], 0x4000);
            var encContentFs = new AesXtsFileSystem(contentDirFs, keyset.SdCardKeys[1], 0x4000);

            return(new SwitchFs(keyset, encContentFs, encSaveFs));
        }
예제 #11
0
 public IEnumerable <DirectoryEntry> Read()
 {
     foreach (KeyValuePair <string, Tuple <string, IAttributeFileSystem> > kv in (ParentFileSystem as PseudoFileSystem).FileDict)
     {
         IAttributeFileSystem fs = kv.Value.Item2;
         string fullPath         = kv.Key;
         int    split            = fullPath.LastIndexOf('/');
         string path             = fullPath.Substring(0, split);
         string name             = kv.Key.Substring(split);
         yield return(new DirectoryEntry(name, fullPath, DirectoryEntryType.File, fs.GetFileSize(kv.Value.Item1)));
     }
 }
예제 #12
0
        public void SetFileAttributes_SetAttributeOnFile()
        {
            IAttributeFileSystem fs = CreateAttributeFileSystem();

            fs.CreateFile("/file".ToU8Span(), 0, CreateFileOptions.None);

            Result rcSet = fs.SetFileAttributes("/file".ToU8Span(), NxFileAttributes.Archive);
            Result rcGet = fs.GetFileAttributes(out NxFileAttributes attributes, "/file".ToU8Span());

            Assert.True(rcSet.IsSuccess());
            Assert.True(rcGet.IsSuccess());
            Assert.Equal(NxFileAttributes.Archive, attributes);
        }
예제 #13
0
        public void SetFileAttributes_SetAttributeOnDirectory()
        {
            IAttributeFileSystem fs = CreateAttributeFileSystem();

            fs.CreateDirectory("/dir".ToU8Span());

            Result rcSet = fs.SetFileAttributes("/dir".ToU8Span(), NxFileAttributes.Archive);
            Result rcGet = fs.GetFileAttributes(out NxFileAttributes attributes, "/dir".ToU8Span());

            Assert.True(rcSet.IsSuccess());
            Assert.True(rcGet.IsSuccess());
            Assert.Equal(NxFileAttributes.Directory | NxFileAttributes.Archive, attributes);
        }
예제 #14
0
파일: SwitchFs.cs 프로젝트: garoxas/LibHac
        public static SwitchFs OpenNandPartition(KeySet keySet, IAttributeFileSystem fileSystem)
        {
            var concatFs = new ConcatenationFileSystem(fileSystem);
            SubdirectoryFileSystem saveDirFs = null;

            if (concatFs.DirectoryExists("/save"))
            {
                SubdirectoryFileSystem.CreateNew(out saveDirFs, concatFs, "/save".ToU8String()).ThrowIfFailure();
            }

            SubdirectoryFileSystem.CreateNew(out SubdirectoryFileSystem contentDirFs, concatFs, "/Contents".ToU8String()).ThrowIfFailure();

            return(new SwitchFs(keySet, contentDirFs, saveDirFs));
        }
예제 #15
0
        public void Add(string path, string internalPath, IAttributeFileSystem fs)
        {
            FileDict[path] = new Tuple <string, IAttributeFileSystem>(internalPath, fs);

            /*PathParser parser = new PathParser(Encoding.ASCII.GetBytes(path));
             * while (!parser.IsFinished())
             * {
             *  if (parser.TryGetNext(out ReadOnlySpan<byte> pb))
             *  {
             *      string p = new string(Encoding.ASCII.GetChars(pb.ToArray()));
             *      ;
             *  }
             * }*/
        }
예제 #16
0
        public Result Read(out long entryCount, Span <DirectoryEntry> entries)
        {
            int i = 0;

            foreach (KeyValuePair <string, Tuple <string, IAttributeFileSystem> > kv in (ParentFileSystem as PseudoFileSystem).FileDict.Skip(CurrentIndex))
            {
                if (entries.Length <= i)
                {
                    break;
                }

                IAttributeFileSystem fs = kv.Value.Item2;
                string fullPath         = kv.Key;
                int    split            = fullPath.LastIndexOf('/');
                string path             = fullPath.Substring(0, split);
                fs.GetFileSize(out long size, kv.Value.Item1.ToU8Span());

                StringUtils.Copy(entries[i].Name, Encoding.UTF8.GetBytes(kv.Key.Substring(split)).AsSpan());
                entries[i].Size       = size;
                entries[i].Attributes = NxFileAttributes.None;
                entries[i].Type       = DirectoryEntryType.File;

                i++;
            }

            foreach (KeyValuePair <string, IStorage> kv in (ParentFileSystem as PseudoFileSystem).StorageDict.Skip(CurrentIndex - (ParentFileSystem as PseudoFileSystem).FileDict.Count))
            {
                if (entries.Length <= i)
                {
                    break;
                }

                string fullPath = kv.Key;
                int    split    = fullPath.LastIndexOf('/');
                kv.Value.GetSize(out long size);

                StringUtils.Copy(entries[i].Name, Encoding.UTF8.GetBytes(kv.Key.Substring(split)).AsSpan());
                entries[i].Size       = size;
                entries[i].Attributes = NxFileAttributes.None;
                entries[i].Type       = DirectoryEntryType.File;

                i++;
            }
            entryCount    = i;
            CurrentIndex += (int)entryCount;

            return(Result.Success);
        }
예제 #17
0
        public static SwitchFs OpenSdCard(Keyset keyset, IAttributeFileSystem fileSystem)
        {
            var concatFs = new ConcatenationFileSystem(fileSystem);

            SubdirectoryFileSystem.CreateNew(out SubdirectoryFileSystem contentDirFs, concatFs, "/Nintendo/Contents".ToU8String()).ThrowIfFailure();

            AesXtsFileSystem encSaveFs = null;

            if (fileSystem.DirectoryExists("/Nintendo/save"))
            {
                SubdirectoryFileSystem.CreateNew(out SubdirectoryFileSystem saveDirFs, concatFs, "/Nintendo/save".ToU8String()).ThrowIfFailure();
                encSaveFs = new AesXtsFileSystem(saveDirFs, keyset.SdCardKeys[0], 0x4000);
            }

            var encContentFs = new AesXtsFileSystem(contentDirFs, keyset.SdCardKeys[1], 0x4000);

            return(new SwitchFs(keyset, encContentFs, encSaveFs));
        }
예제 #18
0
파일: SwitchFs.cs 프로젝트: garoxas/LibHac
        public static SwitchFs OpenSdCard(KeySet keySet, IAttributeFileSystem fileSystem)
        {
            var concatFs = new ConcatenationFileSystem(fileSystem);

            var contentDirFs = new SubdirectoryFileSystem(concatFs);

            contentDirFs.Initialize("/Nintendo/Contents".ToU8String()).ThrowIfFailure();

            AesXtsFileSystem encSaveFs = null;

            if (fileSystem.DirectoryExists("/Nintendo/save"))
            {
                var saveDirFs = new SubdirectoryFileSystem(concatFs);
                saveDirFs.Initialize("/Nintendo/save".ToU8String()).ThrowIfFailure();

                encSaveFs = new AesXtsFileSystem(saveDirFs, keySet.SdCardEncryptionKeys[0].DataRo.ToArray(), 0x4000);
            }

            var encContentFs = new AesXtsFileSystem(contentDirFs, keySet.SdCardEncryptionKeys[1].DataRo.ToArray(), 0x4000);

            return(new SwitchFs(keySet, encContentFs, encSaveFs));
        }
예제 #19
0
 /// <summary>
 /// Initializes a new <see cref="ConcatenationFileSystem"/>.
 /// </summary>
 /// <param name="baseFileSystem">The base <see cref="IAttributeFileSystem"/> for the
 /// new <see cref="ConcatenationFileSystem"/>.</param>
 /// <param name="subFileSize">The size of each sub-file. Once a file exceeds this size, a new sub-file will be created</param>
 public ConcatenationFileSystem(IAttributeFileSystem baseFileSystem, long subFileSize)
 {
     BaseFileSystem = baseFileSystem;
     SubFileSize    = subFileSize;
 }
예제 #20
0
 /// <summary>
 /// Initializes a new <see cref="ConcatenationFileSystem"/>.
 /// </summary>
 /// <param name="baseFileSystem">The base <see cref="IAttributeFileSystem"/> for the
 /// new <see cref="ConcatenationFileSystem"/>.</param>
 public ConcatenationFileSystem(IAttributeFileSystem baseFileSystem) : this(baseFileSystem, DefaultSubFileSize)
 {
 }
예제 #21
0
 public void Add(string path, string internalPath, IAttributeFileSystem fs)
 {
     FileDict[path] = new Tuple <string, IAttributeFileSystem>(internalPath, fs);
 }
예제 #22
0
 public void Add(string path, string internalPath, IAttributeFileSystem fs)
 {
     path           = PathTools.Normalize(path);
     FileDict[path] = new Tuple <string, IAttributeFileSystem>(internalPath, fs);
 }