libElysianVMU 1.6.0
Full-featured, accurate, cross-platform library emulating the Dreamcast's Visual Memory Unit
Loading...
Searching...
No Matches
evmu_file_manager.h
Go to the documentation of this file.
1/*! \file
2 * \brief EvmuFileManager software peripheral
3 * \ingroup file_system
4 *
5 * EvmuFileManager offers a high-level, file-oriented API
6 * above both EvmuFlash and EvmuFat. It's meant to be the
7 * main entry point for loading and exporting ROM images.
8 *
9 * \author 2023 Falco Girgis
10 * \copyright MIT License
11 */
12#ifndef EVMU_FILE_MANAGER_H
13#define EVMU_FILE_MANAGER_H
14
15#include "evmu_fat.h"
16
17/*! \name Type System
18 * \brief Type UUID and cast operators
19 * @{
20 */
21#define EVMU_FILE_MANAGER_TYPE (GBL_TYPEID(EvmuFileManager)) //!< Type UUID for EvmuFileManager
22#define EVMU_FILE_MANAGER(self) (GBL_CAST(EvmuFileManager, self)) //!< Function-style GblInstance cast
23#define EVMU_FILE_MANAGER_CLASS(klass) (GBL_CLASS_CAST(EvmuFileManager, klass)) //!< Function-style GblClass cast
24#define EVMU_FILE_MANAGER_GET_CLASS(self) (GBL_CLASSOF(EvmuFileManager, self)) //!< Get EvmuFileManagerClass from GblInstance
25//! @}
26
27#define EVMU_FILE_MANAGER_NAME "filemanager" //!< EvmuFileManager GblObject name
28#define EVMU_FILE_INDEX_INVALID ((size_t)-1) //!< Sentinel returned when a file index lookup fails
29
30#define GBL_SELF_TYPE EvmuFileManager
31
32GBL_DECLS_BEGIN
33
34/*! \defgroup file_formats File Formats
35 * \ingroup file_system
36 * \brief Supported file formats
37 *
38 * This module contains all APIs pertaining to
39 * importing, exporting, encoding, or decoding
40 * the various VMU-specific file formats.
41 */
42
43GBL_FORWARD_DECLARE_STRUCT(EvmuFileManager)
44
45/*! \struct EvmuFileManagerClass
46 * \extends EvmuFatClass
47 * \brief GblClass vtable structure for EvmuFileManager
48 *
49 * \sa EvmuFileManager
50 */
51GBL_CLASS_DERIVE(EvmuFileManager, EvmuFat)
52 EVMU_RESULT (*pFnLoad) (GBL_SELF, const char* pPath);
53 EVMU_RESULT (*pFnSave) (GBL_SELF, const char* pPath);
54 EVMU_RESULT (*pFnExport)(GBL_CSELF, const EvmuDirEntry* pEntry, const char* pPath);
55GBL_CLASS_END
56
57/*! \struct EvmuFileManager
58 * \extends EvmuFat
59 * \ingroup file_system
60 * \brief High-level file-oriented flash API
61 *
62 * EvmuFileManager is the most high-level, user-friendly
63 * way to manage the VMU's filesystem and handle loading
64 * and saving both both individual ROM images and the
65 * entire flash filesystem.
66 *
67 * \sa EvmuFileManagerClass
68 */
69GBL_INSTANCE_DERIVE_EMPTY(EvmuFileManager, EvmuFat)
70
71//! \cond
72GBL_SIGNALS(EvmuFileManager,
73 (fileAdded, (GBL_INSTANCE_TYPE, pReceiver), (GBL_POINTER_TYPE, pDirEntry)),
74 (fileRemoved, (GBL_INSTANCE_TYPE, pReceiver), (GBL_POINTER_TYPE, pDirEntry))
75)
76//! \endcond
77
78//! Returns the GblType UUID associated with EvmuFileManager
79EVMU_EXPORT GblType EvmuFileManager_type (void) GBL_NOEXCEPT;
80
81/*! \name Filesystem Operations
82 * \brief Methods for serializing and deserializing the filesystem
83 * \relatesalso EvmuFileManager
84 * @{
85 */
86//! Loads a generic image whose type is determined by its extension into flash
87EVMU_EXPORT EVMU_RESULT EvmuFileManager_load (GBL_SELF, const char* pPath) GBL_NOEXCEPT;
88//! Saves a binary image of the entire contents of flash to a file, whose format is determined by its extension
89EVMU_EXPORT EVMU_RESULT EvmuFileManager_save (GBL_CSELF, const char* pPath) GBL_NOEXCEPT;
90//! Defragments the filesystem, consolidating all free blocks, storing all files contiguously
91EVMU_EXPORT EVMU_RESULT EvmuFileManager_defrag (GBL_SELF) GBL_NOEXCEPT;
92//! @}
93
94/*! \name File Discovery
95 * \brief Methods for enumerating, looking-up, and retrieving files
96 * \relatesalso EvmuFileManager
97 * @{
98 */
99//! Returns the number of files which are currently loaded within the filesystem
100EVMU_EXPORT size_t EvmuFileManager_count (GBL_CSELF) GBL_NOEXCEPT;
101//! Returns the directory entry for the file at the given \p index, or NULL if there isn't one
102EVMU_EXPORT EvmuDirEntry* EvmuFileManager_file (GBL_CSELF, size_t index) GBL_NOEXCEPT;
103//! Returns the directory entry for the currently loaded GAME file, or NULL if there isn't one
104EVMU_EXPORT EvmuDirEntry* EvmuFileManager_game (GBL_CSELF) GBL_NOEXCEPT;
105//! Returns the directory entry for the currently loaded ICONDATA.VMS file, or NULL if there isn't one
106EVMU_EXPORT EvmuDirEntry* EvmuFileManager_iconData (GBL_CSELF) GBL_NOEXCEPT;
107//! Searches for a directory entry with the given name, returning it if found or returning NULL if not found
108EVMU_EXPORT EvmuDirEntry* EvmuFileManager_find (GBL_CSELF, const char* pName) GBL_NOEXCEPT;
109//! Iterates over directory entries, passing each with \p pClosure to \p pFnIt, returning early with GBL_TRUE if \p pFnIt returns GBL_TRUE
111 EvmuDirEntryIterFn pFnIt,
112 void* pClosure) GBL_NOEXCEPT;
113//! @}
114
115/*! \name File Operations
116 * \brief Methods for operating on and with files
117 * \relatesalso EvmuFileManager
118 * @{
119 */
120//! Creates storage for a new file with the given info, copying its contents into the filesystem
121EVMU_EXPORT EvmuDirEntry* EvmuFileManager_alloc (GBL_SELF,
122 EvmuNewFileInfo* pInfo,
123 const void* pData) GBL_NOEXCEPT;
124//! Destroys an existing file, releasing resources back to the filesystem
126 EvmuDirEntry* pEntry) GBL_NOEXCEPT;
127//! Performs a generic read from an existing file, returning the number of bytes successfully read.
128//! When \p inclHdr is false, the VMS header/images region is omitted and \p offset is relative to that headerless byte stream.
130 const EvmuDirEntry* pEntry,
131 void* pBuffer,
132 size_t size,
133 size_t offset,
134 GblBool inclHdr) GBL_NOEXCEPT;
135//! Performs a generic write from an existing file, returning the number of bytes successfully written
137 const EvmuDirEntry* pEntry,
138 const void* pBuffer,
139 size_t size,
140 size_t offset) GBL_NOEXCEPT;
141//! Exports an existing file to the given path, with the file format automatically deduced from the extension type
142EVMU_EXPORT EVMU_RESULT EvmuFileManager_export (GBL_CSELF,
143 const EvmuDirEntry* pEntry,
144 const char* pPath) GBL_NOEXCEPT;
145//! @}
146
147/*! \name File Information
148 * \brief Methods for calculating and retrieving file info
149 * \relatesalso EvmuFileManager
150 * @{
151 */
152//! Returns the total byte size of the file on the filesystem, including the VMS header, icons, eyecatc, etc.
154 const EvmuDirEntry* pEntry) GBL_NOEXCEPT;
155//! Returns the byte size of the logical stream exposed by EvmuFileManager_read() for the given \p inclHdr mode.
157 const EvmuDirEntry* pEntry,
158 GblBool inclHdr) GBL_NOEXCEPT;
159//! Returns the file index corresponding to a given directory entry for a file, or EVMU_FILE_INDEX_INVALID if not found
161 const EvmuDirEntry* pEntry) GBL_NOEXCEPT;
162//! Returns the VMS header segment (ONLY) for an existing file (not the entire VMS data with icons, eyecatch, etc)
164 const EvmuDirEntry* pEntry) GBL_NOEXCEPT;
165//! Calculates the 16-bit CRC for an existing file on the filesystem
167 const EvmuDirEntry* pEntry) GBL_NOEXCEPT;
168//! @}
169
170GBL_DECLS_END
171
172#undef GBL_SELF_TYPE
173
174#endif // EVMU_FILE_MANAGER_H
#define EVMU_EXPORT
Define used for adding attributes to export public symbols.
Definition evmu_api.h:18
GblType EvmuFileManager_type(void)
Returns the GblType UUID associated with EvmuFileManager.
High-level file-oriented flash API.
GblBool EvmuFileManager_foreach(const EvmuFileManager *pSelf, EvmuDirEntryIterFn pFnIt, void *pClosure)
Iterates over directory entries, passing each with pClosure to pFnIt, returning early with GBL_TRUE i...
EVMU_RESULT EvmuFileManager_defrag(EvmuFileManager *pSelf)
Defragments the filesystem, consolidating all free blocks, storing all files contiguously.
EvmuDirEntry * EvmuFileManager_alloc(EvmuFileManager *pSelf, EvmuNewFileInfo *pInfo, const void *pData)
Creates storage for a new file with the given info, copying its contents into the filesystem.
size_t EvmuFileManager_write(const EvmuFileManager *pSelf, const EvmuDirEntry *pEntry, const void *pBuffer, size_t size, size_t offset)
Performs a generic write from an existing file, returning the number of bytes successfully written.
uint16_t EvmuFileManager_crc(const EvmuFileManager *pSelf, const EvmuDirEntry *pEntry)
Calculates the 16-bit CRC for an existing file on the filesystem.
size_t EvmuFileManager_read(const EvmuFileManager *pSelf, const EvmuDirEntry *pEntry, void *pBuffer, size_t size, size_t offset, GblBool inclHdr)
EvmuVms * EvmuFileManager_vms(const EvmuFileManager *pSelf, const EvmuDirEntry *pEntry)
Returns the VMS header segment (ONLY) for an existing file (not the entire VMS data with icons,...
size_t EvmuFileManager_free(EvmuFileManager *pSelf, EvmuDirEntry *pEntry)
Destroys an existing file, releasing resources back to the filesystem.
EvmuDirEntry * EvmuFileManager_find(const EvmuFileManager *pSelf, const char *pName)
Searches for a directory entry with the given name, returning it if found or returning NULL if not fo...
EvmuDirEntry * EvmuFileManager_file(const EvmuFileManager *pSelf, size_t index)
Returns the directory entry for the file at the given index, or NULL if there isn't one.
size_t EvmuFileManager_index(const EvmuFileManager *pSelf, const EvmuDirEntry *pEntry)
Returns the file index corresponding to a given directory entry for a file, or EVMU_FILE_INDEX_INVALI...
size_t EvmuFileManager_count(const EvmuFileManager *pSelf)
Returns the number of files which are currently loaded within the filesystem.
EVMU_RESULT EvmuFileManager_save(const EvmuFileManager *pSelf, const char *pPath)
Saves a binary image of the entire contents of flash to a file, whose format is determined by its ext...
EvmuDirEntry * EvmuFileManager_iconData(const EvmuFileManager *pSelf)
Returns the directory entry for the currently loaded ICONDATA.VMS file, or NULL if there isn't one.
size_t EvmuFileManager_visibleBytes(const EvmuFileManager *pSelf, const EvmuDirEntry *pEntry, GblBool inclHdr)
Returns the byte size of the logical stream exposed by EvmuFileManager_read() for the given inclHdr m...
EVMU_RESULT EvmuFileManager_export(const EvmuFileManager *pSelf, const EvmuDirEntry *pEntry, const char *pPath)
Exports an existing file to the given path, with the file format automatically deduced from the exten...
EvmuDirEntry * EvmuFileManager_game(const EvmuFileManager *pSelf)
Returns the directory entry for the currently loaded GAME file, or NULL if there isn't one.
EVMU_RESULT EvmuFileManager_load(EvmuFileManager *pSelf, const char *pPath)
Loads a generic image whose type is determined by its extension into flash.
size_t EvmuFileManager_bytes(const EvmuFileManager *pSelf, const EvmuDirEntry *pEntry)
Returns the total byte size of the file on the filesystem, including the VMS header,...