ShellExtension: Use MUtilities library for the registry operations.
This commit is contained in:
parent
04328154fa
commit
027f4d519d
@ -35,7 +35,7 @@
|
|||||||
#define VER_LAMEXP_MINOR_LO 2
|
#define VER_LAMEXP_MINOR_LO 2
|
||||||
#define VER_LAMEXP_TYPE Alpha
|
#define VER_LAMEXP_TYPE Alpha
|
||||||
#define VER_LAMEXP_PATCH 1
|
#define VER_LAMEXP_PATCH 1
|
||||||
#define VER_LAMEXP_BUILD 1715
|
#define VER_LAMEXP_BUILD 1716
|
||||||
#define VER_LAMEXP_CONFG 1700
|
#define VER_LAMEXP_CONFG 1700
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -29,6 +29,8 @@
|
|||||||
//MUtils
|
//MUtils
|
||||||
#include <MUtils/Global.h>
|
#include <MUtils/Global.h>
|
||||||
#include <MUtils/Exception.h>
|
#include <MUtils/Exception.h>
|
||||||
|
#include <MUtils/OSSupport.h>
|
||||||
|
#include <MUtils/Registry.h>
|
||||||
|
|
||||||
//Qt
|
//Qt
|
||||||
#include <QString>
|
#include <QString>
|
||||||
@ -40,13 +42,9 @@
|
|||||||
#include <QMutexLocker>
|
#include <QMutexLocker>
|
||||||
#include <QtConcurrentRun>
|
#include <QtConcurrentRun>
|
||||||
|
|
||||||
//Win32 API
|
|
||||||
#include <Shlobj.h>
|
|
||||||
#include <Shlwapi.h>
|
|
||||||
|
|
||||||
//Const
|
//Const
|
||||||
static const char *g_lamexpShellAction = "ConvertWithLameXP";
|
static const char *g_lamexpShellAction = "ConvertWithLameXP";
|
||||||
static const char *g_lamexpFileType = "LameXP.SupportedAudioFile";
|
static const char *g_lamexpFileType = "LameXP.SupportedAudioFile";
|
||||||
|
|
||||||
//Mutex
|
//Mutex
|
||||||
QMutex ShellIntegration::m_mutex;
|
QMutex ShellIntegration::m_mutex;
|
||||||
@ -78,9 +76,6 @@ void ShellIntegration::install(bool async)
|
|||||||
|
|
||||||
//Serialize
|
//Serialize
|
||||||
QMutexLocker lock(&m_mutex);
|
QMutexLocker lock(&m_mutex);
|
||||||
|
|
||||||
//Registry key
|
|
||||||
HKEY key = NULL;
|
|
||||||
|
|
||||||
//Init some consts
|
//Init some consts
|
||||||
const QString lamexpFileType(g_lamexpFileType);
|
const QString lamexpFileType(g_lamexpFileType);
|
||||||
@ -90,53 +85,25 @@ void ShellIntegration::install(bool async)
|
|||||||
const QString lamexpShellAction(g_lamexpShellAction);
|
const QString lamexpShellAction(g_lamexpShellAction);
|
||||||
|
|
||||||
//Register the LameXP file type
|
//Register the LameXP file type
|
||||||
if(RegCreateKeyEx(HKEY_CURRENT_USER, MUTILS_WCHR(QString("Software\\Classes\\%1").arg(lamexpFileType)), NULL, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &key, NULL) == ERROR_SUCCESS)
|
MUtils::Registry::reg_value_write(MUtils::Registry::root_user, QString("Software\\Classes\\%1") .arg(lamexpFileType), QString(), lamexpFileInfo);
|
||||||
{
|
MUtils::Registry::reg_value_write(MUtils::Registry::root_user, QString("Software\\Classes\\%1\\shell") .arg(lamexpFileType), QString(), lamexpShellAction);
|
||||||
REG_WRITE_STRING(key, lamexpFileInfo);
|
MUtils::Registry::reg_value_write(MUtils::Registry::root_user, QString("Software\\Classes\\%1\\shell\\%2") .arg(lamexpFileType, lamexpShellAction), QString(), lamexpShellText);
|
||||||
RegCloseKey(key);
|
MUtils::Registry::reg_value_write(MUtils::Registry::root_user, QString("Software\\Classes\\%1\\shell\\%2\\command").arg(lamexpFileType, lamexpShellAction), QString(), lamexpShellCommand);
|
||||||
}
|
|
||||||
if(RegCreateKeyEx(HKEY_CURRENT_USER, MUTILS_WCHR(QString("Software\\Classes\\%1\\shell").arg(lamexpFileType)), NULL, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &key, NULL) == ERROR_SUCCESS)
|
|
||||||
{
|
|
||||||
REG_WRITE_STRING(key, lamexpShellAction);
|
|
||||||
RegCloseKey(key);
|
|
||||||
}
|
|
||||||
if(RegCreateKeyEx(HKEY_CURRENT_USER, MUTILS_WCHR(QString("Software\\Classes\\%1\\shell\\%2").arg(lamexpFileType, lamexpShellAction)), NULL, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &key, NULL) == ERROR_SUCCESS)
|
|
||||||
{
|
|
||||||
REG_WRITE_STRING(key, lamexpShellText);
|
|
||||||
RegCloseKey(key);
|
|
||||||
}
|
|
||||||
if(RegCreateKeyEx(HKEY_CURRENT_USER, MUTILS_WCHR(QString("Software\\Classes\\%1\\shell\\%2\\command").arg(lamexpFileType, lamexpShellAction)), NULL, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &key, NULL) == ERROR_SUCCESS)
|
|
||||||
{
|
|
||||||
REG_WRITE_STRING(key, lamexpShellCommand);
|
|
||||||
RegCloseKey(key);
|
|
||||||
}
|
|
||||||
|
|
||||||
//Detect supported file types
|
//Detect supported file types
|
||||||
QStringList *types = detectTypes(lamexpFileType, lamexpShellAction);
|
QStringList types;
|
||||||
|
detectTypes(lamexpFileType, lamexpShellAction, types);
|
||||||
|
|
||||||
//Add LameXP shell action to all supported file types
|
//Add LameXP shell action to all supported file types
|
||||||
while(types && (!types->isEmpty()))
|
while(!types.isEmpty())
|
||||||
{
|
{
|
||||||
QString currentType = types->takeFirst();
|
QString currentType = types.takeFirst();
|
||||||
|
MUtils::Registry::reg_value_write(MUtils::Registry::root_user, QString("Software\\Classes\\%1\\shell\\%2") .arg(currentType, lamexpShellAction), QString(), lamexpShellText);
|
||||||
if(RegCreateKeyEx(HKEY_CURRENT_USER, MUTILS_WCHR(QString("Software\\Classes\\%1\\shell\\%2").arg(currentType, lamexpShellAction)), NULL, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &key, NULL) == ERROR_SUCCESS)
|
MUtils::Registry::reg_value_write(MUtils::Registry::root_user, QString("Software\\Classes\\%1\\shell\\%2\\command").arg(currentType, lamexpShellAction), QString(), lamexpShellCommand);
|
||||||
{
|
|
||||||
REG_WRITE_STRING(key, lamexpShellText);
|
|
||||||
RegCloseKey(key);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(RegCreateKeyEx(HKEY_CURRENT_USER, MUTILS_WCHR(QString("Software\\Classes\\%1\\shell\\%2\\command").arg(currentType, lamexpShellAction)), NULL, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &key, NULL) == ERROR_SUCCESS)
|
|
||||||
{
|
|
||||||
REG_WRITE_STRING(key, lamexpShellCommand);
|
|
||||||
RegCloseKey(key);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//Shell notification
|
//Shell notification
|
||||||
SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, NULL, NULL);
|
MUtils::OS::shell_change_notification();
|
||||||
|
|
||||||
//Free
|
|
||||||
delete types;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShellIntegration::remove(bool async)
|
void ShellIntegration::remove(bool async)
|
||||||
@ -156,48 +123,35 @@ void ShellIntegration::remove(bool async)
|
|||||||
const QString lamexpShellAction(g_lamexpShellAction);
|
const QString lamexpShellAction(g_lamexpShellAction);
|
||||||
|
|
||||||
//Initialization
|
//Initialization
|
||||||
HKEY key = NULL;
|
|
||||||
QStringList fileTypes;
|
QStringList fileTypes;
|
||||||
|
|
||||||
//Find all registered file types
|
//Find all registered file types
|
||||||
if(RegOpenKeyEx(HKEY_CURRENT_USER, L"Software\\Classes", NULL, KEY_ENUMERATE_SUB_KEYS ,&key) == ERROR_SUCCESS)
|
if(!MUtils::Registry::reg_enum_subkeys(MUtils::Registry::root_user, "Software\\Classes", fileTypes))
|
||||||
{
|
{
|
||||||
wchar_t name[256];
|
qWarning("Failed to enumerate file types!");
|
||||||
|
return;
|
||||||
for(DWORD i = 0; true; i++)
|
|
||||||
{
|
|
||||||
DWORD size = 256;
|
|
||||||
if(RegEnumKeyEx(key, i, name, &size, NULL, NULL, NULL, NULL) == ERROR_SUCCESS)
|
|
||||||
{
|
|
||||||
fileTypes << QString::fromUtf16(reinterpret_cast<const unsigned short*>(name));
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//Remove shell action from all file types
|
//Remove shell action from all file types
|
||||||
while(!fileTypes.isEmpty())
|
while(!fileTypes.isEmpty())
|
||||||
{
|
{
|
||||||
SHDeleteKey(HKEY_CURRENT_USER, MUTILS_WCHR(QString("Software\\Classes\\%1\\shell\\%2").arg(fileTypes.takeFirst(), lamexpShellAction)));
|
MUtils::Registry::reg_key_delete(MUtils::Registry::root_user, QString("Software\\Classes\\%1\\shell\\%2").arg(fileTypes.takeFirst(), lamexpShellAction));
|
||||||
}
|
}
|
||||||
|
|
||||||
//Unregister LameXP file type
|
//Unregister LameXP file type
|
||||||
SHDeleteKey(HKEY_CURRENT_USER, MUTILS_WCHR(QString("Software\\Classes\\%1").arg(lamexpFileType)));
|
MUtils::Registry::reg_key_delete(MUtils::Registry::root_user, QString("Software\\Classes\\%1").arg(lamexpFileType));
|
||||||
|
|
||||||
//Shell notification
|
//Shell notification
|
||||||
SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, NULL, NULL);
|
MUtils::OS::shell_change_notification();
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
// Private Functions
|
// Private Functions
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
QStringList *ShellIntegration::detectTypes(const QString &lamexpFileType, const QString &lamexpShellAction)
|
void ShellIntegration::detectTypes(const QString &lamexpFileType, const QString &lamexpShellAction, QStringList &nativeTypes)
|
||||||
{
|
{
|
||||||
HKEY key = NULL;
|
nativeTypes.clear();
|
||||||
|
|
||||||
QStringList *nativeTypes = new QStringList();
|
|
||||||
QStringList supportedTypes = DecoderRegistry::getSupportedTypes();
|
QStringList supportedTypes = DecoderRegistry::getSupportedTypes();
|
||||||
QStringList extensions;
|
QStringList extensions;
|
||||||
|
|
||||||
@ -220,76 +174,35 @@ QStringList *ShellIntegration::detectTypes(const QString &lamexpFileType, const
|
|||||||
//Map supported extensions to native types
|
//Map supported extensions to native types
|
||||||
while(!extensions.isEmpty())
|
while(!extensions.isEmpty())
|
||||||
{
|
{
|
||||||
QString currentExt = extensions.takeFirst();
|
const QString currentExt = extensions.takeFirst();
|
||||||
|
|
||||||
if(RegOpenKeyEx(HKEY_CLASSES_ROOT, MUTILS_WCHR(currentExt), NULL, KEY_QUERY_VALUE, &key) == ERROR_SUCCESS)
|
QString currentType;
|
||||||
|
if(MUtils::Registry::reg_value_read(MUtils::Registry::root_classes, currentExt, QString(), currentType))
|
||||||
{
|
{
|
||||||
wchar_t data[256];
|
if((currentType.compare(lamexpFileType, Qt::CaseInsensitive) != 0) && (!nativeTypes.contains(currentType, Qt::CaseInsensitive)))
|
||||||
DWORD dataLen = 256 * sizeof(wchar_t);
|
|
||||||
DWORD type = NULL;
|
|
||||||
|
|
||||||
if(RegQueryValueEx(key, NULL, NULL, &type, reinterpret_cast<BYTE*>(data), &dataLen) == ERROR_SUCCESS)
|
|
||||||
{
|
{
|
||||||
if((type == REG_SZ) || (type == REG_EXPAND_SZ))
|
nativeTypes.append(currentType);
|
||||||
{
|
|
||||||
QString currentType = QString::fromUtf16(reinterpret_cast<unsigned short*>(data));
|
|
||||||
if((currentType.compare(lamexpFileType, Qt::CaseInsensitive) != 0) && !nativeTypes->contains(currentType, Qt::CaseInsensitive))
|
|
||||||
{
|
|
||||||
nativeTypes->append(currentType);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
RegCloseKey(key);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if(RegCreateKeyEx(HKEY_CURRENT_USER, MUTILS_WCHR(QString("Software\\Classes\\%1").arg(currentExt)), NULL, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &key, NULL) == ERROR_SUCCESS)
|
MUtils::Registry::reg_value_write(MUtils::Registry::root_user, currentExt, QString(), lamexpFileType);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(MUtils::Registry::reg_value_read(MUtils::Registry::root_user, QString("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\FileExts\\%1\\UserChoice").arg(currentExt), QString(), currentType))
|
||||||
|
{
|
||||||
|
if((currentType.compare(lamexpFileType, Qt::CaseInsensitive) != 0) && (!nativeTypes.contains(currentType, Qt::CaseInsensitive)))
|
||||||
{
|
{
|
||||||
REG_WRITE_STRING(key, lamexpFileType);
|
nativeTypes.append(currentType);
|
||||||
RegCloseKey(key);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(RegOpenKeyEx(HKEY_CURRENT_USER, MUTILS_WCHR(QString("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\FileExts\\%1\\UserChoice").arg(currentExt)), NULL, KEY_QUERY_VALUE, &key) == ERROR_SUCCESS)
|
if(MUtils::Registry::reg_value_read(MUtils::Registry::root_user, QString("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\FileExts\\%1\\OpenWithProgids").arg(currentExt), QString(), currentType))
|
||||||
{
|
{
|
||||||
wchar_t data[256];
|
if((currentType.compare(lamexpFileType, Qt::CaseInsensitive) != 0) && (!nativeTypes.contains(currentType, Qt::CaseInsensitive)))
|
||||||
DWORD dataLen = 256 * sizeof(wchar_t);
|
|
||||||
DWORD type = NULL;
|
|
||||||
|
|
||||||
if(RegQueryValueEx(key, L"Progid", NULL, &type, reinterpret_cast<BYTE*>(data), &dataLen) == ERROR_SUCCESS)
|
|
||||||
{
|
{
|
||||||
if((type == REG_SZ) || (type == REG_EXPAND_SZ))
|
nativeTypes.append(currentType);
|
||||||
{
|
|
||||||
QString currentType = QString::fromUtf16(reinterpret_cast<unsigned short*>(data));
|
|
||||||
if((currentType.compare(lamexpFileType, Qt::CaseInsensitive) != 0) && !nativeTypes->contains(currentType, Qt::CaseInsensitive))
|
|
||||||
{
|
|
||||||
nativeTypes->append(currentType);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
RegCloseKey(key);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(RegOpenKeyEx(HKEY_CURRENT_USER, MUTILS_WCHR(QString("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\FileExts\\%1\\OpenWithProgids").arg(currentExt)), NULL, KEY_QUERY_VALUE, &key) == ERROR_SUCCESS)
|
|
||||||
{
|
|
||||||
wchar_t name[256];
|
|
||||||
for(DWORD i = 0; true; i++)
|
|
||||||
{
|
|
||||||
DWORD size = 256;
|
|
||||||
if(RegEnumValue(key, i, name, &size, NULL, NULL, NULL, NULL) == ERROR_SUCCESS)
|
|
||||||
{
|
|
||||||
QString currentType = QString::fromUtf16(reinterpret_cast<unsigned short*>(name));
|
|
||||||
if((currentType.compare(lamexpFileType, Qt::CaseInsensitive) != 0) && !nativeTypes->contains(currentType, Qt::CaseInsensitive))
|
|
||||||
{
|
|
||||||
nativeTypes->append(currentType);
|
|
||||||
}
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
RegCloseKey(key);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nativeTypes;
|
|
||||||
}
|
}
|
||||||
|
@ -39,6 +39,6 @@ public:
|
|||||||
private:
|
private:
|
||||||
ShellIntegration(void);
|
ShellIntegration(void);
|
||||||
|
|
||||||
static QStringList *detectTypes(const QString &lamexpFileType, const QString &lamexpShellAction);
|
static void detectTypes(const QString &lamexpFileType, const QString &lamexpShellAction, QStringList &nativeTypes);
|
||||||
static QMutex m_mutex;
|
static QMutex m_mutex;
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user