mirror of
https://github.com/Thealexbarney/LibHac.git
synced 2024-11-14 10:49:41 +01:00
Add PathTools.Combine
This commit is contained in:
parent
b92750688e
commit
f7b983ccb2
9 changed files with 33 additions and 16 deletions
|
@ -15,7 +15,7 @@ namespace LibHac.Nand
|
|||
public string FullPath { get; }
|
||||
public OpenDirectoryMode Mode { get; }
|
||||
private DiscDirectoryInfo DirInfo { get; }
|
||||
|
||||
|
||||
public FatFileSystemDirectory(FatFileSystemProvider fs, string path, OpenDirectoryMode mode)
|
||||
{
|
||||
ParentFileSystem = fs;
|
||||
|
@ -38,7 +38,7 @@ namespace LibHac.Nand
|
|||
DirectoryEntryType type = isDir ? DirectoryEntryType.Directory : DirectoryEntryType.File;
|
||||
long length = isDir ? 0 : entry.FileSystem.GetFileLength(entry.FullName);
|
||||
|
||||
yield return new DirectoryEntry(entry.Name, FullPath + '/' + entry.Name, type, length)
|
||||
yield return new DirectoryEntry(entry.Name, PathTools.Combine(FullPath, entry.Name), type, length)
|
||||
{
|
||||
Attributes = entry.Attributes.ToNxAttributes()
|
||||
};
|
||||
|
|
|
@ -18,8 +18,8 @@ namespace LibHac.Fs
|
|||
|
||||
foreach (DirectoryEntry entry in source.Read())
|
||||
{
|
||||
string subSrcPath = PathTools.Normalize(source.FullPath + '/' + entry.Name);
|
||||
string subDstPath = PathTools.Normalize(dest.FullPath + '/' + entry.Name);
|
||||
string subSrcPath = PathTools.Normalize(PathTools.Combine(source.FullPath, entry.Name));
|
||||
string subDstPath = PathTools.Normalize(PathTools.Combine(dest.FullPath, entry.Name));
|
||||
|
||||
if (entry.Type == DirectoryEntryType.Directory)
|
||||
{
|
||||
|
@ -95,7 +95,7 @@ namespace LibHac.Fs
|
|||
|
||||
if (entry.Type != DirectoryEntryType.Directory || !recurse) continue;
|
||||
|
||||
IDirectory subDir = fs.OpenDirectory(directory.FullPath + '/' + entry.Name, OpenDirectoryMode.All);
|
||||
IDirectory subDir = fs.OpenDirectory(PathTools.Combine(directory.FullPath, entry.Name), OpenDirectoryMode.All);
|
||||
|
||||
foreach (DirectoryEntry subEntry in subDir.EnumerateEntries(searchPattern, searchOptions))
|
||||
{
|
||||
|
@ -189,9 +189,10 @@ namespace LibHac.Fs
|
|||
|
||||
foreach (DirectoryEntry entry in directory.Read())
|
||||
{
|
||||
string subPath = PathTools.Combine(directory.FullPath, entry.Name);
|
||||
|
||||
if (entry.Type == DirectoryEntryType.Directory)
|
||||
{
|
||||
string subPath = directory.FullPath + '/' + entry.Name;
|
||||
IDirectory subDir = fs.OpenDirectory(subPath, OpenDirectoryMode.All);
|
||||
|
||||
CleanDirectoryRecursivelyGeneric(subDir);
|
||||
|
@ -199,7 +200,7 @@ namespace LibHac.Fs
|
|||
}
|
||||
else if (entry.Type == DirectoryEntryType.File)
|
||||
{
|
||||
fs.DeleteFile(directory.FullPath + '/' + entry.Name);
|
||||
fs.DeleteFile(subPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ namespace LibHac.Fs
|
|||
DirectoryEntryType type = isDir ? DirectoryEntryType.Directory : DirectoryEntryType.File;
|
||||
long length = isDir ? 0 : ((FileInfo)entry).Length;
|
||||
|
||||
yield return new DirectoryEntry(entry.Name, FullPath + '/' + entry.Name, type, length)
|
||||
yield return new DirectoryEntry(entry.Name, PathTools.Combine(FullPath, entry.Name), type, length)
|
||||
{
|
||||
Attributes = entry.Attributes.ToNxAttributes()
|
||||
};
|
||||
|
|
|
@ -24,7 +24,7 @@ namespace LibHac.Fs
|
|||
|
||||
internal string ResolveLocalPath(string path)
|
||||
{
|
||||
return Path.Combine(BasePath, path.TrimStart('/'));
|
||||
return PathTools.Combine(BasePath, path);
|
||||
}
|
||||
|
||||
public NxFileAttributes GetFileAttributes(string path)
|
||||
|
|
|
@ -217,6 +217,23 @@ namespace LibHac.Fs
|
|||
return path[rootLength] == DirectorySeparator && path.Length > rootLength + 1;
|
||||
}
|
||||
|
||||
public static string Combine(string path1, string path2)
|
||||
{
|
||||
if(path1 == null || path2 == null) throw new NullReferenceException();
|
||||
|
||||
if (string.IsNullOrEmpty(path1)) return path2;
|
||||
if (string.IsNullOrEmpty(path2)) return path1;
|
||||
|
||||
bool hasSeparator = IsDirectorySeparator(path1[path1.Length - 1]) || IsDirectorySeparator(path2[0]);
|
||||
|
||||
if (hasSeparator)
|
||||
{
|
||||
return path1 + path2;
|
||||
}
|
||||
|
||||
return path1 + DirectorySeparator + path2;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal static bool IsDirectorySeparator(char c)
|
||||
{
|
||||
|
|
|
@ -29,7 +29,7 @@ namespace LibHac.Fs.RomFs
|
|||
{
|
||||
while (tab.FindNextDirectory(ref position, out string name))
|
||||
{
|
||||
yield return new DirectoryEntry(name, FullPath + '/' + name, DirectoryEntryType.Directory, 0);
|
||||
yield return new DirectoryEntry(name, PathTools.Combine(FullPath, name), DirectoryEntryType.Directory, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -37,7 +37,7 @@ namespace LibHac.Fs.RomFs
|
|||
{
|
||||
while (tab.FindNextFile(ref position, out RomFileInfo info, out string name))
|
||||
{
|
||||
yield return new DirectoryEntry(name, FullPath + '/' + name, DirectoryEntryType.File, info.Length);
|
||||
yield return new DirectoryEntry(name, PathTools.Combine(FullPath, name), DirectoryEntryType.File, info.Length);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ namespace LibHac.Fs.Save
|
|||
{
|
||||
while (tab.FindNextDirectory(ref position, out string name))
|
||||
{
|
||||
yield return new DirectoryEntry(name, FullPath + '/' + name, DirectoryEntryType.Directory, 0);
|
||||
yield return new DirectoryEntry(name, PathTools.Combine(FullPath, name), DirectoryEntryType.Directory, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -37,7 +37,7 @@ namespace LibHac.Fs.Save
|
|||
{
|
||||
while (tab.FindNextFile(ref position, out SaveFileInfo info, out string name))
|
||||
{
|
||||
yield return new DirectoryEntry(name, FullPath + '/' + name, DirectoryEntryType.File, info.Length);
|
||||
yield return new DirectoryEntry(name, PathTools.Combine(FullPath, name), DirectoryEntryType.File, info.Length);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,8 +9,7 @@ namespace LibHac.Fs
|
|||
|
||||
private string ResolveFullPath(string path)
|
||||
{
|
||||
//todo
|
||||
return RootPath + path;
|
||||
return PathTools.Combine(RootPath, path);
|
||||
}
|
||||
|
||||
public SubdirectoryFileSystem(IFileSystem fs, string rootPath)
|
||||
|
|
|
@ -22,7 +22,7 @@ namespace LibHac.Fs
|
|||
{
|
||||
foreach (DirectoryEntry entry in BaseDirectory.Read())
|
||||
{
|
||||
yield return new DirectoryEntry(entry.Name, FullPath + '/' + entry.Name, entry.Type, entry.Size);
|
||||
yield return new DirectoryEntry(entry.Name, PathTools.Combine(FullPath, entry.Name), entry.Type, entry.Size);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue