public void SetFileAttributes_PathDoesNotExist_ReturnsPathNotFound() { IAttributeFileSystem fs = CreateAttributeFileSystem(); Result rc = fs.SetFileAttributes("/path".ToU8Span(), NxFileAttributes.None); Assert.Equal(ResultFs.PathNotFound.Value, rc); }
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)); }
public void GetFileSize_PathDoesNotExist_ReturnsPathNotFound() { IAttributeFileSystem fs = CreateAttributeFileSystem(); Result rc = fs.GetFileSize(out _, "/path".ToU8Span()); Assert.Equal(ResultFs.PathNotFound.Value, rc); }
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); }
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); }
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); }
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); }
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); }
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); }
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)); }
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))); } }
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); }
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); }
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)); }
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())); * ; * } * }*/ }
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); }
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)); }
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)); }
/// <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; }
/// <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) { }
public void Add(string path, string internalPath, IAttributeFileSystem fs) { FileDict[path] = new Tuple <string, IAttributeFileSystem>(internalPath, fs); }
public void Add(string path, string internalPath, IAttributeFileSystem fs) { path = PathTools.Normalize(path); FileDict[path] = new Tuple <string, IAttributeFileSystem>(internalPath, fs); }