-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
712b0cf
commit 18d5133
Showing
11 changed files
with
207 additions
and
173 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,34 @@ | ||
namespace TLTool; | ||
|
||
/// <summary>A data header entry referencing an external file.</summary> | ||
public sealed class DataHeaderEntry : IDataHeaderEntry | ||
/// <summary>An entry in a data file header.</summary> | ||
public sealed class DataHeaderEntry | ||
{ | ||
/// <summary>The file used as the source for the entry's data.</summary> | ||
public FileInfo FileInfo { get; } | ||
/// <summary>The source for the entry's data.</summary> | ||
public IDataSource DataSource { get; } | ||
|
||
/// <inheritdoc/> | ||
public long Length => FileInfo.Length; | ||
|
||
/// <inheritdoc/> | ||
public string Extension => FileInfo.Extension.TrimStart('.'); | ||
/// <summary>The file extension for the entry, excluding a leading period.</summary> | ||
public string Extension { get; } | ||
|
||
/// <summary>Initializes a new <see cref="DataHeaderEntry"/> instance.</summary> | ||
public DataHeaderEntry(FileInfo file) | ||
{ | ||
ArgumentNullException.ThrowIfNull(file); | ||
FileInfo = file; | ||
DataSource = new FileDataSource(file); | ||
Extension = GetExtension(file.Extension); | ||
|
||
static string GetExtension(string extension) | ||
{ | ||
if (string.IsNullOrEmpty(extension)) | ||
return extension; | ||
|
||
return extension[1..]; | ||
} | ||
} | ||
|
||
/// <inheritdoc/> | ||
public Stream OpenRead() | ||
/// <summary>Initializes a new <see cref="DataHeaderEntry"/> instance.</summary> | ||
public DataHeaderEntry(IDataSource source, string extension) | ||
{ | ||
return FileInfo.OpenRead(); | ||
DataSource = source; | ||
Extension = extension; | ||
} | ||
} |
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,24 @@ | ||
namespace TLTool; | ||
|
||
/// <summary>A data source referencing a file on disk.</summary> | ||
public sealed class FileDataSource : IDataSource | ||
{ | ||
/// <summary>The file referenced by this data source.</summary> | ||
public FileInfo File { get; } | ||
|
||
/// <inheritdoc/> | ||
public long Length => File.Length; | ||
|
||
/// <summary>Initializes a new <see cref="FileDataSource"/> instance.</summary> | ||
public FileDataSource(FileInfo file) | ||
{ | ||
ArgumentNullException.ThrowIfNull(file); | ||
File = file; | ||
} | ||
|
||
/// <inheritdoc/> | ||
public Stream OpenRead() | ||
{ | ||
return File.OpenRead(); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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,11 @@ | ||
namespace TLTool; | ||
|
||
/// <summary>A source of data.</summary> | ||
public interface IDataSource | ||
{ | ||
/// <summary>The uncompressed length of the data, in bytes.</summary> | ||
long Length { get; } | ||
|
||
/// <summary>Opens the data for reading.</summary> | ||
Stream OpenRead(); | ||
} |
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,34 @@ | ||
namespace TLTool; | ||
|
||
public sealed class NameDictionary : Dictionary<uint, string> | ||
{ | ||
public bool TryAdd(string name) | ||
{ | ||
return TryAdd(NameHash.Compute(name), name); | ||
} | ||
|
||
public string GetNameOrFallback(uint hash, string extension) | ||
{ | ||
if (TryGetValue(hash, out string? name)) | ||
return name; | ||
|
||
return $"${hash:X8}.{extension}"; | ||
} | ||
|
||
public void AddNames(TextReader reader) | ||
{ | ||
for (string? line; (line = reader.ReadLine()) is { };) | ||
{ | ||
if (string.IsNullOrEmpty(line)) | ||
continue; | ||
|
||
TryAdd(line); | ||
} | ||
} | ||
|
||
public void AddNamesFromFile(string path) | ||
{ | ||
using var reader = new StreamReader(path); | ||
AddNames(reader); | ||
} | ||
} |
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
Oops, something went wrong.