Package io.github.turtleisaac.nds4j
Class Narc
java.lang.Object
io.github.turtleisaac.nds4j.Narc
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intstatic final intstatic final intstatic final int -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanstatic NarcfromContentsAndNames(ArrayList<byte[]> files, Fnt.Folder filenames, Endianness endiannessOfBeginning) Create a NARC archive from a list of files and (optionally) a filename table.static NarcLoad a NARC archive from a file on diskstatic NarcLoad a NARC archive from a filesystem filestatic NarcfromUnpacked(File dir, boolean removeFilenames, Endianness endiannessOfBeginning) Load an unpacked NARC from a directory on diskstatic NarcfromUnpacked(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).inthashCode()byte[]save()Generate abyte[]representing this NARC.voidsaveToFile(File file) Generate abyte[]representing this NARC, and save it to a file on diskvoidsaveToFile(String path) Generate abyte[]representing this NARC, and save it to a file on diskvoidsetFileByName(String filename, byte[] data) Replace the contents of the NARC subfile with the given filename (path) with the given data.toString()voidUnpacks thisNarcto disk at the specified pathvoidUnpacks thisNarcto 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- aStringcontaining the path to a NARC file on disk- Returns:
- a
Narcobject
-
fromFile
Load a NARC archive from a file on disk- Parameters:
file- aFileobject representing the path to a NARC file on disk- Returns:
- a
Narcobject
-
fromUnpacked
public static Narc fromUnpacked(String dir, boolean removeFilenames, Endianness endiannessOfBeginning) Load an unpacked NARC from a directory on disk- Parameters:
dir- aStringobject 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.BIGorEndianness.LITTLE- Returns:
- a
Narcobject
-
fromUnpacked
public static Narc fromUnpacked(File dir, boolean removeFilenames, Endianness endiannessOfBeginning) Load an unpacked NARC from a directory on disk- Parameters:
dir- aFileobject 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.BIGorEndianness.LITTLE- Returns:
- a
Narcobject - 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- anArrayListofbyte[]'s representing all the subfiles in the NARCfilenames- an (OPTIONAL)Folderrepresenting the NARC's filesystemendiannessOfBeginning- whether the NARC's beginning is encoded in Big Endian or Little Endian - can beEndianness.BIGorEndianness.LITTLE- Returns:
- a
Narcrepresentation of the provided parameters
-
unpack
Unpacks thisNarcto disk at the specified path- Parameters:
dir- aStringcontaining the target directory to unpack the NARC to- Throws:
RuntimeException- if thisNarchas 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 thisNarcto disk at the specified path- Parameters:
dir- aFilecontaining the target directory to unpack the NARC to- Throws:
RuntimeException- if thisNarchas 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- aStringcontaining 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- aFilerepresenting 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- aStringcontaining 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- aStringcontaining 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()
-