Fixes and an ugly hack in DiscUtils

This commit is contained in:
shadowninja108 2018-12-17 18:58:05 -07:00
parent 9b476fa8ce
commit f62b34905e
5 changed files with 37 additions and 15 deletions

View file

@ -435,7 +435,11 @@ namespace DiscUtils.Internal
pattern += "."; pattern += ".";
} }
string query = "^" + Regex.Escape(pattern).Replace(@"\*", ".*").Replace(@"\?", "[^.]") + "$"; string query;
if (pattern == "*.")
query = ".*";
else
query = "^" + Regex.Escape(pattern).Replace(@"\*", ".*").Replace(@"\?", "[^.]") + "$";
return new Regex(query, RegexOptions.IgnoreCase | RegexOptions.CultureInvariant); return new Regex(query, RegexOptions.IgnoreCase | RegexOptions.CultureInvariant);
} }

View file

@ -28,6 +28,11 @@ namespace LibHac.Nand
return Fs.DirectoryExists(directory.Path); return Fs.DirectoryExists(directory.Path);
} }
public override long GetSize(IFile file)
{
return Fs.GetFileInfo(file.Path).Length;
}
public new virtual IStorage OpenFile(IFile file, FileMode mode) public new virtual IStorage OpenFile(IFile file, FileMode mode)
{ {
return Fs.OpenFile(file.Path, mode).AsStorage(); return Fs.OpenFile(file.Path, mode).AsStorage();
@ -49,17 +54,12 @@ namespace LibHac.Nand
string[] dirs = Fs.GetDirectories(directory.Path, searchPattern, searchOption); string[] dirs = Fs.GetDirectories(directory.Path, searchPattern, searchOption);
List<IFileSytemEntry> entries = new List<IFileSytemEntry>(); List<IFileSytemEntry> entries = new List<IFileSytemEntry>();
for (int i = 0; i < dirs.Length; i++) for (int i = 0; i < dirs.Length; i++)
entries.Add(new IDirectory(this, dirs[i])); entries.Add(GetDirectory(dirs[i]));
for (int i = 0; i < files.Length; i++) for (int i = 0; i < files.Length; i++)
entries.Add(new IFile(this, files[i])); entries.Add(GetFile(files[i]));
return entries.ToArray(); return entries.ToArray();
} }
public string GetFullPath(string path)
{
return path;
}
protected override IDirectory GetPath(string path) protected override IDirectory GetPath(string path)
{ {
return new IDirectory(this, path); return new IDirectory(this, path);

View file

@ -11,6 +11,7 @@ namespace LibHac
public abstract bool FileExists(IFile path); public abstract bool FileExists(IFile path);
public abstract bool DirectoryExists(IDirectory path); public abstract bool DirectoryExists(IDirectory path);
public abstract long GetSize(IFile file);
public IStorage OpenFile(IFile file, FileMode mode) public IStorage OpenFile(IFile file, FileMode mode)
{ {
@ -51,6 +52,7 @@ namespace LibHac
{ {
public abstract IFileSystem FileSystem { get; } public abstract IFileSystem FileSystem { get; }
public abstract string Path { get; } public abstract string Path { get; }
public virtual string Name => System.IO.Path.GetFileName(Path);
public abstract bool Exists { get; } public abstract bool Exists { get; }
public IDirectory Parent public IDirectory Parent
@ -108,9 +110,9 @@ namespace LibHac
public override string Path { get; } public override string Path { get; }
public override bool Exists => FileSystem.FileExists(this); public override bool Exists => FileSystem.FileExists(this);
public string Name => System.IO.Path.GetFileNameWithoutExtension(Path);
public string Extension => System.IO.Path.GetExtension(Path); public string Extension => System.IO.Path.GetExtension(Path);
public string FileName => System.IO.Path.GetFileName(Path); public string FileName => System.IO.Path.GetFileName(Path);
public long Length => FileSystem.GetSize(this);
public IFile(IFileSystem filesystem, string path) public IFile(IFileSystem filesystem, string path)
{ {
@ -127,5 +129,16 @@ namespace LibHac
{ {
return FileSystem.OpenFile(this, mode, access); return FileSystem.OpenFile(this, mode, access);
} }
public override bool Equals(object obj)
{
IFile other = (IFile) obj;
return other.FileSystem == FileSystem && other.Path == Path;
}
public override int GetHashCode()
{
return base.GetHashCode();
}
} }
} }

View file

@ -27,23 +27,28 @@ namespace LibHac
return Directory.Exists(Path.Combine(Root, directory.Path)); return Directory.Exists(Path.Combine(Root, directory.Path));
} }
public override long GetSize(IFile file)
{
return new FileInfo(GetFullPath(file)).Length;
}
public override IStorage OpenFile(IFile file, FileMode mode, FileAccess access) public override IStorage OpenFile(IFile file, FileMode mode, FileAccess access)
{ {
return new FileStream(GetFullPath(file), mode, access).AsStorage(); return new StreamStorage(new FileStream(GetFullPath(file), mode, access), false);
} }
public override IFileSytemEntry[] GetFileSystemEntries(IDirectory path, string searchPattern, SearchOption searchOption) public override IFileSytemEntry[] GetFileSystemEntries(IDirectory path, string searchPattern, SearchOption searchOption)
{ {
var result = new List<IFileSytemEntry>(); var result = new List<IFileSytemEntry>();
Console.WriteLine(searchPattern);
DirectoryInfo root = new DirectoryInfo(GetFullPath(path)); DirectoryInfo root = new DirectoryInfo(GetFullPath(path));
foreach(FileSystemInfo info in root.EnumerateFileSystemInfos(searchPattern, searchOption)) foreach(FileSystemInfo info in root.EnumerateFileSystemInfos(searchPattern, searchOption))
{ {
string relativePath = Util.GetRelativePath(info.FullName, Root); string relativePath = Util.GetRelativePath(info.FullName, Root);
if (info.Attributes.HasFlag(FileAttributes.Directory)) if (info.Attributes.HasFlag(FileAttributes.Directory))
result.Add(new IDirectory(this, relativePath)); result.Add(GetDirectory(relativePath));
else else
result.Add(new LocalFile(this, relativePath)); result.Add(GetFile(relativePath));
} }
return result.ToArray(); return result.ToArray();

View file

@ -545,7 +545,6 @@ namespace LibHac
new KeyValue("bis_kek_source", 0x10, set => set.BisKekSource), new KeyValue("bis_kek_source", 0x10, set => set.BisKekSource),
new KeyValue("save_mac_kek_source", 0x10, set => set.SaveMacKekSource), new KeyValue("save_mac_kek_source", 0x10, set => set.SaveMacKekSource),
new KeyValue("save_mac_key_source", 0x10, set => set.SaveMacKeySource), new KeyValue("save_mac_key_source", 0x10, set => set.SaveMacKeySource),
new KeyValue("save_mac_key", 0x10, set => set.SaveMacKey)
}; };
for (int slot = 0; slot < 0x20; slot++) for (int slot = 0; slot < 0x20; slot++)
@ -585,7 +584,8 @@ namespace LibHac
new KeyValue("secure_boot_key", 0x10, set => set.SecureBootKey), new KeyValue("secure_boot_key", 0x10, set => set.SecureBootKey),
new KeyValue("tsec_key", 0x10, set => set.TsecKey), new KeyValue("tsec_key", 0x10, set => set.TsecKey),
new KeyValue("device_key", 0x10, set => set.DeviceKey), new KeyValue("device_key", 0x10, set => set.DeviceKey),
new KeyValue("sd_seed", 0x10, set => set.SdSeed) new KeyValue("sd_seed", 0x10, set => set.SdSeed),
new KeyValue("save_mac_key", 0x10, set => set.SaveMacKey)
}; };
for (int slot = 0; slot < 0x20; slot++) for (int slot = 0; slot < 0x20; slot++)