Prevent mod cache from MD5'ing every file on every boot
This commit is contained in:
parent
9f410ad161
commit
dec1fb9665
|
@ -103,7 +103,7 @@ void mod_activate(struct Mod* mod) {
|
|||
// activate dynos models
|
||||
for (int i = 0; i < mod->fileCount; i++) {
|
||||
struct ModFile* file = &mod->files[i];
|
||||
mod_cache_add(mod, file);
|
||||
mod_cache_add(mod, file, false);
|
||||
if (str_ends_with(file->relativePath, ".bin")) {
|
||||
mod_activate_bin(file);
|
||||
}
|
||||
|
@ -567,7 +567,7 @@ bool mod_load(struct Mods* mods, char* basePath, char* modName) {
|
|||
if (isDirectory) {
|
||||
for (int i = 0; i < mod->fileCount; i++) {
|
||||
struct ModFile* file = &mod->files[i];
|
||||
mod_cache_add(mod, file);
|
||||
mod_cache_add(mod, file, true);
|
||||
LOG_INFO(" - %s", file->relativePath);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -102,6 +102,19 @@ struct ModCacheEntry* mod_cache_get_from_hash(u8* dataHash) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
static bool mod_cache_has_path(const char* path) {
|
||||
if (path == NULL || strlen(path) == 0) { return NULL; }
|
||||
struct ModCacheEntry* node = sModCacheHead;
|
||||
while (node != NULL) {
|
||||
struct ModCacheEntry* next = node->next;
|
||||
if (!strcmp(node->path, path)) {
|
||||
return true;
|
||||
}
|
||||
node = next;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
struct ModCacheEntry* mod_cache_get_from_path(const char* path) {
|
||||
if (path == NULL || strlen(path) == 0) { return NULL; }
|
||||
struct ModCacheEntry* node = sModCacheHead;
|
||||
|
@ -183,7 +196,7 @@ void mod_cache_add_internal(u8* dataHash, u64 lastLoaded, const char* path) {
|
|||
LOG_ERROR("Did not add node for some reason?");
|
||||
}
|
||||
|
||||
void mod_cache_add(struct Mod* mod, struct ModFile* file) {
|
||||
void mod_cache_add(struct Mod* mod, struct ModFile* file, bool useFilePath) {
|
||||
// sanity check
|
||||
if (mod == NULL || file == NULL) {
|
||||
LOG_ERROR("Could not add to cache, mod or file is null");
|
||||
|
@ -206,6 +219,11 @@ void mod_cache_add(struct Mod* mod, struct ModFile* file) {
|
|||
normalize_path(modFilePath);
|
||||
file->cachedPath = strdup(modFilePath);
|
||||
|
||||
// if we already have the filepath, don't MD5 it again
|
||||
if (useFilePath && mod_cache_has_path(file->cachedPath)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// hash and cache
|
||||
mod_cache_md5(file->cachedPath, file->dataHash);
|
||||
mod_cache_add_internal(file->dataHash, 0, strdup(file->cachedPath));
|
||||
|
|
|
@ -13,7 +13,7 @@ struct ModCacheEntry {
|
|||
void mod_cache_shutdown(void);
|
||||
struct ModCacheEntry* mod_cache_get_from_hash(u8* dataHash);
|
||||
struct ModCacheEntry* mod_cache_get_from_path(const char* path);
|
||||
void mod_cache_add(struct Mod* mod, struct ModFile* modFile);
|
||||
void mod_cache_add(struct Mod* mod, struct ModFile* modFile, bool useFilePath);
|
||||
void mod_cache_load(void);
|
||||
void mod_cache_save(void);
|
||||
|
||||
|
|
Loading…
Reference in New Issue