Typedef struct problems (extracting box files)

43 Views Asked by At

I need a little help.

I'm working an an extractor tool, but I have problems with my code.

Can you please help me?

I tried to edit my code multiple times. But I can not make it to work properly.

I can extract files from the archive file, but it won't work properly.

Heres my code:

struct: 
/*
X - File Data

// Directory
  4 - Number Of Files

  // for each file
    X - Filename
    1 - null Filename Terminator
    4 - File offset
    4 - File Size

4 - Directory Offset
*/
C++ code (BoxReader.h)

#pragma once

using namespace std;

typedef struct FileData {

char                    filename[256];
uint32_t                offset;
uint32_t                size;

}FileData;

typedef struct BoxHeader {

uint32_t                numberOfFiles;
uint32_t                directoryOffset;

}BoxHeader;

void unpacker() {

fstream BoxFile("Campaigns.box", ios::in | ios::binary);

if (BoxFile.is_open()) {

    BoxHeader boxHeader;
    BoxFile.read((char*)&boxHeader, sizeof(BoxHeader));

    vector<FileData>

        fileDataList;
    FileData fileData;

    // READING FILE

    while (BoxFile.read((char*)&fileData, sizeof(FileData))) {

        fileDataList.push_back(fileData);
    }
    for (int i = 0; i < fileDataList.size(); i++) {

        BoxFile.seekg(fileDataList[i].offset);

        char* buffer = new char[fileDataList[i].size];

        BoxFile.read(buffer, fileDataList[i].size);

        //EXPORTING FILES

        ofstream outputFile(fileDataList[i].filename, ios::out | ios::binary);

        outputFile.write(buffer, fileDataList[i].size);

        outputFile.close();

        delete[] buffer;
    }
    BoxFile.close();
}

}

0

There are 0 best solutions below