Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Implement something like tar archive in windows environment
Forum Updated to NodeBB v4.3 + New Features

Implement something like tar archive in windows environment

Scheduled Pinned Locked Moved General and Desktop
47 Posts 8 Posters 10.6k Views 4 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Z Offline
    Z Offline
    Zgembo
    wrote on 29 Nov 2018, 10:28 last edited by
    #1

    Hi all,
    I am creating a Qt module for copying (archiving) some data files. Let’s say that I am exporting some files from database and some files from file system (on one PC). What I need is a way to group these files for an easier transfer and manipulation (something like tar archine on Linux systems), because I need to import them on another PC. Does anyone have any idea how to implement something like tar archive on windows or any other way of grouping files?

    Tnx.

    1 Reply Last reply
    0
    • S Offline
      S Offline
      sierdzio
      Moderators
      wrote on 29 Nov 2018, 10:42 last edited by
      #2

      Just use zip with small (or even zero) compression. Or, you can use tar itself, too - works on Windows just like on unixes. Look for gtar libs, for example.

      (Z(:^

      1 Reply Last reply
      2
      • S Offline
        S Offline
        SGaist
        Lifetime Qt Champion
        wrote on 29 Nov 2018, 10:49 last edited by
        #3

        Hi and welcome to devnet,

        To add to @sierdzio, KDE's KArchive module looks like a good candidate for your use case.

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        Z 1 Reply Last reply 30 Nov 2018, 21:01
        3
        • Z Offline
          Z Offline
          Zgembo
          wrote on 29 Nov 2018, 12:11 last edited by
          #4

          Thank you both for your suggestions. I will investigate this approach.

          1 Reply Last reply
          0
          • S SGaist
            29 Nov 2018, 10:49

            Hi and welcome to devnet,

            To add to @sierdzio, KDE's KArchive module looks like a good candidate for your use case.

            Z Offline
            Z Offline
            Zgembo
            wrote on 30 Nov 2018, 21:01 last edited by
            #5

            @SGaist Hi, can you give me some guidance on how to include KArchive modul into windows aplication enviroment? I am using visual studio 2017 with Qt 5.9.4.

            Thank you

            1 Reply Last reply
            0
            • S Offline
              S Offline
              SGaist
              Lifetime Qt Champion
              wrote on 30 Nov 2018, 21:07 last edited by
              #6

              Did you already build the module itself ?

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              Z 1 Reply Last reply 1 Dec 2018, 07:13
              0
              • S SGaist
                30 Nov 2018, 21:07

                Did you already build the module itself ?

                Z Offline
                Z Offline
                Zgembo
                wrote on 1 Dec 2018, 07:13 last edited by
                #7

                @SGaist No, I have just downloaded code from git, https://github.com/KDE/karchive but I do not know how to build it and include into my project.

                A V 2 Replies Last reply 1 Dec 2018, 10:22
                0
                • Z Zgembo
                  1 Dec 2018, 07:13

                  @SGaist No, I have just downloaded code from git, https://github.com/KDE/karchive but I do not know how to build it and include into my project.

                  A Offline
                  A Offline
                  aha_1980
                  Lifetime Qt Champion
                  wrote on 1 Dec 2018, 10:22 last edited by
                  #8

                  @Zgembo

                  you need CMake and then follow the instructions here: https://github.com/KDE/karchive/blob/master/INSTALL

                  Qt has to stay free or it will die.

                  1 Reply Last reply
                  1
                  • Z Offline
                    Z Offline
                    Zgembo
                    wrote on 10 Dec 2018, 10:28 last edited by
                    #9

                    I have found this tutorial online. It works as a charm.
                    http://3adly.blogspot.com/2011/06/qt-folder-compression.html
                    If you do not need compression, as I do not, you can just add second argument to qCompression function 0-means no compression.

                    Tnx,
                    Zgembo

                    Z 1 Reply Last reply 14 Dec 2018, 11:08
                    2
                    • Z Zgembo
                      1 Dec 2018, 07:13

                      @SGaist No, I have just downloaded code from git, https://github.com/KDE/karchive but I do not know how to build it and include into my project.

                      V Offline
                      V Offline
                      VRonin
                      wrote on 10 Dec 2018, 12:16 last edited by
                      #10

                      @Zgembo said in Implement something like tar archive in windows environment:

                      No, I have just downloaded code from git, https://github.com/KDE/karchive but I do not know how to build it and include into my project.

                      https://forum.qt.io/post/377923

                      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                      ~Napoleon Bonaparte

                      On a crusade to banish setIndexWidget() from the holy land of Qt

                      1 Reply Last reply
                      0
                      • Z Zgembo
                        10 Dec 2018, 10:28

                        I have found this tutorial online. It works as a charm.
                        http://3adly.blogspot.com/2011/06/qt-folder-compression.html
                        If you do not need compression, as I do not, you can just add second argument to qCompression function 0-means no compression.

                        Tnx,
                        Zgembo

                        Z Offline
                        Z Offline
                        Zgembo
                        wrote on 14 Dec 2018, 11:08 last edited by Zgembo
                        #11

                        @Zgembo Can someone look at the code on this link. When I try to compress larger files, few GB nothing happens.
                        http://3adly.blogspot.com/2011/06/qt-folder-compression.html

                        1 Reply Last reply
                        0
                        • V Offline
                          V Offline
                          VRonin
                          wrote on 14 Dec 2018, 12:21 last edited by VRonin
                          #12

                          Yes, that post uses qCompress(file.readAll()); so it has to load the entire file in memory and then uses a non-zip-compliant compression.

                          My suggestion stands: use KArchive. You can find a pre-built version (updated as of 2018-12-14, will be deleted in 6months time) with all dependencies in the following links:

                          • MSVC 2015 64 bit
                          • MSVC 2015 32 bit
                          • MinGW 32 bit (does not support bzip2)

                          "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                          ~Napoleon Bonaparte

                          On a crusade to banish setIndexWidget() from the holy land of Qt

                          Z 1 Reply Last reply 15 Dec 2018, 14:48
                          5
                          • V VRonin
                            14 Dec 2018, 12:21

                            Yes, that post uses qCompress(file.readAll()); so it has to load the entire file in memory and then uses a non-zip-compliant compression.

                            My suggestion stands: use KArchive. You can find a pre-built version (updated as of 2018-12-14, will be deleted in 6months time) with all dependencies in the following links:

                            • MSVC 2015 64 bit
                            • MSVC 2015 32 bit
                            • MinGW 32 bit (does not support bzip2)
                            Z Offline
                            Z Offline
                            Zgembo
                            wrote on 15 Dec 2018, 14:48 last edited by
                            #13

                            @VRonin said in Implement something like tar archive in windows environment:

                            Yes, that post uses qCompress(file.readAll()); so it has to load the entire file in memory and then uses a non-zip-compliant compression.

                            My suggestion stands: use KArchive. You can find a pre-built version (updated as of 2018-12-14, will be deleted in 6months time) with all dependencies in the following links:

                            • MSVC 2015 64 bit
                            • MSVC 2015 32 bit
                            • MinGW 32 bit (does not support bzip2)

                            Can I use it with MS Visual studio 2017, and if yes how can I include it in my project? Thank you.

                            1 Reply Last reply
                            0
                            • S Offline
                              S Offline
                              SGaist
                              Lifetime Qt Champion
                              wrote on 15 Dec 2018, 21:17 last edited by
                              #14

                              Yes you can. You have to build the module with VS2017 first.

                              As for how to include it in your project, it's shown on the bottom left of the module documentation.

                              Interested in AI ? www.idiap.ch
                              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                              V Z 2 Replies Last reply 17 Dec 2018, 08:44
                              2
                              • S SGaist
                                15 Dec 2018, 21:17

                                Yes you can. You have to build the module with VS2017 first.

                                As for how to include it in your project, it's shown on the bottom left of the module documentation.

                                V Offline
                                V Offline
                                VRonin
                                wrote on 17 Dec 2018, 08:44 last edited by
                                #15

                                @SGaist said in Implement something like tar archive in windows environment:

                                You have to build the module with VS2017 first.

                                AFAIK MSVC2015 and MSVC2017 are binary compatible (for the first time ever in MSVC history) so you could try downloading and using the 2015 pre-compiled and go from there.

                                @Zgembo said in Implement something like tar archive in windows environment:

                                how can I include it in my project?

                                http://doc.qt.io/qt-5/third-party-libraries.html
                                http://doc.qt.io/qtcreator/creator-project-qmake-libraries.html

                                "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                                ~Napoleon Bonaparte

                                On a crusade to banish setIndexWidget() from the holy land of Qt

                                1 Reply Last reply
                                4
                                • S SGaist
                                  15 Dec 2018, 21:17

                                  Yes you can. You have to build the module with VS2017 first.

                                  As for how to include it in your project, it's shown on the bottom left of the module documentation.

                                  Z Offline
                                  Z Offline
                                  Zgembo
                                  wrote on 17 Dec 2018, 10:15 last edited by
                                  #16

                                  @SGaist Hi, I have tried to build KArchive with Cmake-GUI, but it looks like I am mission extra cmake modules (ECM). I will try @VRonin suggestion to use prebuild libraries from his link. Thank you.

                                  1 Reply Last reply
                                  0
                                  • Z Offline
                                    Z Offline
                                    Zgembo
                                    wrote on 18 Dec 2018, 07:56 last edited by
                                    #17

                                    @VRonin Hi, I have tried to add karchive libraries that I have downloaded from your link, but with out any success. I have used this link as a tutorial https://stackoverflow.com/questions/35008426/link-3rd-party-library-in-visual-studio .
                                    When I try to compile my project I get the error: Cannot open include file: qplatformdefs.h: no such file or directory.

                                    1 Reply Last reply
                                    0
                                    • V Offline
                                      V Offline
                                      VRonin
                                      wrote on 18 Dec 2018, 08:19 last edited by
                                      #18

                                      @Zgembo said in Implement something like tar archive in windows environment:

                                      qplatformdefs.h

                                      That's an additional include.

                                      In Project > Properties > C/C++->General > Additional Include Directories
                                      Click Edit, and enter the path to the directory where the file "qplatformdefs.h" is located

                                      It is in the mkspecs folder of qt, something like: C:\Qt\5.12\msvc2015_64\mkspecs\win32-msvc

                                      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                                      ~Napoleon Bonaparte

                                      On a crusade to banish setIndexWidget() from the holy land of Qt

                                      Z 1 Reply Last reply 18 Dec 2018, 08:52
                                      1
                                      • V VRonin
                                        18 Dec 2018, 08:19

                                        @Zgembo said in Implement something like tar archive in windows environment:

                                        qplatformdefs.h

                                        That's an additional include.

                                        In Project > Properties > C/C++->General > Additional Include Directories
                                        Click Edit, and enter the path to the directory where the file "qplatformdefs.h" is located

                                        It is in the mkspecs folder of qt, something like: C:\Qt\5.12\msvc2015_64\mkspecs\win32-msvc

                                        Z Offline
                                        Z Offline
                                        Zgembo
                                        wrote on 18 Dec 2018, 08:52 last edited by
                                        #19

                                        @VRonin it compiles. Now I have to find some examples of how to use just KArchive to create archive file without any compression.

                                        1 Reply Last reply
                                        0
                                        • V Offline
                                          V Offline
                                          VRonin
                                          wrote on 18 Dec 2018, 09:02 last edited by VRonin
                                          #20

                                          from KArchive\examples\tarlocalfiles

                                          /*  This file is part of the KDE project
                                              Copyright (C) 2013 Maarten De Meyer <de.meyer.maarten@gmail.com>
                                              You may use this file under the terms of the BSD license as follows:
                                              Redistribution and use in source and binary forms, with or without
                                              modification, are permitted provided that the following conditions
                                              are met:
                                              1. Redistributions of source code must retain the above copyright
                                                notice, this list of conditions and the following disclaimer.
                                              2. Redistributions in binary form must reproduce the above copyright
                                                notice, this list of conditions and the following disclaimer in the
                                                documentation and/or other materials provided with the distribution.
                                              THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
                                              IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
                                              OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
                                              IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
                                              INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
                                              NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
                                              DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
                                              THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
                                              (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
                                              THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
                                          */
                                          /*
                                           * TarLocalFiles
                                           * This example shows how to add local files and directories to a KArchive
                                           *
                                           * api: addLocalFile(fileName, destName)
                                           * api: addLocalDirectory(dirName, destName)
                                           *
                                           * Usage: ./tarlocalfiles <file-1> <file-n>
                                          */
                                          #include <QCoreApplication>
                                          #include <QDir>
                                          #include <QFileInfo>
                                          #include <ktar.h>
                                          int main(int argc, char *argv[])
                                          {
                                              QCoreApplication app(argc, argv);
                                              QStringList files(app.arguments());
                                              // Create or open an archive
                                              KTar archive(QStringLiteral("myFiles.tar.gz"));
                                              // Prepare the archive for writing.
                                              if (!archive.open(QIODevice::WriteOnly)) {
                                                  // Failed to open file.
                                                  return 1;
                                              }
                                              if (files.size() <= 1) {
                                                  // No files given.
                                                  qWarning("Usage: ./tarlocalfiles <file>");
                                                  return 1;
                                              }
                                              for (int i = 1; i < files.size(); ++i) {
                                                  QFileInfo localFileOrDir(files.at(i));
                                                  if (localFileOrDir.isFile()) {
                                                      QString name = localFileOrDir.fileName();
                                                      archive.addLocalFile(name, name);
                                                  } else if (localFileOrDir.isDir()) {
                                                      QString name = QDir(files.at(i)).dirName();
                                                      // Add this folder and all its contents
                                                      archive.addLocalDirectory(name, name);
                                                  }
                                              }
                                              archive.close();
                                              return 0;
                                          }
                                          

                                          If you want to compress it see KArchive\examples\bzip2gzip

                                          "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                                          ~Napoleon Bonaparte

                                          On a crusade to banish setIndexWidget() from the holy land of Qt

                                          1 Reply Last reply
                                          0

                                          • Login

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • Users
                                          • Groups
                                          • Search
                                          • Get Qt Extensions
                                          • Unsolved