| 1936 | } |
| 1937 | |
| 1938 | Error GDRESettings::load_pack_uid_cache(bool p_reset) { |
| 1939 | if (!is_pack_loaded()) { |
| 1940 | return ERR_UNAVAILABLE; |
| 1941 | } |
| 1942 | String cache_file = get_loaded_pack_data_dir().path_join("uid_cache.bin"); |
| 1943 | if (!FileAccess::exists(cache_file)) { |
| 1944 | return ERR_FILE_NOT_FOUND; |
| 1945 | } |
| 1946 | Ref<FileAccess> f = FileAccess::open(cache_file, FileAccess::READ); |
| 1947 | |
| 1948 | if (f.is_null()) { |
| 1949 | return ERR_CANT_OPEN; |
| 1950 | } |
| 1951 | |
| 1952 | if (p_reset) { |
| 1953 | ResourceUID::get_singleton()->clear(); |
| 1954 | unique_ids.clear(); |
| 1955 | path_to_uid.clear(); |
| 1956 | } |
| 1957 | |
| 1958 | uint32_t entry_count = f->get_32(); |
| 1959 | for (uint32_t i = 0; i < entry_count; i++) { |
| 1960 | int64_t id = f->get_64(); |
| 1961 | int32_t len = f->get_32(); |
| 1962 | UID_Cache c; |
| 1963 | c.cs.resize_uninitialized(len + 1); |
| 1964 | ERR_FAIL_COND_V(c.cs.size() != len + 1, ERR_FILE_CORRUPT); // out of memory |
| 1965 | c.cs[len] = 0; |
| 1966 | int32_t rl = f->get_buffer((uint8_t *)c.cs.ptrw(), len); |
| 1967 | ERR_FAIL_COND_V(rl != len, ERR_FILE_CORRUPT); |
| 1968 | |
| 1969 | c.saved_to_cache = true; |
| 1970 | unique_ids[id] = c; |
| 1971 | path_to_uid[String::utf8(c.cs)] = id; |
| 1972 | } |
| 1973 | Vector<String> dupes; |
| 1974 | for (auto E : path_to_uid) { |
| 1975 | if (ResourceUID::get_singleton()->has_id(E.second)) { |
| 1976 | String old_path = ResourceUID::get_singleton()->get_id_path(E.second); |
| 1977 | String new_path = E.first; |
| 1978 | if (old_path != new_path) { |
| 1979 | if (old_path.simplify_path() == new_path.simplify_path()) { |
| 1980 | // Sometimes uid caches have duplicate paths when paths were not simplified before saving; this is a workaround |
| 1981 | new_path = new_path.simplify_path(); |
| 1982 | } else if (has_path_loaded(old_path)) { |
| 1983 | if (!has_path_loaded(new_path)) { // had old path, but not new path |
| 1984 | continue; // skip |
| 1985 | } |
| 1986 | // has both |
| 1987 | dupes.push_back(ResourceUID::get_singleton()->id_to_text(E.second) + " -> " + old_path + "\n Replacing with: " + new_path); |
| 1988 | } else if (!has_path_loaded(new_path)) { // has neither |
| 1989 | dupes.push_back(ResourceUID::get_singleton()->id_to_text(E.second) + " -> " + old_path + "\n Replacing with: " + new_path); |
| 1990 | } // else we have the new_path but not the old path |
| 1991 | } |
| 1992 | |
| 1993 | ResourceUID::get_singleton()->set_id(E.second, new_path); |
| 1994 | } else { |
| 1995 | ResourceUID::get_singleton()->add_id(E.second, E.first); |
nothing calls this directly
no test coverage detected