#pragma once #include #include #include namespace updater { // 基于 miniz 的只读解压封装:支持 UTF-8/GBK 条目名、Zip Slip 防护、进度回调 class Unzip { public: struct Entry { std::wstring name; // 解码后的相对路径 unsigned long long size = 0; // 解压后大小 bool directory = false; }; // 返回 false 表示中止解压 using ProgressFunc = std::function; Unzip(); ~Unzip(); Unzip(const Unzip&) = delete; Unzip& operator=(const Unzip&) = delete; bool Open(const std::wstring& zipPath, std::wstring& err); void Close(); bool opened() const { return opened_; } unsigned int EntryCount() const; bool EntryAt(unsigned int index, Entry& out) const; // 判断包内是否所有条目都位于同一个顶层目录下 bool DetectCommonRoot(std::wstring& root) const; // 解压全部条目到 targetDir // stripRoot=true 时去掉公共顶层目录 // writtenFiles 返回实际写入的文件绝对路径 bool ExtractAll(const std::wstring& targetDir, bool stripRoot, ProgressFunc progress, std::vector& writtenFiles, std::wstring& err); private: struct Archive; Archive* archive_ = nullptr; bool opened_ = false; }; }