| 1 | /* Copyright (C) 2010-2020 The RetroArch team |
| 2 | * |
| 3 | * --------------------------------------------------------------------------------------- |
| 4 | * The following license statement only applies to this file (m3u_file.h). |
| 5 | * --------------------------------------------------------------------------------------- |
| 6 | * |
| 7 | * Permission is hereby granted, free of charge, |
| 8 | * to any person obtaining a copy of this software and associated documentation files (the "Software"), |
| 9 | * to deal in the Software without restriction, including without limitation the rights to |
| 10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, |
| 11 | * and to permit persons to whom the Software is furnished to do so, subject to the following conditions: |
| 12 | * |
| 13 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. |
| 14 | * |
| 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, |
| 16 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
| 18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
| 19 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 21 | */ |
| 22 | |
| 23 | #ifndef __LIBRETRO_SDK_FORMAT_M3U_FILE_H__ |
| 24 | #define __LIBRETRO_SDK_FORMAT_M3U_FILE_H__ |
| 25 | |
| 26 | #include <retro_common_api.h> |
| 27 | |
| 28 | #include <stdint.h> |
| 29 | #include <stddef.h> |
| 30 | #include <boolean.h> |
| 31 | |
| 32 | RETRO_BEGIN_DECLS |
| 33 | |
| 34 | /* Trivial handler for M3U playlist files */ |
| 35 | |
| 36 | /* M3U file extension */ |
| 37 | #define M3U_FILE_EXT "m3u" |
| 38 | |
| 39 | /* Prevent direct access to m3u_file_t members */ |
| 40 | typedef struct content_m3u_file m3u_file_t; |
| 41 | |
| 42 | /* Holds all metadata for a single M3U file entry */ |
| 43 | typedef struct |
| 44 | { |
| 45 | char *path; |
| 46 | char *full_path; |
| 47 | char *label; |
| 48 | } m3u_file_entry_t; |
| 49 | |
| 50 | /* Defines entry label formatting when |
| 51 | * writing M3U files to disk */ |
| 52 | enum m3u_file_label_type |
| 53 | { |
| 54 | M3U_FILE_LABEL_NONE = 0, |
| 55 | M3U_FILE_LABEL_NONSTD, |
| 56 | M3U_FILE_LABEL_EXTSTD, |
| 57 | M3U_FILE_LABEL_RETRO |
| 58 | }; |
| 59 | |
| 60 | /* File Initialisation / De-Initialisation */ |
| 61 | |
| 62 | /* Creates and initialises an M3U file |
| 63 | * - If 'path' refers to an existing file, |
| 64 | * contents is parsed |
| 65 | * - If path does not exist, an empty M3U file |
| 66 | * is created |
| 67 | * - Returned m3u_file_t object must be free'd using |
| 68 | * m3u_file_free() |
| 69 | * - Returns NULL in the event of an error */ |
| 70 | m3u_file_t *m3u_file_init(const char *path); |
| 71 | |
| 72 | /* Frees specified M3U file */ |
| 73 | void m3u_file_free(m3u_file_t *m3u_file); |
| 74 | |
| 75 | /* Getters */ |
| 76 | |
| 77 | /* Returns M3U file path */ |
| 78 | char *m3u_file_get_path(m3u_file_t *m3u_file); |
| 79 | |
| 80 | /* Returns number of entries in M3U file */ |
| 81 | size_t m3u_file_get_size(m3u_file_t *m3u_file); |
| 82 | |
| 83 | /* Fetches specified M3U file entry |
| 84 | * - Returns false if 'idx' is invalid, or internal |
| 85 | * entry is NULL */ |
| 86 | bool m3u_file_get_entry( |
| 87 | m3u_file_t *m3u_file, size_t idx, m3u_file_entry_t **entry); |
| 88 | |
| 89 | /* Setters */ |
| 90 | |
| 91 | /* Adds specified entry to the M3U file |
| 92 | * - Returns false if path is invalid, or |
| 93 | * memory could not be allocated for the |
| 94 | * entry */ |
| 95 | bool m3u_file_add_entry( |
| 96 | m3u_file_t *m3u_file, const char *path, const char *label); |
| 97 | |
| 98 | /* Removes all entries in M3U file */ |
| 99 | void m3u_file_clear(m3u_file_t *m3u_file); |
| 100 | |
| 101 | /* Saving */ |
| 102 | |
| 103 | /* Saves M3U file to disk |
| 104 | * - Setting 'label_type' to M3U_FILE_LABEL_NONE |
| 105 | * just outputs entry paths - this the most |
| 106 | * common format supported by most cores |
| 107 | * - Returns false in the event of an error */ |
| 108 | bool m3u_file_save( |
| 109 | m3u_file_t *m3u_file, enum m3u_file_label_type label_type); |
| 110 | |
| 111 | /* Utilities */ |
| 112 | |
| 113 | /* Sorts M3U file entries in alphabetical order */ |
| 114 | void m3u_file_qsort(m3u_file_t *m3u_file); |
| 115 | |
| 116 | /* Returns true if specified path corresponds |
| 117 | * to an M3U file (simple convenience function) */ |
| 118 | bool m3u_file_is_m3u(const char *path); |
| 119 | |
| 120 | RETRO_END_DECLS |
| 121 | |
| 122 | #endif |