k, i'm gonna paste a bunch of code in here cause i'm not sure what is causing this to generate errors. my problem apears to be in
void pkrEdit::export(string file)
if i compile and run exfile gets written to 0 bytes, however if i single step the program it produces and access violation at the line of code
ifAllPkr.read((char *)&buffer, FStruct[i].data_len1);
hope someone can help with this.
main.cpp
Code:#include "pkr.h" int main() { pkrEdit pk; string *dirs; string *files; ofstream test; test.open("test.txt", ios::binary | ios::app); files = new string[pk.numfiles]; dirs = new string[pk.numdirs]; pk.GetDirs(dirs); pk.GetFiles(files); pk.export(files[20]); }
pkr.cpp
pkr.hCode:#include "pkr.h" pkrEdit::pkrEdit() { ifAllPkr.open("ALL.PKR", ios::binary | ios::ate); ifAllPkr.seekg(0, ios::beg); ifAllPkr.read((char *)&HStruct, sizeof(HStruct)); DStruct = new PK_DIR_STRUC[HStruct.num_dirs]; //create an array of dir_structs and file_structs FStruct = new PK_FILE_STRUC[HStruct.num_files]; //= the number of dirs and files for(int i = 0; i < HStruct.num_dirs; i++) //and populate said arrays { ifAllPkr.read((char *)&DStruct[i], sizeof(PK_DIR_STRUC)); } for(i = 0; i < HStruct.num_files; i++) { ifAllPkr.read((char *)&FStruct[i], sizeof(PK_FILE_STRUC)); } numfiles = HStruct.num_files; numdirs = HStruct.num_dirs; // ofAllPkr.open("ALL.PKR", ios::binary | ios::ate); // ofAllPkr.seekp(0, ios::beg); } string * pkrEdit::GetDirs(string *dirs) { for(int i = 0; i < HStruct.num_dirs; i++) { dirs[i] = DStruct[i].path; } return(dirs); } string * pkrEdit::GetFiles(string *files) { for(int i = 0; i < HStruct.num_files; i++) { files[i] = FStruct[i].name; } return(files); } void pkrEdit::import(char *oldFile, char *newfile) {} void pkrEdit::export(string file) { char *buffer; for(int i = 0; i < HStruct.num_files; i++) { if(file == FStruct[i].name) { ifAllPkr.seekg(FStruct[i].data_offset); buffer = new char[FStruct[i].data_len1]; ifAllPkr.read((char *)&buffer, FStruct[i].data_len1); exFile.open(file.c_str(), ios::binary | ios::ate); exFile.write(buffer, FStruct[i].data_len1); exFile.close(); delete[] buffer; } } }
Code:#include <fstream> #include <string> #include <iostream> using namespace std; typedef struct PK_HEAD_STRUC { char ident[4]; int unknown;// always 1 int num_dirs; int num_files; } PK_HEAD; typedef struct PK_DIR_STRUC { char path[32]; int file_offset; int file_count; } PK_DIR; typedef struct PK_FILE_STRUC { char name[32]; int unknown; // always -2 int data_offset; int data_len1; int data_len2; // always == data_len2 } PK_FILE; class pkrEdit { public: int numfiles; int numdirs; pkrEdit(); string *GetDirs(string *dirs); string *GetFiles(string *files); void import(char *oldFile, char *newFile); void export(string file); protected: PK_HEAD_STRUC HStruct; PK_DIR_STRUC *DStruct; PK_FILE_STRUC *FStruct; private: ofstream exFile; ifstream imFile; ofstream ofAllPkr; ifstream ifAllPkr; };
ps. thanks in advance for any help.
btw, i know i still need to go back and cleanup a lot of the memory i allocated just havn't got around to it yet



LinkBack URL
About LinkBacks



, this has been driving me mad all day