| 604 | } |
| 605 | |
| 606 | void PluginManager::save_plugin_version_cache() { |
| 607 | String cache_dir = get_plugin_cache_path().path_join("plugin_versions"); |
| 608 | gdre::ensure_dir(cache_dir); |
| 609 | HashMap<String, HashMap<String, Dictionary>> data; |
| 610 | { |
| 611 | MutexLock lock(plugin_version_cache_mutex); |
| 612 | for (auto &E : plugin_version_cache) { |
| 613 | String cache_key = E.key; |
| 614 | PluginVersion version = E.value; |
| 615 | if (version.is_valid() && (is_prepopping() || !version.is_static_cached)) { |
| 616 | Dictionary version_json = version.to_json(); |
| 617 | String source = version.release_info.plugin_source; |
| 618 | String primary_id = itos(version.release_info.primary_id); |
| 619 | String secondary_id = itos(version.release_info.secondary_id); |
| 620 | if (!data.has(source)) { |
| 621 | data[source] = HashMap<String, Dictionary>(); |
| 622 | } |
| 623 | if (!data[source].has(primary_id)) { |
| 624 | data[source][primary_id] = Dictionary(); |
| 625 | } |
| 626 | data[source][primary_id][secondary_id] = version_json; |
| 627 | } |
| 628 | } |
| 629 | } |
| 630 | |
| 631 | for (auto &source : data) { |
| 632 | for (auto &primary_id : source.value) { |
| 633 | // source/primary_id.json - with secondary_id as the key |
| 634 | String file_name = source.key + "/" + primary_id.key + ".json"; |
| 635 | String path = cache_dir.path_join(file_name); |
| 636 | gdre::ensure_dir(path.get_base_dir()); |
| 637 | auto file = FileAccess::open(path, FileAccess::WRITE); |
| 638 | if (file.is_null()) { |
| 639 | ERR_PRINT("Failed to open plugin version cache file for writing: " + file_name); |
| 640 | continue; |
| 641 | } |
| 642 | String json = JSON::stringify(primary_id.value, " ", false, true); |
| 643 | file->store_string(json); |
| 644 | file->flush(); |
| 645 | file->close(); |
| 646 | } |
| 647 | } |
| 648 | data.clear(); |
| 649 | } |
| 650 | |
| 651 | void PluginManager::_bind_methods() { |
| 652 | // ClassDB::bind_method(D_METHOD("get_plugin_version", "plugin_name", "version"), &PluginManager::get_plugin_version); |