Package io.github.turtleisaac.nds4j
Class Narc
java.lang.Object
io.github.turtleisaac.nds4j.Narc
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
static final int
static final int
static final int
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionboolean
static Narc
fromContentsAndNames
(ArrayList<byte[]> files, Fnt.Folder filenames, Endianness endiannessOfBeginning) Create a NARC archive from a list of files and (optionally) a filename table.static Narc
Load a NARC archive from a file on diskstatic Narc
Load a NARC archive from a filesystem filestatic Narc
fromUnpacked
(File dir, boolean removeFilenames, Endianness endiannessOfBeginning) Load an unpacked NARC from a directory on diskstatic Narc
fromUnpacked
(String dir, boolean removeFilenames, Endianness endiannessOfBeginning) Load an unpacked NARC from a directory on diskbyte[]
getFileByName
(String filename) Return the contents of the file with the given filename (path).int
hashCode()
byte[]
save()
Generate abyte[]
representing this NARC.void
saveToFile
(File file) Generate abyte[]
representing this NARC, and save it to a file on diskvoid
saveToFile
(String path) Generate abyte[]
representing this NARC, and save it to a file on diskvoid
setFileByName
(String filename, byte[] data) Replace the contents of the NARC subfile with the given filename (path) with the given data.toString()
void
Unpacks thisNarc
to disk at the specified pathvoid
Unpacks thisNarc
to disk at the specified path
-
Field Details
-
NARC_HEADER_SIZE
public static final int NARC_HEADER_SIZE- See Also:
-
FATB_HEADER_SIZE
public static final int FATB_HEADER_SIZE- See Also:
-
FIMG_HEADER_SIZE
public static final int FIMG_HEADER_SIZE- See Also:
-
FNTB_HEADER_SIZE
public static final int FNTB_HEADER_SIZE- See Also:
-
-
Constructor Details
-
Narc
public Narc() -
Narc
public Narc(byte[] data) Read NARC data, and create a filename table and a list of files.- Parameters:
data
- abyte[]
representation of aNarc
-
-
Method Details
-
fromFile
Load a NARC archive from a filesystem file- Parameters:
file
- aString
containing the path to a NARC file on disk- Returns:
- a
Narc
object
-
fromFile
Load a NARC archive from a file on disk- Parameters:
file
- aFile
object representing the path to a NARC file on disk- Returns:
- a
Narc
object
-
fromUnpacked
public static Narc fromUnpacked(String dir, boolean removeFilenames, Endianness endiannessOfBeginning) Load an unpacked NARC from a directory on disk- Parameters:
dir
- aString
object containing the path to an unpacked NARC directory on diskremoveFilenames
- whether the NARC should have a Fnt (ignored if there are subfolders within)endiannessOfBeginning
- whether the NARC's beginning is encoded in Big Endian or Little Endian - can beEndianness.BIG
orEndianness.LITTLE
- Returns:
- a
Narc
object
-
fromUnpacked
public static Narc fromUnpacked(File dir, boolean removeFilenames, Endianness endiannessOfBeginning) Load an unpacked NARC from a directory on disk- Parameters:
dir
- aFile
object representing the path to an unpacked NARC directory on diskremoveFilenames
- whether the NARC should have a Fnt (ignored if there are subfolders within)endiannessOfBeginning
- whether the NARC's beginning is encoded in Big Endian or Little Endian - can beEndianness.BIG
orEndianness.LITTLE
- Returns:
- a
Narc
object - Throws:
RuntimeException
- if the specified path on disk does not exist or is not a directory
-
fromContentsAndNames
public static Narc fromContentsAndNames(ArrayList<byte[]> files, Fnt.Folder filenames, Endianness endiannessOfBeginning) Create a NARC archive from a list of files and (optionally) a filename table.- Parameters:
files
- anArrayList
ofbyte[]
's representing all the subfiles in the NARCfilenames
- an (OPTIONAL)Folder
representing the NARC's filesystemendiannessOfBeginning
- whether the NARC's beginning is encoded in Big Endian or Little Endian - can beEndianness.BIG
orEndianness.LITTLE
- Returns:
- a
Narc
representation of the provided parameters
-
unpack
Unpacks thisNarc
to disk at the specified path- Parameters:
dir
- aString
containing the target directory to unpack the NARC to- Throws:
RuntimeException
- if thisNarc
has an internal filesystem, the specified path already exists, a new directory at the specified path could not be created, or a failure to write the subfiles occurredIOException
- if the parent directory of the output subfiles does not exist
-
unpack
Unpacks thisNarc
to disk at the specified path- Parameters:
dir
- aFile
containing the target directory to unpack the NARC to- Throws:
RuntimeException
- if thisNarc
has an internal filesystem, the specified path already exists, a new directory at the specified path could not be created, or a failure to write the subfiles occurredIOException
- if the parent directory of the output subfiles does not exist
-
save
public byte[] save()Generate abyte[]
representing this NARC.- Returns:
- a
byte[]
-
saveToFile
Generate abyte[]
representing this NARC, and save it to a file on disk- Parameters:
path
- aString
containing the path to the file on disk to save as- Throws:
IOException
- if the specified file's parent directory does not exist.
-
saveToFile
Generate abyte[]
representing this NARC, and save it to a file on disk- Parameters:
file
- aFile
representing the path to the file on disk to save as- Throws:
RuntimeException
- if the provided path leads to a directoryIOException
- if the specified file's parent directory does not exist.
-
getFileByName
Return the contents of the file with the given filename (path).- Parameters:
filename
- aString
containing the path to the requested NARC subfile- Returns:
- a
byte[]
containing the contents of the requested NARC subfile - Throws:
RuntimeException
- if file with given name is not found
-
setFileByName
Replace the contents of the NARC subfile with the given filename (path) with the given data.- Parameters:
filename
- aString
containing the path to the specified NARC subfiledata
- abyte[]
containing the contents to set for the specified NARC subfile- Throws:
RuntimeException
- if file with given name is not found
-
toString
-
equals
-
hashCode
public int hashCode()
-