Click here to Skip to main content
15,564,534 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Need some advice here:

I have a school project where I need to learn how to open read and write a compressed file to a directory on the computer>

So, far I have got this far with my code.

#include <iostream>

#include <fstream>

#include <iomanip>

#include <ostream>

#include <string>

using namespace std;

int main(void){

   ofstream ofile;

   // Opening file for writing

   ofile.open ("master.rez");

   if(ofile.is_open()){

   std::cout << ofile << "this line will be written into master.rez."<< endl;

   std::cout << ofile << "this line also will be written into master.rez."<<  endl;

   system("pause");

      ofile.close();

   }else{

      cerr<<"Error opening file!!"<<endl;

   }

   string buf;

   // Opening file for reading

   ifstream ifile;

   ifile.open("master.rez");

   if(ifile.is_open()){

      while(getline(ifile,buf))

      cout<<buf;

      ifile.close();

   }else{

      cerr<<"Error opening file!!"<<endl;

   }

   return 0;

}


So, there is my code I can open the compressed file and read it then open it again with "ifstream" and write the whole compressed file to my directory but I need to be able to read all the files inside of the compressed file and then use "ifstream" to write all the files from the compressed file to the directory like extracting them.

What, is the steps I need to take now in order to do this.

And, also for future terms if I wanted to do this with any compressed file type as long as its not encrypted how and what are the steps for that as well That I need to take thanks. Any help I get is gratefully appreciated.

What I have tried:

I've, got my program to open read and write the entire "master.rez" file to my directory where the "exe" is stored but I need to be able to open the compressed "master.rez" file and read it and write all the files inside of the compressed file aka "master.rez" to my directory where my "exe" is stored.
Posted
Updated 21-Nov-18 20:23pm
v2
Comments
Richard MacCutchan 22-Nov-18 5:37am    
You need to find documentation that explains the format and structure of .rez files.

1 solution

Start by looking at the ZipFile class: How to: Compress and extract files | Microsoft Docs[^]
 
Share this answer
 
Comments
Member 13244531 22-Nov-18 3:42am    
I looked into your link provided but These classes are for ".zip && .gzip", So what if you want to extract files from other compressed file formats besides ".zip && gzip" so do I need to de_compile the compressed file first with "ollydbg or a hex editor" and look for the signature and find the offset for how many files are inside of the compressed file and find the header or ? , Can someone give me a small tutorial it would help a lot okay your help is gratefully appreciated.
OriginalGriff 22-Nov-18 3:54am    
And what do you think most compressed files are?
OriginalGriff 22-Nov-18 4:23am    
If you want to process specific file formats, then you need to do a couple of things:
1) Specify exactly what you are playing with, not talk in general terms about "compressed files" because the generic terms have meaning that don't apply to some formats - just as video game ROMs for example, because they aren't used outside the scope of a particular model of console. In the wide world, "compressed files" mean GAR, TAR, ZIP, CAB, or RAR because they are the ones "real world" developers have to deal with.
2) If you want to deal with game ROMs, then you probably need to find a site dedicated to consoles old consoles, and a forum within that site that deals with the ROMs - this isn't a "gaming" site, its a professional development site and that's rather different.
3) You also need to be aware that reverse engineering ROMs is in breach of copyright and licencing terms, and that this site has some strict rules on that kind of breach (we develop software which has that kind of copyright and / or licence so we're not fond of people who want to break it!) You shoudl probably find a less ethical site, or you risk being banned from this one.
Member 13244531 22-Nov-18 4:32am    
Typical
OriginalGriff 22-Nov-18 4:34am    
Typical what?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900