Skip to content

Archive

Type

Archive

The Archive type represents an archive (wad/pk3/etc) in SLADE.

Properties

Property Type Description
filename string The full path to the archive file on disk
entries ArchiveEntry[] An array of all entries in the archive
rootDir ArchiveDir The root directory of the archive
format ArchiveFormat Information about the archive's format

Constructors

No Constructors

This type can not be created directly in scripts.

See:

Functions

Overview

General

DirAtPath(path) -> ArchiveDir EntryAtPath(path) -> ArchiveEntry FilenameNoPath() -> string Save([path]) -> boolean, string

Entry Manipulation

CreateDir(path) -> ArchiveDir CreateEntry(fullPath, index) -> ArchiveEntry CreateEntryInNamespace(name, namespace) -> ArchiveEntry RemoveEntry(entry) -> boolean RenameEntry(entry, name) -> boolean

Entry Search

FindFirst(options) -> ArchiveEntry FindLast(options) -> ArchiveEntry FindAll(options) -> ArchiveEntry[]


DirAtPath

Parameters

  • path (string): The path of the directory to get

Returns

  • ArchiveDir: The directory in the archive at path, or nil if the path does not exist

Notes

If the archive does not support directories (eg. Doom Wad format) the 'root' directory is always returned, regardless of path.


EntryAtPath

Parameters

  • path (string): The path of the entry to get

Returns

  • ArchiveEntry: The entry in the archive at path, or nil if no entry at the given path exists

Notes

If multiple entries exist with the same path, the first match is returned.


FilenameNoPath

Gets the archive's filename without the full path

Returns

  • string: The archive's filename without the full path

Example

local archive = Archives.OpenFile('C:/games/doom/archive.wad')
App.LogMessage(archive:FilenameNoPath) -- 'archive.wad'

Save

Saves the archive to disk.

Parameters

  • [path] (string): The full path to the file to save as. Default is "", which will use the archive's existing filename

Returns

  • boolean: true if saving succeeded
  • string: An error message if saving failed

Notes

If path is given, this will work like 'Save As' - the archive will be saved to a new file at the given path, overwriting the file if it already exists. This will also update the filename property.

Example

-- Open an archive
local archive = Archives.OpenFile('c:/filename.wad')
App.LogMessage(archive.filename) -- 'c:/filename.wad'

-- Save to existing file (c:/filename.wad)
local ok, err = archive:save()
if not ok then
    App.LogMessage('Failed to save: ' .. err)
end

-- Save as new file
ok, err = archive:Save('c:/newfile.wad')
if not ok then
    App.LogMessage('Failed to save as new file: ' .. err)
end

App.LogMessage(archive.filename) -- 'c:/newfile.wad'

CreateDir

Creates a new directory at path in the archive. Has no effect if the archive format doesn't support directories.

Parameters

  • path (string): The path of the directory to create

Returns

  • ArchiveDir: The directory that was created or nil if the archive format doesn't support directories

CreateEntry

Creates a new entry named fullPath in the archive at index within the target directory.

Parameters

  • fullPath (string): The full path and name of the entry to create
  • index (integer): The index to insert the entry

Returns

Notes

If the Archive is a format that supports directories, fullPath can optionally contain a path eg. Scripts/NewScript.txt.

The new entry will be inserted at index in the directory it is added to (always the root for Archives that don't support directories). If index is -1 or larger than the number of entries in the destination directory, the new entry will be added at the end.

Example

-- Create entry in the root directory of a zip, after all other entries
newEntry = zip:CreateEntry('InRoot.txt', 0)

-- Create entry in a subdirectory of a zip, before all other entries in the subdirectory
newEntry = zip:CreateEntry('Path/To/NewEntry.txt', 1)

-- Create entry in the middle of a wad somewhere
newEntry = wad:CreateEntry('NEWENTRY', 12)

CreateEntryInNamespace

Creates a new entry named name in the Archive, at the end of namespace.

Parameters

  • name (string): The name of the entry
  • namespace (string): The namespace to add the entry to

Returns

Notes

If the Archive supports directories, namespace can be a path.

See below for a list of supported namespaces:

Namespace Wad Archive Markers Zip Archive Directory
patches P_START / P_END patches
sprites S_START / S_END sprites
flats F_START / F_END flats
textures TX_START / TX_END textures
hires HI_START / HI_END hires
colormaps C_START / C_END colormaps
acs A_START / A_END acs
voices V_START / V_END voices
voxels VX_START / VX_END voxels
sounds DS_START / DS_END sounds

RemoveEntry

Removes the given entry from the archive (but does not delete it).

Parameters

Returns

  • boolean: false if the entry was not found in the archive

RenameEntry

Renames the given entry.

Parameters

  • entry (ArchiveEntry): The entry to rename
  • name (string): The new name for the entry

Returns

  • boolean: false if the entry was not found in the archive

FindFirst

Parameters

Returns

  • ArchiveEntry: The first entry found in the archive matching the given options, or nil if no match was found

Notes

If searchSubdirs is true in the options, subdirectories will be searched after the entries in the specified dir.


FindLast

Parameters

Returns

  • ArchiveEntry: The last entry found in the archive matching the given options, or nil if no match was found

Notes

If searchSubdirs is true in the options, subdirectories will be searched after the entries in the specified dir.


FindAll

Parameters

Returns

  • ArchiveEntry[]: All entries found in the archive matching the given options, or an empty array if no match is found