Results 1 to 10 of 10

Thread: Can't open password protected zip file using QuaZip

  1. #1
    Join Date
    Apr 2012
    Location
    India.
    Posts
    88
    Thanked 8 Times in 8 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Can't open password protected zip file using QuaZip

    Dear All,
    I would like to open password protected zip file using QuaZip but it is not working and I can see it says open mode not supported.
    File is stored on my local computer.

    I can unzip normal file.

    Here is my code sample.

    Qt Code:
    1. bool CURLScanner::UnZipFile()
    2. {
    3. QuaZip zip(TEST_ZIP_FILE);
    4. //QuaZip zip(FILE_SAVE_PATH);
    5. zip.open(QuaZip::mdUnzip);
    6.  
    7. QuaZipFile file(&zip);
    8. //QString file_password(m_pURLDownloader->GetFileLastUpdatedTime());
    9. QString file_password("1234");
    10.  
    11. for(bool f=zip.goToFirstFile(); f; f=zip.goToNextFile())
    12. {
    13. printf("\n File Found in zip folder : %s", file.getFileName().toUtf8().constData());
    14.  
    15. file.open(QIODevice::ReadOnly,file_password);
    16.  
    17. QByteArray file_data = file.readAll();
    18. QString file_str(file_data);
    19. if(file_str.isEmpty())
    20. {
    21. printf("\n NO FILE CONTENT");
    22. }
    23. else
    24. {
    25. //do something with the data
    26. printf("\n\n UNZIP FILE CONTENT : %s", file_str.toUtf8().constData());
    27.  
    28. // set destination file
    29. QFile dstFile( TEST_UNZIP_FILE );
    30. //QFile dstFile( FILE_SAVE_PATH_2 );
    31.  
    32. // open the destination file
    33. dstFile.open( QIODevice::WriteOnly | QIODevice::Text );
    34. // write the data from the bytes array into the destination file
    35. dstFile.write( file_data.data() );
    36. //close the destination file
    37. dstFile.close();
    38. }
    39.  
    40. file.close();
    41. }
    42.  
    43. zip.close();
    44.  
    45. return true;
    46. }
    To copy to clipboard, switch view to plain text mode 

    Please help me.
    Thanks,

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Can't open password protected zip file using QuaZip

    Are you using the correct codec? From the QuaZip class description page on SourgeForge:

    This class supports localized file names inside ZIP archive, but you have to set up proper codec with setCodec() function. By default, locale codec will be used, which is probably ok for UNIX systems, but will almost certainly fail with ZIP archives created in Windows. This is because Windows ZIP programs have strange habit of using DOS encoding for file names in ZIP archives.
    Your code doesn't check to see if QuaZip:: open() succeeded. So any assumptions on whether the rest of the code works as expected are flawed.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  3. #3
    Join Date
    Apr 2012
    Location
    India.
    Posts
    88
    Thanked 8 Times in 8 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Can't open password protected zip file using QuaZip

    I have modified my function after your suggestion .. here is the updated code...

    Qt Code:
    1. bool CFileManager::UnZipFile(QString zipFilePath, QString unzipFilePath, QString filePassword)
    2. {
    3. printf("\nPROGRESS : UNZIP FILE REQUESTED ......\n");
    4. bool bFileUnZipDone(false);
    5.  
    6. QFile filePath(zipFilePath);
    7. if(filePath.exists())
    8. {
    9. printf("\nPROGRESS : UnZipFile - file path exists.");
    10. QuaZip zip(zipFilePath);
    11. zip.setFileNameCodec("WINDOWS-1251");
    12.  
    13. if(zip.open(QuaZip::mdUnzip))
    14. {
    15. printf("\nPROGRESS : UnZipFile - zip opened successfully.");
    16. // Iterate over all the files found in zip folder.
    17. QuaZipFile file(&zip);
    18. for(bool fileIter = zip.goToFirstFile(); fileIter ; fileIter = zip.goToNextFile())
    19. {
    20. printf("\nPROGRESS : UnZipFile - inside file loop..");
    21. //file.open(QIODevice::ReadOnly);
    22. if(file.open(QIODevice::ReadOnly,filePassword))// -- THIS FUNCTION IS NOT WORKING AND PRINTS ERROR IN CONSOLE.
    23. {
    24. printf("\nPROGRESS : UnZipFile - zip file opened successfully.");
    25. QByteArray file_data = file.readAll();
    26. QString file_str(file_data);
    27. if(file_str.isEmpty())
    28. {
    29. printf("\nPROGRESS : unzip file data found, saving to a fdisk file...");
    30. bFileUnZipDone = SaveFileToDisk(unzipFilePath, file_data);
    31. }
    32.  
    33. file.close();
    34. }
    35. }
    36.  
    37. zip.close();
    38. }
    39. else
    40. {
    41. printf("\n QuaZip open error : %d ",zip.getZipError());
    42. }
    43. }
    44. return bFileUnZipDone;
    45. }
    To copy to clipboard, switch view to plain text mode 

    Console shows "QuaZipFile:pen(): open mode 1 not supported by this function" message when it reaches to QuaZipFile open function, marked with capital letter comment in above code.

    I would like to unzip file on windows 8.1.

    Please help,
    Thanks.

  4. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Can't open password protected zip file using QuaZip

    "QuaZipFileen(): open mode 1 not supported by this function"
    Well, try another mode then. Maybe unzipping a passworded file requires write permission.

    Can you unzip this file using the WinZIP program on your PC?

    What happens if you make your own ZIP file with a password (in other words, zip something from your PC and put a password on it). Can your program read that?
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  5. #5
    Join Date
    Apr 2012
    Location
    India.
    Posts
    88
    Thanked 8 Times in 8 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Can't open password protected zip file using QuaZip

    I have already tried other mode and all says mode not supported.

    I can create password protected zip on my computer and unzip it using winzip.

    but programmatically I can't unzip file even if it was create on my computer.

    Does anyone tried this programmatically.

    It will be helpful if someone has some working example, please help.

    Is there anyway that JlCompress can do this, I didn't find any.

    Thanks,

  6. #6
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Can't open password protected zip file using QuaZip

    Have you used the debugger to step into the QuaZip code to see where it is failing? The error code is not very informative - you need to find out what is happening inside to cause the failure.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  7. #7
    Join Date
    Apr 2012
    Location
    India.
    Posts
    88
    Thanked 8 Times in 8 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Can't open password protected zip file using QuaZip

    Can someone verify here if zlib supports unzipping of password protected files.

    I found couple website which says like so.

    Thanks,

  8. #8
    Join Date
    Apr 2012
    Location
    India.
    Posts
    88
    Thanked 8 Times in 8 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Can't open password protected zip file using QuaZip

    Update from my side is the password protected sample file which I couldn't open programmatically using QuaZip can be open by some other sample C++ code I found from some other source.

    I have converted that code in static win32 lib and would like to use in my Qt project using QtCreator, work in progress.

    Meanwhile some one really have successfully opened password protected zip file using QuaZip then please let me know.

    Thanks,

  9. #9
    Join Date
    Oct 2016
    Posts
    1
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: Can't open password protected zip file using QuaZip

    I had the same problem. The solution was simple: Don't pass a QString as password. Pass something like
    Qt Code:
    1. password.toLatin1().data()
    To copy to clipboard, switch view to plain text mode 
    . Otherwise it's using another open() function. It should be using
    Qt Code:
    1. open(OpenMode mode, int *method, int *level, bool raw, const char *password =NULL)
    To copy to clipboard, switch view to plain text mode 
    (Open with password just calls this with openMod, 0,0,false,password.

  10. #10
    Join Date
    Apr 2012
    Location
    India.
    Posts
    88
    Thanked 8 Times in 8 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Can't open password protected zip file using QuaZip

    Thanks for your input, I will try your suggested solution.

Similar Threads

  1. download password protected zip file from website
    By Rajesh.Rathod in forum Qt Programming
    Replies: 4
    Last Post: 10th September 2016, 20:01
  2. Unable to open zipped file which is zipped with Quazip
    By zgulser in forum Qt Programming
    Replies: 0
    Last Post: 12th October 2012, 18:14
  3. how use gmail password in open source project
    By solook in forum Qt Programming
    Replies: 2
    Last Post: 22nd August 2012, 10:29
  4. QuaZIP and Password?
    By NoRulez in forum Qt Programming
    Replies: 1
    Last Post: 16th December 2008, 09:10
  5. About Password Protected Files:
    By vermarajeev in forum Qt Programming
    Replies: 7
    Last Post: 16th February 2007, 14:46

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.