@@ -201,6 +201,7 @@ PackageManagerCorePrivate::PackageManagerCorePrivate(PackageManagerCore *core)
201
201
, m_allowCompressedRepositoryInstall(false )
202
202
#endif
203
203
, m_connectedOperations(0 )
204
+ , m_processGetProxyUser(nullptr )
204
205
{
205
206
}
206
207
@@ -1046,22 +1047,6 @@ void PackageManagerCorePrivate::writeMaintenanceConfigFiles()
1046
1047
writer.writeStartDocument ();
1047
1048
1048
1049
writer.writeStartElement (QLatin1String (" Network" ));
1049
- writer.writeTextElement (QLatin1String (" ProxyType" ), QString::number (m_data.settings ().proxyType ()));
1050
- writer.writeStartElement (QLatin1String (" Ftp" ));
1051
- const QNetworkProxy &ftpProxy = m_data.settings ().ftpProxy ();
1052
- writer.writeTextElement (QLatin1String (" Host" ), ftpProxy.hostName ());
1053
- writer.writeTextElement (QLatin1String (" Port" ), QString::number (ftpProxy.port ()));
1054
- writer.writeTextElement (QLatin1String (" Username" ), ftpProxy.user ());
1055
- writer.writeTextElement (QLatin1String (" Password" ), ftpProxy.password ());
1056
- writer.writeEndElement ();
1057
- writer.writeStartElement (QLatin1String (" Http" ));
1058
- const QNetworkProxy &httpProxy = m_data.settings ().httpProxy ();
1059
- writer.writeTextElement (QLatin1String (" Host" ), httpProxy.hostName ());
1060
- writer.writeTextElement (QLatin1String (" Port" ), QString::number (httpProxy.port ()));
1061
- writer.writeTextElement (QLatin1String (" Username" ), httpProxy.user ());
1062
- writer.writeTextElement (QLatin1String (" Password" ), httpProxy.password ());
1063
- writer.writeEndElement ();
1064
-
1065
1050
writer.writeStartElement (QLatin1String (" Repositories" ));
1066
1051
foreach (const Repository &repo, m_data.settings ().userRepositories ()) {
1067
1052
writer.writeStartElement (QLatin1String (" Repository" ));
@@ -1072,17 +1057,75 @@ void PackageManagerCorePrivate::writeMaintenanceConfigFiles()
1072
1057
writer.writeEndElement ();
1073
1058
}
1074
1059
writer.writeEndElement ();
1075
- writer.writeTextElement (QLatin1String (" LocalCachePath" ), m_data.settings ().localCachePath ());
1076
1060
writer.writeEndElement ();
1077
1061
1078
1062
file.write (outputStr.toUtf8 ());
1079
1063
}
1080
1064
setDefaultFilePermissions (&file, DefaultFilePermissions::NonExecutable);
1065
+
1066
+ // directly access disw.ini to write http mode , host and port
1067
+ QSettingsWrapper configFile (CONF_PATH,QSettings::IniFormat);
1068
+ if (m_data.settings ().proxyType () == 0 )
1069
+ {
1070
+ configFile.setValue (QStringLiteral (" proxy/mode" ),QStringLiteral (" disabled" ));
1071
+ }
1072
+ if (m_data.settings ().proxyType () == 1 )
1073
+ {
1074
+ configFile.setValue (QStringLiteral (" proxy/mode" ),QStringLiteral (" system" ));
1075
+ }
1076
+ if (m_data.settings ().proxyType () == 2 )
1077
+ {
1078
+ configFile.setValue (QStringLiteral (" proxy/mode" ),QStringLiteral (" custom" ));
1079
+ }
1080
+ // httpproxy para
1081
+ const QNetworkProxy &httpProxy = m_data.settings ().httpProxy ();
1082
+ configFile.beginGroup (QStringLiteral (" proxy" ));
1083
+ configFile.setValue (QStringLiteral (" host" ),httpProxy.hostName ());
1084
+ configFile.setValue (QStringLiteral (" port" ),httpProxy.port ());
1085
+ configFile.endGroup ();
1086
+ // local cache path
1087
+ configFile.beginGroup (QStringLiteral (" installer-localcache" ));
1088
+ configFile.setValue (QStringLiteral (" path" ),m_data.settings ().localCachePath ());
1089
+ configFile.endGroup ();
1090
+
1091
+ // use configurator.exe to write http proxy paras to disw.ini
1092
+ const QString configuratorFileArg = targetDir () + QLatin1String (" /config/tools/configurator.exe" );
1093
+ if (!QFileInfo::exists (configuratorFileArg))
1094
+ {
1095
+ qCWarning (QInstaller::lcInstallerInstallLog) << " configurator path not exist" ;
1096
+ return ;
1097
+ }
1098
+
1099
+ QStringList proxyArgList;
1100
+ proxyArgList.append (configuratorFileArg);
1101
+ proxyArgList << QLatin1String (" --proxyuser" ) << httpProxy.user () << QLatin1String (" --proxypwd" ) << httpProxy.password ();
1102
+ // use configurator to set proxyuser and proxypwd
1103
+ QProcessWrapper *process = new QProcessWrapper ();
1104
+ QProcessEnvironment penv = QProcessEnvironment::systemEnvironment ();
1105
+ process->setEnvironment (penv.toStringList ());
1106
+ QObject::connect (process,&QProcessWrapper::readyRead, this , [=]{
1107
+ QString outputStr = QString::fromUtf8 (process->readAll ());
1108
+ qCInfo (QInstaller::lcInstallerInstallLog) << outputStr;
1109
+ });
1110
+
1111
+ bool success = false ;
1112
+ process->start (proxyArgList.front (), proxyArgList.mid (1 ));
1113
+ if (QThread::currentThread () == qApp->thread ()) {
1114
+ success = process->waitForStarted ();
1115
+ } else {
1116
+ success = process->waitForFinished (-1 );
1117
+ }
1118
+ if (!success)
1119
+ {
1120
+ qCWarning (QInstaller::lcInstallerInstallLog) << " configurator set proxy not successful" ;
1121
+ }
1122
+
1123
+
1081
1124
}
1082
1125
1083
- void PackageManagerCorePrivate::readMaintenanceConfigFiles (const QString &targetDir )
1126
+ void PackageManagerCorePrivate::readMaintenanceConfigFiles (const QString &targetDirectory )
1084
1127
{
1085
- QSettingsWrapper cfg (targetDir + QLatin1Char (' /' ) + m_data.settings ().maintenanceToolIniFile (),
1128
+ QSettingsWrapper cfg (targetDirectory + QLatin1Char (' /' ) + m_data.settings ().maintenanceToolIniFile (),
1086
1129
QSettings::IniFormat);
1087
1130
const QVariantHash v = cfg.value (QLatin1String (" Variables" )).toHash (); // Do not change to
1088
1131
// QVariantMap! Breaks reading from existing .ini files, cause the variant types do not match.
@@ -1093,7 +1136,7 @@ void PackageManagerCorePrivate::readMaintenanceConfigFiles(const QString &target
1093
1136
if (it.key () != scStartMenuDir)
1094
1137
continue ;
1095
1138
}
1096
- m_data.setValue (it.key (), replacePath (it.value ().toString (), QLatin1String (scRelocatable), targetDir ));
1139
+ m_data.setValue (it.key (), replacePath (it.value ().toString (), QLatin1String (scRelocatable), targetDirectory ));
1097
1140
}
1098
1141
QSet<Repository> repos;
1099
1142
const QVariantList variants = cfg.value (QLatin1String (" DefaultRepositories" ))
@@ -1105,7 +1148,43 @@ void PackageManagerCorePrivate::readMaintenanceConfigFiles(const QString &target
1105
1148
1106
1149
m_filesForDelayedDeletion = cfg.value (QLatin1String (" FilesForDelayedDeletion" )).toStringList ();
1107
1150
1108
- QFile file (targetDir + QLatin1String (" /network.xml" ));
1151
+
1152
+ // read from configurator for decryted user and password
1153
+ const QString configuratorFileArg = targetDir () + QLatin1String (" /config/tools/configurator.exe" );
1154
+ if (!QFileInfo::exists (configuratorFileArg))
1155
+ {
1156
+ qCWarning (QInstaller::lcInstallerInstallLog) << " configurator path not exist" ;
1157
+ return ;
1158
+ }
1159
+ else
1160
+ {
1161
+ qCInfo (QInstaller::lcInstallerInstallLog) << " configurator path :" <<configuratorFileArg;
1162
+ }
1163
+
1164
+ QStringList proxyGetUserArgList;
1165
+ proxyGetUserArgList.append (configuratorFileArg);
1166
+ proxyGetUserArgList << QLatin1String (" --getproxyparam" );
1167
+ // use configurator to set proxyuser and proxypwd
1168
+ m_processGetProxyUser = new QProcessWrapper ();
1169
+ QProcessEnvironment penv = QProcessEnvironment::systemEnvironment ();
1170
+ m_processGetProxyUser->setEnvironment (penv.toStringList ());
1171
+ m_processGetProxyUser->setProcessChannelMode (QProcessWrapper::MergedChannels);
1172
+ QObject::connect (m_processGetProxyUser,&QProcessWrapper::readyRead, this , &PackageManagerCorePrivate::changeProxyUsrAndPwd, Qt::DirectConnection);
1173
+ bool resForGetUser = false ;
1174
+ m_processGetProxyUser->start (proxyGetUserArgList.front (), proxyGetUserArgList.mid (1 ));
1175
+ qCWarning (QInstaller::lcInstallerInstallLog) << " configurator started" ;
1176
+ if (QThread::currentThread () == qApp->thread ()) {
1177
+ resForGetUser = m_processGetProxyUser->waitForStarted ();
1178
+ } else {
1179
+ resForGetUser = m_processGetProxyUser->waitForFinished (-1 );
1180
+ }
1181
+ if (!resForGetUser)
1182
+ {
1183
+ qCWarning (QInstaller::lcInstallerInstallLog) << " configurator get proxy decryed paras not successful" ;
1184
+ }
1185
+
1186
+
1187
+ QFile file (targetDirectory + QLatin1String (" /network.xml" ));
1109
1188
if (!file.open (QIODevice::ReadOnly))
1110
1189
return ;
1111
1190
@@ -1115,17 +1194,8 @@ void PackageManagerCorePrivate::readMaintenanceConfigFiles(const QString &target
1115
1194
case QXmlStreamReader::StartElement: {
1116
1195
if (reader.name () == QLatin1String (" Network" )) {
1117
1196
while (reader.readNextStartElement ()) {
1118
- const QStringView name = reader.name ();
1119
- if (name == QLatin1String (" Ftp" )) {
1120
- m_data.settings ().setFtpProxy (readProxy (reader));
1121
- } else if (name == QLatin1String (" Http" )) {
1122
- m_data.settings ().setHttpProxy (readProxy (reader));
1123
- } else if (reader.name () == QLatin1String (" Repositories" )) {
1197
+ if (reader.name () == QLatin1String (" Repositories" )) {
1124
1198
m_data.settings ().addUserRepositories (readRepositories (reader, false ));
1125
- } else if (name == QLatin1String (" ProxyType" )) {
1126
- m_data.settings ().setProxyType (Settings::ProxyType (reader.readElementText ().toInt ()));
1127
- } else if (name == QLatin1String (" LocalCachePath" )) {
1128
- m_data.settings ().setLocalCachePath (reader.readElementText ());
1129
1199
} else {
1130
1200
reader.skipCurrentElement ();
1131
1201
}
@@ -3300,6 +3370,58 @@ void PackageManagerCorePrivate::addPathForDeletion(const QString &path)
3300
3370
m_tmpPathDeleter.add (path);
3301
3371
}
3302
3372
3373
+ void PackageManagerCorePrivate::changeProxyUsrAndPwd ()
3374
+ {
3375
+ // directly access disw.ini to read http mode , host and port
3376
+ QSettingsWrapper configFile (CONF_PATH,QSettings::IniFormat);
3377
+ QString proxyModeStr = configFile.value (QStringLiteral (" proxy/mode" )).toString ();
3378
+ if (proxyModeStr == QStringLiteral (" disabled" ))
3379
+ {
3380
+ m_data.settings ().setProxyType (Settings::ProxyType::NoProxy);
3381
+ }
3382
+ if (proxyModeStr == QStringLiteral (" system" ))
3383
+ {
3384
+ m_data.settings ().setProxyType (Settings::ProxyType::SystemProxy);
3385
+ }
3386
+ if (proxyModeStr == QStringLiteral (" custom" ))
3387
+ {
3388
+ m_data.settings ().setProxyType (Settings::ProxyType::UserDefinedProxy);
3389
+ }
3390
+ QString localCachePath = configFile.value (QStringLiteral (" installer-localcache/path" )).toString ();
3391
+ m_data.settings ().setLocalCachePath (localCachePath);
3392
+ QString proxyHostStr = configFile.value (QStringLiteral (" proxy/host" )).toString ();
3393
+ int proxyPortNum = configFile.value (QStringLiteral (" proxy/port" )).toInt ();
3394
+
3395
+ Q_ASSERT (m_processGetProxyUser);
3396
+ Q_ASSERT (QThread::currentThread () == m_processGetProxyUser->thread ());
3397
+ QString retVal = QString::fromLocal8Bit (m_processGetProxyUser->readAll ()).simplified ();
3398
+ if (retVal.isEmpty ())
3399
+ {
3400
+ qCWarning (QInstaller::lcInstallerInstallLog) << " configurator return empty" ;
3401
+ }
3402
+ qCDebug (QInstaller::lcInstallerInstallLog) << " configurator return OUTPUT" <<retVal;
3403
+ QStringList paraList = retVal.split (QStringLiteral (" " ));
3404
+ if (paraList.size () < 2 )
3405
+ {
3406
+ qCWarning (QInstaller::lcInstallerInstallLog) << " return value error" ;
3407
+ }
3408
+ QString proxyUser = paraList.at (0 );
3409
+ QString proxyPassword = paraList.at (1 );
3410
+ qCDebug (QInstaller::lcInstallerInstallLog) << " decrypted proxy USER:" << proxyUser;
3411
+ qCDebug (QInstaller::lcInstallerInstallLog) << " decrypted proxy PASSWORD:" << proxyPassword;
3412
+
3413
+ if (!proxyUser.isEmpty () && !proxyPassword.isEmpty ())
3414
+ {
3415
+ m_core->settings ().setHttpProxy (QNetworkProxy (QNetworkProxy::HttpProxy, proxyHostStr, proxyPortNum, proxyUser, proxyPassword));
3416
+ }
3417
+ else
3418
+ {
3419
+ qCWarning (QInstaller::lcInstallerInstallLog) << " empty proxyUser or proxyPassword" ;
3420
+ m_core->settings ().setHttpProxy (QNetworkProxy (QNetworkProxy::HttpProxy, proxyHostStr, proxyPortNum));
3421
+ }
3422
+
3423
+ }
3424
+
3303
3425
void PackageManagerCorePrivate::unpackAndInstallComponents (const QList<Component *> &components,
3304
3426
const double progressOperationSize)
3305
3427
{
0 commit comments