diff --git a/src/Archive.cc b/src/Archive.cc index de9585ab..ffbc537b 100644 --- a/src/Archive.cc +++ b/src/Archive.cc @@ -62,9 +62,7 @@ bool Archive::read_only_mode = false; -uint64_t ArchiveContents::next_id = 0; -std::unordered_map> ArchiveContents::archive_by_name; -std::unordered_map ArchiveContents::archive_by_id; +std::unordered_map ArchiveContents::archive_by_name; ArchiveContents::ArchiveContents(ArchiveType type_, std::string name_, filetype_t filetype_, where_t where_, int flags_, std::string filename_extension_) : id(0), @@ -132,16 +130,6 @@ ArchivePtr Archive::open(const ArchiveContentsPtr& contents, int flags) { return archive; } -ArchivePtr Archive::by_id(uint64_t id) { - auto contents = ArchiveContents::by_id(id); - - if (!contents) { - return nullptr; - } - - return open(contents); -} - int Archive::close() { int ret; @@ -574,39 +562,23 @@ bool ArchiveContents::read_infos_from_cachedb(std::vector *cached_files) { } void ArchiveContents::enter_in_maps(const ArchiveContentsPtr &contents) { - if (!(contents->flags & ARCHIVE_FL_NOCACHE)) { - contents->id = ++next_id; - archive_by_id[contents->id] = contents; - } - archive_by_name[TypeAndName(contents->filetype, contents->name)] = contents; } -ArchiveContentsPtr ArchiveContents::by_id(uint64_t id) { - auto it = archive_by_id.find(id); - - if (it == archive_by_id.end()) { - return nullptr; - } - - return it->second; -} ArchiveContentsPtr ArchiveContents::by_name(filetype_t filetype, const std::string &name) { auto it = archive_by_name.find(TypeAndName(filetype, name)); - if (it == archive_by_name.end() || it->second.expired()) { + if (it == archive_by_name.end()) { return nullptr; } - return it->second.lock(); + return it->second; } void ArchiveContents::clear_cache() { archive_by_name.clear(); - archive_by_id.clear(); - next_id = 0; } diff --git a/src/Archive.h b/src/Archive.h index b0301433..6255b133 100644 --- a/src/Archive.h +++ b/src/Archive.h @@ -56,7 +56,6 @@ typedef std::shared_ptr ArchivePtr; typedef std::shared_ptr ArchiveContentsPtr; #define ARCHIVE_FL_CREATE 0x00100 -#define ARCHIVE_FL_NOCACHE 0x00800 #define ARCHIVE_FL_RDONLY 0x01000 #define ARCHIVE_FL_TOP_LEVEL_ONLY 0x02000 @@ -98,7 +97,6 @@ class ArchiveContents { [[nodiscard]] int is_cache_up_to_date() const; static void enter_in_maps(const ArchiveContentsPtr& contents); - static ArchiveContentsPtr by_id(uint64_t id); static ArchiveContentsPtr by_name(filetype_t filetype, const std::string &name); static void clear_cache(); @@ -113,10 +111,7 @@ class ArchiveContents { }; private: - static uint64_t next_id; - static std::unordered_map> archive_by_name; - static std::unordered_map archive_by_id; - + static std::unordered_map archive_by_name; }; namespace std { @@ -146,9 +141,7 @@ class Archive { ZipSourcePtr source; std::string file; }; - - static ArchivePtr by_id(uint64_t id); - + static ArchivePtr open(const std::string &name, filetype_t filetype, where_t where, int flags); static ArchivePtr open_toplevel(const std::string &name, filetype_t filetype, where_t where, int flags); @@ -184,7 +177,6 @@ class Archive { [[nodiscard]] bool is_empty() const; [[nodiscard]] bool is_file_deleted(uint64_t index) const { return changes[index].status == Change::DELETED; } [[nodiscard]] bool is_writable() const { return (contents->flags & ARCHIVE_FL_RDONLY) == 0; } - [[nodiscard]] bool is_indexed() const { return (contents->flags & ARCHIVE_FL_NOCACHE) == 0 && IS_EXTERNAL(where); } virtual bool check() { return true; } // This is done as part of the constructor, remove? virtual bool close_xxx() { return true; } virtual bool commit_xxx() = 0; diff --git a/src/ParserDir.cc b/src/ParserDir.cc index 8b4b8a40..51df3e83 100644 --- a/src/ParserDir.cc +++ b/src/ParserDir.cc @@ -62,7 +62,7 @@ bool ParserDir::parse() { auto dir_empty = true; { - auto images = Archive::open(filepath, TYPE_DISK, FILE_NOWHERE, ARCHIVE_FL_NOCACHE); + auto images = Archive::open(filepath, TYPE_DISK, FILE_NOWHERE, 0); if (images && !images->is_empty()) { dir_empty = false; @@ -74,7 +74,7 @@ bool ParserDir::parse() { { // TODO: Remove this ugly hack. configuration.roms_zipped = false; - auto files = Archive::open(filepath, TYPE_ROM, FILE_NOWHERE, ARCHIVE_FL_NOCACHE); + auto files = Archive::open(filepath, TYPE_ROM, FILE_NOWHERE, 0); configuration.roms_zipped = true; if (files && !files->is_empty()) { @@ -86,7 +86,7 @@ bool ParserDir::parse() { continue; } else if (is_ziplike(file.name)) { - auto a = Archive::open(filepath / file.name, TYPE_ROM, FILE_NOWHERE, ARCHIVE_FL_NOCACHE); + auto a = Archive::open(filepath / file.name, TYPE_ROM, FILE_NOWHERE, 0); if (a) { auto name = a->name; if (!runtest) { @@ -113,7 +113,7 @@ bool ParserDir::parse() { switch (name_type(filepath)) { case NAME_ZIP: { /* TODO: handle errors */ - auto a = Archive::open(filepath, TYPE_ROM, FILE_NOWHERE, ARCHIVE_FL_NOCACHE); + auto a = Archive::open(filepath, TYPE_ROM, FILE_NOWHERE, 0); if (a) { auto name = a->name; if (!runtest) { @@ -169,7 +169,7 @@ bool ParserDir::parse() { while ((filepath = dir.next()) != "") { if (std::filesystem::is_directory(filepath)) { /* TODO: handle errors */ - auto a = Archive::open(filepath, TYPE_ROM, FILE_NOWHERE, ARCHIVE_FL_NOCACHE); + auto a = Archive::open(filepath, TYPE_ROM, FILE_NOWHERE, 0); if (a) { start_game(a->name, directory_name); parse_archive(TYPE_ROM, a.get());