//static std::error_condition open_zip(std::unique_ptr<random_read> &&file, ptr &result) noexcept; // open a 7Z file and parse its central directory public static std.error_condition open_7z(string filename, out archive_file result) { // ensure we start with a nullptr result result = null; //result.reset(); // see if we are in the cache, and reopen if so m7z_file_impl newimpl = m7z_file_impl.find_cached(filename); //m7z_file_impl::ptr newimpl(m7z_file_impl::find_cached(filename)); if (newimpl == null) { // allocate memory for the 7z file structure try { newimpl = new m7z_file_impl(filename); } //try { newimpl = std.make_unique<m7z_file_impl>(filename); } catch (Exception e) { return(std.errc.not_enough_memory); } var err = newimpl.initialize(); if (err) { return(err); } } // allocate the archive API wrapper result = new m7z_file_wrapper(newimpl); //result.reset(new (std::nothrow) m7z_file_wrapper(std::move(newimpl))); if (result != null) { return(new std.error_condition()); } else { m7z_file_impl.close(newimpl); //m7z_file_impl::close(std::move(newimpl)); return(std.errc.not_enough_memory); } }
public static void close(m7z_file_impl archive) { // if the filename isn't empty, the implementation can be cached if (archive != null && !archive.m_filename.empty()) { archive.m_sharpCompressArchive.Dispose(); archive.m_archive_stream.file = null; #if false // close the open files osd_printf_verbose("un7z: closing archive file %s and sending to cache\n", archive->m_filename); archive->m_archive_stream.file.reset(); // find the first nullptr entry in the cache std::lock_guard <std::mutex> guard(s_cache_mutex); std::size_t cachenum; for (cachenum = 0; cachenum < s_cache.size(); cachenum++) { if (!s_cache[cachenum]) { break; } } // if no room left in the cache, free the bottommost entry if (cachenum == s_cache.size()) { cachenum--; osd_printf_verbose("un7z: removing %s from cache to make space\n", s_cache[cachenum]->m_filename); s_cache[cachenum].reset(); } // move everyone else down and place us at the top for ( ; cachenum > 0; cachenum--) { s_cache[cachenum] = std::move(s_cache[cachenum - 1]); } s_cache[0] = std::move(archive); #endif } // make sure it's cleaned up archive = null; //archive.reset(); }