Results 1 to 8 of 8

Thread: Self-extracting archive

  1. #1
    Join Date
    Jan 2014
    Posts
    76
    Thanks
    17
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Self-extracting archive

    Hi,
    In my application I used qCompress to compress some files and now I would like to create self-extracting archive. It is possible to create self-extracting archive using Qt Installer Framework? I do not know how I can use function like qUncompress from Qt Installer Framework to uncompress my data.
    Thanks,

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Self-extracting archive

    qCompress() and qUncompress() work on data, they do not create any files.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Jan 2014
    Posts
    76
    Thanks
    17
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Self-extracting archive

    Apparently my question was not clear.
    I have function which compresses file using qCompress , QFile and QByteArray

    Qt Code:
    1. void compress(QString sourceFile , QString compressFile)
    2. {
    3. QFile file( sourceFile );
    4. QFile outfile( compressFile );
    5. file.open(QIODevice::ReadOnly);
    6. outfile.open(QIODevice::WriteOnly);
    7. QByteArray data = file.readAll();
    8. QByteArray compressedData = qCompress( data, 9 );
    9. outfile.write( compressedData );
    10. file.close();
    11. outfile.close();
    12. }
    To copy to clipboard, switch view to plain text mode 

    And now I would like to create self-extracting option for this file and I think about Qt Installer framework. Maybe you know if I can use it for this purpose?

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Self-extracting archive

    How would an installer framework create a self-extracting archive? It's an installer framework and not a self-extracting archiver, it creates installers and not self-extracting archives.

    And I have no idea how your code snippet is related to the question.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Jan 2014
    Posts
    76
    Thanks
    17
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Self-extracting archive

    And I have no idea how your code snippet is related to the question.
    For a compressFile which I use in this code I need create a self-extracting archive.
    And I saw that Qt Installer Framework can be customizable so I ask if I can use it for this purpose but ok I understood that not.
    So how I can write this tool using Qt and C++?

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Self-extracting archive

    You can write a program that will uncompress a file embedded into a Qt resource to disk. You don't need to qCompress() the file as resources are already compressed.

    Qt Code:
    1. #include <QApplication>
    2. #include <QFileDialog>
    3. #include <QFile>
    4. #include <QString>
    5.  
    6. int main(int main, char **argv) {
    7. QApplication app(argc, argv);
    8. QString path = QFileDialog::getSaveFileName();
    9. if(path.isEmpty()) return 0;
    10. QFile f(":/myfile");
    11. QFile outfile(path);
    12. outfile.open(QFile::WriteOnly);
    13. f.open(QFile::ReadOnly);
    14. while(!f.atEnd()) {
    15. QByteArray data = f.read(4096);
    16. outfile.write(data);
    17. }
    18. return 0;
    19. }
    To copy to clipboard, switch view to plain text mode 
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. The following user says thank you to wysota for this useful post:

    atomic (8th April 2015)

  8. #7
    Join Date
    Jan 2014
    Posts
    76
    Thanks
    17
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Self-extracting archive

    Thanks for thats, cool idea.
    But I need create application which allow users to create compress / self-extracting archive. I have some idea but I do not know if I can run script like bash / python or my external program to uncompress when Qt Installer finished instalation( when user click 'finish' button )?

  9. #8
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Self-extracting archive

    Assuming you want a generic solution, i.e. One that can make a self-extracting compressed file of an arbitrary input file, then you need to write two applications and do some platform-dependent work.

    The first application you need is a self-contained, small program that uncompress a stream of data embedded within its own executable. This cannot easily depend on any external library other than those absolutely standard on the target platform; ruling out Qt most likely.

    The second application is one that takes an arbitrary file, compresses it and writes a copy of the first program executable, the compressed data, and probably some metadata like original file name and a checksum into a combined file.

    The platform-specific part is how you take a complete executable (program 1) and append or insert the compressed data into it so that it will still run and can find the embedded data within itself to uncompress. This can be anything from reasonably easy to quite difficult depending the nature of executables on the platform and things like maintaining exe signatures or avoiding anti-virus defences. A quick Google for "append data to executable" And variations on that theme will get you most of the way fairly quickly for Windows.
    "We can't solve problems by using the same kind of thinking we used when we created them." -- Einstein
    If you are posting code then please use [code] [/code] tags around it - makes addressing the problem easier.

Similar Threads

  1. Problem creating zip archive with QtIOCompressor
    By TorAn in forum Qt Programming
    Replies: 0
    Last Post: 12th November 2010, 17:54
  2. howto package rpm archive
    By dmendizabal in forum Qt Programming
    Replies: 1
    Last Post: 5th July 2010, 08:02
  3. how to define a dependency on an archive
    By Mike Rumore in forum Newbie
    Replies: 2
    Last Post: 10th February 2010, 21:49
  4. Work offline and Archive web page in Konqueror
    By jamadagni in forum KDE Forum
    Replies: 0
    Last Post: 22nd February 2006, 09:18

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.