-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
125 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
using StarBreaker.FileSystem; | ||
|
||
namespace StarBreaker.P4k; | ||
|
||
public sealed partial class P4kFile : IFileSystem | ||
{ | ||
public IEnumerable<string> GetDirectories(string path) | ||
{ | ||
Span<Range> ranges = stackalloc Range[20]; | ||
var span = path.AsSpan(); | ||
var partsCount = span.Split(ranges, '\\'); | ||
var current = Root; | ||
|
||
for (var index = 0; index < partsCount; index++) | ||
{ | ||
var part = ranges[index]; | ||
if (!current.Children.TryGetValue(string.GetHashCode(span[part]), out var value)) | ||
{ | ||
yield break; | ||
} | ||
|
||
current = value; | ||
} | ||
|
||
foreach (var child in current.Children.Values.Where(x => x.ZipEntry == null)) | ||
{ | ||
yield return child.Name; | ||
} | ||
} | ||
|
||
public IEnumerable<string> GetFiles(string path) | ||
{ | ||
Span<Range> ranges = stackalloc Range[20]; | ||
var span = path.AsSpan(); | ||
var partsCount = span.Split(ranges, '\\'); | ||
|
||
var current = Root; | ||
|
||
for (var index = 0; index < partsCount; index++) | ||
{ | ||
var part = ranges[index]; | ||
if (!current.Children.TryGetValue(string.GetHashCode(span[part]), out var value)) | ||
{ | ||
yield break; | ||
} | ||
|
||
current = value; | ||
} | ||
|
||
foreach (var child in current.Children.Values.Where(x => x.ZipEntry != null)) | ||
{ | ||
yield return child.Name; | ||
} | ||
} | ||
|
||
public bool Exists(string path) | ||
{ | ||
Span<Range> ranges = stackalloc Range[20]; | ||
var span = path.AsSpan(); | ||
var partsCount = span.Split(ranges, '\\'); | ||
var current = Root; | ||
|
||
for (var index = 0; index < partsCount; index++) | ||
{ | ||
var part = ranges[index]; | ||
if (!current.Children.TryGetValue(string.GetHashCode(span[part]), out var value)) | ||
{ | ||
return false; | ||
} | ||
|
||
current = value; | ||
} | ||
|
||
return current.ZipEntry != null; | ||
} | ||
|
||
public Stream OpenRead(string path) | ||
{ | ||
Span<Range> ranges = stackalloc Range[20]; | ||
var span = path.AsSpan(); | ||
var partsCount = span.Split(ranges, '\\'); | ||
var current = Root; | ||
|
||
for (var index = 0; index < partsCount; index++) | ||
{ | ||
var part = ranges[index]; | ||
if (!current.Children.TryGetValue(string.GetHashCode(span[part]), out var value)) | ||
{ | ||
throw new FileNotFoundException(); | ||
} | ||
|
||
current = value; | ||
} | ||
|
||
if (current.ZipEntry == null) | ||
{ | ||
throw new FileNotFoundException(); | ||
} | ||
|
||
return Open(current.ZipEntry); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters