0

我不知道为什么结构中缺少单个数据而其他数据没有,这里是结构

#pragma pack(push, 1)
typedef struct {
    uint32_t            size;
    u_long              crc32;
    char                flags;
    char                filename[MAX_FILENAME_LEN];
} update_file_t;

typedef struct {
    uint32_t            magic;
    uint32_t            num_files;
    update_file_t       files[MAX_FILES];
} update_into_t;
#pragma pack(pop)

// Reading part
update_info_t *upd = (update_info_t *)chunk.memory; // Downloaded by CURLib
update_file_t *files = &upd->files[0];
files->filename // it's always NULL WHY?
files->crc32    // correct
files->size     // correct

不知道怎么回事,可能是CURLib下载错了?服务器正确生成文件

    update_file_t       *file;
update_info_t       upd;
char                file_src[256];
update_file_t       *loc_file;

memset(&upd, 0, sizeof(upd));
upd.magic       = magic;
upd.num_files   = 0;

if (!(Out = fopen(output, "wb"))) {
    std::cout << "Couldn't open the output file for writing" << std::endl;
    return 1;
}

for (int c = 0; c < UPD_MAX_FILES; c++) {
    file = &upd.files[c];

    memset(file->filename, 0, sizeof(file->filename));
    file->crc32 = 0;
    file->flags = 0;
}
loc_file    = updgen_file_list;
file        = upd.files;

while (loc_file->filename && loc_file->flags) {
    if (upd.num_files >= UPD_MAX_FILES) {
        std::cout << "UPD_MAX_FILES exceeded!" << std::endl;
        return 1;
    }

    snprintf(file_src, sizeof(file_src),  "%s/%s", path, loc_file->filename);
    if (!(file->size = CRC32FromFile(file_src, &file->crc32))) {
        std::cout << "Couldn't calculate checksum for " << loc_file->filename << std::endl;
        return 1;
    }

    strncpy(file->filename, loc_file->filename, sizeof(loc_file->filename));
    file->flags = loc_file->flags;

    std::cout << "Added file " << file->filename << ", size: " << std::dec << file->size << " bytes, crc32: " << std::hex << file->crc32 << std::dec << std::endl;

    upd.num_files++;
    loc_file++;
    file++;
}
if (fwrite(&upd, sizeof(upd), 1, Out) != 1) {
    std::cout << "Failed writing the update info to the file!" << std::endl;
    return 1;
}

这是服务器部分代码,我不知道还有什么问题

4

0 回答 0