Beispiel #1
0
// Packages all files in "path" into a .zip file.
void CreateArchive(string path, string name, ArchiveInfo& info)
{
	HZIP hz = CreateZip(name.c_str(), 0);

	HANDLE hFind = INVALID_HANDLE_VALUE;
    WIN32_FIND_DATA ffd;
	string spec;
    stack<string> directories;

    directories.push(path);

    while (!directories.empty()) {
        path = directories.top();
        spec = path + "/*";
        directories.pop();

        hFind = FindFirstFile(spec.c_str(), &ffd);
        if (hFind == INVALID_HANDLE_VALUE)  
            return;

        do {
            if (strcmp(ffd.cFileName, ".") != 0 && strcmp(ffd.cFileName, "..") != 0) {
                if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
					// Add folder to archive.
					ZipAddFolder(hz, string(path + "/" + ffd.cFileName).c_str());
                    directories.push(path + "/" + ffd.cFileName);
                }
                else {
					// Add file to archive.
					ZipAdd(hz, string(path + "/" + ffd.cFileName).c_str(), string(path + "/" + ffd.cFileName).c_str());
					info.files++;
					info.size += FileSize(path + "/" + ffd.cFileName);
                }
            }
        } while (FindNextFile(hFind, &ffd) != 0);

        if (GetLastError() != ERROR_NO_MORE_FILES) {
            FindClose(hFind);
            return;
        }

        FindClose(hFind);
        hFind = INVALID_HANDLE_VALUE;
    }

	CloseZip(hz);
}
Beispiel #2
0
ZIP_API ZRESULT ZipAddDirectory(HZIP zip_handle, const TCHAR* destination_file_name){return ZipAddFolder(zip_handle, destination_file_name);}