Class IndexFile
java.lang.Object
de.mrjulsen.dragnsounds.core.filesystem.IndexFile
- All Implemented Interfaces:
de.mrjulsen.mcdragonlib.data.INBTSerializable
,AutoCloseable
public class IndexFile
extends Object
implements de.mrjulsen.mcdragonlib.data.INBTSerializable, AutoCloseable
A file containing information about all custom sound files in the same directory. Files that are not registered in this index file cannot be accessed.
-
Field Summary
Modifier and TypeFieldDescriptionstatic final int
The current version of the index file save format.static final String
-
Constructor Summary
ConstructorDescriptionIndexFile
(SoundLocation location, boolean readOnly) Get the index file of the given location. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Registers the given sound file in the index file so it can be accessed later.void
Checks all entries and removes files that no longer exist at the current location.void
close()
int
count()
boolean
Deletes the sound file from the disk and from the index file.void
deserializeNbt
(net.minecraft.nbt.CompoundTag nbt) static boolean
existsIn
(SoundLocation location) Checks if an index file exists at the given location.Generates a new id that doesn't already exist at this location.getAll()
getSoundFile
(String soundId) Get the sound file with the given id at the current location of the index file.boolean
Checks if the sound file exists.boolean
Checks if a sound file with the given id exists.boolean
static IndexFile
open
(SoundLocation location, boolean readOnly) Open the index file at the given location.void
save()
Saves the changed index file to disk.net.minecraft.nbt.CompoundTag
-
Field Details
-
INDEX_FILENAME
- See Also:
-
DATA_VERSION
public static final int DATA_VERSIONThe current version of the index file save format.- See Also:
-
-
Constructor Details
-
IndexFile
Get the index file of the given location.- Parameters:
location
- The target directory location.- Throws:
IOException
-
-
Method Details
-
checkAndRepair
public void checkAndRepair()Checks all entries and removes files that no longer exist at the current location. -
getLocation
- Returns:
- The location of this file.
-
add
Registers the given sound file in the index file so it can be accessed later. This is very important, otherwise the sound file gets lost and may be deleted.- Parameters:
file
- The sound file to register.- API Note:
- Cannot be used in read-only mode!
-
has
Checks if a sound file with the given id exists.- Parameters:
soundId
- The id of the custom sound file you want to check.- Returns:
true
if the file exists,false
otherwise.
-
has
Checks if the sound file exists.- Parameters:
file
- The file you want to check.- Returns:
true
if the file exists,false
otherwise.
-
delete
Deletes the sound file from the disk and from the index file.- Parameters:
soundId
- The id of the custom sound file.- Returns:
- Whether the action was successfull.
- API Note:
- Cannot be used in read-only mode!
-
getSoundFile
Get the sound file with the given id at the current location of the index file.- Parameters:
soundId
- The id of the cusotm sound file.- Returns:
- The
SoundFile
if available,null
otherwise.
-
getAll
- Returns:
- A list of all registered sound files that also exist on disk.
-
isReadOnly
public boolean isReadOnly()- Returns:
- If this instance of the file is read-only.
-
save
public void save()Saves the changed index file to disk. Run this every time after changing some values. You can also use try-with-resources which saves the changed index file automatically.- API Note:
- Cannot be used in read-only mode!
-
open
Open the index file at the given location. If no index file exists, a new one will be created (only in memory, not on disk).- Parameters:
location
- The location of the index file.readOnly
- If the instance should be read-only. Use this whenever possible to make the file accessible for other processes.- Returns:
- The index file.
- Throws:
IOException
-
existsIn
Checks if an index file exists at the given location.- Parameters:
location
- The location to check.- Returns:
true
if there is an index file at this location.
-
generateId
Generates a new id that doesn't already exist at this location.- Returns:
- The new id.
-
serializeNbt
public net.minecraft.nbt.CompoundTag serializeNbt()- Specified by:
serializeNbt
in interfacede.mrjulsen.mcdragonlib.data.INBTSerializable
-
deserializeNbt
public void deserializeNbt(net.minecraft.nbt.CompoundTag nbt) - Specified by:
deserializeNbt
in interfacede.mrjulsen.mcdragonlib.data.INBTSerializable
-
close
public void close()- Specified by:
close
in interfaceAutoCloseable
-
count
public int count()- Returns:
- The amount of registered files.
-