Results 1 to 6 of 6

Thread: unpacking rar files

  1. #1
    Join Date
    Feb 2011
    Posts
    354
    Thanks
    17
    Thanked 27 Times in 24 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Windows

    Default unpacking rar files

    Hello. Does qt provide some means for unpacking rar files? Using command line tools isn't a good way, because I need it to be platform-independent and while unpacking I need to receive some information about the unrarring process such as progress indication, volume changing for multipart archives etc.
    Last edited by mentalmushroom; 10th March 2011 at 09:19.

  2. #2
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: unpacking rar files

    I know rarlabs produce Unrar.dll for Windows, maybe they produce similar library for Linux/etc?

  3. #3
    Join Date
    Feb 2011
    Posts
    354
    Thanks
    17
    Thanked 27 Times in 24 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Windows

    Default Re: unpacking rar files

    Yes, unrar.dll is for windows and they also provide portable sources. I hope they are really portable for Linux and Mac. I thought maybe Qt already has some functionality for that purpose.

  4. #4
    Join Date
    Aug 2009
    Posts
    10
    Thanks
    1
    Thanked 2 Times in 2 Posts

    Default Re: unpacking rar files

    I have successfully used QProcess to use unrar on linux and mac. I believe it will work on windows also, but I haven't tested it.

    Qt Code:
    1. /************************************************************************
    2. Copyright 2009 Thomas Anderson
    3.  
    4. This file is part of QBinNews.
    5.  
    6. QBinNews is free software: you can redistribute it and/or modify
    7. it under the terms of the GNU General Public License as published by
    8. the Free Software Foundation, either version 3 of the License, or
    9. (at your option) any later version.
    10.  
    11. QBinNews is distributed in the hope that it will be useful,
    12. but WITHOUT ANY WARRANTY; without even the implied warranty of
    13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    14. GNU General Public License for more details.
    15.  
    16. You should have received a copy of the GNU General Public License
    17. along with QBinNews. If not, see <http://www.gnu.org/licenses/>.
    18. **************************************************************************/
    19.  
    20. #include "qunrarthread.h"
    21. #include <QDebug>
    22.  
    23. QUnrar::QUnrar() : scanCount(0)
    24. {
    25. unrarProcess = new QProcess(this);
    26. connect (unrarProcess, SIGNAL(readyReadStandardOutput()), this, SLOT(readOutputSlot()));
    27. connect (unrarProcess, SIGNAL(readyReadStandardError()), this, SLOT(readErrorSlot()));
    28. connect(unrarProcess, SIGNAL(finished(int,QProcess::ExitStatus)), this, SLOT(finished(int,QProcess::ExitStatus)));
    29. }
    30.  
    31. void QUnrar::beginUnrarSlot(QSharedPointer<UnrarJob> job)
    32. {
    33. scanCount=0;
    34. currentJob = job;
    35. //-o+ tells unrar to automatically overwrite.
    36. //-p- tells unrar to not prompt for password. Not sure what the outcome will be. think is will probably just end maybe with error?
    37. QStringList parameters;
    38. QString basePath(job->basePath + "/extracted");
    39. parameters << "e" << "-o+" << "-p-" << job->rarPath << basePath;
    40. qDebug() << "unrar launch: " << job->rarPath;
    41.  
    42. // QDir temp(job->basePath);
    43. unrarProcess->setWorkingDirectory(job->basePath);
    44. unrarProcess->start(QString("unrar"), parameters);
    45. if (!unrarProcess->waitForStarted(500000))
    46. qDebug() << "process didn't start in QUnrar::beginUnrarSlot";
    47. if (logFile.isOpen())
    48. logFile.close();
    49. logFile.setFileName(job->basePath + "/unrarOut.txt");
    50. logFile.open(QIODevice::WriteOnly);
    51. }
    52.  
    53. void QUnrar::finished(int exitCode, QProcess::ExitStatus exitStatus)
    54. {
    55. logFile.close();
    56. // qDebug() << "inside QUnrar::finished. exitCode is "<< exitCode << " exitStatus is " << exitStatus;
    57. emit endUnrarSignal(currentJob);
    58. currentJob.clear();
    59. }
    60.  
    61. void QUnrar::readOutputSlot()
    62. {
    63. while (unrarProcess->canReadLine())
    64. {
    65. QByteArray line(unrarProcess->readLine());
    66. // qDebug() << line;
    67. if ((!line.contains('%')) && (!line.trimmed().isEmpty()))
    68. {
    69. line = line.trimmed();
    70. logFile.write(line);
    71. logFile.write("\n");
    72. if (line.contains("Extracting from"))
    73. scanCount++;
    74. //update progress
    75. int PercentComplete;
    76. double WorkPercent;
    77. WorkPercent = scanCount/(double)currentJob->rarCount;
    78. WorkPercent *= 100;
    79. PercentComplete = WorkPercent;
    80. emit UpdateProgressSignal(currentJob->jobId, PercentComplete);
    81. }
    82. }
    83. }
    84.  
    85. void QUnrar::readErrorSlot()
    86. {
    87. qDebug() << "error doing unrar";
    88. qDebug() << unrarProcess->readAllStandardError();
    89. if (unrarProcess->state() == QProcess::Running)
    90. {
    91. qDebug() << "attempting to terminate qunrarprocess.";
    92. unrarProcess->terminate();
    93. }
    94. }
    95.  
    96. /////////////////////////////////////
    97.  
    98. QUnrarThread::QUnrarThread() : QThread(), unrarTest(false)
    99. {
    100. }
    101.  
    102. void QUnrarThread::run()
    103. {
    104. QUnrar theUnrar;
    105. QUnrar *unrarPointer = &theUnrar;// i did this so the intellisense would show me the sigs and slots.
    106. connect(this, SIGNAL(beginUnrarSignal(QSharedPointer<UnrarJob>)), unrarPointer,
    107. SLOT(beginUnrarSlot(QSharedPointer<UnrarJob>)));
    108. connect(unrarPointer, SIGNAL(endUnrarSignal(QSharedPointer<UnrarJob>)), this,
    109. SLOT(endUnrarSlot(QSharedPointer<UnrarJob>)));
    110. connect(unrarPointer, SIGNAL(UpdateProgressSignal(int,int)), this, SIGNAL(UpdateProgressSignal(int,int)));
    111.  
    112. exec();
    113. }
    114.  
    115.  
    116. void QUnrarThread::addUnrarSlot(QSharedPointer<UnrarJob> job)
    117. {
    118. unrarQueue.enqueue(*job);
    119. sendJob();
    120. }
    121.  
    122. void QUnrarThread::endUnrarSlot(QSharedPointer<UnrarJob> job)
    123. {
    124. unrarTest = false;
    125. emit unrarDoneSignal(job);
    126. sendJob();
    127. }
    128.  
    129. void QUnrarThread::sendJob()
    130. {
    131. if (unrarQueue.isEmpty())
    132. return;
    133. if (unrarTest == false)
    134. {
    135. QSharedPointer<UnrarJob> tempJob = QSharedPointer<UnrarJob>(new UnrarJob());
    136. *tempJob = unrarQueue.dequeue();
    137. unrarTest = true;
    138. emit beginUnrarSignal(tempJob);
    139. }
    140. }
    To copy to clipboard, switch view to plain text mode 

  5. #5
    Join Date
    Feb 2011
    Posts
    354
    Thanks
    17
    Thanked 27 Times in 24 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Windows

    Default Re: unpacking rar files

    ok, thank you

  6. #6
    Join Date
    May 2012
    Posts
    1
    Platforms
    MacOS X Windows

    Default Re: unpacking rar files

    Hi Tanderson, is there any chance you could provide the rest of the code? (Headers and UnrarJob class etc.)

Similar Threads

  1. Replies: 2
    Last Post: 30th September 2010, 12:26
  2. Replies: 9
    Last Post: 28th April 2010, 09:18
  3. Replies: 12
    Last Post: 17th June 2009, 05:34
  4. visual studio project files - adding extra files
    By luf in forum Qt Programming
    Replies: 3
    Last Post: 13th June 2008, 21:05
  5. how to save sequences of text files and sound files
    By nagpalma in forum Qt Programming
    Replies: 8
    Last Post: 3rd July 2007, 00:06

Tags for this Thread

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.