// open a 7Z file and parse its central directory public static error 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); 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(error.OUT_OF_MEMORY); } error err = newimpl.initialize(); if (err != error.NONE) { return(err); } } try { result = new m7z_file_wrapper(newimpl); //result = std.make_unique<m7z_file_wrapper>(std::move(newimpl)); return(error.NONE); } catch (Exception e) { m7z_file_impl.close(newimpl); return(error.OUT_OF_MEMORY); } }
public static void close(m7z_file_impl archive) { if (archive == null) { return; } // close the open files //global.osd_printf_verbose("un7z: closing archive file {0} and sending to cache\n", archive.m_filename.c_str()); archive.m_sharpCompressArchive.Dispose(); archive.m_archive_stream.osdfile = null; //throw new emu_unimplemented(); #if false // find the first nullptr entry in the cache lock (s_cache_mutex) //std::lock_guard<std::mutex> guard(s_cache_mutex); { int cachenum; for (cachenum = 0; cachenum < s_cache.Length; cachenum++) { if (s_cache[cachenum] == null) { break; } } // if no room left in the cache, free the bottommost entry if (cachenum == s_cache.Length) { cachenum--; global.osd_printf_verbose("un7z: removing {0} from cache to make space\n", s_cache[cachenum].m_filename.c_str()); s_cache[cachenum] = null; } // move everyone else down and place us at the top for ( ; cachenum > 0; cachenum--) { s_cache[cachenum] = s_cache[cachenum - 1]; } s_cache[0] = archive; } #endif }
public m7z_file_wrapper(m7z_file_impl impl) { m_impl = impl; assert(m_impl != null); }