DETECTOR: Modify getFileProperties to cache md5 results

This commit is contained in:
a/ 2021-05-02 20:16:18 +09:00 committed by Eugene Sandulenko
parent 45aa165b80
commit bad9008a89
3 changed files with 47 additions and 46 deletions

View File

@ -500,5 +500,51 @@ public:
*/
bool getFilePropertiesExtern(uint md5Bytes, const FileMap &allFiles, const ADGameDescription &game, const Common::String fname, FileProperties &fileProps) const;
};
/**
* Singleton Cache Storage for Computed MD5s
*/
class MD5CacheManager : public Common::Singleton<MD5CacheManager> {
public:
void setMD5(Common::String fname, Common::String md5) {
md5HashMap.setVal(fname, md5);
}
Common::String getMD5(Common::String fname) {
return md5HashMap.getVal(fname);
}
void setSize(Common::String fname, int32 size) {
sizeHashMap.setVal(fname, size);
}
int32 getSize(Common::String fname) {
return sizeHashMap.getVal(fname);
}
bool contains(Common::String fname) {
return (md5HashMap.contains(fname) && sizeHashMap.contains(fname));
}
MD5CacheManager() {
clear();
}
void clear() {
md5HashMap.clear(true);
sizeHashMap.clear(true);
}
private:
friend class Common::Singleton<MD5CacheManager>;
typedef Common::HashMap<Common::String, Common::String, Common::IgnoreCase_Hash, Common::IgnoreCase_EqualTo> FileHashMap;
typedef Common::HashMap<Common::String, int32, Common::IgnoreCase_Hash, Common::IgnoreCase_EqualTo> SizeHashMap;
FileHashMap md5HashMap;
SizeHashMap sizeHashMap;
};
/** Convenience shortcut for accessing the MD5CacheManager. */
#define MD5Man MD5CacheManager::instance()
/** @} */
#endif

View File

@ -567,51 +567,5 @@ private:
/** Convenience shortcut for accessing the engine manager. */
#define EngineMan EngineManager::instance()
/**
* Singleton Cache Storage for Computed MD5s
*/
class MD5CacheManager : public Common::Singleton<MD5CacheManager> {
public:
void setMD5(Common::String fname, Common::String md5) {
md5HashMap.setVal(fname, md5);
}
Common::String getMD5(Common::String fname) {
return md5HashMap.getVal(fname);
}
void setSize(Common::String fname, int32 size) {
sizeHashMap.setVal(fname, size);
}
int32 getSize(Common::String fname) {
return sizeHashMap.getVal(fname);
}
bool contains(Common::String fname) {
return (md5HashMap.contains(fname) && sizeHashMap.contains(fname));
}
MD5CacheManager() {
clear();
}
void clear() {
md5HashMap.clear(true);
sizeHashMap.clear(true);
}
private:
friend class Common::Singleton<MD5CacheManager>;
typedef Common::HashMap<Common::String, Common::String, Common::IgnoreCase_Hash, Common::IgnoreCase_EqualTo> FileHashMap;
typedef Common::HashMap<Common::String, int32, Common::IgnoreCase_Hash, Common::IgnoreCase_EqualTo> SizeHashMap;
FileHashMap md5HashMap;
SizeHashMap sizeHashMap;
};
/** Convenience shortcut for accessing the MD5CacheManager. */
#define MD5Man MD5CacheManager::instance()
/** @} */
#endif

View File

@ -51,6 +51,7 @@
#include "gui/widgets/tab.h"
#include "gui/widgets/popup.h"
#include "gui/ThemeEval.h"
#include "engines/advancedDetector.h"
#include "graphics/cursorman.h"
#if defined(USE_CLOUD) && defined(USE_LIBCURL)