diff options
Diffstat (limited to 'include/user/ini_file_processor.h')
-rw-r--r-- | include/user/ini_file_processor.h | 198 |
1 files changed, 198 insertions, 0 deletions
diff --git a/include/user/ini_file_processor.h b/include/user/ini_file_processor.h new file mode 100644 index 0000000..77ee0b1 --- /dev/null +++ b/include/user/ini_file_processor.h @@ -0,0 +1,198 @@ +#ifndef _DOLCESDK_PSP2_INI_FILE_PROCESSOR_H_ +#define _DOLCESDK_PSP2_INI_FILE_PROCESSOR_H_ + +#define SCE_INI_FILE_PROCESSOR_ERROR_MODE 0x80840002 +#define SCE_INI_FILE_PROCESSOR_ERROR_EOF 0x80840005 +#define SCE_INI_FILE_PROCESSOR_ERROR_READ_ONLY 0x80840007 +#define SCE_INI_FILE_PROCESSOR_ERROR_FILE_NOT_FOUND 0x80840009 +#define SCE_INI_FILE_PROCESSOR_ERROR_KEY_NOT_FOUND 0x80840010 + +#define SCE_INI_FILE_PROCESSOR_PARSE_COMPLETED 0x00840001 + +#ifdef __cplusplus + +#include <cstddef> + +namespace sce { +namespace Ini { + +class MemAllocator { +public: + typedef void* Allocator(size_t size); + typedef void Deallocator(void* ptr); + + Allocator* allocate; + Deallocator* deallocate; +}; + +class InitParameter { +public: + InitParameter(); + + int unk_0x0; // size or mode? usually 0, seen: 0x1000, 0x2000 + int unk_0x4; // size or mode? usually 0, seen: 0x1000, 0x2000 + MemAllocator* allocator; // can be NULL + int unk_0xc; +}; + +class IniFileProcessor { +public: + IniFileProcessor(); + virtual ~IniFileProcessor(); + + /** + * Initialize INI file processor to work with file + * + * @param[in] param - ::InitParameter + * + * @return 0 on success, < 0 on error. + */ + int initialize(const InitParameter* param); + + /** + * Terminate INI file processor + * + * @return 0 on success, < 0 on error. + */ + int terminate(); + + /** + * Terminate INI file processor when file could not be opened + * + * @return 0 on success, < 0 on error. + */ + int terminateForError(); + + /** + * Get INI as a char array + * + * @param[out] ini - memory where INI data is stored + * @param[out] size - size of the INI data + * + * @return 0 on success, < 0 on error. + */ + int serialize(const char** ini, size_t* size); + + /** + * Process INI as a char array + * + * @param[in] ini - memory where INI data is stored + * @param[in] size - size of the INI data + * + * @return 0 on success, < 0 on error. + */ + int deserialize(const char* ini, size_t size); + + /** + * Open INI file + * + * @param[in] path - path to the INI file to open + * @param[in] mode - file open mode + * @param[in] unk - unknown, set to 0 + * + * @return 0 on success, < 0 on error. + */ + int openFile(const char* path, const char* mode, int unk); + + /** + * Create new INI file and open it. If file is already present, it will be overwritten + * + * @param[in] path - path to the INI file to open + * @param[in] mode - file open mode + * @param[in] unk - unknown, set to 0 + * + * @return 0 on success, < 0 on error. + * + */ + int createFile(const char* path, const char* mode, int unk); + + /** + * Close file + * + * @return 0 on success, < 0 on error. + */ + int closeFile(); + + /** + * Clean temp files + * + * @return 0 on success, < 0 on error. + */ + int cleanup(); + + /** + * Get total number of keys in the opened INI file + * + * @return toatal number of keys, < 0 on error. + */ + int size(); + + /** + * Add key and set value for it + * + * @param[in] key - key string + * @param[in] value - value string + * + * @return 0 on success, < 0 on error. + */ + int add(const char* key, const char* value); + + /** + * Delete key and corresponding value from INI file + * + * @param[in] key - key string + * + * @return 0 on success, < 0 on error. + */ + int del(const char* key); + + /** + * Set value corresponding to set key + * + * @param[in] key - key string + * @param[in] value - value string + * + * @return 0 on success, < 0 on error. + */ + int set(const char* key, const char* value); + + /** + * Find value corresponding to set key + * + * @param[in] key - key string + * @param[out] val - buffer to store value string if found + * @param[in] size - size of outValueBuf + * + * @return 0 on success, < 0 on error. + */ + int get(const char* key, char* val, size_t size); + + /** + * Parse key and corresponding value, one key per call until eof + * + * @param[out] key - buffer to store key string + * @param[out] val - buffer to store value string + * @param[in] size - size of output buffers + * + * @return 0 on success, < 0 on error. + * + */ + int parse(char* key, char* val, size_t size); + + /** + * Reset parser to the beginning of the file + * + * @return 0 on success, < 0 on error. + */ + int reset(); + +private: + void *context; +}; + +} // namespace Ini +} // namespace sce + +#endif // __cplusplus + +#endif // _DOLCESDK_PSP2_INI_FILE_PROCESSOR_H_ |