MCPcopy Create free account
hub / github.com/ThirteenAG/Ultimate-ASI-Loader / LoadVirtualFilesFromZip

Function LoadVirtualFilesFromZip

source/dllmain.cpp:3906–3963  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3904 #endif
3905
3906 void LoadVirtualFilesFromZip()
3907 {
3908 for (const auto& activeDir : sActiveDirectories)
3909 {
3910 for (const auto& entry : sFileLoaderEntries)
3911 {
3912 if (entry.path == activeDir && entry.isFromZip)
3913 {
3914 for (const auto& archive : entry.archives)
3915 {
3916 mz_zip_archive zip_archive = {};
3917 bool reader_initialized = false;
3918
3919 if (archive->is_multi_part)
3920 {
3921 zip_archive.m_pRead = multipart_zip_read_func;
3922 zip_archive.m_pIO_opaque = archive.get();
3923 reader_initialized = mz_zip_reader_init(&zip_archive, archive->total_size, 0);
3924 }
3925 else
3926 {
3927 reader_initialized = mz_zip_reader_init_file(&zip_archive, archive->parts[0].string().c_str(), 0);
3928 }
3929
3930 if (reader_initialized)
3931 {
3932 for (uint32_t i = 0; i < mz_zip_reader_get_num_files(&zip_archive); i++)
3933 {
3934 mz_zip_archive_file_stat file_stat;
3935 if (mz_zip_reader_file_stat(&zip_archive, i, &file_stat) && !mz_zip_reader_is_file_a_directory(&zip_archive, i))
3936 {
3937 std::filesystem::path internalPath(file_stat.m_filename);
3938 if (!internalPath.has_root_path() && internalPath.begin() != internalPath.end() && *internalPath.begin() == activeDir)
3939 {
3940 auto virtualPath = lexicallyRelativeCaseIns(internalPath, activeDir);
3941 auto normalizedPath = NormalizePath(virtualPath);
3942 std::unique_lock lock(virtualFilesMutex);
3943 auto it = virtualFilesByPath.find(normalizedPath);
3944 int newPri = entry.priority - 1000;
3945 if (it == virtualFilesByPath.end() || it->second->priority < newPri)
3946 {
3947 auto virtualFile = std::make_shared<VirtualFile>(archive, i, file_stat.m_uncomp_size, newPri);
3948 virtualFilesByPath[normalizedPath] = virtualFile;
3949 if (it == virtualFilesByPath.end())
3950 {
3951 virtualFilesCount.fetch_add(1, std::memory_order_release);
3952 }
3953 }
3954 }
3955 }
3956 }
3957 mz_zip_reader_end(&zip_archive);
3958 }
3959 }
3960 }
3961 }
3962 }
3963 }

Callers 1

LoadPluginsAndRestoreIATFunction · 0.85

Calls 10

mz_zip_reader_initFunction · 0.85
mz_zip_reader_init_fileFunction · 0.85
mz_zip_reader_file_statFunction · 0.85
lexicallyRelativeCaseInsFunction · 0.85
NormalizePathFunction · 0.85
mz_zip_reader_endFunction · 0.85
beginMethod · 0.80
endMethod · 0.80

Tested by

no test coverage detected