summaryrefslogtreecommitdiffstats
path: root/src/libs/installer/registerfiletypeoperation.cpp
diff options
context:
space:
mode:
authorKatja Marttila <katja.marttila@theqtcompany.com>2016-02-01 15:23:23 +0200
committerKatja Marttila <katja.marttila@theqtcompany.com>2016-02-29 12:17:57 +0000
commit1d781f73424095d816e7c360abf6ab2c127cb8b3 (patch)
tree3cee57bcea3458a3ce3f5b6e0a549bce63010383 /src/libs/installer/registerfiletypeoperation.cpp
parent7b6c2da46f9fab73d75aaf42ed7fbb063f4369f3 (diff)
Fix arguments in RegisterFileType
When using RegisterFileType, argumens include progId. Removed it from arguments and saved as member variable. This way progId won't interfere argument check count and it can be used also in undo operation. Change-Id: Ic80a54a28b5e171a5d4e3023b58eb1636a16fa49 Reviewed-by: Karsten Heimrich <karsten.heimrich@theqtcompany.com>
Diffstat (limited to 'src/libs/installer/registerfiletypeoperation.cpp')
-rw-r--r--src/libs/installer/registerfiletypeoperation.cpp55
1 files changed, 33 insertions, 22 deletions
diff --git a/src/libs/installer/registerfiletypeoperation.cpp b/src/libs/installer/registerfiletypeoperation.cpp
index 89d1934c3..bce1db239 100644
--- a/src/libs/installer/registerfiletypeoperation.cpp
+++ b/src/libs/installer/registerfiletypeoperation.cpp
@@ -81,6 +81,7 @@ static QVariantHash readHive(QSettingsWrapper *const settings, const QString &hi
RegisterFileTypeOperation::RegisterFileTypeOperation(PackageManagerCore *core)
: UpdateOperation(core)
+ , m_optionalArgumentsRead(false)
{
setName(QLatin1String("RegisterFileType"));
}
@@ -92,11 +93,10 @@ void RegisterFileTypeOperation::backup()
bool RegisterFileTypeOperation::performOperation()
{
#ifdef Q_OS_WIN
- QStringList args = arguments();
- QString progId = takeProgIdArgument(args);
-
+ ensureOptionalArgumentsRead();
if (!checkArgumentCount(2, 5, tr("<extension> <command> [description [contentType [icon]]]")))
return false;
+ QStringList args = arguments();
bool allUsers = false;
PackageManagerCore *const core = packageManager();
@@ -106,19 +106,16 @@ bool RegisterFileTypeOperation::performOperation()
QSettingsWrapper settings(QLatin1String(allUsers ? "HKEY_LOCAL_MACHINE" : "HKEY_CURRENT_USER")
, QSettingsWrapper::NativeFormat);
- const QString extension = args.at(0);
- if (progId.isEmpty())
- progId = QString::fromLatin1("%1_auto_file").arg(extension);
- const QString classesProgId = QString::fromLatin1("Software/Classes/") + progId;
- const QString classesFileType = QString::fromLatin1("Software/Classes/.%2").arg(extension);
- const QString classesApplications = QString::fromLatin1("Software/Classes/Applications/") + progId;
+ const QString classesProgId = QString::fromLatin1("Software/Classes/") + m_progId;
+ const QString classesFileType = QString::fromLatin1("Software/Classes/.%2").arg(args.at(0));
+ const QString classesApplications = QString::fromLatin1("Software/Classes/Applications/") + m_progId;
// backup old value
setValue(QLatin1String("oldType"), readHive(&settings, classesFileType));
// register new values
- settings.setValue(QString::fromLatin1("%1/Default").arg(classesFileType), progId);
- settings.setValue(QString::fromLatin1("%1/OpenWithProgIds/%2").arg(classesFileType, progId), QString());
+ settings.setValue(QString::fromLatin1("%1/Default").arg(classesFileType), m_progId);
+ settings.setValue(QString::fromLatin1("%1/OpenWithProgIds/%2").arg(classesFileType, m_progId), QString());
settings.setValue(QString::fromLatin1("%1/shell/Open/Command/Default").arg(classesProgId), args.at(1));
settings.setValue(QString::fromLatin1("%1/shell/Open/Command/Default").arg(classesApplications), args.at(1));
@@ -154,13 +151,11 @@ bool RegisterFileTypeOperation::performOperation()
bool RegisterFileTypeOperation::undoOperation()
{
#ifdef Q_OS_WIN
+ ensureOptionalArgumentsRead();
QStringList args = arguments();
- QString progId = takeProgIdArgument(args);
- if (args.count() < 2 || args.count() > 5) {
- setErrorString(tr("Register File Type: Invalid arguments"));
+ if (!checkArgumentCount(2, 5, tr("Register File Type: Invalid arguments")))
return false;
- }
bool allUsers = false;
PackageManagerCore *const core = packageManager();
@@ -170,12 +165,9 @@ bool RegisterFileTypeOperation::undoOperation()
QSettingsWrapper settings(QLatin1String(allUsers ? "HKEY_LOCAL_MACHINE" : "HKEY_CURRENT_USER")
, QSettingsWrapper::NativeFormat);
- const QString extension = args.at(0);
- if (progId.isEmpty())
- progId = QString::fromLatin1("%1_auto_file").arg(extension);
- const QString classesProgId = QString::fromLatin1("Software/Classes/") + progId;
- const QString classesFileType = QString::fromLatin1("Software/Classes/.%2").arg(extension);
- const QString classesApplications = QString::fromLatin1("Software/Classes/Applications/") + progId;
+ const QString classesProgId = QString::fromLatin1("Software/Classes/") + m_progId;
+ const QString classesFileType = QString::fromLatin1("Software/Classes/.%2").arg(args.at(0));
+ const QString classesApplications = QString::fromLatin1("Software/Classes/Applications/") + m_progId;
// Quoting MSDN here: When uninstalling an application, the ProgIDs and most other registry information
// associated with that application should be deleted as part of the uninstallation.However, applications
@@ -197,7 +189,7 @@ bool RegisterFileTypeOperation::undoOperation()
settings.endGroup();
} else {
// some changes happened, remove the only save value we know about
- settings.remove(QString::fromLatin1("%1/OpenWithProgIds/%2").arg(classesFileType, progId));
+ settings.remove(QString::fromLatin1("%1/OpenWithProgIds/%2").arg(classesFileType, m_progId));
}
// remove ProgId and Applications entry
@@ -218,3 +210,22 @@ bool RegisterFileTypeOperation::testOperation()
{
return true;
}
+
+void RegisterFileTypeOperation::ensureOptionalArgumentsRead()
+{
+#ifdef Q_OS_WIN
+ if (m_optionalArgumentsRead)
+ return;
+
+ m_optionalArgumentsRead = true;
+
+ QStringList args = arguments();
+
+ m_progId = takeProgIdArgument(args);
+
+ if (m_progId.isEmpty() && args.count() > 0)
+ m_progId = QString::fromLatin1("%1_auto_file").arg(args.at(0));
+
+ setArguments(args);
+#endif
+}