-
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.
Read file directory index, if it exists
- Loading branch information
Showing
3 changed files
with
113 additions
and
14 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
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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
module dbpf.files.dir; | ||
|
||
import dbpf : Version; | ||
|
||
import std.typecons : Flag, No, Yes; | ||
|
||
/// | ||
struct Entry(Flag!"isResource" isResource) { | ||
import dbpf.tgi : Tgi; | ||
align(1): | ||
/// | ||
Tgi tgi; | ||
/// Resource ID. | ||
static if (isResource) uint resourceId; | ||
/// Size of an uncompressed file, in bytes. | ||
uint size; | ||
} | ||
|
||
static assert(Entry!(No.isResource).alignof == 1); | ||
static assert(Entry!(No.isResource).sizeof == 16); | ||
static assert(Entry!(Yes.isResource).alignof == 1); | ||
static assert(Entry!(Yes.isResource).sizeof == 20); | ||
|
||
/// | ||
struct Directory(Version indexVersion) { | ||
import dbpf : UncompressedFile; | ||
|
||
static if (indexVersion == Version.sc4Index) alias DirectoryEntry = Entry!(No.isResource); | ||
static if (indexVersion == Version.sc4Index) alias DirectoryEntry = Entry!(Yes.isResource); | ||
|
||
/// | ||
DirectoryEntry[] entries; | ||
|
||
/// | ||
this(ref UncompressedFile file) { | ||
import std.algorithm : copy; | ||
import std.conv : castFrom; | ||
|
||
this.entries = new DirectoryEntry[file.size / DirectoryEntry.sizeof]; | ||
auto entriesBytes = castFrom!(DirectoryEntry*).to!(ubyte*)(entries.ptr); | ||
assert(file.contents.copy(entriesBytes[0..(entries.length * DirectoryEntry.sizeof)]).length == 0, ""); | ||
} | ||
} |