1 /* Copyright (C) 2010-2019 The RetroArch team 2 * 3 * --------------------------------------------------------------------------------------- 4 * The following license statement only applies to this file (manual_content_scan.c). 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 __MANUAL_CONTENT_SCAN_H 24 #define __MANUAL_CONTENT_SCAN_H 25 26 #include <retro_common_api.h> 27 #include <libretro.h> 28 29 #include <boolean.h> 30 31 #include <lists/string_list.h> 32 #include <formats/logiqx_dat.h> 33 34 #include "playlist.h" 35 36 RETRO_BEGIN_DECLS 37 38 /* Defines all possible system name types 39 * > Use content directory name 40 * > Use custom name 41 * > Use database name */ 42 enum manual_content_scan_system_name_type 43 { 44 MANUAL_CONTENT_SCAN_SYSTEM_NAME_CONTENT_DIR = 0, 45 MANUAL_CONTENT_SCAN_SYSTEM_NAME_CUSTOM, 46 MANUAL_CONTENT_SCAN_SYSTEM_NAME_DATABASE 47 }; 48 49 /* Defines all possible core name types 50 * > Autodetect core (DETECT) 51 * > Use manually set core */ 52 enum manual_content_scan_core_type 53 { 54 MANUAL_CONTENT_SCAN_CORE_DETECT = 0, 55 MANUAL_CONTENT_SCAN_CORE_SET 56 }; 57 58 /* Defines all possible return values for 59 * manual_content_scan_validate_dat_file_path() */ 60 enum manual_content_scan_dat_file_path_status 61 { 62 MANUAL_CONTENT_SCAN_DAT_FILE_UNSET = 0, 63 MANUAL_CONTENT_SCAN_DAT_FILE_OK, 64 MANUAL_CONTENT_SCAN_DAT_FILE_INVALID, 65 MANUAL_CONTENT_SCAN_DAT_FILE_TOO_LARGE 66 }; 67 68 /* Holds all configuration parameters required 69 * for a manual content scan task */ 70 typedef struct 71 { 72 char playlist_file[PATH_MAX_LENGTH]; 73 char content_dir[PATH_MAX_LENGTH]; 74 char system_name[PATH_MAX_LENGTH]; 75 char database_name[PATH_MAX_LENGTH]; 76 char core_name[PATH_MAX_LENGTH]; 77 char core_path[PATH_MAX_LENGTH]; 78 char file_exts[PATH_MAX_LENGTH]; 79 char dat_file_path[PATH_MAX_LENGTH]; 80 bool core_set; 81 bool search_recursively; 82 bool search_archives; 83 bool filter_dat_content; 84 bool overwrite_playlist; 85 } manual_content_scan_task_config_t; 86 87 /*****************/ 88 /* Configuration */ 89 /*****************/ 90 91 /* Pointer access 92 * > This is a little ugly, but it allows us to 93 * make use of standard 'menu_settings' code 94 * for several config parameters (rather than 95 * implementing unnecessary custom menu entries) */ 96 97 /* Returns a pointer to the internal 98 * 'content_dir' string */ 99 char *manual_content_scan_get_content_dir_ptr(void); 100 101 /* Returns size of the internal 102 * 'content_dir' string */ 103 size_t manual_content_scan_get_content_dir_size(void); 104 105 /* Returns a pointer to the internal 106 * 'system_name_custom' string */ 107 char *manual_content_scan_get_system_name_custom_ptr(void); 108 109 /* Returns size of the internal 110 * 'system_name_custom' string */ 111 size_t manual_content_scan_get_system_name_custom_size(void); 112 113 /* Returns a pointer to the internal 114 * 'file_exts_custom' string */ 115 char *manual_content_scan_get_file_exts_custom_ptr(void); 116 117 /* Returns size of the internal 118 * 'file_exts_custom' string */ 119 size_t manual_content_scan_get_file_exts_custom_size(void); 120 121 /* Returns a pointer to the internal 122 * 'dat_file_path' string */ 123 char *manual_content_scan_get_dat_file_path_ptr(void); 124 125 /* Returns size of the internal 126 * 'dat_file_path' string */ 127 size_t manual_content_scan_get_dat_file_path_size(void); 128 129 /* Returns a pointer to the internal 130 * 'search_recursively' bool */ 131 bool *manual_content_scan_get_search_recursively_ptr(void); 132 133 /* Returns a pointer to the internal 134 * 'search_archives' bool */ 135 bool *manual_content_scan_get_search_archives_ptr(void); 136 137 /* Returns a pointer to the internal 138 * 'filter_dat_content' bool */ 139 bool *manual_content_scan_get_filter_dat_content_ptr(void); 140 141 /* Returns a pointer to the internal 142 * 'overwrite_playlist' bool */ 143 bool *manual_content_scan_get_overwrite_playlist_ptr(void); 144 145 /* Sanitisation */ 146 147 /* Removes invalid characters from 148 * 'system_name_custom' string */ 149 void manual_content_scan_scrub_system_name_custom(void); 150 151 /* Removes period (full stop) characters from 152 * 'file_exts_custom' string and converts to 153 * lower case */ 154 void manual_content_scan_scrub_file_exts_custom(void); 155 156 /* Checks 'dat_file_path' string and resets it 157 * if invalid */ 158 enum manual_content_scan_dat_file_path_status 159 manual_content_scan_validate_dat_file_path(void); 160 161 /* Menu setters */ 162 163 /* Sets content directory for next manual scan 164 * operation. 165 * Returns true if content directory is valid. */ 166 bool manual_content_scan_set_menu_content_dir(const char *content_dir); 167 168 /* Sets system name for the next manual scan 169 * operation. 170 * Returns true if system name is valid. 171 * NOTE: 172 * > Only sets 'system_name_type' and 'system_name_database' 173 * > 'system_name_content_dir' and 'system_name_custom' are 174 * (by necessity) handled elsewhere 175 * > This may look fishy, but it's not - it's a menu-specific 176 * function, and this is simply the cleanest way to handle 177 * the setting... */ 178 bool manual_content_scan_set_menu_system_name( 179 enum manual_content_scan_system_name_type system_name_type, 180 const char *system_name); 181 182 /* Sets core name for the next manual scan 183 * operation (+ core path and other associated 184 * parameters). 185 * Returns true if core name is valid. */ 186 bool manual_content_scan_set_menu_core_name( 187 enum manual_content_scan_core_type core_type, 188 const char *core_name); 189 190 /* Menu getters */ 191 192 /* Fetches content directory for next manual scan 193 * operation. 194 * Returns true if content directory is valid. */ 195 bool manual_content_scan_get_menu_content_dir(const char **content_dir); 196 197 /* Fetches system name for the next manual scan operation. 198 * Returns true if system name is valid. 199 * NOTE: This corresponds to the 'System Name' value 200 * displayed in menus - this is not identical to the 201 * actual system name used when generating the playlist */ 202 bool manual_content_scan_get_menu_system_name(const char **system_name); 203 204 /* Fetches core name for the next manual scan operation. 205 * Returns true if core name is valid. */ 206 bool manual_content_scan_get_menu_core_name(const char **core_name); 207 208 /* Menu utility functions */ 209 210 /* Creates a list of all possible 'system name' menu 211 * strings, for use in 'menu_displaylist' drop-down 212 * lists and 'menu_cbs_left/right' 213 * > Returns NULL in the event of failure 214 * > Returned string list must be free()'d */ 215 struct string_list *manual_content_scan_get_menu_system_name_list( 216 const char *path_content_database, bool show_hidden_files); 217 218 /* Creates a list of all possible 'core name' menu 219 * strings, for use in 'menu_displaylist' drop-down 220 * lists and 'menu_cbs_left/right' 221 * > Returns NULL in the event of failure 222 * > Returned string list must be free()'d */ 223 struct string_list *manual_content_scan_get_menu_core_name_list(void); 224 225 /****************/ 226 /* Task Helpers */ 227 /****************/ 228 229 /* Parses current manual content scan settings, 230 * and extracts all information required to configure 231 * a manual content scan task. 232 * Returns false if current settings are invalid. */ 233 bool manual_content_scan_get_task_config( 234 manual_content_scan_task_config_t *task_config, 235 const char *path_dir_playlist 236 ); 237 238 /* Creates a list of all valid content in the specified 239 * content directory 240 * > Returns NULL in the event of failure 241 * > Returned string list must be free()'d */ 242 struct string_list *manual_content_scan_get_content_list(manual_content_scan_task_config_t *task_config); 243 244 /* Adds specified content to playlist, if not already 245 * present */ 246 void manual_content_scan_add_content_to_playlist( 247 manual_content_scan_task_config_t *task_config, 248 playlist_t *playlist, const char *content_path, 249 int content_type, logiqx_dat_t *dat_file); 250 251 RETRO_END_DECLS 252 253 #endif 254