compress and decompress

I´ve checked out zlib and a ton of other libraries, mostly based on zlib, but I´m lost.
From bugs with password protected files over 32bit only up to requiring MFC or other stuff, it appears to be a HUGE task just to get it installed, let alone figuring out how to use it.

In the end I figured, I don´t need any of the stuff that can cause problems, I need the core functions for compress and decompress, but I couldn´t find those separate.

Here is what I´m trying to do:

I have a 64bit GUI application written in C++ using MinGW-w64/GCC++.
Let´s just say it doesn´t have any further content, but just 2 buttons, one to launch a compress function, the other to launch an extract function.

I have a folder, containing files and subfolders containing more files.
For a start all names of folders and files can be hardcoded into the functions.

Upon buttonclick 1 I want to take the complete folder with all its content and copy it in compressed form into one target file.
Upon buttonclick 2 I want to open the target file and extract all files back to their original location.

I don´t need password protection, I don´t care for a specific algorithm, speed and compression rate are not important, it doesn´t have to be compatible with any existing compression format, it doesn´t have to be portable, but I would like to have 2 simple functions doing the job without the hassle of building and installing huge 3rd party libraries.

Is there an easy way to do this?
I cant give you exact code, but I can give you an idea as to how you should approach this. Use the <dirent.h> file (it is comes with code-blocks) to handle your directory handling.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// Get all of the plugins in the directory
void ScanDirectory(const char* Directory) {// Look up
    DIR *dp;// The directory we are reading from
    struct dirent *dirp;// The current file
    if((dp  = opendir(Directory)) == NULL) {// Make sure we could open the directory
        return;
    }// End of If statement

    while ((dirp = readdir(dp)) != NULL) {// Go through the directory
        if(dirp->d_name[0] != '.') {//Make sure we found a file or a directory
            if(string(dirp->d_name).find(".")) {// If we found a file

                 // We found a file to compress
                 // InsertFileNameIntoCompressedFile()
                 // CompressFIle()

            } else {// If we found another directory

                // InsertDirectoryNameIntoCompressedFile()
                // Scan all of the files in this directory adn compress them
                /*
                    You need to recall ScanDirectory to get all of the files
                    in the directory that we just found.
                */
          

            }// End of if statement
        }// End of if statement
    }// End of while loop

    closedir(dp);// Close the directory
    delete dp;// Free the allocated memory
    delete dirp;// Free the allocated memory
}// End of ScanDirectory(const char*) 


In this code snipet a made a function that will travers all of the files and directorys inside of a directory(the functions argument is the directory that you would like to scan). If you look at the comments inside the the code you will see things like InsertDirectoryName...() This will add the directorys name so that when you incompress the data you will know what the name of the directory/file is. With the code above the compressed file is to look something like this.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#d Directory Name
    #f FileName
    Compressed Data
    #f FileName
    Compressed Data
    #f FileName
    Compressed Data
    #d DirectoryName
        #f FileName
        Compressed Data
        .........
        .........
    #d DirectoryName
        #f FileName
        Compressed Data
        .........
        .........


I added the #d/#f so that when you are extractin the data and you come acrosss a '#' you can check to see the the nexh character is a 'd' or an 'f' if it is a 'd' then you found a directory and you can do what needs to be done, and if you find an 'f' you can uncompress its data. So when you push your 'Compress' button it will run the function above (REMEMBER YOU NEED TO FIX IT TI FIT YOUR NEEDS) and when you are decompressing you can simply read the file and do what needs to be done.
Thanks for the answer.
Meanwhile I found out, compression and multiple files in an archive are two independent things, so this solves 1/2 the task, for the actual compression I´m right now reading a few interesting things, hopefully I´ll get that part solved as well.
Oh, cool. I hope you figure it out.
Topic archived. No new replies allowed.