Skip to content

Commit a8bc4e4

Browse files
committed
Removed old code
1 parent 232fc7b commit a8bc4e4

File tree

1 file changed

+0
-248
lines changed

1 file changed

+0
-248
lines changed

src/nbl/system/CArchiveLoaderZip.cpp

Lines changed: 0 additions & 248 deletions
Original file line numberDiff line numberDiff line change
@@ -386,254 +386,6 @@ core::smart_refctd_ptr<IFileArchive> CArchiveLoaderZip::createArchive_impl(core:
386386
return createArchiveFromZIP(std::move(file), password);
387387
}
388388
}
389-
#if 0
390-
core::smart_refctd_ptr<IFileArchive> CArchiveLoaderZip::createArchive_impl(core::smart_refctd_ptr<system::IFile>&& file, const std::string_view& password) const
391-
{
392-
if (!file)
393-
return nullptr;
394-
395-
uint16_t sig;
396-
{
397-
IFile::success_t success;
398-
file->read(success,&sig,0,sizeof(sig));
399-
if (!success)
400-
return nullptr;
401-
}
402-
403-
std::shared_ptr<core::vector<IFileArchive::SFileList::SEntry>> items = std::make_shared<core::vector<IFileArchive::SFileList::SEntry>>();
404-
core::vector<SZIPFileHeader> itemsMetadata;
405-
// load file entries
406-
{
407-
const bool isGZip = sig==0x8b1fu;
408-
409-
//
410-
auto addItem = [&items,&itemsMetadata](const std::string& _path, const size_t offset, const SZIPFileHeader& meta) -> void
411-
{
412-
// we need to have a filename or we skip
413-
if (_path.empty())
414-
return;
415-
416-
auto& item = items->emplace_back();
417-
item.pathRelativeToArchive = _path;
418-
item.size = meta.DataDescriptor.UncompressedSize;
419-
item.offset = offset;
420-
item.ID = itemsMetadata.size();
421-
item.allocatorType = meta.CompressionMethod ? IFileArchive::EAT_VIRTUAL_ALLOC:IFileArchive::EAT_NULL;
422-
itemsMetadata.push_back(meta);
423-
};
424-
425-
//
426-
size_t offset = 0ull;
427-
auto readStringFromFile = [&file,&offset](auto charCallback) -> bool
428-
{
429-
char c = 0x45; // make sure we start with non-zero char
430-
while (c)
431-
{
432-
IFile::success_t success;
433-
file->read(success,&c,offset,sizeof(c));
434-
if (!success)
435-
return false;
436-
offset += success.getBytesToProcess();
437-
charCallback(c);
438-
}
439-
// if string is not null terminated, something went wrong reading the file
440-
return !c;
441-
};
442-
443-
//
444-
std::string filename;
445-
filename.reserve(ISystem::MAX_FILENAME_LENGTH);
446-
if (isGZip)
447-
{
448-
SGZIPMemberHeader gzipHeader;
449-
{
450-
IFile::success_t success;
451-
file->read(success,&gzipHeader,0ull,sizeof(gzipHeader));
452-
if (!success)
453-
return nullptr;
454-
offset += success.getBytesToProcess();
455-
}
456-
457-
//! The gzip file format seems to think that there can be multiple files in a gzip file
458-
//! TODO: But OLD Irrlicht Impl doesn't honor it!?
459-
if (gzipHeader.sig!=0x8b1fu)
460-
return nullptr;
461-
462-
// now get the file info
463-
if (gzipHeader.flags&EGZF_EXTRA_FIELDS)
464-
{
465-
// read lenth of extra data
466-
uint16_t dataLen;
467-
IFile::success_t success;
468-
file->read(success,&dataLen,offset,sizeof(dataLen));
469-
if (!success)
470-
return nullptr;
471-
offset += success.getBytesToProcess();
472-
// skip the extra data
473-
offset += dataLen;
474-
}
475-
//
476-
if (gzipHeader.flags&EGZF_FILE_NAME)
477-
{
478-
filename.clear();
479-
if (!readStringFromFile([&](const char c){filename.push_back(c);}))
480-
return nullptr;
481-
}
482-
//
483-
if (gzipHeader.flags&EGZF_COMMENT)
484-
{
485-
if (!readStringFromFile([](const char c){}))
486-
return nullptr;
487-
}
488-
// skip crc16
489-
if (gzipHeader.flags&EGZF_CRC16)
490-
offset += 2;
491-
492-
493-
SZIPFileHeader header;
494-
memset(&header,0,sizeof(SZIPFileHeader));
495-
header.FilenameLength = filename.length();
496-
header.CompressionMethod = gzipHeader.compressionMethod;
497-
header.DataDescriptor.CompressedSize = file->getSize()-(offset+sizeof(uint64_t));
498-
499-
const size_t itemOffset = offset;
500-
501-
offset += header.DataDescriptor.CompressedSize;
502-
// read CRC
503-
{
504-
IFile::success_t success;
505-
file->read(success,&header.DataDescriptor.CRC32,offset,sizeof(header.DataDescriptor.CRC32));
506-
if (!success)
507-
return nullptr;
508-
offset += success.getBytesToProcess();
509-
}
510-
// read uncompressed size
511-
{
512-
IFile::success_t success;
513-
file->read(success,&header.DataDescriptor.UncompressedSize,offset,sizeof(header.DataDescriptor.UncompressedSize));
514-
if (!success)
515-
return nullptr;
516-
offset += success.getBytesToProcess();
517-
}
518-
519-
//
520-
addItem(filename,itemOffset,header);
521-
}
522-
else
523-
{
524-
while (true)
525-
{
526-
SZIPFileHeader zipHeader;
527-
{
528-
IFile::success_t success;
529-
file->read(success,&zipHeader,offset,sizeof(zipHeader));
530-
if (!success)
531-
break;
532-
offset += success.getBytesToProcess();
533-
}
534-
535-
if (zipHeader.Sig!=0x04034b50u)
536-
break;
537-
538-
filename.resize(zipHeader.FilenameLength);
539-
{
540-
IFile::success_t success;
541-
file->read(success,filename.data(),offset,zipHeader.FilenameLength);
542-
if (!success)
543-
break;
544-
offset += success.getBytesToProcess();
545-
}
546-
547-
// AES encryption
548-
if ((zipHeader.GeneralBitFlag&ZIP_FILE_ENCRYPTED) && (zipHeader.CompressionMethod==99))
549-
{
550-
SZipFileExtraHeader extraHeader;
551-
SZipFileAESExtraData data;
552-
553-
size_t localOffset = offset;
554-
offset += zipHeader.ExtraFieldLength;
555-
while (true)
556-
{
557-
{
558-
IFile::success_t success;
559-
file->read(success,&extraHeader,localOffset,sizeof(extraHeader));
560-
if (!success)
561-
break;
562-
localOffset += success.getBytesToProcess();
563-
if (localOffset>offset)
564-
break;
565-
}
566-
567-
if (extraHeader.ID!=0x9901u)
568-
continue;
569-
570-
{
571-
IFile::success_t success;
572-
file->read(success,&data,localOffset,sizeof(data));
573-
if (!success)
574-
break;
575-
localOffset += success.getBytesToProcess();
576-
if (localOffset>offset)
577-
break;
578-
}
579-
if (data.Vendor[0]=='A' && data.Vendor[1]=='E')
580-
{
581-
#ifdef _NBL_COMPILE_WITH_ZIP_ENCRYPTION_
582-
// encode values into Sig
583-
// AE-Version | Strength | ActualMode
584-
zipHeader.Sig =
585-
((data.Version & 0xff) << 24) |
586-
(data.EncryptionStrength << 16) |
587-
(data.CompressionMode);
588-
break;
589-
#else
590-
filename.clear(); // no support, can't decrypt
591-
#endif
592-
}
593-
}
594-
}
595-
else
596-
offset += zipHeader.ExtraFieldLength;
597-
598-
// if bit 3 was set, use CentralDirectory for setup
599-
if (zipHeader.GeneralBitFlag&ZIP_INFO_IN_DATA_DESCRIPTOR)
600-
{
601-
SZIPFileCentralDirEnd dirEnd;
602-
dirEnd.Sig = 0u;
603-
604-
// First place where the end record could be stored
605-
offset = file->getSize()-sizeof(SZIPFileCentralDirEnd)+1ull;
606-
while (dirEnd.Sig!=SZIPFileCentralDirEnd::ExpectedSig)
607-
{
608-
IFile::success_t success;
609-
file->read(success,&dirEnd,--offset,sizeof(dirEnd));
610-
if (!success)
611-
return nullptr;
612-
}
613-
items->reserve(dirEnd.TotalEntries);
614-
itemsMetadata.reserve(dirEnd.TotalEntries);
615-
offset = dirEnd.Offset;
616-
#if 0
617-
while (scanCentralDirectoryHeader(offset)) {}
618-
#endif
619-
assert(false); // if you ever hit this, msg @devsh
620-
break;
621-
}
622-
623-
addItem(filename,offset,zipHeader);
624-
// move forward length of data
625-
offset += zipHeader.DataDescriptor.CompressedSize;
626-
}
627-
}
628-
}
629-
630-
assert(items->size()==itemsMetadata.size());
631-
if (items->empty())
632-
return nullptr;
633-
634-
return core::make_smart_refctd_ptr<CArchive>(std::move(file),core::smart_refctd_ptr(m_logger.get()), items, std::move(itemsMetadata));
635-
}
636-
#endif
637389

638390
CFileArchive::file_buffer_t CArchiveLoaderZip::CArchive::getFileBuffer(const IFileArchive::SFileList::found_t& item)
639391
{

0 commit comments

Comments
 (0)