| 
									
										
										
										
											2023-01-05 13:25:55 +01:00
										 |  |  | /**************************************************************************/ | 
					
						
							|  |  |  | /*  godot_plugin_config.cpp                                               */ | 
					
						
							|  |  |  | /**************************************************************************/ | 
					
						
							|  |  |  | /*                         This file is part of:                          */ | 
					
						
							|  |  |  | /*                             GODOT ENGINE                               */ | 
					
						
							|  |  |  | /*                        https://godotengine.org                         */ | 
					
						
							|  |  |  | /**************************************************************************/ | 
					
						
							|  |  |  | /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ | 
					
						
							|  |  |  | /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur.                  */ | 
					
						
							|  |  |  | /*                                                                        */ | 
					
						
							|  |  |  | /* Permission is hereby granted, free of charge, to any person obtaining  */ | 
					
						
							|  |  |  | /* a copy of this software and associated documentation files (the        */ | 
					
						
							|  |  |  | /* "Software"), to deal in the Software without restriction, including    */ | 
					
						
							|  |  |  | /* without limitation the rights to use, copy, modify, merge, publish,    */ | 
					
						
							|  |  |  | /* distribute, sublicense, and/or sell copies of the Software, and to     */ | 
					
						
							|  |  |  | /* permit persons to whom the Software is furnished to do so, subject to  */ | 
					
						
							|  |  |  | /* the following conditions:                                              */ | 
					
						
							|  |  |  | /*                                                                        */ | 
					
						
							|  |  |  | /* The above copyright notice and this permission notice shall be         */ | 
					
						
							|  |  |  | /* included in all copies or substantial portions of the Software.        */ | 
					
						
							|  |  |  | /*                                                                        */ | 
					
						
							|  |  |  | /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,        */ | 
					
						
							|  |  |  | /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF     */ | 
					
						
							|  |  |  | /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ | 
					
						
							|  |  |  | /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY   */ | 
					
						
							|  |  |  | /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,   */ | 
					
						
							|  |  |  | /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE      */ | 
					
						
							|  |  |  | /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.                 */ | 
					
						
							|  |  |  | /**************************************************************************/ | 
					
						
							| 
									
										
										
										
											2020-04-24 00:45:14 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-13 23:30:53 +03:00
										 |  |  | #include "godot_plugin_config.h"
 | 
					
						
							| 
									
										
										
										
											2023-06-08 14:51:32 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-02 11:14:29 -07:00
										 |  |  | #ifndef DISABLE_DEPRECATED
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-24 00:45:14 -07:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * Set of prebuilt plugins. | 
					
						
							| 
									
										
										
										
											2020-06-22 09:17:26 +02:00
										 |  |  |  * Currently unused, this is just for future reference: | 
					
						
							| 
									
										
										
										
											2020-04-24 00:45:14 -07:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2021-01-14 15:05:42 +03:00
										 |  |  | // static const PluginConfigAndroid MY_PREBUILT_PLUGIN = {
 | 
					
						
							| 
									
										
										
										
											2021-07-13 23:30:53 +03:00
										 |  |  | //    /*.valid_config =*/true,
 | 
					
						
							|  |  |  | //    /*.last_updated =*/0,
 | 
					
						
							|  |  |  | //    /*.name =*/"GodotPayment",
 | 
					
						
							|  |  |  | //    /*.binary_type =*/"local",
 | 
					
						
							|  |  |  | //    /*.binary =*/"res://android/build/libs/plugins/GodotPayment.release.aar",
 | 
					
						
							|  |  |  | //    /*.local_dependencies =*/{},
 | 
					
						
							|  |  |  | //     /*.remote_dependencies =*/String("com.android.billingclient:billing:2.2.1").split("|"),
 | 
					
						
							|  |  |  | //     /*.custom_maven_repos =*/{}
 | 
					
						
							| 
									
										
										
										
											2020-06-22 09:17:26 +02:00
										 |  |  | // };
 | 
					
						
							| 
									
										
										
										
											2020-04-24 00:45:14 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-13 23:30:53 +03:00
										 |  |  | String PluginConfigAndroid::resolve_local_dependency_path(String plugin_config_dir, String dependency_path) { | 
					
						
							| 
									
										
										
										
											2020-04-24 00:45:14 -07:00
										 |  |  | 	String absolute_path; | 
					
						
							| 
									
										
										
										
											2020-12-15 12:04:21 +00:00
										 |  |  | 	if (!dependency_path.is_empty()) { | 
					
						
							| 
									
										
										
										
											2021-06-03 15:41:22 +02:00
										 |  |  | 		if (dependency_path.is_absolute_path()) { | 
					
						
							| 
									
										
										
										
											2020-04-24 00:45:14 -07:00
										 |  |  | 			absolute_path = ProjectSettings::get_singleton()->globalize_path(dependency_path); | 
					
						
							|  |  |  | 		} else { | 
					
						
							| 
									
										
										
										
											2022-08-29 19:34:01 -05:00
										 |  |  | 			absolute_path = plugin_config_dir.path_join(dependency_path); | 
					
						
							| 
									
										
										
										
											2020-04-24 00:45:14 -07:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return absolute_path; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-13 23:30:53 +03:00
										 |  |  | PluginConfigAndroid PluginConfigAndroid::resolve_prebuilt_plugin(PluginConfigAndroid prebuilt_plugin, String plugin_config_dir) { | 
					
						
							| 
									
										
										
										
											2021-01-14 15:05:42 +03:00
										 |  |  | 	PluginConfigAndroid resolved = prebuilt_plugin; | 
					
						
							|  |  |  | 	resolved.binary = resolved.binary_type == PluginConfigAndroid::BINARY_TYPE_LOCAL ? resolve_local_dependency_path(plugin_config_dir, prebuilt_plugin.binary) : prebuilt_plugin.binary; | 
					
						
							| 
									
										
										
										
											2020-12-15 12:04:21 +00:00
										 |  |  | 	if (!prebuilt_plugin.local_dependencies.is_empty()) { | 
					
						
							| 
									
										
										
										
											2020-04-24 00:45:14 -07:00
										 |  |  | 		resolved.local_dependencies.clear(); | 
					
						
							|  |  |  | 		for (int i = 0; i < prebuilt_plugin.local_dependencies.size(); i++) { | 
					
						
							|  |  |  | 			resolved.local_dependencies.push_back(resolve_local_dependency_path(plugin_config_dir, prebuilt_plugin.local_dependencies[i])); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return resolved; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-13 23:30:53 +03:00
										 |  |  | Vector<PluginConfigAndroid> PluginConfigAndroid::get_prebuilt_plugins(String plugins_base_dir) { | 
					
						
							| 
									
										
										
										
											2021-01-14 15:05:42 +03:00
										 |  |  | 	Vector<PluginConfigAndroid> prebuilt_plugins; | 
					
						
							| 
									
										
										
										
											2020-04-24 00:45:14 -07:00
										 |  |  | 	return prebuilt_plugins; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-13 23:30:53 +03:00
										 |  |  | bool PluginConfigAndroid::is_plugin_config_valid(PluginConfigAndroid plugin_config) { | 
					
						
							| 
									
										
										
										
											2020-12-15 12:04:21 +00:00
										 |  |  | 	bool valid_name = !plugin_config.name.is_empty(); | 
					
						
							| 
									
										
										
										
											2021-01-14 15:05:42 +03:00
										 |  |  | 	bool valid_binary_type = plugin_config.binary_type == PluginConfigAndroid::BINARY_TYPE_LOCAL || | 
					
						
							| 
									
										
										
										
											2021-10-28 15:19:35 +02:00
										 |  |  | 			plugin_config.binary_type == PluginConfigAndroid::BINARY_TYPE_REMOTE; | 
					
						
							| 
									
										
										
										
											2020-04-24 00:45:14 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	bool valid_binary = false; | 
					
						
							|  |  |  | 	if (valid_binary_type) { | 
					
						
							| 
									
										
										
										
											2020-12-15 12:04:21 +00:00
										 |  |  | 		valid_binary = !plugin_config.binary.is_empty() && | 
					
						
							| 
									
										
										
										
											2021-10-28 15:19:35 +02:00
										 |  |  | 				(plugin_config.binary_type == PluginConfigAndroid::BINARY_TYPE_REMOTE || | 
					
						
							|  |  |  | 						FileAccess::exists(plugin_config.binary)); | 
					
						
							| 
									
										
										
										
											2020-04-24 00:45:14 -07:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	bool valid_local_dependencies = true; | 
					
						
							| 
									
										
										
										
											2020-12-15 12:04:21 +00:00
										 |  |  | 	if (!plugin_config.local_dependencies.is_empty()) { | 
					
						
							| 
									
										
										
										
											2020-04-24 00:45:14 -07:00
										 |  |  | 		for (int i = 0; i < plugin_config.local_dependencies.size(); i++) { | 
					
						
							|  |  |  | 			if (!FileAccess::exists(plugin_config.local_dependencies[i])) { | 
					
						
							|  |  |  | 				valid_local_dependencies = false; | 
					
						
							|  |  |  | 				break; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return valid_name && valid_binary && valid_binary_type && valid_local_dependencies; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-13 23:30:53 +03:00
										 |  |  | uint64_t PluginConfigAndroid::get_plugin_modification_time(const PluginConfigAndroid &plugin_config, const String &config_path) { | 
					
						
							| 
									
										
										
										
											2020-05-24 02:33:07 +02:00
										 |  |  | 	uint64_t last_updated = FileAccess::get_modified_time(config_path); | 
					
						
							|  |  |  | 	last_updated = MAX(last_updated, FileAccess::get_modified_time(plugin_config.binary)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for (int i = 0; i < plugin_config.local_dependencies.size(); i++) { | 
					
						
							|  |  |  | 		String binary = plugin_config.local_dependencies.get(i); | 
					
						
							|  |  |  | 		last_updated = MAX(last_updated, FileAccess::get_modified_time(binary)); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return last_updated; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-13 23:30:53 +03:00
										 |  |  | PluginConfigAndroid PluginConfigAndroid::load_plugin_config(Ref<ConfigFile> config_file, const String &path) { | 
					
						
							| 
									
										
										
										
											2021-01-14 15:05:42 +03:00
										 |  |  | 	PluginConfigAndroid plugin_config = {}; | 
					
						
							| 
									
										
										
										
											2020-04-24 00:45:14 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (config_file.is_valid()) { | 
					
						
							|  |  |  | 		Error err = config_file->load(path); | 
					
						
							|  |  |  | 		if (err == OK) { | 
					
						
							|  |  |  | 			String config_base_dir = path.get_base_dir(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-14 15:05:42 +03:00
										 |  |  | 			plugin_config.name = config_file->get_value(PluginConfigAndroid::CONFIG_SECTION, PluginConfigAndroid::CONFIG_NAME_KEY, String()); | 
					
						
							|  |  |  | 			plugin_config.binary_type = config_file->get_value(PluginConfigAndroid::CONFIG_SECTION, PluginConfigAndroid::CONFIG_BINARY_TYPE_KEY, String()); | 
					
						
							| 
									
										
										
										
											2020-04-24 00:45:14 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-14 15:05:42 +03:00
										 |  |  | 			String binary_path = config_file->get_value(PluginConfigAndroid::CONFIG_SECTION, PluginConfigAndroid::CONFIG_BINARY_KEY, String()); | 
					
						
							|  |  |  | 			plugin_config.binary = plugin_config.binary_type == PluginConfigAndroid::BINARY_TYPE_LOCAL ? resolve_local_dependency_path(config_base_dir, binary_path) : binary_path; | 
					
						
							| 
									
										
										
										
											2020-04-24 00:45:14 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-14 15:05:42 +03:00
										 |  |  | 			if (config_file->has_section(PluginConfigAndroid::DEPENDENCIES_SECTION)) { | 
					
						
							|  |  |  | 				Vector<String> local_dependencies_paths = config_file->get_value(PluginConfigAndroid::DEPENDENCIES_SECTION, PluginConfigAndroid::DEPENDENCIES_LOCAL_KEY, Vector<String>()); | 
					
						
							| 
									
										
										
										
											2020-12-15 12:04:21 +00:00
										 |  |  | 				if (!local_dependencies_paths.is_empty()) { | 
					
						
							| 
									
										
										
										
											2020-04-24 00:45:14 -07:00
										 |  |  | 					for (int i = 0; i < local_dependencies_paths.size(); i++) { | 
					
						
							|  |  |  | 						plugin_config.local_dependencies.push_back(resolve_local_dependency_path(config_base_dir, local_dependencies_paths[i])); | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-14 15:05:42 +03:00
										 |  |  | 				plugin_config.remote_dependencies = config_file->get_value(PluginConfigAndroid::DEPENDENCIES_SECTION, PluginConfigAndroid::DEPENDENCIES_REMOTE_KEY, Vector<String>()); | 
					
						
							|  |  |  | 				plugin_config.custom_maven_repos = config_file->get_value(PluginConfigAndroid::DEPENDENCIES_SECTION, PluginConfigAndroid::DEPENDENCIES_CUSTOM_MAVEN_REPOS_KEY, Vector<String>()); | 
					
						
							| 
									
										
										
										
											2020-04-24 00:45:14 -07:00
										 |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			plugin_config.valid_config = is_plugin_config_valid(plugin_config); | 
					
						
							| 
									
										
										
										
											2020-05-24 02:33:07 +02:00
										 |  |  | 			plugin_config.last_updated = get_plugin_modification_time(plugin_config, path); | 
					
						
							| 
									
										
										
										
											2020-04-24 00:45:14 -07:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return plugin_config; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-02 11:14:29 -07:00
										 |  |  | void PluginConfigAndroid::get_plugins_binaries(String binary_type, Vector<PluginConfigAndroid> plugins_configs, Vector<String> &r_result) { | 
					
						
							| 
									
										
										
										
											2020-12-15 12:04:21 +00:00
										 |  |  | 	if (!plugins_configs.is_empty()) { | 
					
						
							| 
									
										
										
										
											2020-04-24 00:45:14 -07:00
										 |  |  | 		for (int i = 0; i < plugins_configs.size(); i++) { | 
					
						
							| 
									
										
										
										
											2021-01-14 15:05:42 +03:00
										 |  |  | 			PluginConfigAndroid config = plugins_configs[i]; | 
					
						
							| 
									
										
										
										
											2020-04-24 00:45:14 -07:00
										 |  |  | 			if (!config.valid_config) { | 
					
						
							|  |  |  | 				continue; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			if (config.binary_type == binary_type) { | 
					
						
							| 
									
										
										
										
											2023-07-02 11:14:29 -07:00
										 |  |  | 				r_result.push_back(config.binary); | 
					
						
							| 
									
										
										
										
											2020-04-24 00:45:14 -07:00
										 |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-14 15:05:42 +03:00
										 |  |  | 			if (binary_type == PluginConfigAndroid::BINARY_TYPE_LOCAL) { | 
					
						
							| 
									
										
										
										
											2023-07-02 11:14:29 -07:00
										 |  |  | 				r_result.append_array(config.local_dependencies); | 
					
						
							| 
									
										
										
										
											2020-04-24 00:45:14 -07:00
										 |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-14 15:05:42 +03:00
										 |  |  | 			if (binary_type == PluginConfigAndroid::BINARY_TYPE_REMOTE) { | 
					
						
							| 
									
										
										
										
											2023-07-02 11:14:29 -07:00
										 |  |  | 				r_result.append_array(config.remote_dependencies); | 
					
						
							| 
									
										
										
										
											2020-04-24 00:45:14 -07:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-02 11:14:29 -07:00
										 |  |  | void PluginConfigAndroid::get_plugins_custom_maven_repos(Vector<PluginConfigAndroid> plugins_configs, Vector<String> &r_result) { | 
					
						
							| 
									
										
										
										
											2020-12-15 12:04:21 +00:00
										 |  |  | 	if (!plugins_configs.is_empty()) { | 
					
						
							| 
									
										
										
										
											2020-04-24 00:45:14 -07:00
										 |  |  | 		for (int i = 0; i < plugins_configs.size(); i++) { | 
					
						
							| 
									
										
										
										
											2021-01-14 15:05:42 +03:00
										 |  |  | 			PluginConfigAndroid config = plugins_configs[i]; | 
					
						
							| 
									
										
										
										
											2020-04-24 00:45:14 -07:00
										 |  |  | 			if (!config.valid_config) { | 
					
						
							|  |  |  | 				continue; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-02 11:14:29 -07:00
										 |  |  | 			r_result.append_array(config.custom_maven_repos); | 
					
						
							| 
									
										
										
										
											2020-04-24 00:45:14 -07:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-02 11:14:29 -07:00
										 |  |  | void PluginConfigAndroid::get_plugins_names(Vector<PluginConfigAndroid> plugins_configs, Vector<String> &r_result) { | 
					
						
							| 
									
										
										
										
											2020-12-15 12:04:21 +00:00
										 |  |  | 	if (!plugins_configs.is_empty()) { | 
					
						
							| 
									
										
										
										
											2020-04-24 00:45:14 -07:00
										 |  |  | 		for (int i = 0; i < plugins_configs.size(); i++) { | 
					
						
							| 
									
										
										
										
											2021-01-14 15:05:42 +03:00
										 |  |  | 			PluginConfigAndroid config = plugins_configs[i]; | 
					
						
							| 
									
										
										
										
											2020-04-24 00:45:14 -07:00
										 |  |  | 			if (!config.valid_config) { | 
					
						
							|  |  |  | 				continue; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-02 11:14:29 -07:00
										 |  |  | 			r_result.push_back(config.name); | 
					
						
							| 
									
										
										
										
											2020-04-24 00:45:14 -07:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2023-07-02 11:14:29 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | #endif // DISABLE_DEPRECATED
 |