--------------------------------- PackageWriter::AddFile Add a file to the writer and create a package entry for it - takes ownership
| 46 | // Add a file to the writer and create a package entry for it - takes ownership |
| 47 | // |
| 48 | void PackageWriter::AddFile(core::File* const file, std::string const& rootDir, core::E_CompressionType const compression) |
| 49 | { |
| 50 | m_Files.emplace_back(core::PkgEntry(), file, std::string()); |
| 51 | core::PkgEntry& entry = m_Files[m_Files.size() - 1].entry; |
| 52 | std::string& relName = m_Files[m_Files.size() - 1].relName; |
| 53 | |
| 54 | // assign the name the relative path of the file compared to the root directory of the package writer |
| 55 | relName = core::FileUtil::GetRelativePath(file->GetName(), rootDir); |
| 56 | |
| 57 | entry.fileId = GetHash(relName); |
| 58 | entry.compressionType = compression; |
| 59 | entry.nameLength = static_cast<uint16>(relName.size()); |
| 60 | |
| 61 | // try opening the file for now, so that we can get the size, keep it open for copying content later |
| 62 | if (!file->Open(core::FILE_ACCESS_MODE::Read)) |
| 63 | { |
| 64 | LOG("PackageWriter::AddFile > unable to open file '" + relName + std::string("'!"), core::LogLevel::Warning); |
| 65 | return; |
| 66 | } |
| 67 | |
| 68 | // get the file size |
| 69 | entry.size = file->GetSize(); |
| 70 | } |
| 71 | |
| 72 | //--------------------------------- |
| 73 | // PackageWriter::RemoveFile |
no test coverage detected