@@ -216,7 +216,8 @@ PluginFinishType LibzipPlugin::extractFiles(const QList<FileEntry> &files, const
216216 return PFT_Cancel;
217217 } else {
218218 setPassword (query.password ());
219- zip_set_default_password (archive, m_strPassword.toUtf8 ().constData ());
219+ QByteArray passwordBytes = passwordUnicode (m_strPassword, 0 );
220+ zip_set_default_password (archive, passwordBytes.constData ());
220221 lastNeedPasswordIndex = i;
221222 i--;
222223 }
@@ -269,7 +270,8 @@ PluginFinishType LibzipPlugin::extractFiles(const QList<FileEntry> &files, const
269270 return PFT_Cancel;
270271 } else {
271272 setPassword (query.password ());
272- zip_set_default_password (archive, m_strPassword.toUtf8 ().constData ());
273+ QByteArray passwordBytes = passwordUnicode (m_strPassword, 0 );
274+ zip_set_default_password (archive, passwordBytes.constData ());
273275 i--;
274276 }
275277 } else {
@@ -668,12 +670,16 @@ bool LibzipPlugin::writeEntry(zip_t *archive, const QString &entry, const Compre
668670 // 设置压缩的加密算法
669671 if (options.bEncryption && !options.strEncryptionMethod .isEmpty ()) { // ReadOnlyArchiveInterface::password()
670672 int ret = 0 ;
673+ QByteArray passwordBytes = passwordUnicode (options.strPassword , 0 );
674+ qInfo () << " Setting encryption for file, method:" << options.strEncryptionMethod
675+ << " password length:" << options.strPassword .length ()
676+ << " encoded bytes length:" << passwordBytes.length ();
671677 if (QLatin1String (" AES128" ) == options.strEncryptionMethod ) {
672- ret = zip_file_set_encryption (archive, uindex, ZIP_EM_AES_128, options. strPassword . toUtf8 () .constData ());
678+ ret = zip_file_set_encryption (archive, uindex, ZIP_EM_AES_128, passwordBytes .constData ());
673679 } else if (QLatin1String (" AES192" ) == options.strEncryptionMethod ) {
674- ret = zip_file_set_encryption (archive, uindex, ZIP_EM_AES_192, options. strPassword . toUtf8 () .constData ());
680+ ret = zip_file_set_encryption (archive, uindex, ZIP_EM_AES_192, passwordBytes .constData ());
675681 } else if (QLatin1String (" AES256" ) == options.strEncryptionMethod ) {
676- ret = zip_file_set_encryption (archive, uindex, ZIP_EM_AES_256, options. strPassword . toUtf8 () .constData ());
682+ ret = zip_file_set_encryption (archive, uindex, ZIP_EM_AES_256, passwordBytes .constData ());
677683 }
678684 if (ret != 0 ) {
679685 emit error ((" Failed to set compression options for entry: %1" ));
@@ -1216,6 +1222,7 @@ QByteArray LibzipPlugin::passwordUnicode(const QString &strPassword, int iIndex)
12161222
12171223 // chinese
12181224 if (b) {
1225+ qInfo () << " Password contains Chinese characters, using codec:" << m_listCodecs[iIndex];
12191226 QTextCodec *utf8 = QTextCodec::codecForName (" UTF-8" );
12201227 QTextCodec *gbk = QTextCodec::codecForName (m_listCodecs[iIndex].toUtf8 ().data ());
12211228 // QTextCodec *gbk = QTextCodec::codecForName("UTF-8");
@@ -1227,6 +1234,7 @@ QByteArray LibzipPlugin::passwordUnicode(const QString &strPassword, int iIndex)
12271234 QByteArray gb_bytes = gbk->fromUnicode (strUnicode);
12281235 return gb_bytes; // 获取其char *115645 【专业版】【1060】【归档管理器】【5.12.0.2】无法解压中文密码的zip压缩包(含有长名称)
12291236 } else {
1237+ qInfo () << " Password is non-Chinese, using UTF-8 encoding" ;
12301238 return strPassword.toUtf8 ();
12311239 }
12321240 } else {
0 commit comments