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
29#define GBL_SELF_TYPE EvmuFileManager
30
31GBL_DECLS_BEGIN
32
33/*! \defgroup file_formats File Formats
34 * \ingroup file_system
35 * \brief Supported file formats
36 *
37 * This module contains all APIs pertaining to
38 * importing, exporting, encoding, or decoding
39 * the various VMU-specific file formats.
40 */
41
42GBL_FORWARD_DECLARE_STRUCT(EvmuFileManager)
43
44/*! \struct EvmuFileManagerClass
45 * \extends EvmuFatClass
46 * \brief GblClass vtable structure for EvmuFileManager
47 *
48 * \sa EvmuFileManager
49 */
50GBL_CLASS_DERIVE(EvmuFileManager, EvmuFat)
51 EVMU_RESULT (*pFnLoad) (GBL_SELF, const char* pPath);
52 EVMU_RESULT (*pFnSave) (GBL_SELF, const char* pPath);
53 EVMU_RESULT (*pFnExport)(GBL_CSELF, const EvmuDirEntry* pEntry, const char* pPath);
54GBL_CLASS_END
55
56/*! \struct EvmuFileManager
57 * \extends EvmuFat
58 * \ingroup file_system
59 * \brief High-level file-oriented flash API
60 *
61 * EvmuFileManager is the most high-level, user-friendly
62 * way to manage the VMU's filesystem and handle loading
63 * and saving both both individual ROM images and the
64 * entire flash filesystem.
65 *
66 * \sa EvmuFileManagerClass
67 */
68GBL_INSTANCE_DERIVE_EMPTY(EvmuFileManager, EvmuFat)
69
70//! \cond
71GBL_SIGNALS(EvmuFileManager,
72 (fileAdded, (GBL_INSTANCE_TYPE, pReceiver), (GBL_POINTER_TYPE, pDirEntry)),
73 (fileRemoved, (GBL_INSTANCE_TYPE, pReceiver), (GBL_POINTER_TYPE, pDirEntry))
74)
75//! \endcond
76
77//! Returns the GblType UUID associated with EvmuFileManager
79
80/*! \name Filesystem Operations
81 * \brief Methods for serializing and deserializing the filesystem
82 * \relatesalso EvmuFileManager
83 * @{
84 */
85//! Loads a generic image whose type is determined by its extension into flash
86EVMU_EXPORT EVMU_RESULT EvmuFileManager_load (GBL_SELF, const char* pPath) GBL_NOEXCEPT;
87//! Saves a binary image of the entire contents of flash to a file, whose format is determined by its extension
88EVMU_EXPORT EVMU_RESULT EvmuFileManager_save (GBL_CSELF, const char* pPath) GBL_NOEXCEPT;
89//! Defragments the filesystem, consolidating all free blocks, storing all files contiguously
90EVMU_EXPORT EVMU_RESULT EvmuFileManager_defrag (GBL_SELF) GBL_NOEXCEPT;
91//! @}
92
93/*! \name File Discovery
94 * \brief Methods for enumerating, looking-up, and retrieving files
95 * \relatesalso EvmuFileManager
96 * @{
97 */
98//! Returns the number of files which are currently loaded within the filesystem
99EVMU_EXPORT size_t EvmuFileManager_count (GBL_CSELF) GBL_NOEXCEPT;
100//! Returns the directory entry for the file at the given \p index, or NULL if there isn't one
101EVMU_EXPORT EvmuDirEntry* EvmuFileManager_file (GBL_CSELF, size_t index) GBL_NOEXCEPT;
102//! Returns the directory entry for the currently loaded GAME file, or NULL if there isn't one
103EVMU_EXPORT EvmuDirEntry* EvmuFileManager_game (GBL_CSELF) GBL_NOEXCEPT;
104//! Returns the directory entry for the currently loaded ICONDATA.VMS file, or NULL if there isn't one
105EVMU_EXPORT EvmuDirEntry* EvmuFileManager_iconData (GBL_CSELF) GBL_NOEXCEPT;
106//! Searches for a directory entry with the given name, returning it if found or returning NULL if not found
107EVMU_EXPORT EvmuDirEntry* EvmuFileManager_find (GBL_CSELF, const char* pName) GBL_NOEXCEPT;
108//! Iterates over directory entries, passing each with \p pClosure to \p pFnIt, returning early with GBL_TRUE if \p pFnIt returns GBL_TRUE
110 EvmuDirEntryIterFn pFnIt,
111 void* pClosure) GBL_NOEXCEPT;
112//! @}
113
114/*! \name File Operations
115 * \brief Methods for operating on and with files
116 * \relatesalso EvmuFileManager
117 * @{
118 */
119//! Creates storage for a new file with the given info, copying its contents into the filesystem
120EVMU_EXPORT EvmuDirEntry* EvmuFileManager_alloc (GBL_SELF,
121 EvmuNewFileInfo* pInfo,
122 const void* pData) GBL_NOEXCEPT;
123//! Destroys an existing file, releasing resources back to the filesystem
125 EvmuDirEntry* pEntry) GBL_NOEXCEPT;
126//! Performs a generic read from an existing file, returning the number of bytes successfully read
128 const EvmuDirEntry* pEntry,
129 void* pBuffer,
130 size_t size,
131 size_t offset,
132 GblBool inclHdr) GBL_NOEXCEPT;
133//! Performs a generic write from an existing file, returning the number of bytes successfully written
135 const EvmuDirEntry* pEntry,
136 const void* pBuffer,
137 size_t size,
138 size_t offset) GBL_NOEXCEPT;
139//! Exports an existing file to the given path, with the file format automatically deduced from the extension type
140EVMU_EXPORT EVMU_RESULT EvmuFileManager_export (GBL_CSELF,
141 const EvmuDirEntry* pEntry,
142 const char* pPath) GBL_NOEXCEPT;
143//! @}
144
145/*! \name File Information
146 * \brief Methods for calculating and retrieving file info
147 * \relatesalso EvmuFileManager
148 * @{
149 */
150//! Returns the total byte size of the file on the filesystem, including the VMS header, icons, eyecatc, etc.
152 const EvmuDirEntry* pEntry) GBL_NOEXCEPT;
153//! Returns the file index corresponding to a given directory entry for a file
155 const EvmuDirEntry* pEntry) GBL_NOEXCEPT;
156//! Returns the VMS header segment (ONLY) for an existing file (not the entire VMS data with icons, eyecatch, etc)
158 const EvmuDirEntry* pEntry) GBL_NOEXCEPT;
159//! Calculates the 16-bit CRC for an existing file on the filesystem
161 const EvmuDirEntry* pEntry) GBL_NOEXCEPT;
162//! @}
163
164GBL_DECLS_END
165
166#undef GBL_SELF_TYPE
167
168#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.
uint8_t GblBool
uintptr_t GblType
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)
Performs a generic read from an existing file, returning the number of bytes successfully read.
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.
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.
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,...
#define GBL_CLASS_CAST(cType, klass)
#define GBL_CLASSOF(cType, self)
#define GBL_CAST(cType, self)