1 /* Copyright  (C) 2010-2019 The RetroArch team
2  *
3  * ---------------------------------------------------------------------------------------
4  * The following license statement only applies to this file (core_updater_list.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 __CORE_UPDATER_LIST_H
24 #define __CORE_UPDATER_LIST_H
25 
26 #include <retro_common_api.h>
27 #include <libretro.h>
28 
29 #include <lists/string_list.h>
30 
31 #include <boolean.h>
32 
33 RETRO_BEGIN_DECLS
34 
35 /* Defines all possible 'types' of core
36  * updater list - corresponds to core
37  * delivery method:
38  * > Buildbot
39  * > Play feature delivery (PFD) */
40 enum core_updater_list_type
41 {
42    CORE_UPDATER_LIST_TYPE_UNKNOWN = 0,
43    CORE_UPDATER_LIST_TYPE_BUILDBOT,
44    CORE_UPDATER_LIST_TYPE_PFD
45 };
46 
47 /* Holds all date info for a core file
48  * on the buildbot */
49 typedef struct
50 {
51    unsigned year;
52    unsigned month;
53    unsigned day;
54 } core_updater_list_date_t;
55 
56 /* Holds all info related to a core
57  * file on the buildbot */
58 typedef struct
59 {
60    char *remote_filename;
61    char *remote_core_path;
62    char *local_core_path;
63    char *local_info_path;
64    char *display_name;
65    char *description;
66    struct string_list *licenses_list;
67    core_updater_list_date_t date;   /* unsigned alignment */
68    uint32_t crc;
69    bool is_experimental;
70 } core_updater_list_entry_t;
71 
72 /* Prevent direct access to core_updater_list_t
73  * members */
74 typedef struct core_updater_list core_updater_list_t;
75 
76 /**************************************/
77 /* Initialisation / De-Initialisation */
78 /**************************************/
79 
80 /* Creates a new, empty core updater list.
81  * Returns a handle to a new core_updater_list_t object
82  * on success, otherwise returns NULL. */
83 core_updater_list_t *core_updater_list_init(void);
84 
85 /* Resets (removes all entries of) specified core
86  * updater list */
87 void core_updater_list_reset(core_updater_list_t *core_list);
88 
89 /* Frees specified core updater list */
90 void core_updater_list_free(core_updater_list_t *core_list);
91 
92 /***************/
93 /* Cached List */
94 /***************/
95 
96 /* Creates a new, empty cached core updater list
97  * (i.e. 'global' list).
98  * Returns false in the event of an error. */
99 bool core_updater_list_init_cached(void);
100 
101 /* Fetches cached core updater list */
102 core_updater_list_t *core_updater_list_get_cached(void);
103 
104 /* Frees cached core updater list */
105 void core_updater_list_free_cached(void);
106 
107 /***********/
108 /* Getters */
109 /***********/
110 
111 /* Returns number of entries in core updater list */
112 size_t core_updater_list_size(core_updater_list_t *core_list);
113 
114 /* Returns 'type' (core delivery method) of
115  * specified core updater list */
116 enum core_updater_list_type core_updater_list_get_type(
117       core_updater_list_t *core_list);
118 
119 /* Fetches core updater list entry corresponding
120  * to the specified entry index.
121  * Returns false if index is invalid. */
122 bool core_updater_list_get_index(
123       core_updater_list_t *core_list,
124       size_t idx,
125       const core_updater_list_entry_t **entry);
126 
127 /* Fetches core updater list entry corresponding
128  * to the specified remote core filename.
129  * Returns false if core is not found. */
130 bool core_updater_list_get_filename(
131       core_updater_list_t *core_list,
132       const char *remote_filename,
133       const core_updater_list_entry_t **entry);
134 
135 /* Fetches core updater list entry corresponding
136  * to the specified core.
137  * Returns false if core is not found. */
138 bool core_updater_list_get_core(
139       core_updater_list_t *core_list,
140       const char *local_core_path,
141       const core_updater_list_entry_t **entry);
142 
143 /***********/
144 /* Setters */
145 /***********/
146 
147 /* Reads the contents of a buildbot core list
148  * network request into the specified
149  * core_updater_list_t object.
150  * Returns false in the event of an error. */
151 bool core_updater_list_parse_network_data(
152       core_updater_list_t *core_list,
153       const char *path_dir_libretro,
154       const char *path_libretro_info,
155       const char *network_buildbot_url,
156       const char *data, size_t len);
157 
158 /* Reads the list of cores currently available
159  * via play feature delivery (PFD) into the
160  * specified core_updater_list_t object.
161  * Returns false in the event of an error. */
162 bool core_updater_list_parse_pfd_data(
163       core_updater_list_t *core_list,
164       const char *path_dir_libretro,
165       const char *path_libretro_info,
166       const struct string_list *pfd_cores);
167 
168 RETRO_END_DECLS
169 
170 #endif
171